def __init__(self): self.kcreds = get_keystone_creds() self.keystone = ksclient.Client(**self.kcreds) self.ncreds = get_nova_creds() self.nova = novaclient.Client("1.1",**self.ncreds) self.glance_endpoint = self.keystone.service_catalog.url_for(service_type='image',endpoint_type='publicURL') self.glance = glanceclient.Client('1',self.glance_endpoint, token=self.keystone.auth_token)
def getHeat(): creds = get_keystone_creds() keystone = ksclient.Client(**creds) token = keystone.auth_token auth_token = token heat = Client('1', endpoint=heat_port(), token=auth_token) return heat
def create_instances(test_properties): # (sri) Add creation of test environment here default_name = "ubuntu" keystone_creds = credentials.get_keystone_creds() #Get images containing Ubuntu keystone = ksclient.Client(**keystone_creds) glance_endpoint = keystone.service_catalog.url_for( service_type='image', endpoint_type='publicURL') glance = glclient.Client(glance_endpoint, token=keystone.auth_token) ubuntu_images = [ img for img in glance.images.list() if default_name in img["name"]] #Create images nova_creds = credentials.get_nova_creds() nova = nvclient.Client(**nova_creds) for flavor_name, num_instances_of_flavor in test_properties["num_instances_of_flavor"].iteritems(): flavor = nova.flavors.find(name=flavor_name) created_instances = [ nova.servers.create(name=img["name"]+"_vm", image=img["id"], flavor=flavor, max_count=num_instances_of_flavor) for img in ubuntu_images ]
def __init__(self, image_name, image_path, vm_name, vm_ram, vm_disk, vm_vcpus): """ Constructor to create a Connection, an Image Instance and a VM Instance :param image_name: The name of the image to be created. :param image_path: The path of the image for creation. :param vm_name: The name of the virtual machine to create :param vm_ram: The ram size of the virtual machine. :param vm_disk: The disk size of the virtual machine. :param vm_vcpus: Number of CPU's required by the virtual machine. """ logging.basicConfig( filename='openstack.log', level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') try: cloud_adapter = Cloud_Attributes() logging.info('Establishing Connection.') # Connections with keystoneClient(identity API) -------------------- creds = get_keystone_creds() self.keystone = ksclient.Client(**creds) # Connections with novaClient(compute API) -------------------- creds = get_nova_creds() self.nova = nvclient.Client(**creds) except: logging.error('Invalid Credentials.') logging.critical('Connection Aborted.') raise # Creating IMAGE instance -------------------- try: logging.info('Creating Image Instance.') image = Image_Adapter(image_name, image_path) except: logging.error('Image not Created.') raise # Creating VM instance -------------------- try: logging.info('Creating Virtual Machine.') image_list = cloud_adapter.get_os_specific_image_list(image_name) image_details = image_list.get(image_name) image_id = image_details.get('Image_ID') instance = VM_Adapter(vm_name, image_id, vm_ram, vm_disk, vm_vcpus) except: logging.error('Virtual Machine not Created.') raise
def create_topology(): quantum_creds= get_keystone_creds() quantum = client.Client(**quantum_creds) nova_creds = get_nova_creds() nova = nvclient.Client(**nova_creds) network_object=network_subnet(quantum) network_object.Create_network() network_object.Create_subnet() #enter the nova code to boot instances security_grp_object=security_groups(quantum) security_grp_object.create_security_groups() security_grp_object.create_security_group_rules() load_balancer=Load_Balancer_floating_ip(mysets.network_id,mysets.subnet_mapping, mysets.ip_mapping, mysets.sec_id,quantum); load_balancer.Create_Loadbalancers()
def get_keystone_client(): kscreds = get_keystone_creds() from keystoneclient.v2_0 import Client as ks try: keystone = ks(**kscreds) except: e = sys.exc_info()[0] print('ERROR: %s' % e.message) raise if 'OS_TENANT_NAME' not in os.environ.keys(): os.environ['OS_TENANT_NAME'] = keystone.project_name if 'OS_TENANT_ID' not in os.environ.keys(): os.environ['OS_TENANT_ID'] = keystone.project_id return keystone
def get_glance(): """ get glance - create the glance object @ params none @ returns - glance object """ kscreds = get_keystone_creds() keystone = keystoneclient.v2_0.client.Client(**kscreds) auth_token = keystone.auth_token image_url = keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL') image_url = re.sub(r'/v2/$', '', image_url, flags=re.IGNORECASE) glance = Client('2', endpoint=image_url, token=auth_token) return glance
def get_heat(self): """ get_heat - return an instance of the heat client @requires - credentials.py @params: none @returns: instance of the heatclient.client.Client """ kscreds = get_keystone_creds() ks = ksclient(**kscreds) heat_url = ks.service_catalog.url_for(service_type='orchestration', endpoint_type='publicURL') auth_token = ks.auth_token heat = Client('1', endpoint=heat_url, token=auth_token) return heat
def get_images_list(): creds = get_keystone_creds() keystone = ksclient.Client(**creds) glance_endpoint = keystone.service_catalog.url_for(service_type='image', endpoint_type='public') glance = glclient.Client(glance_endpoint, token=keystone.auth_token) images = glance.images.list() detailed_list = list(images) images_name = [] for x in detailed_list: if (x["status"] == "active" and x["visibility"] == "public"): images_name.append([x["name"], x["id"]]) images_name.sort() return images_name
def get_servers(host): creds = get_keystone_creds() auth = identity.v3.Password(**creds) sess = session.Session(auth=auth) nova = client.Client('2',session=sess) servers = {} for server in nova.servers.list(): try: if server.to_dict()['OS-EXT-SRV-ATTR:host'] == host: # NOTE: network name should not be statically assigned servers[server.to_dict()['addresses']['external-flat'][0]['addr']] = server.name except Exception as e: print 'problem with getting info for server: ' + str(server.to_dict()['id']) print str(e) pass return servers
def __init__(self): #del os.environ['OS_TENANT_NAME'] # test for env var not set _creds = get_keystone_creds() self.my_tenant_name = os.environ.get('OS_TENANT_NAME') try: self.keystone = ksclient.Client(**_creds) except Exception as e: print "keystone could not auth with vars: ",creds print "client error:" ,e sys.exit(1) tenants = self.keystone.tenants.list() # return value: tenants_data [<Tenant {u'enabled': #search tenant list for my tenant name and then get tenant UUID self.my_tenant_uuid = '???' for t in tenants: if self.my_tenant_name == t.to_dict()['name']: self.my_tenant_uuid = t.to_dict()['id'] print 'KeystoneMgr created for tenant ',self.my_tenant_name
def __init__(self, image_name, image_path): """ Constructor to create a Connection and an Image Instance. :param image_name: The name of the image to be created. :param image_path: The path of the image for creation. """ logging.basicConfig(filename='openstack.log', level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' , datefmt='%m/%d/%Y %I:%M:%S %p') logging.info('Establishing Connection.') # Establishing Connections -------------------- try: # Connections with keystoneClient(identity API) -------------------- creds = get_keystone_creds() self.keystone = ksclient.Client(**creds) # Connections with novaClient(compute API) -------------------- creds = get_nova_creds() self.nova = nvclient.Client(**creds) except: logging.error('Connection not Established.') raise # Creating IMAGE instance -------------------- try: logging.info('Creating Image.') self.is_image_present = False image = self.create(image_name, image_path) self.image = image except: logging.error('Image not Created.') main.delete() raise
import keystoneclient.v2_0.client as keystone import glanceclient as glance import novaclient.v1_1.client as nova import os import time from credentials import get_keystone_creds from credentials import get_nova_creds if __name__ == '__main__': keystoneInfo = get_keystone_creds() novaInfo = get_nova_creds() keystoneclient = keystone.Client(**keystoneInfo) novaclient = nova.Client(**novaInfo) endPoint = keystoneclient.service_catalog.get_urls(service_type = 'image')[0] glanceclient = glance.Client('1', endPoint, token = keystoneclient.auth_token) images = glanceclient.images.list() image_create = None for image in images: if image.name.find('ubuntu') > -1: print image.id, '\t', image.name flavor = novaclient.flavors.find(name="m1.micro") instance = novaclient.servers.create(name=image.id, image=image, flavor=flavor) # check whether the instance has been successfully started status = instance.status while status == 'BUILD': time.sleep(5) instance = novaclient.servers.get(instance.id)
from keystoneclient.v2_0 import client as keystonec from credentials import get_keystone_creds if len(sys.argv) == 2: tenant_name = sys.argv[1] print "Deleting routers from tenant %s " % tenant_name else: print "You must provide tenant_name" sys.exit() config = ConfigParser.ConfigParser() config.read("adduser-cloud.conf") # Getting auth token from keystone try: creds = get_keystone_creds() keystone = keystonec.Client(**creds) except keystonec.exceptions.Unauthorized: print "Invalid keystone username or password" sys.exit() quantum = quantumc.Client('2.0', endpoint_url=config.get("quantum","endpoint"), token = keystone.auth_token) tenant = keystone.tenants.find(name=tenant_name) # Disassociate all floating IPs from given tenant: for fip in quantum.list_floatingips(tenant_id=tenant.id)["floatingips"]: quantum.update_floatingip(fip["id"],{"floatingip":{"port_id":None}})
import keystoneclient.v2_0.client as ksclient from credentials import get_keystone_creds print "Getting credentials" creds = get_keystone_creds() print "Connecting to keystone client" keystone = ksclient.Client(**creds) print "Getting auth token" print keystone.auth_token
#from credentials import get_glance_creds from heatclient.client import Client as heatClient from credentials import get_keystone_creds from keystoneclient.v2_0 import client as keystoneclient from tenant import get_tenant tenant = get_tenant() creds = get_keystone_creds(tenant) keystone = keystoneclient.Client(**creds) heat_endpoint = keystone.service_catalog.url_for(service_type='orchestration', endpoint_type='publicURL') heat = heatClient('1', endpoint=heat_endpoint, token=keystone.auth_token) stacks = heat.stacks.list() print list(stacks)
import keystoneclient.v2_0.client as ksclient from credentials import get_keystone_creds creds = get_keystone_creds() # See <a href="openrc-creds" /> keystone = ksclient.Client(**creds) glance_endpoint = keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL') network_endpoint = keystone.service_catalog.url_for(service_type='network', endpoint_type='publicURL') compute_endpoint = keystone.service_catalog.url_for(service_type='compute', endpoint_type='publicURL') #neutron_endpoint = keystone.service_catalog.url_for(service_type='neutron', # endpoint_type='publicURL') print "glance endpoint is : " + glance_endpoint print "network endpoint is : " + network_endpoint print "compute endpoint is : " + compute_endpoint #print "neutron endpoint is : " + neutron_endpoint
def keystone_auth(): creds = get_keystone_creds() keystone = creds tokenID = keystone.auth_token return tokenID
def getCeilometer(): CEILOMETER_URL='http://localhost:8777' creds = get_keystone_creds() ceilometer = ceilo.Client(endpoint=CEILOMETER_URL, **creds ) return ceilometer
import keystoneclient.v2_0.client as ksclient import glanceclient.v2.client as glclient import novaclient.v1_1.client as nvclient import credentials import time default_name = "ubuntu" default_flavor = "m1.micro" keystone_creds = credentials.get_keystone_creds() #Get images containing Ubuntu keystone = ksclient.Client(**keystone_creds) glance_endpoint = keystone.service_catalog.url_for( service_type='image', endpoint_type='publicURL') glance = glclient.Client(glance_endpoint, token=keystone.auth_token) ubuntu_images = [ img for img in glance.images.list() if default_name in img["name"]] #Create images nova_creds = credentials.get_nova_creds() nova = nvclient.Client(**nova_creds) flavor = nova.flavors.find(name="m1.micro") created_instances = [ nova.servers.create(name=img["name"]+"_vm", image=img["id"], flavor=flavor) for img in ubuntu_images ]