Пример #1
0
 def test_get_openstack_resource_by_uuid(self, fake_is_uuid_like):
     fake_manager = mock.MagicMock()
     fake_manager.get.return_value = 'fake_resource_data'
     resource_data = utils.get_openstack_resource(fake_manager,
                                                  'fake_resource',
                                                  'fake_resource_type')
     self.assertEqual('fake_resource_data', resource_data)
Пример #2
0
 def test_get_openstack_resource_by_uuid(self, fake_is_uuid_like):
     fake_manager = mock.MagicMock()
     fake_manager.get.return_value = 'fake_resource_data'
     resource_data = utils.get_openstack_resource(fake_manager,
                                                  'fake_resource',
                                                  'fake_resource_type')
     self.assertEqual('fake_resource_data', resource_data)
Пример #3
0
def validate_image(cli, image):
    """Validate image"""

    try:
        image_found = api_utils.get_openstack_resource(cli.glance().images, image, "images")
    except (glance_exception.NotFound, exception.ResourceNotFound):
        raise exception.ImageNotFound(image_id=image)
    except glance_exception.HTTPForbidden:
        raise exception.ImageNotAuthorized(image_id=image)
    if not image_found.get("os_distro"):
        raise exception.OSDistroFieldNotFound(image_id=image)
    return image_found
Пример #4
0
def validate_image(cli, image):
    """Validate image"""

    try:
        image_found = api_utils.get_openstack_resource(cli.glance().images,
                                                       image, 'images')
    except (glance_exception.NotFound, exception.ResourceNotFound):
        raise exception.ImageNotFound(image_id=image)
    except glance_exception.HTTPForbidden:
        raise exception.ImageNotAuthorized(image_id=image)
    if not image_found.get('os_distro'):
        raise exception.OSDistroFieldNotFound(image_id=image)
    return image_found
Пример #5
0
    def _get_image_data(self, context, image_ident):
        """Retrieves os_distro and other metadata from the Glance image.

        :param image_ident: image id or name of baymodel.
        """
        try:
            cli = clients.OpenStackClients(context)
            return api_utils.get_openstack_resource(cli.glance().images,
                                                    image_ident, 'images')
        except glanceclient.exc.NotFound:
            raise exception.ImageNotFound(image_id=image_ident)
        except glanceclient.exc.HTTPForbidden:
            raise exception.ImageNotAuthorized(image_id=image_ident)
Пример #6
0
 def wrapper(func, *args, **kwargs):
     cluster_template = args[1]
     cluster_distro = cluster_template.cluster_distro
     if not cluster_distro:
         try:
             cli = clients.OpenStackClients(pecan.request.context)
             image_id = cluster_template.image_id
             image = api_utils.get_openstack_resource(
                 cli.glance().images, image_id, 'images')
             cluster_distro = image.get('os_distro')
         except Exception:
             pass
     cluster_type = (cluster_template.server_type, cluster_distro,
                     cluster_template.coe)
     driver.Driver.get_driver(*cluster_type)
     return func(*args, **kwargs)
Пример #7
0
 def wrapper(func, *args, **kwargs):
     cluster_template = args[1]
     cluster_distro = cluster_template.cluster_distro
     if not cluster_distro:
         try:
             cli = clients.OpenStackClients(pecan.request.context)
             image_id = cluster_template.image_id
             image = api_utils.get_openstack_resource(cli.glance().images,
                                                      image_id,
                                                      'images')
             cluster_distro = image.get('os_distro')
         except Exception:
             pass
     cluster_type = (cluster_template.server_type,
                     cluster_distro,
                     cluster_template.coe)
     driver.Driver.get_driver(*cluster_type)
     return func(*args, **kwargs)