示例#1
0
 public function stopitAction($node)
 {
     if ($node != 'pg1' and $node != 'pg2') {
         return new Response("Sorry, this controller cannot take down anything other than pg1 or pg2");
     }
     $Ec2Client = new Ec2Client(['version' => 'latest', 'region' => 'us-east-1']);
     // Find the instance id
     $ec2_desc = $Ec2Client->DescribeInstances(array('Filters' => array(array('Name' => 'tag:Name', 'Values' => array($node)))));
     if (!$ec2_desc) {
         return new Response("Sorry didnt find any instance by Name tag: {$node}");
     }
     $instid = $ec2_desc['Reservations']['0']['Instances']['0']['InstanceId'];
     $inststate = $ec2_desc['Reservations']['0']['Instances']['0']['State']['Name'];
     $stopresponse = $Ec2Client->stopInstances(array('InstanceIds' => array($instid), 'Force' => true));
     return new Response("<b>Sent force shutdown call on {$node}({$instid})</b> <br />" . "The previous state was: {$inststate}<br />" . "Got the following response:" . "<pre>" . print_r($stopresponse['StoppingInstances'], true) . print_r($stopresponse['@metadata'], true) . "</pre>");
 }