예제 #1
0
def add_lts_image(glance_client=None, image_name=None, release=None):
    """Add an Ubuntu LTS image to the current deployment.

    :param glance: Authenticated glanceclient
    :type glance: glanceclient.Client
    :param image_name: Label for the image in glance
    :type image_name: str
    :param release: Name of ubuntu release.
    :type release: str
    """
    image_name = image_name or LTS_IMAGE_NAME
    release = release or LTS_RELEASE
    if not glance_client:
        keystone_session = openstack_utils.get_overcloud_keystone_session()
        glance_client = openstack_utils.get_glance_session_client(
            keystone_session)
    if openstack_utils.get_images_by_name(glance_client, image_name):
        logging.warning('Using existing glance image')
    else:
        image_url = openstack_utils.find_ubuntu_image(
            release=release,
            arch='amd64')
        openstack_utils.create_image(
            glance_client,
            image_url,
            image_name)
예제 #2
0
파일: setup.py 프로젝트: javacruft/zaza
def add_image(image_url, glance_client=None, image_name=None, tags=[]):
    """Retrieve image from ``image_url`` and add it to glance.

    :param image_url: Retrievable URL with image data
    :type image_url: str
    :param glance: Authenticated glanceclient
    :type glance: glanceclient.Client
    :param image_name: Label for the image in glance
    :type image_name: str
    :param tags: List of tags to add to image
    :type tags: list of str
    """
    if not glance_client:
        keystone_session = openstack_utils.get_overcloud_keystone_session()
        glance_client = openstack_utils.get_glance_session_client(
            keystone_session)
    if image_name:
        image = openstack_utils.get_images_by_name(glance_client, image_name)

    if image:
        logging.warning('Using existing glance image "{}" ({})'.format(
            image_name, image[0].id))
    else:
        logging.info('Downloading image {}'.format(image_name or image_url))
        openstack_utils.create_image(glance_client,
                                     image_url,
                                     image_name,
                                     tags=tags)
예제 #3
0
 def test_create_image_use_tempdir(self):
     glance_mock = mock.MagicMock()
     self.patch_object(openstack_utils.os.path, "exists")
     self.patch_object(openstack_utils, "download_image")
     self.patch_object(openstack_utils, "upload_image_to_glance")
     self.patch_object(openstack_utils.tempfile, "gettempdir")
     self.gettempdir.return_value = "wibbly"
     openstack_utils.create_image(glance_mock, 'http://cirros/c.img', 'bob')
     self.exists.return_value = False
     self.download_image.assert_called_once_with('http://cirros/c.img',
                                                 'wibbly/c.img')
     self.upload_image_to_glance.assert_called_once_with(
         glance_mock, 'wibbly/c.img', 'bob')
예제 #4
0
def add_cirros_image(glance_client=None, image_name=None):
    """Add a cirros image to the current deployment.

    :param glance: Authenticated glanceclient
    :type glance: glanceclient.Client
    :param image_name: Label for the image in glance
    :type image_name: str
    """
    image_name = image_name or CIRROS_IMAGE_NAME
    if not glance_client:
        keystone_session = openstack_utils.get_overcloud_keystone_session()
        glance_client = openstack_utils.get_glance_session_client(
            keystone_session)
    if openstack_utils.get_images_by_name(glance_client, image_name):
        logging.warning('Using existing glance image')
    else:
        image_url = openstack_utils.find_cirros_image(arch='x86_64')
        openstack_utils.create_image(
            glance_client,
            image_url,
            image_name)
예제 #5
0
 def test_410_glance_image_create_delete(self):
     """Create an image and then delete it."""
     image_url = openstack_utils.find_cirros_image(arch='x86_64')
     image = openstack_utils.create_image(self.glance_client, image_url,
                                          'cirrosimage')
     openstack_utils.delete_image(self.glance_client, image.id)