Esempio n. 1
0
 def migrate(self, source_obj, *args, **kwargs):
     int_ip_address = _allocate_ip_address(self.cloud)
     nova_client = clients.compute_client(self.cloud)
     self.created_object = nova_client.servers.create(
         image=kwargs[self.image_var_name],
         flavor=kwargs[self.flavor_var_name].flavor_id,
         name='trans_vol_{}'.format(source_obj.object_id.id),
         config_drive=True,
         nics=[{
             'net-id': kwargs[self.net_var_name].object_id.id
         }],
         meta=dict(cidr=str(int_ip_address),
                   internal_address=str(int_ip_address.ip),
                   access_key=RSA1024_KEY.get_base64()))
     try:
         self.created_object = clients.wait_for(_object_status_is,
                                                nova_client, 'servers',
                                                self.created_object.id,
                                                'active')
     except clients.Timeout:
         self._delete_vm()
         raise base.AbortMigration(
             'Timeout waiting for VM %s to start on %s',
             self.created_object.id, self.location)
     result = self.load_from_cloud(compute.Server, self.cloud,
                                   self.created_object)
     return {self.var_name: result}
Esempio n. 2
0
def _delete_vm(cloud, vm_id):
    nova_client = clients.compute_client(cloud)
    for do_reset in (False, True):
        try:
            if do_reset:
                clients.retry(nova_client.servers.reset_state,
                              vm_id,
                              expected_exceptions=[nova_exceptions.NotFound])
            try:
                clients.retry(nova_client.servers.delete,
                              vm_id,
                              expected_exceptions=[nova_exceptions.NotFound])
            except nova_exceptions.NotFound:
                raise
            except nova_exceptions.ClientException:
                LOG.error('Failed to delete VM %s from cloud %s',
                          vm_id,
                          cloud.name,
                          exc_info=True)
                continue
            if clients.wait_for(_object_is_deleted, nova_client, 'servers',
                                vm_id, nova_exceptions.NotFound):
                return True
        except nova_exceptions.NotFound:
            return True
        except clients.Timeout:
            continue
    LOG.error('Timeout waiting for VM %s from cloud %s to be deleted',
              vm_id,
              cloud.name,
              exc_info=True)
    return False
Esempio n. 3
0
 def _detach_volume(self, cloud, volume, vm_id, abort_migration=False):
     volume_id = volume.object_id.id
     nova_client = clients.compute_client(cloud)
     cinder_client = clients.volume_client(
         cloud, _scope(volume.tenant.object_id.id))
     if _object_is_deleted(cinder_client, 'volumes', volume_id,
                           cinder_exceptions.NotFound):
         return
     if _object_status_is(cinder_client, 'volumes', volume_id, 'in-use'):
         nova_client.volumes.delete_server_volume(vm_id, volume_id)
         try:
             clients.wait_for(_object_status_is, cinder_client, 'volumes',
                              volume_id, 'available')
         except clients.Timeout:
             if abort_migration:
                 raise base.AbortMigration(
                     'Volume %s in cloud %s couldn\'t attach', volume_id,
                     cloud.name)
Esempio n. 4
0
 def _attach_volume(self, cloud, volume, vm_id):
     volume_id = volume.object_id.id
     nova_client = clients.compute_client(cloud)
     cinder_client = clients.volume_client(
         cloud, _scope(volume.tenant.object_id.id))
     if _object_status_is(cinder_client, 'volumes', volume_id, 'available'):
         nova_client.volumes.create_server_volume(vm_id, volume_id,
                                                  '/dev/vdb')
         try:
             clients.wait_for(_object_status_is, cinder_client, 'volumes',
                              volume_id, 'in-use')
         except clients.Timeout:
             raise base.AbortMigration(
                 'Volume %s in cloud %s couldn\'t attach', volume_id,
                 cloud.name)
     else:
         raise base.AbortMigration(
             'Volume %s in cloud %s is not available for attachment',
             volume_id, cloud.name)
Esempio n. 5
0
 def _upload_cirros_image(self, session):
     image_client = clients.image_client(self.cloud)
     with open(_get_image_location(), 'r') as f:
         img = image_client.images.create(data=f,
                                          name=IMAGE_FILENAME,
                                          container_format='bare',
                                          disk_format='qcow2',
                                          is_public=False,
                                          protected=False,
                                          owner=_get_admin_tenant_id(
                                              self.cloud, session))
         return clients.wait_for(_object_status_is, image_client, 'images',
                                 img.id, 'active')
Esempio n. 6
0
 def migrate(self, source_obj, *args, **kwargs):
     dst_tenant_id = _get_object_tenant_id(self.dst_cloud, source_obj)
     volume_client = clients.volume_client(self.dst_cloud,
                                           _scope(dst_tenant_id))
     ovr_source_obj = self.override(source_obj)
     zone = ovr_source_obj.availability_zone
     vol = clients.retry(volume_client.volumes.create,
                         size=ovr_source_obj.size,
                         display_name=ovr_source_obj.name,
                         display_description=ovr_source_obj.description,
                         volume_type=ovr_source_obj.volume_type,
                         availability_zone=zone,
                         metadata=ovr_source_obj.metadata)
     try:
         self.created_object = clients.wait_for(_object_status_is,
                                                volume_client, 'volumes',
                                                vol.id, 'available')
     except clients.Timeout:
         self._delete_volume(vol)
         raise base.AbortMigration('Volume didn\'t become active')
     result = self.load_from_cloud(storage.Volume, self.dst_cloud,
                                   self.created_object)
     return dict(dst_object=result)
Esempio n. 7
0
 def wait_status(status):
     return clients.wait_for(_object_status_is, nova_client, 'servers',
                             instace_id, status)