예제 #1
0
    def delete_appliances(self):
        """Remove all appliances marked as DISABLED.

        :return: True if the cleaning was successfull
        :rtype: bool
        """
        LOG.info("Cleaning up appliances")
        glance = glanceclient.Client(session=self.connect())
        try:
            img_generator = glance.images.list()
            image_list = list(img_generator)
        except Exception as err:
            LOG.error("Could not retrieve the image list for "
                      "the backend '%s'" % self.cloud_id)
            LOG.exception(err)
            return False

        is_deleted = True
        for image in image_list:
            if image.get('IK_STATUS') == 'DISABLED':
                try:
                    LOG.debug("Deleting image '%s'" % image['id'])
                    glance.images.delete(image['id'])
                    LOG.debug(
                        "Image '%s' successfully deleted" % image['id']
                    )
                except Exception as err:
                    LOG.error(
                        "Image '%s' cannot be deleted" % image['id']
                    )
                    LOG.error(err)
                    is_deleted = False
        return is_deleted
예제 #2
0
def get_glanceclient():
    session = _get_session()

    return glance.Client(
        session=session,
        region_name=os.environ.get('OS_REGION_NAME')
    )
예제 #3
0
def get_glance(funname, auth_info, ver='v2'):
    import glanceclient.v1.client as glanceclient1
    import glanceclient.v2.client as glanceclient2
    keystone = auth_info["keystone"]
    cacert = auth_info["cacert"]
    clientcert = auth_info["clientcert"]
    clientkey = auth_info["clientkey"]
    insecure = auth_info["insecure"]
    glance_endpoint = keystone.service_catalog.url_for(service_type='image')
    logger.info(
        "[%s]call glanceclient.Client('%s',token='%s',insecure=%s,cert_file='%s',key_file='%s',cacert='%s')"
        % (funname, glance_endpoint, keystone.auth_token, insecure, clientcert,
           clientkey, cacert))
    if 'v1' == ver:
        logger.info("return glanceclient1")
        return glanceclient1.Client(glance_endpoint,
                                    token=keystone.auth_token,
                                    insecure=insecure,
                                    cert_file=clientcert,
                                    key_file=clientkey,
                                    cacert=cacert)
    else:
        logger.info("return glanceclient2")
        return glanceclient2.Client(glance_endpoint,
                                    token=keystone.auth_token,
                                    insecure=insecure,
                                    cert_file=clientcert,
                                    key_file=clientkey,
                                    cacert=cacert)
예제 #4
0
    def __init__(self,
                 username=None,
                 password=None,
                 tenant_name=None,
                 auth_url=None):
        """
        Initialize openstack util

        :param username: keystone username
        :type  username: string
        :param password: keystone password
        :type  password: string
        :param tenant_name: keystone tenant name
        :type  tenant_name: string
        :param auth_url: keystone authentication URL
        :type  auth_url: string
        """

        keystone_auth_args = {
            'username': username,
            'password': password,
            'tenant_name': tenant_name,
            'auth_url': auth_url
        }
        _logger.info(
            "obtaining keystone token for user %s, tenant %s against auth url %s"
            % (username, tenant_name, auth_url))
        keystone_client = ksclient.Client(**keystone_auth_args)
        glance_endpoint = keystone_client.service_catalog.url_for(
            service_type='image', endpoint_type='publicURL')
        _logger.info("image endpoint from service catalog is %s" %
                     glance_endpoint)
        self.glance_client = glclient.Client(glance_endpoint,
                                             token=keystone_client.auth_token)
예제 #5
0
    def deprecate_appliance(self, appliance_id):
        """Mark an appliance in glance as deprecated.

        :param appliance_id: the id of the appliance
        :type appliance_id: str
        :return: True if the appliance has been successfully marked
        :rtype: bool
        """
        LOG.info("Marking appliance '%s' as deprecated" % appliance_id)
        try:
            glance = glanceclient.Client(session=self.connect())

            glance_images = utils.find_images(glance, appliance_id)
            if not glance_images:
                LOG.error(
                    "Cannot mark image for removal: image '%s' "
                    "not found" % appliance_id
                )
                return False
        except Exception as err:
            LOG.error("Cannot set the appliance '%s' as deprecated "
                      " for the backend '%s'" % (appliance_id, self.cloud_id))
            LOG.exception(err)
            raise exception.UnknownError(err)
        properties = {'IK_STATUS': 'DISABLED'}
        for image in glance_images:
            LOG.debug("Marking image for removal: '%s'" % image.id)
            glance.images.update(image.id, visibility='private', **properties)
        return True
예제 #6
0
def authenticate():
    """
    This function returns authenticated nova and glance objects
    """
    try:
        keystone = ksclient.Client(auth_url=environ.get('OS_AUTH_URL'),
                                   username=environ.get('OS_USERNAME'),
                                   password=environ.get('OS_PASSWORD'),
                                   tenant_name=environ.get('OS_TENANT_NAME'),
                                   region_name=environ.get('OS_REGION_NAME'))
        nova = nvclient.Client("2",
                               auth_url=environ.get('OS_AUTH_URL'),
                               username=environ.get('OS_USERNAME'),
                               api_key=environ.get('OS_PASSWORD'),
                               project_id=environ.get('OS_TENANT_NAME'),
                               region_name=environ.get('OS_REGION_NAME'))
    except:
        print(
            'Sourcing openstack environment variabels failed, please check that the environment variables are set correctly.'
        )
        sys.exit(2)

    glance_endpoint = keystone.service_catalog.url_for(service_type='image')
    glance = glclient.Client(glance_endpoint, token=keystone.auth_token)

    return nova, glance
예제 #7
0
 def _reload_connection(self):
     '''Called before any operation, it check if credentials has changed
     Throw keystoneclient.apiclient.exceptions.AuthorizationFailure
     '''
     #TODO control the timing and possible token timeout, but it seams that python client does this task for us :-)
     if self.reload_client:
         #test valid params
         if len(self.n_creds) < 4:
             raise ksExceptions.ClientException(
                 "Not enough parameters to connect to openstack")
         self.nova = nClient.Client(2, **self.n_creds)
         self.keystone = ksClient.Client(**self.k_creds)
         self.glance_endpoint = self.keystone.service_catalog.url_for(
             service_type='image', endpoint_type='publicURL')
         self.glance = glClient.Client(
             self.glance_endpoint,
             token=self.keystone.auth_token,
             **self.k_creds)  #TODO check k_creds vs n_creds
         self.ne_endpoint = self.keystone.service_catalog.url_for(
             service_type='network', endpoint_type='publicURL')
         self.neutron = neClient.Client('2.0',
                                        endpoint_url=self.ne_endpoint,
                                        token=self.keystone.auth_token,
                                        **self.k_creds)
         self.reload_client = False
예제 #8
0
    def get_image_client(self):
        ctx = context.ctx()

        glance_endpoint = keystone_utils.get_endpoint_for_project('glance')
        return glanceclient.Client(glance_endpoint.url,
                                   token=ctx.auth_token,
                                   region_name=glance_endpoint.region)
예제 #9
0
 def get_image_client(self, context):
     security_ctx = context.security
     glance_endpoint = keystone_utils.get_endpoint_for_project(
         security_ctx, 'glance')
     return glanceclient.Client(glance_endpoint.url,
                                token=security_ctx.auth_token,
                                region_name=glance_endpoint.region)
예제 #10
0
 def glance(self, region):
     """Get Glance client for the region."""
     if region not in self._glance:
         # Glance client lazy initialisation
         _glance = glance_client.Client(session=self._auth_session,
                                        region_name=region)
         self._glance[region] = _glance
     return self._glance[region]
예제 #11
0
 def _connect_glance(self):
     if self._glance_connection_tried:
         return
     self._glance_connection_tried = True
     glance_endpoint = self._keystone.service_catalog.url_for(
         service_type='image')
     self._glance = glanceclient.Client(glance_endpoint,
                                        token=self._keystone.auth_token)
     self.logger.info('glance connected')
예제 #12
0
 def __init__(self, keystone_instance):
     """
     Find the image endpoint
     """
     glance_endpoint = keystone_instance.keystone_endpoint_find(
         service_type='image')
     self.glanceclient = glance_client.Client(
         glance_endpoint,
         token=keystone_instance.keystone_return_authtoken())
예제 #13
0
def glance_client():
    glance_log = logging.getLogger("glanceclient.common.http")
    glance_log.setLevel(logging.WARNING)
    keystone = keystone_client()
    glance_endpoint = keystone.service_catalog.url_for(service_type='image')
    return glclient.Client(
        glance_endpoint,
        token=keystone.auth_token
    )
예제 #14
0
 def __init__(self, name='', args=None):
     super(GlanceV2Driver, self).__init__(name, args=args)
     datasource_driver.ExecutionDriver.__init__(self)
     self.creds = args
     session = ds_utils.get_keystone_session(self.creds)
     self.glance = glclient.Client(session=session)
     self.add_executable_client_methods(self.glance, 'glanceclient.v2.')
     self.initialize_update_methods()
     self._init_end_start_poll()
예제 #15
0
    def __init__(self, name='', keys='', inbox=None, datapath=None, args=None):
        super(GlanceV2Driver, self).__init__(name, keys, inbox, datapath, args)
        self.creds = args

        keystone = ksclient.Client(**self.creds)
        glance_endpoint = keystone.service_catalog.url_for(
            service_type='image', endpoint_type='publicURL')
        self.glance = glclient.Client(glance_endpoint,
                                      token=keystone.auth_token)
        self.initialized = True
예제 #16
0
 def __init__(self, creds):
     endpoint = None
     if 'endpoint_type' in creds:
         del creds['endpoint_type']
     if 'session' in creds:
         endpoint = creds['session'].get_endpoint(service_type='image',
                                                  interface='internal')
     self.glanceclient = glance_client.Client('2',
                                              endpoint_override=endpoint,
                                              **creds)
예제 #17
0
def get_glance_client(project_name, domain_name):
    """Get a glance client"""
    LOG.debug("Get a glance client for the project: '%s'" % project_name)

    endpoint_type = CONF.endpoint_type
    try:
        sess = get_session(project_name=project_name, domain_name=domain_name)
        if endpoint_type:
            LOG.debug("Glance client is accessing Glance through the "
                      "following endpoint type: %s" % endpoint_type)
            glance_client = glanceclient.Client(session=sess,
                                                interface=endpoint_type)
        else:
            glance_client = glanceclient.Client(session=sess)
    except webob.exc.HTTPForbidden as err:
        LOG.error("Connection to Glance failed.")
        LOG.exception(err)
        return None
    return glance_client
예제 #18
0
    def login(self, tenant_name, username, password, auth_url):
        keystone = keystone_client.Client(tenant_name=tenant_name,
                                          username=username,
                                          password=password,
                                          auth_url=auth_url)

        glance_endpoint = keystone.service_catalog.url_for(
            service_type='image', endpoint_type='publicURL')
        self._glance = glance_client.Client(glance_endpoint,
                                            token=keystone.auth_token)
예제 #19
0
파일: base.py 프로젝트: vutuong/tacker
 def glanceclient(cls):
     vim_params = cls.get_credentials()
     auth = v3.Password(auth_url=vim_params['auth_url'],
         username=vim_params['username'],
         password=vim_params['password'],
         project_name=vim_params['project_name'],
         user_domain_name=vim_params['user_domain_name'],
         project_domain_name=vim_params['project_domain_name'])
     verify = 'True' == vim_params.pop('cert_verify', 'False')
     auth_ses = session.Session(auth=auth, verify=verify)
     return glance_client.Client(session=auth_ses)
예제 #20
0
def get_glance_client():
    global __glance_client
    if not __glance_client:
        keystone = get_keystone_client()
        glance_endpoint = keystone.service_catalog.url_for(service_type='image')

        __glance_client = glanceclient.Client(
            glance_endpoint, token=keystone.auth_token
        )

    return __glance_client
예제 #21
0
def glanceList():
    print "glance image-list"
    credentials = auth.get_credentials()
    keystone = ksclient.Client(**credentials)
    token = keystone.auth_token

    print "auth_token = " + token

    glance_endpoint = keystone.service_catalog.url_for(service_type='image')
    glance = glclient.Client(glance_endpoint, token=token)

    images = glance.images.list()
    print list(images)
예제 #22
0
def glance_client():
    var = getattr(localdata, 'glance_client', None)
    if var is None:
        keystone = ksclient.Client(
            auth_url=conf.openstack_api['keystone_url'],
            username=conf.openstack_api['user'],
            password=conf.openstack_api['password'],
            tenant_name=conf.openstack_api['tenant_name'])
        glance_endpoint = keystone.service_catalog.url_for(
            service_type='image')
        var = glclient.Client(glance_endpoint, token=keystone.auth_token)
        setattr(localdata, 'glance_client', var)
    return var
예제 #23
0
def check_test_ok(env_id):

    auth_token = get_auth_token()
    headers = {
        'Content-type': 'application/json',
        'Accept': 'application/json',
        'X-Auth-Token': auth_token
    }

    app_id = ""

    #resp_app = requests.get('http://'+ip+':8082/v1//environments/'+env_id+'/services/'+app_id,headers=headers)

    #resp_app = requests.get('http://'+ip+':8082/v1/images/detail',headers=headers)
    #print

    #resp_app = resp_app.json()

    #v1/images/detail

    #from muranoclient.glance import client as gl_client

    #gl_client.Client(endpoint=endpoint, type_name ="" , type_version="")

    #auth_token = get_auth_token()
    #initializing MuranoClient
    #mc = v1_client.Client(endpoint=endpoint, token= auth_token,timeout = 60)
    #mc.environmen

    #print resp_app.__dict__

    keystone = ksclient.Client(auth_url="http://" + ip + ":35357/v2.0",
                               username=username,
                               password=password,
                               tenant_name=tenantname)

    import glanceclient.v2.client as glclient

    glance_endpoint = keystone.service_catalog.url_for(
        service_type='image', endpoint_type='publicURL')

    print glance_endpoint

    glance = glclient.Client(endpoint, token=keystone.auth_token)

    images = glance.images.list()

    print images.next()
    #return keystone.auth_token

    return images
예제 #24
0
    def _get_glance_client(version, is_api):
        if version == '1':
            if is_api:
                return api_clients.ApiClientV1(session=get_session())
            else:
                return client_v1.Client(session=get_session())

        if version == '2':
            if is_api:
                return api_clients.ApiClientV2(session=get_session())
            else:
                return client_v2.Client(session=get_session())

        raise ValueError("Unexpected glance version: {!r}".format(version))
def glanceAuthentication():
    keystone = ksclient.Client(auth_url=env['OS_AUTH_URL'],
                               username=env['OS_USERNAME'],
                               password=env['OS_PASSWORD'],
                               tenant_name=env['OS_TENANT_NAME'],
                               region_name=env['OS_REGION_NAME'])
    glance_endpoint = keystone.service_catalog.url_for(service_type='image')
    glance = glclient.Client(glance_endpoint, token=keystone.auth_token)
    return glance


###tests
#var=keystoneAuthentication()
#var=glanceAuthentication()
예제 #26
0
    def __init__(self):
        self.creds = Credentials()
        self.auth = v3.Password(
            auth_url=self.creds.osp_auth_url,
            project_id=self.creds.osp_project_id,
            project_name=self.creds.osp_project_name,
            user_domain_name=self.creds.osp_user_domain_name,
            project_domain_id=self.creds.osp_project_domain_id,
            username=self.creds.osp_username,
            password=self.creds.osp_password)

        self.session = session.Session(auth=self.auth)
        self.nova = Client('2', session=self.session)
        self.glance = glclient.Client('2', session=self.session)
예제 #27
0
    def get_image_list(self, properties=None):
        """Return the list of images.

        :param properties: a list of properties to use for filtering
        :type properties: dict
        :return: a list of appliances
        :rtype: list
        """
        glance = glanceclient.Client(session=self.connect())
        try:
            img_generator = glance.images.list()
            image_list = list(img_generator)
        except Exception as err:
            raise exception.UnknownError(err)
        return image_list
예제 #28
0
파일: auth.py 프로젝트: CCI-MOC/ui
def loginTenant(username, password, tenantName, auth_url):
    """
	Create keystone, nova, and glance clients for tenant; on tenant selection
	"""
    keystone = ksclient.Client(auth_url='http://%s:5000/v2.0' % auth_url,
                               username=username,
                               password=password,
                               tenant_name=tenantName)
    nova = nvclient.Client(auth_url='http://%s:5000/v2.0' % auth_url,
                           username=username,
                           api_key=password,
                           project_id=tenantName)
    glance_endpoint = keystone.service_catalog.url_for(service_type='image')
    glance = glclient.Client(glance_endpoint, token=keystone.auth_token)
    return keystone, nova, glance
예제 #29
0
 def get_glance_client(self):
     """
     glance_client.images
     glance_client.image_tags
     glance_clientimage_members
     glance_client.tasks
     glance_client.metadefs_resource_type
     glance_client.metadefs_property
     glance_client.metadefs_object
     glance_client.metadefs_tag
     glance_client.metadefs_namespace
     """
     session = self._get_session_for_service()
     glance_client = glance.Client(session=session)
     return glance_client
예제 #30
0
    def add_appliance(self, appliance):
        """Add an appliance.

        :param appliance: an appliance to add to Glance
        :type appliance: dict
        :return: True if the appliance could be added successfully
        :rtype: bool
        """
        glance = glanceclient.Client(session=self.connect())
        LOG.info('Adding appliance: ' + appliance['title'])
        filename = appliance['location']
        image_format = appliance['format']
        image_properties = {}
        min_ram = 0
        if appliance.min_ram:
            min_ram = appliance.min_ram
        if CONF.min_ram > min_ram:
            min_ram = CONF.min_ram
        try:
            image_data = open(filename, 'rb')
        except IOError as err:
            LOG.error("Cannot open image file: '%s'" % filename)
            LOG.exception(err)
            return False

        image_properties['IK_STATUS'] = 'ENABLED'

        LOG.debug(
            "Creating image '%s' (format: '%s', "
            "properties %s)" % (appliance.title,
                                str.lower(image_format),
                                image_properties)
        )

        glance_image = glance.images.create(
            name=appliance['title'],
            disk_format=str.lower(image_format),
            container_format="bare",
            visibility=CONF.image_visibility,
        )
        glance.images.upload(glance_image.id, image_data)
        glance.images.update(glance_image.id, **image_properties)
        if (min_ram > 0):
            glance.images.update(glance_image.id, min_ram=min_ram)

        image_data.close()

        return True