本文整理汇总了Python中foam.geni.db.GeniDB.getEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python GeniDB.getEnabled方法的具体用法?Python GeniDB.getEnabled怎么用?Python GeniDB.getEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类foam.geni.db.GeniDB
的用法示例。
在下文中一共展示了GeniDB.getEnabled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pub_change_slice_controller
# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getEnabled [as 别名]
def pub_change_slice_controller(self, slice_id, controller_url, **kwargs):
slice_id = slice_id.replace(":","_")
slice_id = slice_id.replace("name_","nam__")
'''
Changes the slice controller url.
'''
if slice_id not in self.slice_info_dict:
self._log.info("Slice is probably not started yet, doing nothing...")
return ""
#raise Exception("Something went wrong with the fs recovery")
#retrieve updated dict as a json file from foam db folder
filedir = './opt/ofelia/ofam/local/db'
filename = os.path.join(filedir, 'expedient_slices_info.json')
if os.path.isfile(filename):
f = open(filename, 'r')
self.slice_info_dict = json.load(f)
f.close()
else:
self._log.info("Slice is probably not started yet, doing nothing...")
return ""
slice_of_rspec = create_ofv3_rspec(slice_id, self.slice_info_dict[slice_id]['project_name'],
self.slice_info_dict[slice_id]['project_desc'],
self.slice_info_dict[slice_id]['slice_name'],
self.slice_info_dict[slice_id]['slice_desc'], controller_url,
self.slice_info_dict[slice_id]['owner_email'],
self.slice_info_dict[slice_id]['owner_password'],
self.slice_info_dict[slice_id]['switch_slivers'],
self.create_slice_fs(self.slice_info_dict[slice_id]['switch_slivers']))
self.slice_info_dict[slice_id]['controller_url'] = controller_url
slice_urn = "urn:publicid:IDN+openflow:foam:"+ str(THIS_SITE_TAG) +"+slice+" + "id_" + str(slice_id) + "name_" + str(self.slice_info_dict[slice_id]['slice_name'])
creds = [] #creds are not needed at least for now: to be fixed
user_info = {}
user_info["urn"] = "urn:publicid:IDN+openflow:foam"+ str(THIS_SITE_TAG) +"+ch+" + "user+" + str(self.slice_info_dict[slice_id]['owner_email']) #temp hack
user_info["email"] = str(self.slice_info_dict[slice_id]['owner_email'])
if GeniDB.sliceExists(slice_urn):
sliv_urn = GeniDB.getSliverURN(slice_urn)
else:
raise Exception("Something went wrong with the fs recovery, slice does not exist!")
sliver = GeniDB.getSliverObj(sliv_urn)
is_allocated_by_FV = GeniDB.getEnabled(sliv_urn)
was_allocated_by_FV = is_allocated_by_FV
try:
#old_exp_shutdown_success = legexpgapi2_apih.pub_Shutdown(slice_urn, creds, [])
old_exp_shutdown_success = self.priv_DeleteSliver(slice_urn, creds, [])
except Exception, e:
import traceback
traceback.print_exc()
raise Exception("Exception while trying to shutdown old slice!")
示例2: pub_get_granted_flowspace
# 需要导入模块: from foam.geni.db import GeniDB [as 别名]
# 或者: from foam.geni.db.GeniDB import getEnabled [as 别名]
def pub_get_granted_flowspace(self, slice_id, **kwargs):
'''
Return FlowVisor Rules for the slice.
'''
slice_id = slice_id.replace(":","_")
slice_id = slice_id.replace("name_","nam__")
def parse_granted_flowspaces(gfs):
gfs_list=[]
for fs in gfs:
fs_dict = dict(
flowspace=dict(),
openflow=dict()
)
fs_dict['openflow']=[]
fs_dict['flowspace']=dict(
mac_src_s=int_to_mac(fs.mac_src_s),
mac_src_e=int_to_mac(fs.mac_src_e),
mac_dst_s=int_to_mac(fs.mac_dst_s),
mac_dst_e=int_to_mac(fs.mac_dst_e),
eth_type_s=fs.eth_type_s,
eth_type_e=fs.eth_type_e,
vlan_id_s=fs.vlan_id_s,
vlan_id_e=fs.vlan_id_e,
ip_src_s=int_to_dotted_ip(fs.ip_src_s),
ip_dst_s=int_to_dotted_ip(fs.ip_dst_s),
ip_src_e=int_to_dotted_ip(fs.ip_src_e),
ip_dst_e=int_to_dotted_ip(fs.ip_dst_e),
ip_proto_s=fs.ip_proto_s,
ip_proto_e=fs.ip_proto_e,
tp_src_s=fs.tp_src_s,
tp_dst_s=fs.tp_dst_s,
tp_src_e=fs.tp_src_e,
tp_dst_e=fs.tp_dst_e,
)
openflow_dict=dict(
dpid=fs.dpid,
direction=fs.direction,
port_number_s=fs.port_number_s,
port_number_e=fs.port_number_e,
)
existing_fs = False
for prev_dict_list in gfs_list:
prev_dict = prev_dict_list[0]
if fs_dict['flowspace'] == prev_dict['flowspace']:
if openflow_dict not in prev_dict['openflow']:
prev_dict['openflow'].append(openflow_dict)
existing_fs = True
break
if not existing_fs:
fs_dict['openflow'].append(openflow_dict)
fs_list = [fs_dict]
gfs_list.append(fs_list)
return gfs_list
if slice_id in self.slice_info_dict:
slice_urn = "urn:publicid:IDN+openflow:foam:"+ str(THIS_SITE_TAG) +"+slice+" + "id_" + str(slice_id) + "name_" + str(self.slice_info_dict[slice_id]['slice_name'])
else:
return []
if GeniDB.sliceExists(slice_urn):
sliv_urn = GeniDB.getSliverURN(slice_urn)
else:
return []
#raise Exception(parseFVexception(e))
sliver = GeniDB.getSliverObj(sliv_urn)
is_allocated_by_FV = GeniDB.getEnabled(sliv_urn)
if is_allocated_by_FV == True:
#that means that the flow space as requested was allocated
#so retrieve the fs in the form Expedient understands
#TODO: check that ecery time this corresponds to the actual flowspec that FOAM has
#retrieve updated dict as a json file from foam db folder
filedir = './opt/ofelia/ofam/local/db'
filename = os.path.join(filedir, 'expedient_slices_info.json')
if os.path.isfile(filename):
f = open(filename, 'r')
self.slice_info_dict = json.load(f)
f.close()
else:
self._log.info("Slice is probably not started yet, doing nothing...")
return []
if slice_id not in self.slice_info_dict:
raise Exception("Something went wrong with the fs recovery")
all_efs = self.create_slice_fs(self.slice_info_dict[slice_id]['switch_slivers'])
gfs = []
try:
gfs = parse_granted_flowspaces(all_efs)
except Exception,e:
import traceback
traceback.print_exc()
self._log.exception("FlowSpace for the allocated slice is not returned")
raise Exception(parseFVexception(e))
#self._log.info("FlowSpace for the allocated slice is returned")
#for fs_list in gfs:
# fs = fs_list[0]
# self._log.info(fs['flowspace'])
# self._log.info(fs['openflow'])
if gfs == []:
self._log.info("Empty FlowSpace for the allocated slice returned! Need to debug...")
return gfs