本文整理汇总了Python中infrasim.workspace.Workspace.get_workspace方法的典型用法代码示例。如果您正苦于以下问题:Python Workspace.get_workspace方法的具体用法?Python Workspace.get_workspace怎么用?Python Workspace.get_workspace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类infrasim.workspace.Workspace
的用法示例。
在下文中一共展示了Workspace.get_workspace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CNode
# 需要导入模块: from infrasim.workspace import Workspace [as 别名]
# 或者: from infrasim.workspace.Workspace import get_workspace [as 别名]
class CNode(object):
def __init__(self, node_info=None):
self.__tasks_list = []
self.__node = node_info
self.__node_name = ""
self.workspace = None
self.__sol_enabled = None
self.__netns = None
self.__logger = infrasim_log.get_logger(LoggerType.model.value)
@property
def netns(self):
return self.__netns
def get_task_list(self):
return self.__tasks_list
def get_node_name(self):
return self.__node_name
def set_node_name(self, name):
self.__node_name = name
def get_node_info(self):
return self.__node
@run_in_namespace
def precheck(self):
if self.__is_running():
return
for task in self.__tasks_list:
task.precheck()
def terminate_workspace(self):
if Workspace.check_workspace_exists(self.__node_name):
shutil.rmtree(self.workspace.get_workspace())
self.__logger.info("[Node] Node {} runtime workspcace is destroyed".
format(self.__node_name))
print "Node {} runtime workspace is destroyed.".format(self.__node_name)
def init(self):
"""
1. Prepare CNode attributes:
- self.__node
2. Then use this information to init workspace
3. Use this information to init sub module
"""
if 'name' in self.__node:
self.set_node_name(self.__node['name'])
else:
raise ArgsNotCorrect("[Node] No node name is given in node information.")
self.__logger = infrasim_log.get_logger(LoggerType.model.value,
self.__node_name)
if self.__node['compute'] is None:
raise ArgsNotCorrect("[Node] No compute information")
if 'sol_enable' not in self.__node:
self.__node['sol_enable'] = True
self.__sol_enabled = self.__node['sol_enable']
self.__netns = self.__node.get("namespace")
# If user specify "network_mode" as "bridge" but without MAC
# address, generate one for this network.
for network in self.__node['compute']['networks']:
if 'mac' not in network:
uuid_val = uuid.uuid4()
str1 = str(uuid_val)[-2:]
str2 = str(uuid_val)[-4:-2]
str3 = str(uuid_val)[-6:-4]
network['mac'] = ":".join(["52:54:BE", str1, str2, str3])
# If user specify "nmve" controller(drive) in "storage_backend"
# with NO serial, generate one for it, since QEMU now (2.10.1)
# treat "serail" as a mandatory attribute for "nvme"
for storage in self.__node['compute']['storage_backend']:
if storage.get('type') == 'nvme':
if not storage.get('serial', ''):
storage['serial'] = helper.random_serial()
if self.__sol_enabled:
socat_obj = CSocat()
socat_obj.logger = self.__logger
socat_obj.set_priority(0)
socat_obj.set_task_name("{}-socat".format(self.__node_name))
self.__tasks_list.append(socat_obj)
bmc_info = self.__node.get('bmc', {})
bmc_obj = CBMC(bmc_info)
bmc_obj.logger = self.__logger
bmc_obj.set_priority(1)
bmc_obj.set_task_name("{}-bmc".format(self.__node_name))
bmc_obj.enable_sol(self.__sol_enabled)
bmc_obj.set_log_path("/var/log/infrasim/{}/openipmi.log".
format(self.__node_name))
bmc_obj.set_node_name(self.__node['name'])
self.__tasks_list.append(bmc_obj)
#.........这里部分代码省略.........