def CreateSliver(self,xrn,rspec_string,users,creds,options): xrn = Xrn(xrn, 'slice') slice_leaf = xrn.get_leaf() slice_hrn = xrn.get_hrn() authority = xrn.get_authority_hrn() expiration_date = self.driver.get_expiration(creds, slice_hrn) return self.driver.create_sliver (slice_leaf,authority,rspec_string, users, options, expiration_date)
def CreateSliver(self, xrn, rspec_string, users, creds, options): xrn = Xrn(xrn, "slice") slice_leaf = xrn.get_leaf() slice_hrn = xrn.get_hrn() authority = xrn.get_authority_hrn() expiration_date = self.driver.get_expiration(creds, slice_hrn) return self.driver.create_sliver(slice_leaf, authority, rspec_string, users, options, expiration_date)
def create_sliver (self,slice_leaf,authority,rspec_string, users, options, expiration_date): rspec = RSpec(rspec_string,'OcfVt') requested_attributes = rspec.version.get_slice_attributes() requested_attributes = self.shell.convert_to_uuid(requested_attributes) #Converts component_id URNs to UUIDs projectName = authority#users[0]['slice_record']['authority'] sliceName = slice_leaf self.shell.CreateSliver(requested_attributes,projectName,sliceName,expiration_date) created_vms = list() nodes = list() for slivers in requested_attributes: node = self.shell.GetNodes(uuid=slivers['component_id']) #print "\n\n\n\n\n\nslivers: %s\n\n\n\n\n\n" % slivers['slivers'] for vm in slivers['slivers']: #node = self.shell.GetNodes(uuid=vm['server-id']) if not node in nodes: nodes.append(node) try: #print "\n\n\n\n\n\nusers: %s\n\n\n\n\n\n" % str(users) for user in users: xrn = Xrn(user['urn'], 'user') user_name = xrn.get_leaf() # Store user SSH key for future use for user_key in user['keys']: if not VirtualMachineKeys.objects.filter(project_uuid=vm["project-id"], slice_uuid=vm["slice-id"], vm_uuid=vm['uuid'],user_name=user_name ,ssh_key=user_key): key_entry = VirtualMachineKeys(project_uuid=vm["project-id"], slice_uuid=vm["slice-id"], vm_uuid=vm['uuid'],user_name=user_name ,ssh_key=user_key) key_entry.save() except Exception as e: logging.error("create_sliver > Could not store user SSH key. Details: %s" % str(e)) #ip = self.shell.get_ip_from_vm(vm_name=vm['name'],slice_name=vm['slice-name'],project=authority) #created_vms.append({'vm-name':vm['name'],'vm-ip':ip,'vm-state':'ongoing','slice-name':slice_leaf,'node-name':node.name}) #add ssh keys to ldap of ssh gateway if len(nodes): logging.info("create_slice > Connecting to LDAP") session = ldapManager() con = session.bind() logging.info("create_slice > Connected to LDAP. Connection: %s" % str(con)) if con: logging.info("LDAP: trying to create the following users: %s" % str(users)) for user in users: logging.info("Sending users to LDAP") #logging.error("project: "+str(projectName)+" slicename"+str(sliceName)) ldapprj = "%s.%s" % (projectName, sliceName) ldapprj = ldapprj.replace("\\" ,"") logging.info("LDAP project: " + ldapprj) session.add_modify_project_users(con, user["urn"], ldapprj, user["keys"]) logging.info("User added to project: " + str(ldapprj) + ", SSH key: " + str(user['keys'])) #status=session.add_project(con,projectName+"."+sliceName) #if status != 0: #logging.error("users"+users) # for index,user in enumerate(users): #logging.error(user) # status=session.add_user(con,"user"+str(index),user['urn'],projectName+"."+sliceName,user['keys']) # if status ==0: # logging.error("can't add user to ldap of ssh gateway:"+ str(user)) #else: # logging.error("can't add project to ldap of ssh gateway: "+projectName+"."+sliceName) else: logging.error("Cannot contact LDAP of the SSH gateway") return self.aggregate.get_rspec(slice_leaf=slice_leaf,projectName=projectName,version=rspec.version,created_vms=created_vms,new_nodes=nodes)
def ListResources(self, options): slice_xrn = options.get('geni_slice_urn', None) if slice_xrn: xrn = Xrn(slice_xrn,'slice') slice_leaf = xrn.get_leaf() options['slice'] = slice_leaf rspec = self.driver.list_resources(options) if options.has_key('geni_compressed') and options['geni_compressed'] == True: rspec = zlib.compress(rspec).encode('base64') return rspec
def ListResources(self, options): slice_xrn = options.get("geni_slice_urn", None) if slice_xrn: xrn = Xrn(slice_xrn, "slice") slice_leaf = xrn.get_leaf() options["slice"] = slice_leaf rspec = self.driver.list_resources(options) if options.has_key("geni_compressed") and options["geni_compressed"] == True: rspec = zlib.compress(rspec).encode("base64") return rspec
def reset_slice(self,xrn): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice (slice_leaf,authority,action='reset_slice')
def DeleteSliver(self, xrn, options): #TODO: Check the options or xrn to get a single vm. xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_leaf,authority,action='delete_slice')
def SliverStatus (self, xrn, options): xrn = Xrn(xrn,'slice') slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.sliver_status(slice_leaf,authority,options)
def reset_slice(self, xrn): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_leaf, authority, action="reset_slice")
def DeleteSliver(self, xrn, options): # TODO: Check the options or xrn to get a single vm. xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_leaf, authority, action="delete_slice")
def SliverStatus(self, xrn, options): xrn = Xrn(xrn, "slice") slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.sliver_status(slice_leaf, authority, options)
def create_sliver(self, slice_leaf, authority, rspec_string, users, options, expiration_date): rspec = RSpec(rspec_string, 'OcfVt') requested_attributes = rspec.version.get_slice_attributes() requested_attributes = self.shell.convert_to_uuid( requested_attributes) #Converts component_id URNs to UUIDs projectName = authority #users[0]['slice_record']['authority'] sliceName = slice_leaf self.shell.CreateSliver(requested_attributes, projectName, sliceName, expiration_date) created_vms = list() nodes = list() for slivers in requested_attributes: node = self.shell.GetNodes(uuid=slivers['component_id']) #print "\n\n\n\n\n\nslivers: %s\n\n\n\n\n\n" % slivers['slivers'] for vm in slivers['slivers']: #node = self.shell.GetNodes(uuid=vm['server-id']) if not node in nodes: nodes.append(node) try: #print "\n\n\n\n\n\nusers: %s\n\n\n\n\n\n" % str(users) for user in users: xrn = Xrn(user['urn'], 'user') user_name = xrn.get_leaf() # Store user SSH key for future use for user_key in user['keys']: if not VirtualMachineKeys.objects.filter( project_uuid=vm["project-id"], slice_uuid=vm["slice-id"], vm_uuid=vm['uuid'], user_name=user_name, ssh_key=user_key): key_entry = VirtualMachineKeys( project_uuid=vm["project-id"], slice_uuid=vm["slice-id"], vm_uuid=vm['uuid'], user_name=user_name, ssh_key=user_key) key_entry.save() except Exception as e: logging.error( "create_sliver > Could not store user SSH key. Details: %s" % str(e)) #ip = self.shell.get_ip_from_vm(vm_name=vm['name'],slice_name=vm['slice-name'],project=authority) #created_vms.append({'vm-name':vm['name'],'vm-ip':ip,'vm-state':'ongoing','slice-name':slice_leaf,'node-name':node.name}) #add ssh keys to ldap of ssh gateway if len(nodes): logging.info("create_slice > Connecting to LDAP") session = ldapManager() con = session.bind() logging.info("create_slice > Connected to LDAP. Connection: %s" % str(con)) if con: logging.info("LDAP: trying to create the following users: %s" % str(users)) for user in users: logging.info("Sending users to LDAP") #logging.error("project: "+str(projectName)+" slicename"+str(sliceName)) ldapprj = "%s.%s" % (projectName, sliceName) ldapprj = ldapprj.replace("\\", "") logging.info("LDAP project: " + ldapprj) session.add_modify_project_users(con, user["urn"], ldapprj, user["keys"]) logging.info("User added to project: " + str(ldapprj) + ", SSH key: " + str(user['keys'])) #status=session.add_project(con,projectName+"."+sliceName) #if status != 0: #logging.error("users"+users) # for index,user in enumerate(users): #logging.error(user) # status=session.add_user(con,"user"+str(index),user['urn'],projectName+"."+sliceName,user['keys']) # if status ==0: # logging.error("can't add user to ldap of ssh gateway:"+ str(user)) #else: # logging.error("can't add project to ldap of ssh gateway: "+projectName+"."+sliceName) else: logging.error("Cannot contact LDAP of the SSH gateway") return self.aggregate.get_rspec(slice_leaf=slice_leaf, projectName=projectName, version=rspec.version, created_vms=created_vms, new_nodes=nodes)