本文整理汇总了Python中host.Host方法的典型用法代码示例。如果您正苦于以下问题:Python host.Host方法的具体用法?Python host.Host怎么用?Python host.Host使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host
的用法示例。
在下文中一共展示了host.Host方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def init(self, config, force=False):
def _make_hosts(resource):
"""Builds Host objects for `resource`.
A `resource` can be either (i) a dict with Host entries,
or (ii) a list of Host entries.
"""
if isinstance(resource, list):
return sum(map(_make_hosts, resource), [])
else:
return [Host(address=resource['address'],
alias=resource.get('alias', None),
user=resource.get('user', None),
keyfile=resource.get('keyfile', None),
port=resource.get('port', None),
extra=resource.get('extra', {}))]
network = config['provider']['network']
eths = config['provider']['eths']
roles = {r: _make_hosts(vs) for (r, vs) in config['resources'].items()}
return (roles, network, eths)
示例2: create_cluster
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def create_cluster(self, name, host_names, hostshare_dir, dockershare_dir, docker_tag, docker_user):
print("Cluster Manager: received create cluster request")
#group hosts into a list
host_list = []
for host_name in host_names:
if not host_name in self.active_hosts:
host = Host(host_name)
self.active_hosts[host_name] = host
host_list.append(self.active_hosts[host_name])
#create a new cluster
cluster = Cluster(name, host_list)
#initialize the new cluster
cluster.initialize(hostshare_dir, dockershare_dir, docker_tag, docker_user)
#finish initialization, add cluster to list
self.cluster_list[name] = cluster
示例3: current_host
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def current_host(config):
hosts={ }
import sys
import inspect
import pkgutil
import importlib
from host import Host
# Try to get the current host as specified in the config file
# Otherwise resort to the Default host
h_config = config.get_global_config()['host']
host_class = h_config['type']
#Iterate through all the members of this class
module_names = [name for _, name, _ in pkgutil.iter_modules([__name__])]
for mod in module_names:
importlib.import_module(__name__+'.'+mod)
for mod in module_names:
for name, obj in inspect.getmembers(sys.modules[__name__+'.'+mod]):
if inspect.isclass(obj):
hosts[obj.__name__]=obj
if host_class in hosts:
return hosts[host_class](h_config)
else:
host = Host(h_config)
return host
示例4: parse_onos_host_nodes
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def parse_onos_host_nodes(self):
onos_hosts = None
with open(self.network_configuration.conf_path + "onos_hosts.json", "r") as in_file:
onos_hosts = json.loads(in_file.read())
for onos_host_dict in onos_hosts:
host_switch_id = self.onos_sw_device_id_to_node_id_mapping(onos_host_dict["location"]["elementId"])
host_switch_obj = self.get_node_object(host_switch_id)
# Onos links do not give host-switch links, so need to add Port to each switch
host_port_json = {"port": onos_host_dict["location"]["port"]}
host_switch_port = Port(host_switch_obj, port_json=host_port_json)
host_switch_obj.ports[int(host_switch_port.port_number)] = host_switch_port
# Add the host to the graph
host_id = "h" + host_switch_id[1:] + onos_host_dict["location"]["port"]
self.host_ids.add(host_id)
h_obj = Host(host_id,
self,
onos_host_dict["ipAddresses"][0],
onos_host_dict["mac"],
host_switch_obj,
host_switch_port)
# Make the connections both on switch and host side
host_switch_obj.host_ports.append(int(onos_host_dict["location"]["port"]))
host_switch_obj.attached_hosts.append(h_obj)
host_switch_port.attached_host = h_obj
self.graph.add_node(host_id, node_type="host", h=h_obj)
self.add_link(host_id,
int(0),
host_switch_id,
int(host_switch_port.port_number))
示例5: force_stop_all
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def force_stop_all(self, hosts):
for host_name in hosts:
host = Host(host_name)
host.kill_all_vms()
示例6: terminate
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def terminate(self, clean = False):
for host in self.__hosts:
h = Host(host)
h.kill_all_vms()
if not clean:
self.__current_status = 6 #Terminated
示例7: create_host
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def create_host(self, host, **kwargs):
"""Create client host object and set defaults."""
self.clientobj = Host(
host = host,
user = kwargs.pop("user", ""),
server = kwargs.pop("server", self.server),
nfsversion = kwargs.pop("nfsversion", self.nfsversion),
proto = kwargs.pop("proto", self.proto),
port = kwargs.pop("port", self.port),
sec = kwargs.pop("sec", self.sec),
export = kwargs.pop("export", self.export),
mtpoint = kwargs.pop("mtpoint", self.mtpoint),
datadir = kwargs.pop("datadir", self.datadir),
mtopts = kwargs.pop("mtopts", self.mtopts),
nomount = kwargs.pop("nomount", self.nomount),
tracename = kwargs.pop("tracename", self.tracename),
trcdelay = kwargs.pop("trcdelay", self.trcdelay),
tcpdump = kwargs.pop("tcpdump", self.tcpdump),
tbsize = kwargs.pop("tbsize", self.tbsize),
notrace = kwargs.pop("notrace", self.notrace),
rpcdebug = kwargs.pop("rpcdebug", self.rpcdebug),
nfsdebug = kwargs.pop("nfsdebug", self.nfsdebug),
dbgname = kwargs.pop("dbgname", self.dbgname),
messages = kwargs.pop("messages", self.messages),
tmpdir = kwargs.pop("tmpdir", self.tmpdir),
iptables = kwargs.pop("iptables", self.iptables),
sudo = kwargs.pop("sudo", self.sudo),
)
self.clients.append(self.clientobj)
return self.clientobj
示例8: add_host
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def add_host(self, host_id, link, flows):
"""Adds a new host to the network.
Args:
host_id (str): The network address of the host.
link (Link): The link that the host is connected to.
flows (dict): All the flows that are going out of the host.
"""
host = Host(self, host_id)
self.nodes[host_id] = host
示例9: add_flow
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def add_flow(self, flow_id, src, dest, data_amount, start_time, flowtype):
"""Adds a new flow to the network.
Args:
flow_id (str): id of the flow
src (Host): source host
dest (Host): destination host
data_amount (float): amount of data to be sent in MB
start_time (float): when the flow starts sending packets in seconds
flowtype (str): the type of congestion control algorithm the flow
will use. Valid parameters are "fast", "reno", or None, which
defaults to TCP Tahoe.
"""
# Convert data_amount from megabytes to bits
num_bits = data_amount * BYTE_TO_BIT * MEGABIT_TO_BIT
if flowtype is not None:
if "fast" == flowtype.lower():
flow = FAST_TCP(self, flow_id, src, dest, num_bits, start_time)
elif "reno" == flowtype.lower():
flow = FlowReno(self, flow_id, src, dest, num_bits, start_time)
else:
flow = Flow(self, flow_id, src, dest, num_bits, start_time)
else:
flow = Flow(self, flow_id, src, dest, num_bits, start_time)
self.flows[flow_id] = flow
self._num_active_flows += 1
# Add flows to src and dest
src.add_flow(flow)
dest.add_flow(flow)
示例10: parse_mininet_host_nodes
# 需要导入模块: import host [as 别名]
# 或者: from host import Host [as 别名]
def parse_mininet_host_nodes(self):
mininet_host_nodes = None
mininet_port_links = None
with open(self.network_configuration.conf_path + "mininet_host_nodes.json", "r") as in_file:
mininet_host_nodes = json.loads(in_file.read())
with open(self.network_configuration.conf_path + "mininet_port_links.json", "r") as in_file:
mininet_port_links = json.loads(in_file.read())
for sw in mininet_host_nodes:
# For every host
for mininet_host_dict in mininet_host_nodes[sw]:
host_switch_obj = self.get_node_object(mininet_host_dict["host_switch_id"])
# Add the host to the graph
self.host_ids.add(mininet_host_dict["host_name"])
sw_obj = self.get_node_object(sw)
#try:
h_obj = Host(mininet_host_dict["host_name"],
self,
mininet_host_dict["host_IP"],
mininet_host_dict["host_MAC"],
host_switch_obj,
sw_obj.ports[mininet_port_links[mininet_host_dict["host_name"]]['0'][1]])
#except KeyError:
#import pdb; pdb.set_trace()
# h_obj = Host(mininet_host_dict["host_name"],
# self,
# mininet_host_dict["host_IP"],
# mininet_host_dict["host_MAC"],
# host_switch_obj,
# None)
#print "sw_obj.ports:"
#print sw_obj.ports
#print "port index:"
#print mininet_port_links[mininet_host_dict["host_name"]]['0'][1]
#print "attached host:"
#print sw_obj.ports[mininet_port_links[mininet_host_dict["host_name"]]['0'][1]].attached_host
#print "attached host to append on switch side:"
#print h_obj
# Make the connections both on switch and host side
sw_obj.host_ports.append(mininet_port_links[mininet_host_dict["host_name"]]['0'][1])
sw_obj.attached_hosts.append(h_obj)
sw_obj.ports[mininet_port_links[mininet_host_dict["host_name"]]['0'][1]].attached_host = h_obj
self.graph.add_node(mininet_host_dict["host_name"], node_type="host", h=h_obj)