def glance_obj(self): """ GlanceClient object """ if self._glance_obj: return self._glance_obj url = self._get_url(self.url, self.port, self.version) return GlanceClient(endpoint=url, token=self.token)
def create_glance_client(host_ip): """ 创建glance客户端 """ if host_ip in _GLANCE_CLIENT_MAP: return _GLANCE_CLIENT_MAP[host_ip] rc_data = get_rc(host_ip) client = GlanceClient(session=get_session(host_ip), endpoint_override=rc_data.glance_url) _GLANCE_CLIENT_MAP[host_ip] = client return client
def __init__(self, controller_ip, user='******', password='******', tenant='admin', cert=None, env=None, proxy_session=None): logger.debug('Init OpenStack clients on {0}'.format(controller_ip)) self.controller_ip = controller_ip self.username = user self.password = password self.tenant = tenant if cert is None: auth_url = 'http://{0}:5000/v2.0/'.format(self.controller_ip) self.path_to_cert = None self.insecure = True else: auth_url = 'https://{0}:5000/v2.0/'.format(self.controller_ip) with gen_temp_file(prefix="fuel_cert_", suffix=".pem") as f: f.write(cert) self.path_to_cert = f.name self.insecure = False logger.debug('Auth URL is {0}'.format(auth_url)) auth = KeystonePassword(username=user, password=password, auth_url=auth_url, tenant_name=tenant) self.session = session.Session(auth=auth, verify=self.path_to_cert) self.keystone = KeystoneClient(session=self.session) self.keystone.management_url = auth_url self.nova = nova_client.Client(version=2, session=self.session) self.cinder = cinderclient.Client(version=2, session=self.session) self.neutron = neutron_client.Client(session=self.session) self.glance = GlanceClient(session=self.session) endpoint_url = self.session.get_endpoint(service_type='orchestration', endpoint_type='publicURL') token = self.session.get_token() self.heat = HeatClient(endpoint=endpoint_url, token=token) self.env = env
def get_stats(self): """Retrieves stats from glance""" keystone = self.get_keystone() data = { self.prefix: {} } glance_endpoint = keystone.service_catalog.url_for(service_type='image') tenant_list = keystone.tenants.list() client = GlanceClient(glance_endpoint, token=keystone.auth_token) for tenant in tenant_list: data[self.prefix]["tenant-%s" % tenant.name] = { 'images': {} } data_tenant = data[self.prefix]["tenant-%s" % tenant.name] data_tenant['images']['count'] = 0 data_tenant['images']['bytes'] = 0 image_list = client.images.list(filters={'owner': tenant.id}) for image in image_list: data_tenant['images']['count'] += 1 data_tenant['images']['bytes'] += int(image['size']) if image['size'] else 0 return data
def init_session(): """Initialization of keystone session, glance, nova and neutron clients. Returns: tuple: glance_client, nova_client, neutron_client """ AUTH_URL = os.environ.get('OS_AUTH_URL') if not AUTH_URL: print("AUTH_URL must be set") sys.exit(1) PROJECT_DOMAIN_NAME = os.environ.get('OS_PROJECT_DOMAIN_NAME', 'default') USER_DOMAIN_NAME = os.environ.get('OS_USER_DOMAIN_NAME', 'default') PROJECT_NAME = os.environ.get('OS_PROJECT_NAME', 'admin') USERNAME = os.environ.get('OS_USERNAME', 'admin') PASSWORD = os.environ.get('OS_PASSWORD', 'password') auth = identity.v3.Password(auth_url=AUTH_URL, username=USERNAME, user_domain_name=USER_DOMAIN_NAME, password=PASSWORD, project_name=PROJECT_NAME, project_domain_name=PROJECT_DOMAIN_NAME) session = _session.Session(auth=auth) glance_client = GlanceClient(session=session) images = list(glance_client.images.list()) if not images: print("At least one image must exist") sys.exit(1) nova_client = NovaClient(version=2, session=session) neutron_client = NeutronClient(session=session, project_name=session.get_project_id()) return glance_client, nova_client, neutron_client
def glance(self): if not self._glance_client: endpoints = self.keystone.service_catalog.get_endpoints() endpoint = endpoints['image'][0]['publicURL'] self._glance_client = GlanceClient(endpoint, **self.credentials) return self._glance_client