本文整理汇总了Python中network.Network.list_networks方法的典型用法代码示例。如果您正苦于以下问题:Python Network.list_networks方法的具体用法?Python Network.list_networks怎么用?Python Network.list_networks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.list_networks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Openstack
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import list_networks [as 别名]
#.........这里部分代码省略.........
raise SOSError(SOSError.NOT_FOUND_ERR, "Network {0} not found".format(network_name))
storage_ports = self.get_varray_iscsi_storageports(varray)
for port in storage_ports:
port_info = dict()
port_info['native_guid'] = port['native_guid']
port_info['port_name'] = port['port_name']
try:
ip_address = port['ip_address']
port_info['ip_address'] = ip_address
if (self.is_ip_pingable(ip_address)):
network = port['network']
network_detail = common.show_by_href(self.__ipAddr, self.__port, network)
port_info['network'] = network_detail['name']
self._logger.debug('Select storage port %s: ', port_info)
return network_detail
else:
self._logger.debug('Skip storage port %s: ', port_info)
except KeyError:
self._logger.debug('Skip storage port %s: ', port_info)
continue
def is_ip_pingable(self, ip_address):
self._logger.debug('ping ip address %s ', ip_address)
try:
(out, err) = self._execute('ping', '-c', '2', ip_address)
self._logger.debug(out)
return True
except Exception as ex:
return False
def get_ip_networks(self, varray):
networks = self._network.list_networks(varray)
ip_networks = []
resources = self.get_bulk_details(networks, self.URI_NETWORK_BULK)
for x in resources['network']:
if (x['transport_type'] == 'IP'):
ip_networks.append(x)
return ip_networks
def get_bulk_details(self, resources, bulkuri):
ids = []
for each in resources :
ids.append(each['id'])
body = json.dumps({'id' : ids})
(s, h) = common.service_json_request(self.__ipAddr, self.__port,
"POST",
bulkuri,
body)
return common.json_decode(s)
'''
Attach host initiators to a network
Parameters:
name: name of the host
network: name of the network to be attached
Return:
network details in JSON
'''
def add_initiator_to_network(self, host, initiator, network, varray):
if (network['transport_type'] == 'IP' and initiator['protocol'] == 'iSCSI'):
return self._network.add_endpoint(varray, network['name'], initiator['initiator_port'])
示例2: network_process_cli
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import list_networks [as 别名]
def network_process_cli(config, auth, opt):
if opt['--delimeter'] is None:
delimeter = " "
else:
delimeter = opt['--delimeter']
if opt['--format'] is None:
o_format = "text"
else:
o_format = opt['--format']
n = Network(
hostname=config.host,
auth=auth,
o_format=o_format,
delimeter=delimeter
)
if opt['list'] is True:
n.list_networks(include_extattrs=opt['--extattrs'])
elif opt['search'] is True:
n.search(
name=opt['<name>'],
site=opt['<site>'],
attribute=opt['<attribute>'],
value=opt['<value>'],
network=opt['--network'],
)
elif opt['get'] is True:
network = opt['<network>']
n.get(network)
elif opt['fixedaddresses'] is True:
network = opt['<network>']
n.fixedaddresses(network)
elif opt['option'] is True and opt['create']:
network_block = opt['<network_block>']
option_name = opt['<option>']
option_value = opt['<value>']
if '\-' in option_value:
option_value = option_value.replace('\-', '-')
n.create_option(network_block, option_name, option_value)
elif opt['attr'] is True and opt['create']:
network_block = opt['<network_block>']
attr_name = opt['<option>']
attr_value = opt['<value>']
n.create_attr(network_block, attr_name, attr_value)
elif opt['create'] is True:
if not opt['range']:
network = opt['<network>']
name = opt['<name>']
disable = opt['--disable']
if disable is None:
disable = True
if isinstance(disable, str):
if disable.upper() == 'TRUE':
disable = True
elif disable.upper() == 'FALSE':
disable = False
try:
members = opt['--members'].split(',')
except AttributeError:
members = []
n.create_network(
network,
name,
disable=disable,
members=members,
)
if n.api_out.has_error:
print "Unable to Create Network: %s" % network
sys.exit(2)
else:
print "Network Created Successfully"
n.get(network)
elif opt['range'] is True:
start = opt['<start>']
end = opt['<end>']
name = opt['<name>']
comment = opt['--comment']
disable = opt['--disable']
if disable is None:
disable = True
# Make a method out of this
# def parse_disable
if isinstance(disable, str):
if disable.upper() == 'TRUE':
disable = True
elif disable.upper() == 'FALSE':
disable = False
n.create_range(
name,
start,
end,
disable=disable,
)
#.........这里部分代码省略.........