Beispiel #1
0
 def get_volume_mountpoint(self):
     volume = create_cinder_client(self.context).volumes.get(volume_id)
     mountpoint = volume.attachments[0]['device']
     if mountpoint[0] is not "/":
         return "/%s" % mountpoint
     else:
         return mountpoint
Beispiel #2
0
 def test_create_with_catalog_all_opts(self):
     cfg.CONF.set_override('cinder_service_type', 'volume')
     cfg.CONF.set_override('os_region_name', 'RegionTwo')
     client = remote.create_cinder_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.volume_public_url_region_two,
                      client.client.management_url)
Beispiel #3
0
 def load(context):
     client = create_cinder_client(context)
     rdstorages = client.rdstorage.list()
     for rdstorage in rdstorages:
         LOG.debug("rdstorage=" + str(rdstorage))
     return [StorageDevice(storage_info)
             for storage_info in rdstorages]
Beispiel #4
0
 def get_volume_mountpoint(self):
     volume = create_cinder_client(self.context).volumes.get(volume_id)
     mountpoint = volume.attachments[0]['device']
     if mountpoint[0] is not "/":
         return "/%s" % mountpoint
     else:
         return mountpoint
Beispiel #5
0
 def test_create_with_catalog_all_opts(self):
     cfg.CONF.set_override('cinder_service_type', 'volume')
     cfg.CONF.set_override('os_region_name', 'RegionTwo')
     client = remote.create_cinder_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.volume_public_url_region_two,
                      client.client.management_url)
Beispiel #6
0
    def _create_server_volume_heat(self, flavor, image_id, security_groups, service_type, volume_size):
        client = create_heat_client(self.context)
        novaclient = create_nova_client(self.context)
        cinderclient = create_cinder_client(self.context)
        heat_template = template.HeatTemplate().template()
        parameters = {
            "KeyName": "heatkey",
            "Flavor": flavor["name"],
            "VolumeSize": volume_size,
            "ServiceType": "mysql",
            "InstanceId": self.id,
        }
        stack_name = "trove-%s" % self.id
        stack = client.stacks.create(stack_name=stack_name, template=heat_template, parameters=parameters)
        stack = client.stacks.get(stack_name)

        utils.poll_until(
            lambda: client.stacks.get(stack_name),
            lambda stack: stack.stack_status in ["CREATE_COMPLETE", "CREATE_FAILED"],
            sleep_time=2,
            time_out=HEAT_TIME_OUT,
        )

        resource = client.resources.get(stack.id, "BaseInstance")
        server = novaclient.servers.get(resource.physical_resource_id)

        resource = client.resources.get(stack.id, "DataVolume")
        volume = cinderclient.volumes.get(resource.physical_resource_id)
        volume_info = self._build_volume(volume)

        self.update_db(compute_instance_id=server.id, volume_id=volume.id)

        return server, volume_info
Beispiel #7
0
 def test_create_with_conf_override_trailing_slash(self):
     cinder_url_from_conf = 'http://example.com/'
     tenant_from_ctx = 'abc'
     cfg.CONF.set_override('cinder_url', cinder_url_from_conf)
     client = remote.create_cinder_client(
         TroveContext(tenant=tenant_from_ctx))
     self.assertEqual('%s%s' % (cinder_url_from_conf, tenant_from_ctx),
                      client.client.management_url)
Beispiel #8
0
 def test_create_with_conf_override_trailing_slash(self):
     cinder_url_from_conf = 'http://example.com/'
     tenant_from_ctx = uuid.uuid4().hex
     cfg.CONF.set_override('cinder_url', cinder_url_from_conf)
     client = remote.create_cinder_client(
         TroveContext(tenant=tenant_from_ctx))
     self.assertEqual('%s%s' % (cinder_url_from_conf, tenant_from_ctx),
                      client.client.management_url)
Beispiel #9
0
    def test_create_with_conf_override(self):
        cinder_url_from_conf = 'http://example.com'
        tenant_from_ctx = uuid.uuid4().hex
        cfg.CONF.set_override('cinder_url', cinder_url_from_conf)

        client = remote.create_cinder_client(
            TroveContext(tenant=tenant_from_ctx))
        self.assertEqual('%s/%s' % (cinder_url_from_conf, tenant_from_ctx),
                         client.client.management_url)
Beispiel #10
0
    def test_create_with_conf_override(self):
        cinder_url_from_conf = 'http://example.com'
        tenant_from_ctx = 'abc'
        cfg.CONF.set_override('cinder_url', cinder_url_from_conf)

        client = remote.create_cinder_client(
            TroveContext(tenant=tenant_from_ctx))
        self.assertEqual('%s/%s' % (cinder_url_from_conf, tenant_from_ctx),
                         client.client.management_url)
Beispiel #11
0
 def load(cls, context, id, include_deleted=False):
     instance = load_mgmt_instance(cls, context, id, include_deleted)
     client = remote.create_cinder_client(context)
     try:
         instance.volume = client.volumes.get(instance.volume_id)
     except Exception:
         instance.volume = None
         # Populate the volume_used attribute from the guest agent.
     instance_models.load_guest_info(instance, context, id)
     instance.root_history = mysql_models.RootHistory.load(context=context, instance_id=id)
     return instance
Beispiel #12
0
 def load(cls, context, id):
     instance = load_mgmt_instance(cls, context, id)
     client = remote.create_cinder_client(context)
     try:
         instance.volume = client.volumes.get(instance.volume_id)
     except Exception:
         instance.volume = None
         # Populate the volume_used attribute from the guest agent.
     instance_models.load_guest_info(instance, context, id)
     instance.root_history = mysql_models.RootHistory.load(context=context,
                                                           instance_id=id)
     return instance
Beispiel #13
0
 def load(cls, volume_type_id, context=None, client=None):
     if not (client or context):
         raise trove_exception.InvalidModelError(
             "client or context must be provided to load a volume_type")
     if not client:
         client = remote.create_cinder_client(context)
     try:
         volume_type = client.volume_types.get(volume_type_id)
     except cinder_exception.NotFound:
         raise trove_exception.NotFound(uuid=volume_type_id)
     except cinder_exception.ClientException as ce:
         raise trove_exception.TroveError(str(ce))
     return cls(volume_type)
Beispiel #14
0
    def _create_server_volume_heat(self, flavor, image_id,
                                   datastore_manager,
                                   volume_size, availability_zone):
        LOG.debug(_("begin _create_server_volume_heat for id: %s") % self.id)
        client = create_heat_client(self.context)
        novaclient = create_nova_client(self.context)

        template_obj = template.load_heat_template(datastore_manager)
        heat_template_unicode = template_obj.render()
        try:
            heat_template = heat_template_unicode.encode('ascii')
        except UnicodeEncodeError:
            LOG.error(_("heat template ascii encode issue"))
            raise TroveError("heat template ascii encode issue")

        parameters = {"Flavor": flavor["name"],
                      "VolumeSize": volume_size,
                      "InstanceId": self.id,
                      "ImageId": image_id,
                      "DatastoreManager": datastore_manager,
                      "AvailabilityZone": availability_zone}
        stack_name = 'trove-%s' % self.id
        client.stacks.create(stack_name=stack_name,
                             template=heat_template,
                             parameters=parameters)
        stack = client.stacks.get(stack_name)

        utils.poll_until(
            lambda: client.stacks.get(stack_name),
            lambda stack: stack.stack_status in ['CREATE_COMPLETE',
                                                 'CREATE_FAILED'],
            sleep_time=2,
            time_out=HEAT_TIME_OUT)

        resource = client.resources.get(stack.id, 'BaseInstance')
        server = novaclient.servers.get(resource.physical_resource_id)

        if CONF.trove_volume_support:
            cinderclient = create_cinder_client(self.context)
            resource = client.resources.get(stack.id, 'DataVolume')
            volume = cinderclient.volumes.get(resource.physical_resource_id)
            volume_info = self._build_volume(volume)
            self.update_db(compute_instance_id=server.id, volume_id=volume.id)
        else:
            volume_info = self._build_volume_info(volume_size)
            self.update_db(compute_instance_id=server.id)

        LOG.debug(_("end _create_server_volume_heat for id: %s") % self.id)
        return server, volume_info
Beispiel #15
0
    def _create_server_volume_heat(self, flavor, image_id, datastore_manager,
                                   volume_size, availability_zone):
        LOG.debug(_("begin _create_server_volume_heat for id: %s") % self.id)
        client = create_heat_client(self.context)
        novaclient = create_nova_client(self.context)
        cinderclient = create_cinder_client(self.context)

        template_obj = template.load_heat_template(datastore_manager)
        heat_template_unicode = template_obj.render()
        try:
            heat_template = heat_template_unicode.encode('ascii')
        except UnicodeEncodeError:
            LOG.error(_("heat template ascii encode issue"))
            raise TroveError("heat template ascii encode issue")

        parameters = {
            "Flavor": flavor["name"],
            "VolumeSize": volume_size,
            "InstanceId": self.id,
            "ImageId": image_id,
            "DatastoreManager": datastore_manager,
            "AvailabilityZone": availability_zone
        }
        stack_name = 'trove-%s' % self.id
        client.stacks.create(stack_name=stack_name,
                             template=heat_template,
                             parameters=parameters)
        stack = client.stacks.get(stack_name)

        utils.poll_until(lambda: client.stacks.get(stack_name),
                         lambda stack: stack.stack_status in
                         ['CREATE_COMPLETE', 'CREATE_FAILED'],
                         sleep_time=2,
                         time_out=HEAT_TIME_OUT)

        resource = client.resources.get(stack.id, 'BaseInstance')
        server = novaclient.servers.get(resource.physical_resource_id)

        resource = client.resources.get(stack.id, 'DataVolume')
        volume = cinderclient.volumes.get(resource.physical_resource_id)
        volume_info = self._build_volume(volume)

        self.update_db(compute_instance_id=server.id, volume_id=volume.id)
        LOG.debug(_("end _create_server_volume_heat for id: %s") % self.id)
        return server, volume_info
Beispiel #16
0
    def allowed_datastore_version_volume_types(cls, context,
                                               datastore_name,
                                               datastore_version_name):
        """
        List all allowed volume types for a given datastore and
        datastore version. If datastore version metadata is
        provided, then the valid volume types in that list are
        allowed. If datastore version metadata is not provided
        then all volume types known to cinder are allowed.
        """
        if datastore_name and datastore_version_name:
            # first obtain the list in the dsvmetadata
            datastore_version_id = cls._datastore_version_find(
                datastore_name, datastore_version_name)

            metadata = cls.list_datastore_version_volume_type_associations(
                datastore_version_id)

            # then get the list from cinder
            cinder_volume_types = remote.create_cinder_client(
                context).volume_types.list()

            # if there's metadata: intersect,
            # else, whatever cinder has.
            if (metadata.count() != 0):
                # the volume types from metadata first
                volume_types = tuple(f.value for f in metadata)

                # Cinder volume type names are unique, intersect
                ds_volume_types = (f for f in cinder_volume_types
                                   if ((f.name in volume_types) or
                                       (f.id in volume_types)))
                allowed_volume_types = tuple(
                    volume_type_model(volume_type=item)
                    for item in ds_volume_types)
            else:
                allowed_volume_types = tuple(
                    volume_type_model(volume_type=item)
                    for item in cinder_volume_types)

            return allowed_volume_types
        else:
            msg = _("Specify the datastore_name and datastore_version_name.")
            raise exception.BadRequest(msg)
Beispiel #17
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("Starting to create the volume for the instance"))

        volume_client = create_cinder_client(self.context)
        volume_desc = ("mysql volume for %s" % self.id)
        volume_ref = volume_client.volumes.create(volume_size,
                                                  name="mysql-%s" % self.id,
                                                  description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(lambda: volume_client.volumes.get(volume_ref.id),
                         lambda v_ref: v_ref.status in ['available', 'error'],
                         sleep_time=2,
                         time_out=VOLUME_TIME_OUT)

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ['error']:
            raise VolumeCreationFailure()
        LOG.debug(_("Created volume %s") % v_ref)
        # The mapping is in the format:
        # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
        # setting the delete_on_terminate instance to true=1
        mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1)
        bdm = CONF.block_device_mapping
        block_device = {bdm: mapping}
        volumes = [{'id': v_ref.id, 'size': v_ref.size}]
        LOG.debug("block_device = %s" % block_device)
        LOG.debug("volume = %s" % volumes)

        device_path = CONF.device_path
        mount_point = CONF.mount_point
        LOG.debug(_("device_path = %s") % device_path)
        LOG.debug(_("mount_point = %s") % mount_point)

        volume_info = {
            'block_device': block_device,
            'device_path': device_path,
            'mount_point': mount_point,
            'volumes': volumes
        }
        return volume_info
Beispiel #18
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("Starting to create the volume for the instance"))

        volume_client = create_cinder_client(self.context)
        volume_desc = ("mysql volume for %s" % self.id)
        volume_ref = volume_client.volumes.create(
            volume_size, name="mysql-%s" % self.id, description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(
            lambda: volume_client.volumes.get(volume_ref.id),
            lambda v_ref: v_ref.status in ['available', 'error'],
            sleep_time=2,
            time_out=VOLUME_TIME_OUT)

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ['error']:
            raise VolumeCreationFailure()
        LOG.debug(_("Created volume %s") % v_ref)
        # The mapping is in the format:
        # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
        # setting the delete_on_terminate instance to true=1
        mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1)
        bdm = CONF.block_device_mapping
        block_device = {bdm: mapping}
        volumes = [{'id': v_ref.id,
                    'size': v_ref.size}]
        LOG.debug("block_device = %s" % block_device)
        LOG.debug("volume = %s" % volumes)

        device_path = CONF.device_path
        mount_point = CONF.mount_point
        LOG.debug(_("device_path = %s") % device_path)
        LOG.debug(_("mount_point = %s") % mount_point)

        volume_info = {'block_device': block_device,
                       'device_path': device_path,
                       'mount_point': mount_point,
                       'volumes': volumes}
        return volume_info
Beispiel #19
0
    def allowed_datastore_version_volume_types(cls, context, datastore_name,
                                               datastore_version_name):
        """
        List all allowed volume types for a given datastore and
        datastore version. If datastore version metadata is
        provided, then the valid volume types in that list are
        allowed. If datastore version metadata is not provided
        then all volume types known to cinder are allowed.
        """
        if datastore_name and datastore_version_name:
            # first obtain the list in the dsvmetadata
            datastore_version_id = cls._datastore_version_find(
                datastore_name, datastore_version_name)

            metadata = cls.list_datastore_version_volume_type_associations(
                datastore_version_id)

            # then get the list from cinder
            cinder_volume_types = remote.create_cinder_client(
                context).volume_types.list()

            # if there's metadata: intersect,
            # else, whatever cinder has.
            if (metadata.count() != 0):
                # the volume types from metadata first
                volume_types = tuple(f.value for f in metadata)

                # Cinder volume type names are unique, intersect
                ds_volume_types = (f for f in cinder_volume_types if (
                    (f.name in volume_types) or (f.id in volume_types)))
                allowed_volume_types = tuple(
                    volume_type_model(volume_type=item)
                    for item in ds_volume_types)
            else:
                allowed_volume_types = tuple(
                    volume_type_model(volume_type=item)
                    for item in cinder_volume_types)

            return allowed_volume_types
        else:
            msg = _("Specify the datastore_name and datastore_version_name.")
            raise exception.BadRequest(msg)
Beispiel #20
0
    def __init__(self, volume_type=None, context=None, volume_type_id=None):
        """
        Initialize the volume type either from the volume_type parameter, or
        by querying cinder using the context provided.
        """

        if volume_type and not (volume_type_id or context):
            self.volume_type = volume_type
        elif volume_type_id and context:
            try:
                client = create_cinder_client(context)
                self.volume_type = client.volume_types.get(volume_type_id)
            except cinder_exception.NotFound:
                raise trove_exception.NotFound(uuid=volume_type_id)
            except cinder_exception.ClientException as ce:
                raise trove_exception.TroveError(str(ce))

            return
        else:
            raise trove_exception.InvalidModelError(
                errors="An invalid set of arguments were provided.")
Beispiel #21
0
    def __init__(self, volume_type=None, context=None, volume_type_id=None):
        """
        Initialize the volume type either from the volume_type parameter, or
        by querying cinder using the context provided.
        """

        if volume_type and not (volume_type_id or context):
            self.volume_type = volume_type
        elif volume_type_id and context:
            try:
                client = create_cinder_client(context)
                self.volume_type = client.volume_types.get(volume_type_id)
            except cinder_exception.NotFound:
                raise trove_exception.NotFound(uuid=volume_type_id)
            except cinder_exception.ClientException as ce:
                raise trove_exception.TroveError(str(ce))

            return
        else:
            raise trove_exception.InvalidModelError(
                errors="An invalid set of arguments were provided.")
Beispiel #22
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("begin _create_volume for id: %s") % self.id)
        volume_client = create_cinder_client(self.context)
        volume_desc = ("mysql volume for %s" % self.id)
        volume_ref = volume_client.volumes.create(
            volume_size, name="mysql-%s" % self.id, description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(
            lambda: volume_client.volumes.get(volume_ref.id),
            lambda v_ref: v_ref.status in ['available', 'error'],
            sleep_time=2,
            time_out=VOLUME_TIME_OUT)

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ['error']:
            raise VolumeCreationFailure()
        LOG.debug(_("end _create_volume for id: %s") % self.id)
        return self._build_volume(v_ref)
Beispiel #23
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("Starting to create the volume for the instance"))

        volume_client = create_cinder_client(self.context)
        volume_desc = "mysql volume for %s" % self.id
        volume_ref = volume_client.volumes.create(volume_size, name="mysql-%s" % self.id, description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(
            lambda: volume_client.volumes.get(volume_ref.id),
            lambda v_ref: v_ref.status in ["available", "error"],
            sleep_time=2,
            time_out=VOLUME_TIME_OUT,
        )

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ["error"]:
            raise VolumeCreationFailure()
        return self._build_volume(v_ref)
Beispiel #24
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("begin _create_volume for id: %s") % self.id)
        volume_client = create_cinder_client(self.context)
        volume_desc = ("mysql volume for %s" % self.id)
        volume_ref = volume_client.volumes.create(volume_size,
                                                  name="mysql-%s" % self.id,
                                                  description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(lambda: volume_client.volumes.get(volume_ref.id),
                         lambda v_ref: v_ref.status in ['available', 'error'],
                         sleep_time=2,
                         time_out=VOLUME_TIME_OUT)

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ['error']:
            raise VolumeCreationFailure()
        LOG.debug(_("end _create_volume for id: %s") % self.id)
        return self._build_volume(v_ref)
Beispiel #25
0
    def _create_server_volume_heat(self, flavor, image_id, security_groups,
                                   service_type, volume_size,
                                   availability_zone):
        client = create_heat_client(self.context)
        novaclient = create_nova_client(self.context)
        cinderclient = create_cinder_client(self.context)
        heat_template = template.HeatTemplate().template()
        parameters = {
            "KeyName": "heatkey",
            "Flavor": flavor["name"],
            "VolumeSize": volume_size,
            "ServiceType": service_type,
            "InstanceId": self.id,
            "AvailabilityZone": availability_zone
        }
        stack_name = 'trove-%s' % self.id
        stack = client.stacks.create(stack_name=stack_name,
                                     template=heat_template,
                                     parameters=parameters)
        stack = client.stacks.get(stack_name)

        utils.poll_until(lambda: client.stacks.get(stack_name),
                         lambda stack: stack.stack_status in
                         ['CREATE_COMPLETE', 'CREATE_FAILED'],
                         sleep_time=2,
                         time_out=HEAT_TIME_OUT)

        resource = client.resources.get(stack.id, 'BaseInstance')
        server = novaclient.servers.get(resource.physical_resource_id)

        resource = client.resources.get(stack.id, 'DataVolume')
        volume = cinderclient.volumes.get(resource.physical_resource_id)
        volume_info = self._build_volume(volume)

        self.update_db(compute_instance_id=server.id, volume_id=volume.id)

        return server, volume_info
Beispiel #26
0
 def volume_client(self):
     if not self._volume_client:
         self._volume_client = create_cinder_client(self.context)
     return self._volume_client
Beispiel #27
0
 def __init__(self, context):
     volume_types = remote.create_cinder_client(context).volume_types.list()
     self.volume_types = [
         VolumeType(volume_type=item) for item in volume_types
     ]
Beispiel #28
0
 def load(context):
     client = create_cinder_client(context)
     rdstorages = client.rdstorage.list()
     for rdstorage in rdstorages:
         LOG.debug("rdstorage=" + str(rdstorage))
     return [StorageDevice(storage_info) for storage_info in rdstorages]
Beispiel #29
0
 def get_client(cls, context):
     return remote.create_cinder_client(context)
Beispiel #30
0
 def test_create_with_catalog_and_default_service_type(self):
     client = remote.create_cinder_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.volumev2_public_url,
                      client.client.management_url)
Beispiel #31
0
 def test_create_with_catalog_and_default_service_type(self):
     client = remote.create_cinder_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.volumev2_public_url,
                      client.client.management_url)
Beispiel #32
0
 def __init__(self, context):
     volume_types = create_cinder_client(context).volume_types.list()
     self.volume_types = [VolumeType(volume_type=item)
                          for item in volume_types]
Beispiel #33
0
 def volume_client(self):
     if not self._volume_client:
         self._volume_client = create_cinder_client(self.context)
     return self._volume_client