示例#1
0
    def upload_image(self, context, session, instance, vdi_uuids, image_id):
        """Requests that the Glance plugin bundle the specified VDIs and
        push them into Glance using the specified human-friendly name.
        """
        # NOTE(sirp): Currently we only support uploading images as VHD, there
        # is no RAW equivalent (yet)
        LOG.debug(_("Asking xapi to upload to glance %(vdi_uuids)s as"
                    " ID %(image_id)s"),
                  locals(),
                  instance=instance)

        glance_api_servers = glance.get_api_servers()
        glance_host, glance_port, glance_use_ssl = glance_api_servers.next()

        properties = {
            'auto_disk_config': instance['auto_disk_config'],
            'os_type': instance['os_type'] or CONF.default_os_type,
        }

        params = {
            'vdi_uuids': vdi_uuids,
            'image_id': image_id,
            'glance_host': glance_host,
            'glance_port': glance_port,
            'glance_use_ssl': glance_use_ssl,
            'sr_path': vm_utils.get_sr_path(session),
            'auth_token': getattr(context, 'auth_token', None),
            'properties': properties
        }

        session.call_plugin_serialized('glance', 'upload_vhd', **params)
示例#2
0
文件: glance.py 项目: DSpeichert/nova
    def upload_image(self, context, session, instance, vdi_uuids, image_id):
        """Requests that the Glance plugin bundle the specified VDIs and
        push them into Glance using the specified human-friendly name.
        """
        # NOTE(sirp): Currently we only support uploading images as VHD, there
        # is no RAW equivalent (yet)
        LOG.debug(_("Asking xapi to upload to glance %(vdi_uuids)s as"
                    " ID %(image_id)s"), locals(), instance=instance)

        glance_api_servers = glance.get_api_servers()
        glance_host, glance_port, glance_use_ssl = glance_api_servers.next()

        properties = {
            'auto_disk_config': instance['auto_disk_config'],
            'os_type': instance['os_type'] or CONF.default_os_type,
        }

        params = {'vdi_uuids': vdi_uuids,
                  'image_id': image_id,
                  'glance_host': glance_host,
                  'glance_port': glance_port,
                  'glance_use_ssl': glance_use_ssl,
                  'sr_path': vm_utils.get_sr_path(session),
                  'auth_token': getattr(context, 'auth_token', None),
                  'properties': properties}

        session.call_plugin_serialized('glance', 'upload_vhd', **params)
示例#3
0
文件: api.py 项目: arbrandes/nova
    def generate_image_url(image_ref, context):
        """Generate an image URL from an image_ref.

        :param image_ref: The image ref to generate URL
        :param context: The `nova.context.Context` object for the request
        """
        return "%s/images/%s" % (next(glance.get_api_servers(context)),
                                 image_ref)
示例#4
0
文件: api.py 项目: zsvic/nova
    def generate_image_url(image_ref, context):
        """Generate an image URL from an image_ref.

        :param image_ref: The image ref to generate URL
        :param context: The `nova.context.Context` object for the request
        """
        return "%s/images/%s" % (next(
            glance.get_api_servers(context)), image_ref)
示例#5
0
文件: glance.py 项目: yuans/nova
    def upload_image(self, context, session, instance, vdi_uuids, image_id):
        """Requests that the Glance plugin bundle the specified VDIs and
        push them into Glance using the specified human-friendly name.
        """
        # NOTE(sirp): Currently we only support uploading images as VHD, there
        # is no RAW equivalent (yet)
        max_attempts = CONF.glance_num_retries + 1
        sleep_time = 0.5
        glance_api_servers = glance.get_api_servers()
        properties = {
            'auto_disk_config': instance['auto_disk_config'],
            'os_type': instance['os_type'] or CONF.default_os_type,
        }

        if agent.USE_AGENT_SM_KEY in instance["system_metadata"]:
            properties[agent.USE_AGENT_KEY] = \
                instance["system_metadata"][agent.USE_AGENT_SM_KEY]

        for attempt_num in xrange(1, max_attempts + 1):

            (glance_host, glance_port,
             glance_use_ssl) = glance_api_servers.next()

            try:

                params = {
                    'vdi_uuids': vdi_uuids,
                    'image_id': image_id,
                    'glance_host': glance_host,
                    'glance_port': glance_port,
                    'glance_use_ssl': glance_use_ssl,
                    'sr_path': vm_utils.get_sr_path(session),
                    'auth_token': getattr(context, 'auth_token', None),
                    'properties': properties
                }

                LOG.debug(_("Asking xapi to upload to glance %(vdi_uuids)s as"
                            " ID %(image_id)s"
                            " glance server: %(glance_host)s:%(glance_port)d"
                            " attempt %(attempt_num)d/%(max_attempts)d"),
                          locals(),
                          instance=instance)

                return session.call_plugin_serialized('glance', 'upload_vhd',
                                                      **params)

            except session.XenAPI.Failure as exc:
                _type, _method, error = exc.details[:3]
                if error == 'RetryableError':
                    LOG.error(_('upload_vhd failed: %r') % (exc.details[3:], ))
                else:
                    raise
            time.sleep(sleep_time)
            sleep_time = min(2 * sleep_time, 15)

        raise exception.CouldNotUploadImage(image_id=image_id)
示例#6
0
    def upload_image(self, context, session, instance, vdi_uuids, image_id):
        """Requests that the Glance plugin bundle the specified VDIs and
        push them into Glance using the specified human-friendly name.
        """
        # NOTE(sirp): Currently we only support uploading images as VHD, there
        # is no RAW equivalent (yet)
        max_attempts = CONF.glance_num_retries + 1
        sleep_time = 0.5
        glance_api_servers = glance.get_api_servers()
        properties = {
            'auto_disk_config': instance['auto_disk_config'],
            'os_type': instance['os_type'] or CONF.default_os_type,
        }

        if agent.USE_AGENT_SM_KEY in instance["system_metadata"]:
            properties[agent.USE_AGENT_KEY] = \
                instance["system_metadata"][agent.USE_AGENT_SM_KEY]

        for attempt_num in xrange(1, max_attempts + 1):

            (glance_host,
             glance_port,
             glance_use_ssl) = glance_api_servers.next()

            try:

                params = {'vdi_uuids': vdi_uuids,
                          'image_id': image_id,
                          'glance_host': glance_host,
                          'glance_port': glance_port,
                          'glance_use_ssl': glance_use_ssl,
                          'sr_path': vm_utils.get_sr_path(session),
                          'auth_token': getattr(context, 'auth_token', None),
                          'properties': properties}

                LOG.debug(_("Asking xapi to upload to glance %(vdi_uuids)s as"
                            " ID %(image_id)s"
                            " glance server: %(glance_host)s:%(glance_port)d"
                            " attempt %(attempt_num)d/%(max_attempts)d"),
                            locals(), instance=instance)

                return session.call_plugin_serialized('glance',
                                                      'upload_vhd',
                                                      **params)

            except session.XenAPI.Failure as exc:
                _type, _method, error = exc.details[:3]
                if error == 'RetryableError':
                    LOG.error(_('upload_vhd failed: %r') %
                              (exc.details[3:],))
                else:
                    raise
            time.sleep(sleep_time)
            sleep_time = min(2 * sleep_time, 15)

        raise exception.CouldNotUploadImage(image_id=image_id)
示例#7
0
 def test_get_ipv4_api_servers(self):
     self.flags(glance_api_servers=["10.0.1.1:9292", "https://10.0.0.1:9293", "http://10.0.2.2:9294"])
     glance_host = ["10.0.1.1", "10.0.0.1", "10.0.2.2"]
     api_servers = glance.get_api_servers()
     i = 0
     for server in api_servers:
         i += 1
         self.assertIn(server[0], glance_host)
         if i > 2:
             break
示例#8
0
文件: glance.py 项目: wingo1990/nova
    def _call_glance_plugin(self, session, fn, params):
        glance_api_servers = glance.get_api_servers()

        def pick_glance(kwargs):
            g_host, g_port, g_use_ssl = glance_api_servers.next()
            kwargs['glance_host'] = g_host
            kwargs['glance_port'] = g_port
            kwargs['glance_use_ssl'] = g_use_ssl

        return session.call_plugin_serialized_with_retry(
            'glance', fn, CONF.glance_num_retries, pick_glance, **params)
示例#9
0
文件: glance.py 项目: ammonite/nova
    def _call_glance_plugin(self, session, fn, params):
        glance_api_servers = glance.get_api_servers()

        def pick_glance(kwargs):
            g_host, g_port, g_use_ssl = glance_api_servers.next()
            kwargs['glance_host'] = g_host
            kwargs['glance_port'] = g_port
            kwargs['glance_use_ssl'] = g_use_ssl

        return session.call_plugin_serialized_with_retry(
            'glance', fn, CONF.glance_num_retries, pick_glance, **params)
示例#10
0
 def test_get_ipv4_api_servers(self):
     self.flags(glance_api_servers=[
         '10.0.1.1:9292', 'https://10.0.0.1:9293', 'http://10.0.2.2:9294'
     ])
     glance_host = ['10.0.1.1', '10.0.0.1', '10.0.2.2']
     api_servers = glance.get_api_servers()
     i = 0
     for server in api_servers:
         i += 1
         self.assertIn(server[0], glance_host)
         if i > 2:
             break
示例#11
0
 def test_get_ipv6_api_servers(self):
     self.flags(glance_api_servers=['[2001:2012:1:f101::1]:9292',
                           'https://[2010:2013:1:f122::1]:9293',
                           'http://[2001:2011:1:f111::1]:9294'])
     glance_host = ['2001:2012:1:f101::1', '2010:2013:1:f122::1',
                     '2001:2011:1:f111::1']
     api_servers = glance.get_api_servers()
     i = 0
     for server in api_servers:
         i += 1
         self.assertIn(server[0], glance_host)
         if i > 2:
             break
示例#12
0
 def test_get_ipv4_api_servers(self):
     self.flags(api_servers=['10.0.1.1:9292',
                             'https://10.0.0.1:9293',
                             'http://10.0.2.2:9294'], group='glance')
     glance_host = ['10.0.1.1', '10.0.0.1',
                     '10.0.2.2']
     api_servers = glance.get_api_servers()
     i = 0
     for server in api_servers:
         i += 1
         self.assertIn(server[0], glance_host)
         if i > 2:
             break
示例#13
0
文件: test_glance.py 项目: tomzo/nova
 def test_get_ipv6_api_servers(self):
     self.flags(
         api_servers=[
             "[2001:2012:1:f101::1]:9292",
             "https://[2010:2013:1:f122::1]:9293",
             "http://[2001:2011:1:f111::1]:9294",
         ],
         group="glance",
     )
     glance_host = ["2001:2012:1:f101::1", "2010:2013:1:f122::1", "2001:2011:1:f111::1"]
     api_servers = glance.get_api_servers()
     i = 0
     for server in api_servers:
         i += 1
         self.assertIn(server[0], glance_host)
         if i > 2:
             break
def send_request(image_id, auth_token, operation, config_strategy_data={}):
    """This method will build a request to be sent to Glance
       for adding metadata to an image

    :param image_id: id of the new image or snapshot
    :param auth_token: authentication token for update
    :param operation: Operation to send in the request. Operations supported
        are add, replace, and remove
    :param config_strategy_data: metadata to be added to the image
    """
    # Grab the Glance host information to build the connection
    api_servers = glance.get_api_servers()
    glance_host = api_servers.next()
    conn = httplib.HTTPConnection(glance_host[0], glance_host[1])

    resource_path = '/v2/images/%s' % image_id

    headers = {
            'X-Auth-Token': auth_token,
            'Content-Type': 'application/openstack-images-v2.0-json-patch'
        }

    # Here we are creating a new dictionary with the operation that
    # we plan to take on the new image/snapshot and the
    # configuration strategy data that was pulled from the Glance database
    # of the image that we are snapshotting from. This is an internal fix
    # that will be removed when the python-glanceclient V2 API work is done.
    data = {}
    data[operation] = '/configuration_strategy'
    if operation != 'remove':
        data['value'] = config_strategy_data

    # Package the dictionary as an array and dump it to a string. We are
    # putting this in an array as a requirement for PATCH.
    data_str = json.dumps([data])

    # Build the request
    conn.request('PATCH', resource_path, body=data_str, headers=headers)
    resp = conn.getresponse()

    if 200 <= resp.status < 300:
        pass
    else:
        # We need to inform the user the transfer failed
        raise exception.InvalidRequest()
示例#15
0
    def _call_glance_plugin(self, context, instance, session, fn, params):
        glance_api_servers = glance.get_api_servers()

        def pick_glance(kwargs):
            server = next(glance_api_servers)
            kwargs['endpoint'] = server.url
            # NOTE(sdague): is the return significant here at all?
            return server.host

        def retry_cb(context, instance, exc=None):
            if exc:
                exc_info = sys.exc_info()
                LOG.debug(six.text_type(exc), exc_info=exc_info)
                compute_utils.add_instance_fault_from_exc(
                    context, instance, exc, exc_info)

        cb = functools.partial(retry_cb, context, instance)

        return session.call_plugin_serialized_with_retry(
            'glance', fn, CONF.glance.num_retries, pick_glance, cb, **params)
    def _call_glance_plugin(self, context, instance, session, fn, params):
        glance_api_servers = glance.get_api_servers()

        def pick_glance(kwargs):
            server = next(glance_api_servers)
            kwargs['endpoint'] = server
            # NOTE(sdague): is the return significant here at all?
            return server

        def retry_cb(context, instance, exc=None):
            if exc:
                exc_info = sys.exc_info()
                LOG.debug(six.text_type(exc), exc_info=exc_info)
                compute_utils.add_instance_fault_from_exc(
                    context, instance, exc, exc_info)

        cb = functools.partial(retry_cb, context, instance)

        return session.call_plugin_serialized_with_retry(
            'glance', fn, CONF.glance.num_retries, pick_glance, cb, **params)
示例#17
0
    def _call_glance_plugin(self, context, instance, session, fn, params):
        glance_api_servers = glance.get_api_servers()

        def pick_glance(kwargs):
            g_host, g_port, g_use_ssl = next(glance_api_servers)
            kwargs['glance_host'] = g_host
            kwargs['glance_port'] = g_port
            kwargs['glance_use_ssl'] = g_use_ssl
            return g_host

        def retry_cb(context, instance, exc=None):
            if exc:
                exc_info = sys.exc_info()
                LOG.debug(exc.message, exc_info=exc_info)
                compute_utils.add_instance_fault_from_exc(
                    context, instance, exc, exc_info)

        cb = functools.partial(retry_cb, context, instance)

        return session.call_plugin_serialized_with_retry(
            'glance', fn, CONF.glance.num_retries, pick_glance, cb, **params)
示例#18
0
文件: glance.py 项目: arbrandes/nova
    def _call_glance_plugin(self, context, instance, session, fn, image_id,
                            params):
        glance_api_servers = glance.get_api_servers(context)
        sr_path = vm_utils.get_sr_path(session)
        extra_headers = glance.generate_identity_headers(context)

        def pick_glance(kwargs):
            server = next(glance_api_servers)
            kwargs['endpoint'] = server
            kwargs['api_version'] = 2
            # NOTE(sdague): is the return significant here at all?
            return server

        def retry_cb(context, instance, exc=None):
            if exc:
                exc_info = sys.exc_info()
                LOG.debug(six.text_type(exc), exc_info=exc_info)
                compute_utils.add_instance_fault_from_exc(
                    context, instance, exc, exc_info)

        cb = functools.partial(retry_cb, context, instance)

        return fn(session, CONF.glance.num_retries, pick_glance, cb, image_id,
                  sr_path, extra_headers, **params)
示例#19
0
文件: glance.py 项目: tuitang00/nova
    def _call_glance_plugin(self, context, instance, session, fn, image_id,
                            params):
        glance_api_servers = glance.get_api_servers()
        sr_path = vm_utils.get_sr_path(session)
        extra_headers = glance.generate_identity_headers(context)

        def pick_glance(kwargs):
            server = next(glance_api_servers)
            kwargs['endpoint'] = server
            kwargs['api_version'] = 2
            # NOTE(sdague): is the return significant here at all?
            return server

        def retry_cb(context, instance, exc=None):
            if exc:
                exc_info = sys.exc_info()
                LOG.debug(six.text_type(exc), exc_info=exc_info)
                compute_utils.add_instance_fault_from_exc(
                    context, instance, exc, exc_info)

        cb = functools.partial(retry_cb, context, instance)

        return fn(session, CONF.glance.num_retries, pick_glance, cb, image_id,
                  sr_path, extra_headers, **params)