def Provision(self, urns, credentials, options): geni_best_effort = self._option(options, "geni_best_effort", ret=True) geni_users = self._option(options, "geni_users", ret=[]) # Expiration in credentials expiration = geni_creds.get_cred_exp(logger, credentials[0]["geni_value"]) # Expiration in slice slice_resources = db_sync_manager.get_slices(urns[0]) # Convert expiration date in slice credential to expected datetime format try: # Expiration in slice (from Allocate reservation) expiration = slice_resources["slivers"]["geni_expires"] expiration = dates.rfc3339_to_datetime(expiration) expiration = dates.datetime_to_rfc3339(expiration) except: pass if "geni_end_time" in options: expiration = max(expiration, dates.rfc3339_to_datetime(options["geni_end_time"])) # TODO check the end_time against the duration of the credential try: self._checkRSpecVersion(options["geni_rspec_version"]) r_rspec, r_sliver_list = self._delegate.provision( urns, self.requestCertificate(), credentials, geni_best_effort, expiration, geni_users) result = {"geni_rspec": r_rspec, "geni_slivers": self._convertExpiresDate(r_sliver_list)} except Exception as e: return self._errorReturn(e) return self._successReturn(result)
def _allocate_ports_in_slice(self, nodes, sliceVlansPairs=None, slice_urn=None): ports_take_part_info={'ports':[]} for n in nodes: for e in n['interfaces']: for vlan in e['vlan']: current_vlan = vlan['tag'] current_port = e['component_id'] ports_take_part_info['ports'].append({'port' : current_port, 'vlan' : current_vlan}) if not ports_take_part_info['ports']: if sliceVlansPairs != None: print "#### Getting VLANs from new format Rspec" for port in sliceVlansPairs: for item in port: if isinstance(item,dict): try: item["port"] = item.pop("port_id") except: pass ports_take_part_info['ports'].append(item) else: # Get from DB try: slice_resources=db_sync_manager.get_slices(slice_urn) vlan_pairs_db = slice_resources["vlan-pairs"] for port in vlan_pairs_db: for item in port: if isinstance(item,dict): # try: # item["port"] = item.pop("port_id") # except: # pass ports_take_part_info['ports'].append(item) except: raise Exception("No data on the selected slice avaialble in database!") return ports_take_part_info
def get_slice_vlan_pairs(self, slice_urn): if slice_urn: try: slice_resources=db_sync_manager.get_slices(slice_urn) sliceVlansPairs = slice_resources["vlan-pairs"] return sliceVlansPairs except : return {}
def get_slice_vlan_pairs(self, slice_urn): if slice_urn: try: slice_resources = db_sync_manager.get_slices(slice_urn) sliceVlansPairs = slice_resources["vlan-pairs"] return sliceVlansPairs except: return {}
def get_link_db(self, slice_urn=None): if slice_urn: try: slice_resources=db_sync_manager.get_slices(slice_urn) links_db = slice_resources["slivers"] sliver_tmp = [] for sliver in links_db["geni_sliver_urn"]: sliver_tmp.append(sliver.keys()[0]) links_db["geni_sliver_urn"] = sliver_tmp # links_db["geni_sliver_urn"] = links_db["geni_sliver_urn"][0].keys()[0] nodes = slice_resources["nodes"] links = slice_resources["links"] sliver_id = links[0]["sliver_id"] return links_db, nodes, links except : return {}
def get_link_db(self, slice_urn=None): if slice_urn: try: slice_resources = db_sync_manager.get_slices(slice_urn) links_db = slice_resources["slivers"] sliver_tmp = [] for sliver in links_db["geni_sliver_urn"]: sliver_tmp.append(sliver.keys()[0]) links_db["geni_sliver_urn"] = sliver_tmp # links_db["geni_sliver_urn"] = links_db["geni_sliver_urn"][0].keys()[0] nodes = slice_resources["nodes"] links = slice_resources["links"] sliver_id = links[0]["sliver_id"] return links_db, nodes, links except: return {}
def __update_operational_status_slivers(self, urn, status): slices = db_sync_manager.get_slices(urn) dict_status = {"slivers": {"geni_operational_status": status}} self.__update_slivers(urn, dict_status)
def __update_slivers(self, urn, dict_slivers): slices = db_sync_manager.get_slices(urn) if "slivers" in dict_slivers: dict_slivers = dict_slivers["slivers"] slices["slivers"].update(dict_slivers) db_sync_manager.set_slices(urn, slices)
def __update_operational_status_slivers(self, urn, status): slices = db_sync_manager.get_slices(urn) dict_status = {"slivers": {"geni_operational_status": status}} self.__update_slivers(urn, dict_status)
def __update_slivers(self, urn, dict_slivers): slices = db_sync_manager.get_slices(urn) if "slivers" in dict_slivers: dict_slivers = dict_slivers["slivers"] slices["slivers"].update(dict_slivers) db_sync_manager.set_slices(urn, slices)