public function __construct(StoryTeller $st, $params = array()) { // call our parent parent::__construct($st, $params); // remember the name of this VM $this->amiId = $params[0]; // get the data about the instance from EC2 $this->image = fromEc2()->getImage($this->amiId); }
public function __construct(StoryTeller $st, $params = array()) { // call our parent parent::__construct($st, $params); // get the VM details from the hosts table $this->vmDetails = fromHostsTable()->getDetailsForHost($params[0]); if ($this->vmDetails) { // remember the name of this VM $this->instanceName = $this->vmDetails->ec2Name; // get the data about the instance from EC2 $this->instance = fromEc2()->getInstance($this->instanceName); // add the instance data to the vmDetails too, to keep that // up to date $this->vmDetails->ec2Instance = $this->instance; } }
/** * * @param Ec2VmDetails $vmDetails * @return boolean */ public function isRunning($vmDetails) { // what are we doing? $log = usingLog()->startAction("determine status of EC2 VM '{$vmDetails->hostId}'"); // get the instance data $instance = fromEc2()->getInstance($vmDetails->hostId); if (!$instance) { $log->endAction("no such instance"); return false; } $isRunning = fromEc2InstanceIsRunning($vmDetails->ec2Name)->getInstanceIsRunning(); if (!$isRunning) { $log->endAction("VM is not running"); return false; } // all done $log->endAction("VM is running"); return true; }
public function markAllVolumesAsDeleteOnTermination() { $this->requiresValidHost(__METHOD__); // what are we doing? $log = usingLog()->startAction("mark all volumes on EC2 VM '{$this->instanceName}' to be deleted on termination"); // create a list of all of the volumes we're going to modify $ebsVolumes = array(); foreach ($this->instance['BlockDeviceMappings'] as $origEbsVolume) { $ebsVolume = array('DeviceName' => $origEbsVolume['DeviceName'], 'Ebs' => array('DeleteOnTermination' => true)); $ebsVolumes[] = $ebsVolume; } // get the AWS EC2 client to work with $ec2Client = fromAws()->getEc2Client(); // let's mark all of the volumes as needing to be deleted // on termination $ec2Client->modifyInstanceAttribute(array('InstanceId' => $this->instance['InstanceId'], 'BlockDeviceMappings' => $ebsVolumes)); // now, we need to make sure that actually worked $this->instance = fromEc2()->getInstance($this->instanceName); // var_dump("\n\n\nAFTER MODIFY INSTANCE ATTRIBUTE\n\n"); // var_dump($this->instance); // that should be that $log->endAction(); }