Beispiel #1
0
def config_image(config_parser, p_vip, user_name, password, tenant_name):
    # Get the default image.
    session = get_session(p_vip=p_vip,
                          username=user_name,
                          password=password,
                          project_name=tenant_name,
                          domain_name=DEFAULT_DOMAIN_ID)
    glance = GlanceClient(version='2', session=session)
    count = 0
    default_image = None
    alt_image = None
    for image in glance.images.list():
        count += 1
        if image.name == IMAGE_NAME_4_1:
            default_image = image
        else:
            alt_image = image
    if count == 0:
        raise NotSupportedError('At least 1 image in glance is required.')
    default_image = default_image or alt_image
    LOG.info('Use image %s as default image in tempest', default_image.name)
    alt_image = alt_image or default_image
    LOG.info('Use image %s as alter image in tempest', alt_image.name)
    config_parser.set('compute', 'image_ref', default_image.id)
    config_parser.set('compute', 'image_ref_alt', alt_image.id)
    config_parser.set('heat_plugin', 'image_ref', default_image.id)
    config_parser.set('heat_plugin', 'minimal_image_ref', default_image.id)
Beispiel #2
0
 def _init_glance_client(self):
     # To handle the token timeout issues
     # Default timeout is 1 hour
     # Re authenticate and get a new token
     self.ks_client.authenticate()
     glance_endpoint = self.ks_client.service_catalog.url_for(service_type='image', endpoint_type='publicURL')
     self.glance = GlanceClient('2', glance_endpoint, token=self.ks_client.auth_token)
Beispiel #3
0
 def __init__(self, **kwargs):
     """
     :param kwargs: *version = version of GlanceClient
     *region_name = region name of GlanceClient
     """
     super().__init__(**kwargs)
     self._connection = GlanceClient(version=kwargs['version'],
                                     session=self.authentication.session,
                                     region_name=self.region_name)
Beispiel #4
0
def image_name_to_id(host_vars, user, password, tenant, auth_url):
    auth = identity.Password(auth_url=auth_url, username=user,
                         password=password, tenant_name=tenant)
    sess = session.Session(auth=auth)
    token = auth.get_token(sess)
    endpoint = auth.get_endpoint(sess, service_name='glance', service_type='image')
    glance = GlanceClient('2', endpoint=endpoint, token=token)
    for i in glance.images.list():
        if i.name == host_vars:
          return i.id
    raise errors.AnsibleFilterError('There is no image of name {0} accessible for tenant {1}'.format(host_vars, tenant))
Beispiel #5
0
def image_id_to_name(host_vars, user, password, tenant, auth_url):
    auth = identity.Password(auth_url=auth_url, username=user,
                         password=password, tenant_name=tenant)
    sess = session.Session(auth=auth)
    token = auth.get_token(sess)
    endpoint = auth.get_endpoint(sess, service_name='glance', service_type='image')
    glance = GlanceClient('2', endpoint=endpoint, token=token)
    try:
          return glance.images.get(host_vars).name
    except glanceclient.exc.HTTPNotFound:
        raise errors.AnsibleFilterError('There is no image of id {0} accessible for tenant {1}'.format(host_vars, tenant))
Beispiel #6
0
    def rebuild_node(deploy, node):
        # type (redstack.domain.Deploy, redstack.domain.Node, int, int) -> bool
        """ 
        Rebuild an openstack node with Nova API binding.

        Use nova API to rebuild an Openstack node. Return bool indicating result of rebuild. The rebuild will
        be retried x amount of times before indicating total failure by returning False.

        :param deploy: Deploy object with deployment details
        :param node: Node object representing server to rebuild
        :raises: RebuildException if the node fails to rebuild correctly
        """
        sess = Openstack.create_ost_auth_session(deploy)
        nova = novaclient.Client("2", session=sess, region_name=deploy.region)
        glance = GlanceClient("2", session=sess, region_name=deploy.region)
        server = nova.servers.get(node.server_id)

        images = retry(
            glance.images.list, 5,
            (keystoneauth1_exceptions.connection.ConnectFailure, IndexError))

        image_id = None
        for image in images:
            if deploy.image_name == image.name:
                image_id = image.id

        if image_id:
            retry(server.rebuild, 5,
                  (keystoneauth1_exceptions.connection.ConnectFailure,
                   IndexError), image_id)
        else:
            raise ConfigException(
                "Could not find image {0} to rebuild with".format(
                    deploy.image_name))

        server = nova.servers.get(node.server_id)

        start = time.time()
        while server.status != 'REBUILD':
            server = nova.servers.get(node.server_id)

            # Fail if the node never responds
            if time.time() - start > 480:
                raise RebuildException(
                    "Instance failed to respond to request for rebuild")

        while server.status not in ["ACTIVE", "ERROR"]:
            server = nova.servers.get(node.server_id)

        if server.status == 'ACTIVE':
            return
        else:
            raise RebuildException(
                "Instance fell into ERROR state after rebuild")
Beispiel #7
0
def glance_client(api_session, region_name=None, version=None, interface=None):
    """
    :rtype: glanceclient.v2.client.Client
    """

    version = float(version or plugin_settings.IMAGE_API_VERSION)
    region_name = region_name or plugin_settings.DEFAULT_REGION
    interface = interface or plugin_settings.DEFAULT_INTERFACE
    return GlanceClient(version=version,
                        interface=interface,
                        session=api_session,
                        region_name=region_name)
def os_connect(os_creds: OSCreds, version: str = "2") -> OSConnection:
    loader = loading.get_plugin_loader('password')
    auth = loader.load_from_options(auth_url=os_creds.auth_url,
                                    username=os_creds.name,
                                    password=os_creds.passwd,
                                    project_id=os_creds.tenant)
    auth_sess = session.Session(auth=auth)

    glance = GlanceClient(version, session=auth_sess)
    nova = NovaClient(version, session=auth_sess)
    cinder = CinderClient(os_creds.name,
                          os_creds.passwd,
                          os_creds.tenant,
                          os_creds.auth_url,
                          insecure=os_creds.insecure,
                          api_version=version)
    return OSConnection(nova, cinder, glance)
Beispiel #9
0
    def drvCreateCloudClient(self, credentials):
        cloudConfig = self.getTargetConfiguration()
        server = cloudConfig['name']
        port = cloudConfig['nova_port']
        projectName = cloudConfig['project_name']
        try:
            session = KeystoneSession()

            def authenticate(self, **kwargs):
                secure = kwargs.pop('secure')
                authUrl = self._authUrl(server, port, secure=secure)
                keystoneCli = KeystoneClient(self.KEYSTONE_API_VERSION,
                                             tenant_name=projectName,
                                             auth_url=authUrl,
                                             username=credentials['username'],
                                             password=credentials['password'],
                                             session=session)
                auth = v2_auth.Password(keystoneCli.auth_url,
                                        username=credentials['username'],
                                        password=credentials['password'])
                session.auth = auth
                keystoneCli.authenticate()
                auth.auth_ref = keystoneCli.auth_ref

                return keystoneCli

            keystoneCli = self._secureToInsecureFallback(authenticate)
            novaCli = self.NovaClientClass(auth_token=keystoneCli.auth_token,
                                           project_id=projectName,
                                           auth_url=keystoneCli.auth_url,
                                           session=session)
            endpoint = session.get_endpoint(service_type="image")
            glanceCli = GlanceClient(self.GLANCE_CLIENT_VERSION,
                                     endpoint=endpoint,
                                     project_id=projectName,
                                     token=keystoneCli.auth_token,
                                     session=session)
            clients = ConsolidatedClient(keystoneCli, novaCli, glanceCli)
        except Exception, e:
            raise errors.PermissionDenied(
                message="Error initializing client: %s" % (e, ))
Beispiel #10
0
 def glance(self):
     if not self._glance:
         self._glance = GlanceClient(2, session=self.session)
     return self._glance
Beispiel #11
0
 def glance(self):
     endpoint = self.__make_endpoint(
         self._get_url_for_svc(service_type='image'))
     return GlanceClient(version='1',
                         session=self.keystone_session,
                         endpoint_override=endpoint)