Example #1
0
    def delete(self, **kwargs):
        vm_id = ctx.instance.runtime_properties.get(EXTERNAL_ID)
        if not vm_id:
            ctx.logger.warn('Id of vm not found, skip stopping.')
            return

        ctx.logger.info('Deleting SmartX VM {}.'.format(vm_id))
        with ComputeHelper(Client()) as helper:
            if not self.get_vm(helper, vm_id):
                ctx.logger.info(
                    'SmartX VM:{} is not exist, no need to delete'.format(
                        vm_id))
                return
            data = {'include_volumes': True}
            job_info = helper.delete_vm(vm_id, json.dumps(data))
            self.wait_job(helper, job_info['job_id'])
        clear_runtime_properties()
        ctx.logger.info('SmartX VM {} deleted.'.format(vm_id))
Example #2
0
    def delete(self):
        instance_id = ctx.instance.runtime_properties.get(
            common_constants.EXTERNAL_ID)

        if not instance_id:
            ctx.logger.info(
                'The virtual machine does not exist, skip the delete.')
            return
        if not self.get_vm(instance_id):
            ctx.logger.info(
                'The virtual machine does not exist, skip the delete.')
            return
        try:
            ctx.logger.info(
                'Deleting FusionCompute VM {}.'.format(instance_id))
            self.fc_client.servers.delete(instance_id)
        except Exception as e:
            raise NonRecoverableError(
                "Delete instance {0} failed! The error message is {1}.".format(
                    instance_id, e))
        clear_runtime_properties()
Example #3
0
 def delete(self, **kwargs):
     ctx.logger.info('Start to delete subnet...')
     ret_msg = "Delete subnet successfully..."
     if not self.use_external_resource:
         subnet_id = ctx.instance.runtime_properties['subnet_info'][
             'SubnetId']
         request_body = {'SubnetId': subnet_id}
         ctx.logger.info(
             'Try to delete subnet with parameters:{}'.format(request_body))
         timeout = time.time() + 600  # default timeout:10min
         while time.time() < timeout:
             try:
                 NetworkHelper().delete_subnet(request_body)
             except Exception as e:
                 ret_msg = str(e)
                 if "ResourceInUse" in ret_msg:
                     time.sleep(10)
                     continue
                 else:
                     ret_msg = 'Delete subnet:{} failed,Error Message:{}'.format(
                         subnet_id, e)
             clear_runtime_properties()
             ctx.logger.info(ret_msg)
             break
         else:
             clear_runtime_properties()
             ctx.logger.info(
                 'Delete subnet:{} failed,Error Message:{}'.format(
                     subnet_id, ret_msg))
     else:
         clear_runtime_properties()
         ctx.logger.info(ret_msg)
Example #4
0
    def delete(self):
        volume_id = ctx.instance.runtime_properties['external_id']
        instance_id = ctx.instance.runtime_properties.get('vm_id')
        ctx.logger.info('Detach Volume {} from {}.'.format(
            volume_id, instance_id))
        if instance_id and self.is_mounted(instance_id, volume_id):
            self.detach_volume(instance_id, volume_id)

        volume_info = self.fc_client.volumes.get(volume_id)

        if not volume_info:
            ctx.logger.info('The volume has been deleted.')
        elif volume_info['status'] == fc_constants.FC_VOLUME_STATE_AVAILABLE:
            try:
                self.fc_client.volumes.delete(volume_id)
            except Exception as e:
                raise NonRecoverableError(
                    'Delete volume {0} failed, the error message is {1}'.
                    format(volume_id, e))

        clear_runtime_properties()
        self.remove_vm_info()
Example #5
0
    def delete(self, **kwargs):
        volume_id = ctx.instance.runtime_properties.get(EXTERNAL_ID)
        ctx.logger.info('SmartX volume {} deleted.'.format(volume_id))
        if not volume_id:
            ctx.logger.warn('No SmartX volume id provided.')
            return
        try:
            ctx.logger.info('Deleting SmartX volume {}.'.format(volume_id))
            with VolumeHelper(Client()) as helper:
                volume_info = helper.get_volume(volume_id)
                target_instance = self.get_related_vm()
                vm_info = target_instance.runtime_properties.get(
                    'compute_info')

                self.detach_volume(helper, vm_info, volume_info)

                job_info = helper.delete_volume(volume_id)
                self.wait_job(helper, job_info['job_id'])
            ctx.logger.info('SmartX volume {} deleted.'.format(volume_id))
            clear_runtime_properties()
        except Exception as e:
            raise NonRecoverableError(
                'Delete SmartX volume {} failed: {}'.format(volume_id, e))
Example #6
0
 def delete(self):
     # Delete the network instance
     clear_runtime_properties()
Example #7
0
 def delete(self):
     clear_runtime_properties()