def get_to_glance_client(self): auth_ref = self.get_to_auth_ref() token = auth_ref['token']['id'] endpoint_url = 'http://{ip}:9292/v1'.format(ip=self.to_auth_ip) glance = glance_client('1', endpoint=endpoint_url, token=token) return glance
def get_glance_session(): ''' Returns a glance client connection ''' glance_session = glance_client('2', session=get_keystone_sess()) return glance_session
def __init__(self, **args): """Init NovaInstance.""" self._wait_interval = args.pop('wait_interval', 1) self._keystone = keystone_client.Client(**args) glance_endpoint = self._keystone.service_catalog.url_for(service_type='image', endpoint_type='internalURL') neutron_endpoint = self._keystone.service_catalog.url_for(service_type='network', endpoint_type='internalURL') nova_endpoint = self._keystone.service_catalog.url_for(service_type='compute', endpoint_type='internalURL') self._neutron = neutron_client.Client(endpoint_url=neutron_endpoint, token=self._keystone.auth_token) self._glance = glance_client('2', glance_endpoint, token=self._keystone.auth_token) self.debug = args.pop('debug') if self.debug: LOG.setLevel(logging.DEBUG) self.ovs_data = args.pop('ovs_data') self.dhcp_logs = args.pop('dhcp_logs') self.dhcp_ping_test = args.pop('dhcp_ping_test') self.capture_tcpdump = args.pop('capture_tcpdump') self.show_console_log = args.pop('show_console_log') nova_args = deepcopy(args) self._nova = nova_client.Client('2', nova_args.pop('username'), nova_args.pop('password'), auth_token=self._keystone.auth_token, project_id=nova_args.pop('tenant_name'), **nova_args)
def get_server_info(sess, project_id): server_list = [] nova = nova_client.Client("2", session=sess) glance = glance_client("2", service_type="image", session=sess) servers = nova.servers.list(search_opts={"all_tenants": True}) for server in servers: if server.tenant_id != project_id: continue server_dict = {} server_dict["name"] = server.name server_dict["status"] = str(server.status) server_dict["created_date"] = str(parser.parse(server.created)) server_dict["id"] = server.id server_dict["networks"] = [] for network in server.addresses.keys(): network_dict = {"name": network, "addresses": []} for address in server.addresses[network]: network_dict["addresses"].append({ "addr": address["addr"], "type": address["OS-EXT-IPS:type"], }) server_dict["networks"].append(network_dict) image = glance.images.get(str(server.image["id"])) server_dict["image_name"] = str(image.name) server_dict["image_id"] = str(image.id) server_list.append(server_dict) return server_list
def main(): parser = argparse.ArgumentParser( description="Test RHOS components functionality") parser.add_argument("ticket_id", help="Maintenance ticket ID / Random string") args = parser.parse_args() try: open('overcloud_conf.ini', "r") if confparser.has_section('neutron'): operation = "Neutron: Validating 'overcloud_conf.ini'" neutron = neutron_client.Client(session=overcloud_auth()) val_overcloud_conf('neutron', operation, neutron) print("Neutron is true") val_neutron(args, neutron) if confparser.has_section('glance'): print("Glance is true") operation = "Glance: Validating 'overcloud_conf.ini'" glance = glance_client('2', session=overcloud_auth()) val_overcloud_conf('glance', operation, glance) val_glance(args, glance) if confparser.has_section('nova'): print("Nova is true") operation = "Nova: Validating 'overcloud_conf.ini'" nova = nova_client.Client('2', session=overcloud_auth()) neutron = neutron_client.Client(session=overcloud_auth()) glance = glance_client('2', session=overcloud_auth()) val_overcloud_conf('nova', operation, nova) timeout = task_timeout('nova') val_nova(args, nova, neutron, glance, timeout) if confparser.has_section('cinder'): print("Cinder is true") operation = "Cinder: Validating 'overcloud_conf.ini'" cinder = cinder_client.Client("2", session=overcloud_auth()) val_overcloud_conf('cinder', operation, cinder) timeout = task_timeout('cinder') val_cinder(args, cinder, timeout) except IOError: sys.exit( 'ERROR: Overcloud configuration file {}/overcloud_conf.ini does not exist' .format(os.getcwd())) except Exception as e: component.add_row([operation, "FAILED", str(e)]) print(component)
def get_from_glance_client(self): auth_ref = self.get_from_auth_ref() endpoint_url = '{ip}:{port}'.format(ip=self.from_auth_ip, port=self.from_glance_port) glance = glance_client('2', session=auth_ref.session, endpoint=endpoint_url) return glance
def __init__(self, username, password, tenant_name, auth_url): self.keystone = key_v2.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url) image_url = self.keystone.service_catalog.url_for(service_type='image') self.glance = glance_client('1', endpoint=image_url, token=self.keystone.auth_token) self.cinder = cinder_v1.Client(username, password, tenant_name, auth_url)
def get_to_glance_client(self): auth_ref = self.get_to_auth_ref() endpoint_url = '{ip}:{port}'.format( ip=self.to_auth_ip, port=self.to_glance_port, ) glance = glance_client('2', endpoint=endpoint_url, session=auth_ref.session) return glance
def main(): args = vars(parse_args()) args = get_env(args) extensions = open_shell()._discover_extensions("1.1") nova = nova_v1.Client(args['username'], args['password'], args['tenant_name'], args['auth_url'], extensions=extensions, cacert=args['ca_cert']) keystone = key_v2.Client(username=args['username'], password=args['password'], tenant_name=args['tenant_name'], auth_url=args['auth_url'], cacert=args['ca_cert'],) neutron = neutron_v2.Client(username=args['username'], password=args['password'], tenant_name=args['tenant_name'], auth_url=args['auth_url'], cacert=args['ca_cert'],) cinder = cinder_v1.Client(args['username'], args['password'], args['tenant_name'], args['auth_url'], cacert=args['ca_cert'],) swift = swiftclient.client.Connection(auth_version='2', user=args['username'], key=args['password'], tenant_name=args['tenant_name'], authurl=args['auth_url']) token = keystone.auth_token service_catalog = keystone.service_catalog catalog = service_catalog.catalog['serviceCatalog'] glance_ip = None for endpoint in catalog: if 'image' == endpoint['type']: glance_ip = endpoint['endpoints'][0]['publicURL'] glance = glance_client('1', endpoint=glance_ip, token=token) creds = keystone.ec2.list(keystone.user_id) if len(creds) == 0: keystone.ec2.create(keystone.user_id, keystone.tenant_id) creds = keystone.ec2.list(keystone.user_id) cred = creds[-1] s3_url = urlparse(keystone.service_catalog.url_for(service_type='object-store')) host, port = s3_url.netloc.split(':') s3 = boto.connect_s3(aws_access_key_id=cred.access, aws_secret_access_key=cred.secret, host=host, port=int(port), is_secure=False, calling_format=s3_connection.OrdinaryCallingFormat()) code.interact(local=locals())
def get_server_info(psess): server_list = [] nova = nova_client.Client('2', session=psess) glance = glance_client('2', service_type='image', session=psess) servers = nova.servers.list() for server in servers: server_dict = {} server_dict['name'] = server.name server_dict['status'] = str(server.status) server_dict['created_date'] = str(parser.parse(server.created)) server_dict['id'] = server.id image = glance.images.get(str(server.image['id'])) server_dict['image_name'] = str(image.name) server_dict['image_id'] = str(image.id) server_list.append(server_dict) return server_list
def get_server_info(psess, region): server_list=[] nova = nova_client.Client('2', session=psess,region_name=region) glance = glance_client('2', service_type='image', interface='publicURL', session=psess,region_name=region) servers = nova.servers.list() for server in servers: server_dict = {} server_dict['name'] = server.name server_dict['status'] = str(server.status) server_dict['created_date'] = str(parser.parse(server.created)) server_dict['id'] = server.id image = glance.images.get(str(server.image['id'])) server_dict['image_name'] = str(image.name) server_dict['image_id'] = str(image.id) server_list.append(server_dict) return server_list
def __init__(self, log_file=None): self.session = self._get_auth_session() self.nova = novaclient.Client(version=NOVA_VERSION, session=self.session) self.neutron = neutronclient.Client(session=self.session) self.glance = glance_client('2', session=self.session) self.heat = Heat_Client('1', session=self.session) images = self.glance.images.list() self.hypervisors = self.get_hypervisors() self.flavors = self.get_flavors() self.networks = self.get_networks() self.zones = self.nova.availability_zones.list() self.services = {} self.sfc_queue = [] self.finished = False self.log_file = log_file self.network_id = self.set_network('DARK-net', '192.168.0.0/16') if log_file is not None: logging.basicConfig(filename=self.log_file, level=logging.INFO)
def __reset_clients(self, username, password, tenant_name, auth_url): self.keystone = key_v2.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url) self.nova = nova_v1.Client(username, password, tenant_name, auth_url) self.cinder = cinder_v1.Client(username, password, tenant_name, auth_url) self.neutron = neutron_v2.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url) token = self.keystone.auth_token image_endpoint = self.keystone.service_catalog.url_for(service_type='image') self.glance = glance_client('1', endpoint=image_endpoint, token=token)
def glance_api(self): """Kết nối tới glance""" return glance_client('2', session=self.sess)
# This script creates an instance called "instance2" from keystoneclient.v2_0 import client as keystone_client from glanceclient import Client as glance_client from novaclient.v1_1 import client as nova_client keystone = keystone_client.Client(username='******', password='******', tenant_name='userj', auth_url='http://controller:35357/v2.0') endpoint = keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL') glance = glance_client('2', endpoint, token=keystone.auth_token) nova = nova_client.Client('userj', 'Password123', 'userj', 'http://controller:35357/v2.0') nova.servers.create(name='instance2', flavor=nova.flavors.find(name="m1.small"), image=nova.images.find(name="ubuntu-trusty-14.04"), nics=[{'net-id': '71ae39ba-28a0-4635-baa7-8bdc28dac1ea'}], key_name="demo-key")
#!/usr/bin/python # openstack example python-let: glance-image-list.py # # Author: JuanJo Ciarlante <*****@*****.**> # License: http://www.apache.org/licenses/LICENSE-2.0 # vim: si et sw=4 ts=4 import os from keystoneclient.v2_0 import client as keystone_client from glanceclient import Client as glance_client def get_creds(): # create a dictionary as e.g.: {'username': env['OS_USERNAME'], ... return {key: os.environ.get('OS_{}'.format(key.upper())) for key in ('auth_url', 'username', 'password', 'tenant_name', 'region_name')} creds = get_creds() keystone_cli = keystone_client.Client(**creds) ks_token = keystone_cli.auth_token ep_glance = keystone_cli.service_catalog.url_for(service_type='image') glance_cli = glance_client(1, endpoint=ep_glance, token=ks_token) # For each image, print its id and name for image in glance_cli.images.list(): print image.id, image.name
def get_image_list(self): glance = glance_client(version="2", session=self.session) images = glance.images.list() image_list = [image["name"] for image in images] return image_list
def glance_h(self): if not getattr(self, '_glance_h', None): self._glance_h = glance_client('2', session=self.session) return self._glance_h
def get_to_glance_client(self): auth_ref = self.get_to_auth_ref() endpoint_url = '{ip}:{port}'.format(ip=self.to_auth_ip, port=self.to_glance_port,) glance = glance_client('2', endpoint=endpoint_url, session=auth_ref.session) return glance