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 reset_slice(xrn): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() slice_urn = xrn.get_urn() authority = xrn.get_authority_hrn() slice_action = aggregate.crud_slice (slice_urn,authority,action='reset_slice') return {'output': '', 'geni_api': 2, 'code': {'am_type': 'sfa', 'geni_code': 0}, 'value': slice_action} #driver.crud_slice (slice_urn,authority,action='reset_slice')
def DeleteSliver(self, xrn, options): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() slice_urn = xrn.get_urn() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_urn, authority, action='delete_slice')
def SliverStatus(self, slice_urn): sliver_status = get_sliver_status(slice_urn) if len(sliver_status) == 0: xrn = Xrn(slice_urn, 'slice') slice_leaf = xrn.get_leaf() sliver_status = ['The requested flowspace for slice %s is still pending for approval' %slice_leaf] granted_fs = {'granted_flowspaces':get_sliver_status(slice_urn)} return [granted_fs]
def stop_slice(self, xrn): xrn = Xrn(xrn) slice_urn = xrn.get_urn() slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_urn, authority, action='stop_slice')
def CreateSliver(self, xrn, rspec_string, users,creds, options): #XXX: How can the expiration time be checked? xrn = Xrn(xrn, 'slice') slice_urn = xrn.get_urn() slice_leaf = xrn.get_leaf() slice_hrn = xrn.get_hrn() authority = xrn.get_authority_hrn() expiration_date = self.driver.get_expiration_date(slice_hrn, creds)# XXX: AM may require get slice_expiration from the registry return self.driver.create_sliver (slice_urn,slice_leaf,authority,rspec_string, users, options, expiration_date)
def SliverStatus(self, slice_urn): sliver_status = get_sliver_status(slice_urn) if len(sliver_status) == 0: xrn = Xrn(slice_urn, 'slice') slice_leaf = xrn.get_leaf() sliver_status = [ 'The requested flowspace for slice %s is still pending for approval' % slice_leaf ] granted_fs = {'granted_flowspaces': get_sliver_status(slice_urn)} return [granted_fs]
def ListResources(self, options): slice_xrn = options.get('geni_slice_urn', None) if slice_xrn: xrn = Xrn(slice_xrn,'slice') slice_urn = xrn.get_urn() slice_leaf = xrn.get_leaf() options['slice'] = slice_leaf else: slice_leaf = None slice_urn = None rspec = self.driver.list_resources(slice_urn,slice_leaf,options) if options.has_key('geni_compressed') and options['geni_compressed'] == True: rspec = zlib.compress(rspec).encode('base64') return rspec
def call(self, xrn, creds, type): xrn = Xrn(xrn, type=type) # validate the cred valid_creds = self.api.auth.checkCredentials(creds, "remove") self.api.auth.verify_object_permission(xrn.get_hrn()) #log the call origin_hrn = Credential( string=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info( "interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s" % (self.api.interface, self.name, origin_hrn, xrn.get_urn())) return self.api.manager.Remove(self.api, xrn)
def SliverStatus(self, slice_urn): try: print "-----------------------------------------------------------SliverStatus" sliver_status = get_sliver_status(slice_urn) print sliver_status if len(sliver_status) == 0: xrn = Xrn(slice_urn, 'slice') slice_leaf = xrn.get_leaf() sliver_status = ['The requested flowspace for slice %s is still pending for approval' %slice_leaf] granted_fs = {'granted_flowspaces':get_sliver_status(slice_urn)} return [granted_fs] except Exception as e: import traceback print traceback.print_exc() raise e
def ListResources(self, options): slice_xrn = options.get('geni_slice_urn', None) if slice_xrn: xrn = Xrn(slice_xrn, 'slice') slice_urn = xrn.get_urn() slice_leaf = xrn.get_leaf() options['slice'] = slice_leaf else: slice_leaf = None slice_urn = None rspec = self.driver.list_resources(slice_urn, slice_leaf, options) if options.has_key( 'geni_compressed') and options['geni_compressed'] == True: rspec = zlib.compress(rspec).encode('base64') return rspec
def call(self, xrn, creds, type): xrn = Xrn(xrn, type=type) # validate the cred valid_creds = self.api.auth.checkCredentials(creds, "remove") self.api.auth.verify_object_permission(xrn.get_hrn()) # log the call origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info( "interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s" % (self.api.interface, self.name, origin_hrn, xrn.get_urn()) ) return self.api.manager.Remove(self.api, xrn)
def reset_slice(xrn): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() slice_urn = xrn.get_urn() authority = xrn.get_authority_hrn() slice_action = aggregate.crud_slice(slice_urn, authority, action='reset_slice') return { 'output': '', 'geni_api': 2, 'code': { 'am_type': 'sfa', 'geni_code': 0 }, 'value': slice_action } #driver.crud_slice (slice_urn,authority,action='reset_slice')
def SliverStatus(self, slice_urn): try: print "-----------------------------------------------------------SliverStatus" sliver_status = get_sliver_status(slice_urn) print sliver_status if len(sliver_status) == 0: xrn = Xrn(slice_urn, 'slice') slice_leaf = xrn.get_leaf() sliver_status = [ 'The requested flowspace for slice %s is still pending for approval' % slice_leaf ] granted_fs = {'granted_flowspaces': get_sliver_status(slice_urn)} return [granted_fs] except Exception as e: import traceback print traceback.print_exc() raise e
def to_sfa_rspec(rspec, content_type=None): if not isinstance(rspec, RSpec): pg_rspec = RSpec(rspec) else: pg_rspec = rspec version_manager = VersionManager() sfa_version = version_manager._get_version('sfa', '1') sfa_rspec = RSpec(version=sfa_version) #nodes = pg_rspec.version.get_nodes() #sfa_rspec.version.add_nodes(nodes()) #sfa_rspec.version.add_links(pg_rspec.version.get_links()) #return sfa_rspec.toxml() # get network networks = pg_rspec.version.get_networks() network_hrn = networks[0]["name"] network_element = sfa_rspec.xml.add_element('network', name=network_hrn, id=network_hrn) # get nodes pg_nodes_elements = pg_rspec.version.get_nodes() nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers() i = 1 for pg_node in pg_nodes_elements: attribs = dict(pg_node.items()) attribs['id'] = 'n' + str(i) node_element = network_element.add_element('node') for attrib in attribs: if type(attribs[attrib]) == str: node_element.set(attrib, attribs[attrib]) urn = pg_node["component_id"] if urn: if type(urn) == list: # legacy code, not sure if urn is ever a list... urn = urn[0] hostname = Xrn.urn_split(urn)[-1] hostname_element = node_element.add_element('hostname') hostname_element.set_text(hostname) if hostname in nodes_with_slivers: node_element.add_element('sliver') for hardware_type in pg_node["hardware_types"]: if "name" in hardware_type: node_element.add_element("hardware_type", name=hardware_type["name"]) # just copy over remaining child elements #for child in pg_node_element.getchildren(): # node_element.append(transform(child).getroot()) i = i + 1 return sfa_rspec.toxml()
def get_node_objs(node_elems): nodes = [] for node_elem in node_elems: node = Node(node_elem.attrib, node_elem) nodes.append(node) if 'component_id' in node_elem.attrib: node['authority_id'] = Xrn( node_elem.attrib['component_id']).get_authority_urn() # get hardware types hardware_type_elems = node_elem.xpath( './hardware_type | ./default:hardware_type') node['hardware_types'] = [ hw_type.get_instance(HardwareType) for hw_type in hardware_type_elems ] # get location location_elems = node_elem.xpath('./location | ./default:location') locations = [ location_elem.get_instance(Location) for location_elem in location_elems ] if len(locations) > 0: node['location'] = locations[0] # get interfaces iface_elems = node_elem.xpath('./interface | ./default:interface') node['interfaces'] = [ iface_elem.get_instance(Interface) for iface_elem in iface_elems ] # get services service_elems = node_elem.xpath('./services | ./default:service') if service_elems: node['services'] = PGv2Services.get_services(node_elem) # get slivers sliver_elems = node_elem.xpath('./sliver | ./default:slivers') if sliver_elems: node['slivers'] = OcfOfSlivers.get_slivers(sliver_elems) available_elems = node_elem.xpath( './available | ./default:available') if len(available_elems ) > 0 and 'name' in available_elems[0].attrib: if available_elems[0].attrib.get('now', '').lower() == 'true': node['boot_state'] = 'boot' else: node['boot_state'] = 'disabled' return nodes
def to_sfa_rspec(rspec, content_type = None): if not isinstance(rspec, RSpec): pg_rspec = RSpec(rspec) else: pg_rspec = rspec version_manager = VersionManager() sfa_version = version_manager._get_version('sfa', '1') sfa_rspec = RSpec(version=sfa_version) #nodes = pg_rspec.version.get_nodes() #sfa_rspec.version.add_nodes(nodes()) #sfa_rspec.version.add_links(pg_rspec.version.get_links()) #return sfa_rspec.toxml() # get network networks = pg_rspec.version.get_networks() network_hrn = networks[0]["name"] network_element = sfa_rspec.xml.add_element('network', name=network_hrn, id=network_hrn) # get nodes pg_nodes_elements = pg_rspec.version.get_nodes() nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers() i = 1 for pg_node in pg_nodes_elements: attribs = dict(pg_node.items()) attribs['id'] = 'n'+str(i) node_element = network_element.add_element('node') for attrib in attribs: if type(attribs[attrib]) == str: node_element.set(attrib, attribs[attrib]) urn = pg_node["component_id"] if urn: if type(urn)==list: # legacy code, not sure if urn is ever a list... urn = urn[0] hostname = Xrn.urn_split(urn)[-1] hostname_element = node_element.add_element('hostname') hostname_element.set_text(hostname) if hostname in nodes_with_slivers: node_element.add_element('sliver') for hardware_type in pg_node["hardware_types"]: if "name" in hardware_type: node_element.add_element("hardware_type", name=hardware_type["name"]) # just copy over remaining child elements #for child in pg_node_element.getchildren(): # node_element.append(transform(child).getroot()) i = i+1 return sfa_rspec.toxml()
def add_slivers(xml, of_xml): network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] else: network_urn = 'ocf.ofam' network_elem = xml.add_element('network', name=Xrn(network_urn).get_hrn()) slivers = of_xml.xpath('//rspec/*') for sliver in slivers: network_elem.append(sliver) return slivers
def add_leases(xml, leases, channels): network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] elif len(leases) > 0: network_urn = Xrn( leases[0]['component_id']).get_authority_urn().split(':')[0] network_elem = xml.add_element('network', name=network_urn) else: network_elem = xml # group the leases by slice and timeslots grouped_leases = [] while leases: slice_id = leases[0]['slice_id'] start_time = leases[0]['start_time'] duration = leases[0]['duration'] group = [] for lease in leases: if slice_id == lease['slice_id'] and start_time == lease[ 'start_time'] and duration == lease['duration']: group.append(lease) grouped_leases.append(group) for lease1 in group: leases.remove(lease1) lease_elems = [] for lease in grouped_leases: #lease_fields = ['lease_id', 'component_id', 'slice_id', 'start_time', 'duration'] lease_fields = ['slice_id', 'start_time', 'duration'] lease_elem = network_elem.add_instance('lease', lease[0], lease_fields) lease_elems.append(lease_elem) # add nodes of this lease for node in lease: lease_elem.add_instance('node', node, ['component_id']) # add reserved channels of this lease #channels = [{'channel_id': 1}, {'channel_id': 2}] for channel in channels: if channel['slice_id'] == lease[0]['slice_id'] and channel[ 'start_time'] == lease[0]['start_time'] and channel[ 'duration'] == lease[0]['duration']: lease_elem.add_instance('channel', channel, ['channel_num'])
def get_networks(self): network_names = set() nodes = self.xml.xpath('//default:node[@component_manager_id] | //node[@component_manager_id]', namespaces=self.namespaces) for node in nodes: if 'component_manager_id' in node.attrib: network_urn = node.get('component_manager_id') if network_urn.startswith("urn:"): network_hrn = Xrn(network_urn).get_hrn() else: # some component_manager_ids are hrns instead of urns?? network_hrn = network_urn network_names.add(network_hrn) network_names = list(network_names) networks = [{"name": x} for x in network_names] return networks
def CreateSliver(self, xrn, rspec_string, users, creds, options): #XXX: How can the expiration time be checked? xrn = Xrn(xrn, 'slice') slice_urn = xrn.get_urn() slice_leaf = xrn.get_leaf() slice_hrn = xrn.get_hrn() authority = xrn.get_authority_hrn() expiration_date = self.driver.get_expiration_date( slice_hrn, creds ) # XXX: AM may require get slice_expiration from the registry return self.driver.create_sliver(slice_urn, slice_leaf, authority, rspec_string, users, options, expiration_date)
def call(self, xrns, creds, options={}): # use details=False by default, only when explicitly specified do we want # to mess with the testbed details if 'details' in options: details = options['details'] else: details = False type = None if not isinstance(xrns, types.ListType): type = Xrn(xrns).get_type() xrns = [xrns] hrns = [urn_to_hrn(xrn)[0] for xrn in xrns] #find valid credentials valid_creds = self.api.auth.checkCredentials(creds, 'resolve') #log the call origin_hrn = Credential( string=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info( "interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" % (self.api.interface, origin_hrn, hrns, self.name)) # send the call to the right manager return self.api.manager.Resolve(self.api, xrns, type, details=details)
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 add_nodes(xml, nodes): network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] elif len(nodes) > 0 and nodes[0].get('component_manager_id'): network_urn = nodes[0]['component_manager_id'] network_elem = xml.add_element('network', name = Xrn(network_urn).get_hrn()) else: network_elem = xml # needs to be improuved to retreive the gateway addr dynamically. gateway_addr = 'nitlab.inf.uth.gr' node_elems = [] for node in nodes: node_fields = ['component_manager_id', 'component_id', 'boot_state'] node_elem = network_elem.add_instance('node', node, node_fields) node_elems.append(node_elem) # determine network hrn network_hrn = None if 'component_manager_id' in node and node['component_manager_id']: network_hrn = Xrn(node['component_manager_id']).get_hrn() # set component_name attribute and hostname element if 'component_id' in node and node['component_id']: component_name = Xrn(xrn=node['component_id']).get_leaf() node_elem.set('component_name', component_name) hostname_elem = node_elem.add_element('hostname') hostname_elem.set_text(component_name) # set site id if 'authority_id' in node and node['authority_id']: node_elem.set('site_id', node['authority_id']) # add locaiton location = node.get('location') if location: node_elem.add_instance('location', location, Location.fields) # add 3D Position of the node position_3d = node.get('position_3d') if position_3d: node_elem.add_instance('position_3d', position_3d, Position3D.fields) # all nitos nodes are exculsive exclusive_elem = node_elem.add_element('exclusive') exclusive_elem.set_text('TRUE') # In order to access nitos nodes, one need to pass through the nitos gateway # here we advertise Nitos access gateway address gateway_elem = node_elem.add_element('gateway') gateway_elem.set_text(gateway_addr) # add granularity of the reservation system granularity = node.get('granularity')['grain'] if granularity: #node_elem.add_instance('granularity', granularity, granularity.fields) granularity_elem = node_elem.add_element('granularity') granularity_elem.set_text(str(granularity)) # add hardware type #hardware_type = node.get('hardware_type') #if hardware_type: # node_elem.add_instance('hardware_type', hardware_type) hardware_type_elem = node_elem.add_element('hardware_type') hardware_type_elem.set_text(node.get('hardware_type')) if isinstance(node.get('interfaces'), list): for interface in node.get('interfaces', []): node_elem.add_instance('interface', interface, ['component_id', 'client_id', 'ipv4']) #if 'bw_unallocated' in node and node['bw_unallocated']: # bw_unallocated = etree.SubElement(node_elem, 'bw_unallocated', units='kbps').text = str(int(node['bw_unallocated'])/1000) PGv2Services.add_services(node_elem, node.get('services', [])) tags = node.get('tags', []) if tags: for tag in tags: tag_elem = node_elem.add_element(tag['tagname']) tag_elem.set_text(tag['value']) NITOSv1Sliver.add_slivers(node_elem, node.get('slivers', []))
def add_nodes(xml, nodes): network_elems = xml.xpath('//network') if len(network_elems) > 0: network_elem = network_elems[0] elif len(nodes) > 0 and nodes[0].get('component_manager_id'): network_urn = nodes[0]['component_manager_id'] network_elem = xml.add_element('network', name=Xrn(network_urn).get_hrn()) else: network_elem = xml node_elems = [] for node in nodes: node_fields = [ 'component_manager_id', 'component_id', 'client_id', 'sliver_id', 'exclusive' ] node_elem = network_elem.add_instance('node', node, node_fields) node_elems.append(node_elem) # set component name if node.get('component_id'): component_name = xrn_to_hostname(node['component_id']) node_elem.set('component_name', component_name) if node.get('hostname'): simple_elem = node_elem.add_element('hostname') simple_elem.set_text(node['hostname']) # set hardware types if node.get('hardware_types'): for hardware_type in node.get('hardware_types', []): for field in OcfVtServer.fields: #node_elem.add_instance(field,{field:hardware_type[field]},[])#XXX Ugly notation simple_elem = node_elem.add_element(field) simple_elem.set_text(hardware_type[field]) # set location if node.get('location'): node_elem.add_instance('location', node['location'], Location.fields) # set interfaces PGv2Interface.add_interfaces(node_elem, node.get('interfaces')) #if node.get('interfaces'): # for interface in node.get('interfaces', []): # node_elem.add_instance('interface', interface, ['component_id', 'client_id']) # set available element if node.get('boot_state'): if node.get('boot_state').lower() == 'boot': available_elem = node_elem.add_element('available', now='true') else: available_elem = node_elem.add_element('available', now='false') # add services if node.get('services'): for service in node.get('services', []): fields = service.fields s = node_elem.add_element('service', type=str( service.__class__.__name__)) for field in fields: if service[field]: simple_elem = s.add_element( field) #node_elem.add_element(field) simple_elem.set_text(service[field]) #PGv2Services.add_services(node_elem, node.get('services', [])) # add slivers slivers = node.get('slivers', []) if slivers: for sliver in slivers: fields = sliver.fields s = node_elem.add_element('sliver', type=str( sliver.__class__.__name__)) for field in fields: if sliver[field]: simple_elem = s.add_element( field) #node_elem.add_element(field) simple_elem.set_text(sliver[field]) # we must still advertise the available sliver types #slivers = Sliver({'type': 'plab-vserver'}) # we must also advertise the available initscripts #slivers['tags'] = [] #if node.get('pl_initscripts'): # for initscript in node.get('pl_initscripts', []): # slivers['tags'].append({'name': 'initscript', 'value': initscript['name']}) #PGv2SliverType.add_slivers(node_elem, slivers) return node_elems
def SliverStatus (self, xrn, options): slice_urn = xrn xrn = Xrn(xrn,'slice') slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.sliver_status(slice_urn,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 stop_slice(self,xrn): xrn = Xrn(xrn) slice_urn = xrn.get_urn() slice_leaf = xrn.get_leaf() authority = xrn.get_authority_hrn() return self.driver.crud_slice (slice_urn,authority,action='stop_slice')
def DeleteSliver(self, xrn, options): xrn = Xrn(xrn) slice_leaf = xrn.get_leaf() slice_urn = xrn.get_urn() authority = xrn.get_authority_hrn() return self.driver.crud_slice(slice_urn,authority,action='delete_slice')