Esempio n. 1
0
 /**
  * ModifyInstanceAttribute action
  *
  * Modifies the specified attribute of the specified instance.
  * You can specify only one attribute at a time.
  * To modify some attributes, the instance must be stopped.
  *
  * @param   string                $instanceId The ID of the Instance.
  * @param   InstanceAttributeType $attribute  The attribute name.
  * @param   mixed                 $value      The attribute value can be string, boolean,
  *                                            array or object depends on attribute name.
  * @return  bool                  Returns TRUE on success
  * @throws  ClientException
  * @throws  Ec2Exception
  * @throws  \BadFunctionCallException
  */
 public function modifyInstanceAttribute($instanceId, InstanceAttributeType $attribute, $value)
 {
     $result = false;
     $options = array('InstanceId' => (string) $instanceId);
     $attribute = (string) $attribute;
     if (in_array($attribute, array(InstanceAttributeType::TYPE_INSTANCE_TYPE, InstanceAttributeType::TYPE_KERNEL, InstanceAttributeType::TYPE_RAMDISK, InstanceAttributeType::TYPE_USER_DATA, InstanceAttributeType::TYPE_INSTANCE_INITIATED_SHUTDOWN_BEHAVIOR, InstanceAttributeType::TYPE_SRIOV_NET_SUPPORT))) {
         $options[ucfirst($attribute) . '.Value'] = (string) $value;
     } else {
         if (in_array($attribute, array(InstanceAttributeType::TYPE_SOURCE_DEST_CHECK, InstanceAttributeType::TYPE_DISABLE_API_TERMINATION))) {
             $options[ucfirst($attribute) . '.Value'] = is_string($value) && ($value === 'true' || $value === 'false') ? $value : ($value ? 'true' : 'false');
         } else {
             if ($attribute == InstanceAttributeType::TYPE_BLOCK_DEVICE_MAPPING) {
                 if (!$value instanceof InstanceBlockDeviceMappingResponseList) {
                     $value = new InstanceBlockDeviceMappingResponseList($value);
                 }
                 $options = array_merge($options, $value->getQueryArrayBare('BlockDeviceMapping'));
             } else {
                 if ($attribute == InstanceAttributeType::TYPE_GROUP_SET) {
                     if (!$value instanceof ListDataType) {
                         $value = new ListDataType($value);
                     }
                     $options = array_merge($options, $value->getQueryArrayBare('GroupId'));
                 } else {
                     if ($attribute == InstanceAttributeType::TYPE_EBS_OPTIMIZED) {
                         $options['EbsOptimized'] = is_string($value) && ($value === 'true' || $value === 'false') ? $value : ($value ? 'true' : 'false');
                     } else {
                         throw new \BadFunctionCallException(sprintf('Unexpected attribute "%s" in the %s', $attribute, __FUNCTION__));
                     }
                 }
             }
         }
     }
     $action = ucfirst(__FUNCTION__);
     $response = $this->client->call($action, $options);
     if ($response->getError() === false) {
         $sxml = simplexml_load_string($response->getRawContent());
         if ((string) $sxml->return != 'true') {
             throw new Ec2Exception(sprintf('Amazon Ec2 could not %s InstanceId:"%s". It returned "%s"', $action, $options['InstanceId'], $sxml->return));
         }
         $result = true;
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Loads InstanceBlockDeviceMappingResponseList from simple xml object
  *
  * @param   \SimpleXMLElement $sxml
  * @return  InstanceBlockDeviceMappingResponseList Returns InstanceBlockDeviceMappingResponseList
  */
 protected function _loadInstanceBlockDeviceMappingResponseList(\SimpleXMLElement $sxml)
 {
     $list = new InstanceBlockDeviceMappingResponseList();
     $list->setEc2($this->ec2);
     if (!empty($sxml->item)) {
         foreach ($sxml->item as $v) {
             $item = new InstanceBlockDeviceMappingResponseData();
             $item->setEc2($this->ec2);
             $item->deviceName = $this->exist($v->deviceName) ? (string) $v->deviceName : null;
             $item->setEbs($this->_loadEbsInstanceBlockDeviceMappingResponseData($v->ebs));
             $list->append($item);
             unset($item);
         }
     }
     return $list;
 }