コード例 #1
0
ファイル: test_rpcapi.py プロジェクト: dinghb/manila
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE)
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
         host='fake_host',
     )
     share_server = db_utils.create_share_server()
     share_group = {'id': 'fake_share_group_id', 'host': 'fake_host'}
     share_group_snapshot = {'id': 'fake_share_group_id'}
     host = 'fake_host'
     self.fake_share = jsonutils.to_primitive(share)
     # mock out the getattr on the share db model object since jsonutils
     # doesn't know about those extra attributes to pull in
     self.fake_share['instance'] = jsonutils.to_primitive(share.instance)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_snapshot['share_instance'] = jsonutils.to_primitive(
         snapshot.instance)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_share_group = jsonutils.to_primitive(share_group)
     self.fake_share_group_snapshot = jsonutils.to_primitive(
         share_group_snapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
コード例 #2
0
ファイル: manager.py プロジェクト: openstack/manila
    def manage_share(self,
                     context,
                     share_id,
                     driver_options,
                     request_spec,
                     filter_properties=None):
        """Ensure that the host exists and can accept the share."""
        def _manage_share_set_error(self, context, ex, request_spec):
            # NOTE(haixin) if failed to scheduler backend for manage share,
            # and we do not commit quota usages here, so we should set size 0
            # because we don't know the real size of the size, and we will
            # skip quota cuts when unmanage share with manage_error status.
            self._set_share_state_and_notify('manage_share', {
                'status': constants.STATUS_MANAGE_ERROR,
                'size': 0
            }, context, ex, request_spec)

        share_ref = db.share_get(context, share_id)

        try:
            self.driver.host_passes_filters(context, share_ref['host'],
                                            request_spec, filter_properties)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _manage_share_set_error(self, context, ex, request_spec)
        else:
            share_rpcapi.ShareAPI().manage_share(context, share_ref,
                                                 driver_options)
コード例 #3
0
ファイル: migration.py プロジェクト: saitgulmez/manila
    def revert_access_rules(self, share_instances, share_server,
                            dest_host=None):
        shares_instance_ids = []
        for share_instance in share_instances:
            # Cast all rules to 'queued_to_apply' so that they can be
            # re-applied.
            shares_instance_ids.append(share_instance['id'])
            updates = {'state': constants.ACCESS_STATE_QUEUED_TO_APPLY}
            self.access_helper.get_and_update_share_instance_access_rules(
                self.context, updates=updates,
                share_instance_id=share_instance['id'])

        if dest_host:
            rpcapi = share_rpcapi.ShareAPI()
            rpcapi.update_access_for_instances(self.context, dest_host,
                                               shares_instance_ids,
                                               share_server)
        else:
            for share_instance in share_instances:
                self.access_helper.update_access_rules(
                    self.context, share_instance['id'],
                    share_server=share_server)

        for share_instance in share_instances:
            utils.wait_for_access_update(
                self.context, self.db, share_instance,
                self.migration_wait_access_rules_timeout)
コード例 #4
0
    def manage_share(self,
                     context,
                     share_id,
                     driver_options,
                     request_spec,
                     filter_properties=None):
        """Ensure that the host exists and can accept the share."""
        def _manage_share_set_error(self, context, ex, request_spec):
            # NOTE(nidhimittalhada): set size as 1 because design expects size
            # to be set, it also will allow us to handle delete/unmanage
            # operations properly with this errored share according to quotas.
            self._set_share_state_and_notify('manage_share', {
                'status': constants.STATUS_MANAGE_ERROR,
                'size': 1
            }, context, ex, request_spec)

        share_ref = db.share_get(context, share_id)

        try:
            self.driver.host_passes_filters(context, share_ref['host'],
                                            request_spec, filter_properties)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _manage_share_set_error(self, context, ex, request_spec)
        else:
            share_rpcapi.ShareAPI().manage_share(context, share_ref,
                                                 driver_options)
コード例 #5
0
    def migrate_share_to_host(self,
                              context,
                              share_id,
                              host,
                              force_host_copy,
                              request_spec,
                              filter_properties=None):
        """Ensure that the host exists and can accept the share."""
        def _migrate_share_set_error(self, context, ex, request_spec):
            self._set_share_state_and_notify(
                'migrate_share_to_host',
                {'task_state': constants.STATUS_TASK_STATE_MIGRATION_ERROR},
                context, ex, request_spec)

        try:
            tgt_host = self.driver.host_passes_filters(context, host,
                                                       request_spec,
                                                       filter_properties)

        except exception.NoValidHost as ex:
            _migrate_share_set_error(self, context, ex, request_spec)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _migrate_share_set_error(self, context, ex, request_spec)
        else:
            share_ref = db.share_get(context, share_id)
            try:
                share_rpcapi.ShareAPI().migrate_share(context, share_ref,
                                                      tgt_host,
                                                      force_host_copy)
            except Exception as ex:
                with excutils.save_and_reraise_exception():
                    _migrate_share_set_error(self, context, ex, request_spec)
コード例 #6
0
ファイル: manager.py プロジェクト: openstack/manila
    def extend_share(self,
                     context,
                     share_id,
                     new_size,
                     reservations,
                     request_spec=None,
                     filter_properties=None):
        def _extend_share_set_error(self, context, ex, request_spec):
            share_state = {'status': constants.STATUS_AVAILABLE}
            self._set_share_state_and_notify('extend_share', share_state,
                                             context, ex, request_spec)

        share = db.share_get(context, share_id)
        try:
            target_host = self.driver.host_passes_filters(
                context, share['host'], request_spec, filter_properties)
            target_host.consume_from_share(
                {'size': int(new_size) - share['size']})
            share_rpcapi.ShareAPI().extend_share(context, share, new_size,
                                                 reservations)
        except exception.NoValidHost as ex:
            quota.QUOTAS.rollback(context,
                                  reservations,
                                  project_id=share['project_id'],
                                  user_id=share['user_id'],
                                  share_type_id=share['share_type_id'])
            _extend_share_set_error(self, context, ex, request_spec)
            self.message_api.create(context,
                                    message_field.Action.EXTEND,
                                    share['project_id'],
                                    resource_type=message_field.Resource.SHARE,
                                    resource_id=share['id'],
                                    exception=ex)
コード例 #7
0
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     share = db_utils.create_share(
         availability_zone=CONF.storage_availability_zone,
         status=constants.STATUS_AVAILABLE)
     access = db_utils.create_access(share_id=share['id'])
     snapshot = db_utils.create_snapshot(share_id=share['id'])
     share_replica = db_utils.create_share_replica(
         id='fake_replica',
         share_id='fake_share_id',
     )
     share_server = db_utils.create_share_server()
     cg = {'id': 'fake_cg_id', 'host': 'fake_host'}
     cgsnapshot = {'id': 'fake_cg_id'}
     host = {'host': 'fake_host', 'capabilities': 1}
     self.fake_share = jsonutils.to_primitive(share)
     self.fake_share_replica = jsonutils.to_primitive(share_replica)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.fake_cg = jsonutils.to_primitive(cg)
     self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot)
     self.fake_host = jsonutils.to_primitive(host)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
コード例 #8
0
ファイル: helper.py プロジェクト: vkmc/manila
    def __init__(self, context, db, share):

        self.db = db
        self.share = share
        self.context = context
        self.share_rpc = share_rpc.ShareAPI()
        self.wait_access_rules_timeout = (
            CONF.data_access_wait_access_rules_timeout)
コード例 #9
0
ファイル: helper.py プロジェクト: openstack/manila
    def __init__(self, context, db, share):

        self.db = db
        self.share = share
        self.context = context
        self.share_rpc = share_rpc.ShareAPI()
        self.access_helper = access_manager.ShareInstanceAccess(self.db, None)
        self.wait_access_rules_timeout = (
            CONF.data_access_wait_access_rules_timeout)
コード例 #10
0
    def migration_start(self, context, ignore_list, share_id,
                        share_instance_id, dest_share_instance_id,
                        connection_info_src, connection_info_dest):

        LOG.debug(
            "Received request to migrate share content from share instance "
            "%(instance_id)s to instance %(dest_instance_id)s.", {
                'instance_id': share_instance_id,
                'dest_instance_id': dest_share_instance_id
            })

        share_ref = self.db.share_get(context, share_id)
        share_instance_ref = self.db.share_instance_get(context,
                                                        share_instance_id,
                                                        with_share_data=True)

        share_rpcapi = share_rpc.ShareAPI()

        mount_path = CONF.mount_tmp_location

        try:
            copy = data_utils.Copy(
                os.path.join(mount_path, share_instance_id),
                os.path.join(mount_path, dest_share_instance_id), ignore_list,
                CONF.check_hash)

            self._copy_share_data(context, copy, share_ref, share_instance_id,
                                  dest_share_instance_id, connection_info_src,
                                  connection_info_dest)
        except exception.ShareDataCopyCancelled:
            share_rpcapi.migration_complete(context, share_instance_ref,
                                            dest_share_instance_id)
            return
        except Exception:
            self.db.share_update(
                context, share_id,
                {'task_state': constants.TASK_STATE_DATA_COPYING_ERROR})
            msg = _("Failed to copy contents from instance %(src)s to "
                    "instance %(dest)s.") % {
                        'src': share_instance_id,
                        'dest': dest_share_instance_id
                    }
            LOG.exception(msg)
            share_rpcapi.migration_complete(context, share_instance_ref,
                                            dest_share_instance_id)
            raise exception.ShareDataCopyFailed(reason=msg)
        finally:
            self.busy_tasks_shares.pop(share_id, None)

        LOG.info(
            "Completed copy operation of migrating share content from share "
            "instance %(instance_id)s to instance %(dest_instance_id)s.", {
                'instance_id': share_instance_id,
                'dest_instance_id': dest_share_instance_id
            })
コード例 #11
0
    def migrate_share_to_host(self,
                              context,
                              share_id,
                              host,
                              force_host_assisted_migration,
                              preserve_metadata,
                              writable,
                              nondisruptive,
                              preserve_snapshots,
                              new_share_network_id,
                              new_share_type_id,
                              request_spec,
                              filter_properties=None):
        """Ensure that the host exists and can accept the share."""

        share_ref = db.share_get(context, share_id)

        def _migrate_share_set_error(self, context, ex, request_spec):
            instance = next((x for x in share_ref.instances
                             if x['status'] == constants.STATUS_MIGRATING),
                            None)
            if instance:
                db.share_instance_update(
                    context, instance['id'],
                    {'status': constants.STATUS_AVAILABLE})
            self._set_share_state_and_notify(
                'migrate_share_to_host',
                {'task_state': constants.TASK_STATE_MIGRATION_ERROR}, context,
                ex, request_spec)

        try:
            tgt_host = self.driver.host_passes_filters(context, host,
                                                       request_spec,
                                                       filter_properties)

        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _migrate_share_set_error(self, context, ex, request_spec)
        else:

            try:
                share_rpcapi.ShareAPI().migration_start(
                    context, share_ref, tgt_host.host,
                    force_host_assisted_migration, preserve_metadata, writable,
                    nondisruptive, preserve_snapshots, new_share_network_id,
                    new_share_type_id)
            except Exception as ex:
                with excutils.save_and_reraise_exception():
                    _migrate_share_set_error(self, context, ex, request_spec)
コード例 #12
0
ファイル: manager.py プロジェクト: swipswaps/manila
    def manage_share(self,
                     context,
                     share_id,
                     driver_options,
                     request_spec,
                     filter_properties=None):
        """Ensure that the host exists and can accept the share."""
        def _manage_share_set_error(self, context, ex, request_spec):
            self._set_share_state_and_notify(
                'manage_share', {'status': constants.STATUS_MANAGE_ERROR},
                context, ex, request_spec)

        share_ref = db.share_get(context, share_id)

        try:
            self.driver.host_passes_filters(context, share_ref['host'],
                                            request_spec, filter_properties)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                _manage_share_set_error(self, context, ex, request_spec)
        else:
            share_rpcapi.ShareAPI().manage_share(context, share_ref,
                                                 driver_options)
コード例 #13
0
ファイル: test_rpcapi.py プロジェクト: yuyuyu101/manila
 def setUp(self):
     super(ShareRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     shr = {}
     shr['host'] = 'fake_host'
     shr['availability_zone'] = CONF.storage_availability_zone
     shr['status'] = "available"
     share = db.share_create(self.context, shr)
     acs = {}
     acs['access_type'] = "ip"
     acs['access_to'] = "123.123.123.123"
     acs['share_id'] = share['id']
     access = db.share_access_create(self.context, acs)
     snap = {}
     snap['share_id'] = share['id']
     snapshot = db.share_snapshot_create(self.context, snap)
     server = {'id': 'fake_share_server_id', 'host': 'fake_host'}
     share_server = db.share_server_create(self.context, server)
     self.fake_share = jsonutils.to_primitive(share)
     self.fake_access = jsonutils.to_primitive(access)
     self.fake_snapshot = jsonutils.to_primitive(snapshot)
     self.fake_share_server = jsonutils.to_primitive(share_server)
     self.ctxt = context.RequestContext('fake_user', 'fake_project')
     self.rpcapi = share_rpcapi.ShareAPI()
コード例 #14
0
 def __init__(self):
     self.host_manager = importutils.import_object(
         CONF.scheduler_host_manager)
     self.share_rpcapi = share_rpcapi.ShareAPI()
コード例 #15
0
ファイル: api.py プロジェクト: mbr4v0v/manila
 def __init__(self, db_driver=None):
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.share_rpcapi = share_rpcapi.ShareAPI()
     super(API, self).__init__(db_driver)
コード例 #16
0
 def __init__(self):
     super(ShareNetworkController, self).__init__()
     self.share_rpcapi = share_rpcapi.ShareAPI()
コード例 #17
0
 def request_service_capabilities(self, context):
     share_rpcapi.ShareAPI().publish_service_capabilities(context)