本文整理汇总了Python中neutronclient.common.utils.str2dict函数的典型用法代码示例。如果您正苦于以下问题:Python str2dict函数的具体用法?Python str2dict怎么用?Python str2dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str2dict函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_none_string_to_dictionary
def test_none_string_to_dictionary(self):
input_str = ''
expected = {}
self.assertEqual(expected, utils.str2dict(input_str))
input_str = None
expected = {}
self.assertEqual(expected, utils.str2dict(input_str))
示例2: test_str2dict_required_keys
def test_str2dict_required_keys(self):
self.assertDictEqual(
{'key1': 'value1', 'key2': 'value2', 'key3': 'value3'},
utils.str2dict('key1=value1,key2=value2,key3=value3',
required_keys=['key1', 'key2'],
optional_keys=['key3']))
self.assertDictEqual(
{'key1': 'value1', 'key2': 'value2'},
utils.str2dict('key1=value1,key2=value2',
required_keys=['key1', 'key2']))
e = self.assertRaises(argparse.ArgumentTypeError,
utils.str2dict, 'key1=value1',
required_keys=['key1', 'key2'])
self.assertEqual("Required key(s) 'key2' not specified.", str(e))
示例3: test_str2dict_optional_keys
def test_str2dict_optional_keys(self):
self.assertDictEqual({'key1': 'value1'},
utils.str2dict('key1=value1',
optional_keys=['key1', 'key2']))
self.assertDictEqual({'key1': 'value1', 'key2': 'value2'},
utils.str2dict('key1=value1,key2=value2',
optional_keys=['key1', 'key2']))
e = self.assertRaises(argparse.ArgumentTypeError,
utils.str2dict,
'key1=value1,key2=value2,key3=value3',
optional_keys=['key1', 'key2'])
self.assertEqual("Invalid key(s) 'key3' specified. "
"Valid key(s): 'key1, key2'.",
str(e))
示例4: args2body_extradhcpopt
def args2body_extradhcpopt(self, parsed_args, port):
ops = []
if parsed_args.extra_dhcp_opts:
# the extra_dhcp_opt params (opt_name & opt_value)
# must come in pairs, if there is a parm error
# both must be thrown out.
opt_ele = {}
edo_err_msg = _("Invalid --extra-dhcp-opt option, can only be: "
"opt_name=<dhcp_option_name>,opt_value=<value>. "
"You can repeat this option.")
for opt in parsed_args.extra_dhcp_opts:
if opt.split('=')[0] in ['opt_value', 'opt_name']:
opt_ele.update(utils.str2dict(opt))
if (('opt_name' in opt_ele) and
('opt_value' in opt_ele)):
if opt_ele['opt_value'] == 'null':
opt_ele['opt_value'] = None
ops.append(opt_ele)
opt_ele = {}
else:
raise exceptions.CommandError(edo_err_msg)
else:
raise exceptions.CommandError(edo_err_msg)
if ops:
port.update({'extra_dhcp_opts': ops})
示例5: args2body
def args2body(self, parsed_args):
_network_id = neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'network', parsed_args.network_id)
body = {'port': {'admin_state_up': parsed_args.admin_state,
'network_id': _network_id, }, }
if parsed_args.mac_address:
body['port'].update({'mac_address': parsed_args.mac_address})
if parsed_args.device_id:
body['port'].update({'device_id': parsed_args.device_id})
if parsed_args.tenant_id:
body['port'].update({'tenant_id': parsed_args.tenant_id})
if parsed_args.name:
body['port'].update({'name': parsed_args.name})
ips = []
if parsed_args.fixed_ip:
for ip_spec in parsed_args.fixed_ip:
ip_dict = utils.str2dict(ip_spec)
if 'subnet_id' in ip_dict:
subnet_name_id = ip_dict['subnet_id']
_subnet_id = neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'subnet', subnet_name_id)
ip_dict['subnet_id'] = _subnet_id
ips.append(ip_dict)
if ips:
body['port'].update({'fixed_ips': ips})
self.args2body_secgroup(parsed_args, body['port'])
self.args2body_extradhcpopt(parsed_args, body['port'])
return body
示例6: args2body_extradhcpopt
def args2body_extradhcpopt(self, parsed_args, port):
ops = []
if parsed_args.extra_dhcp_opts:
# the extra_dhcp_opt params (opt_name & opt_value)
# must come in pairs, if there is a parm error
# both must be thrown out.
opt_ele = {}
edo_err_msg = _(
"Invalid --extra-dhcp-opt option, can only be: "
"opt_name=<dhcp_option_name>,opt_value=<value>,"
"ip_version={4,6}. "
"You can repeat this option."
)
for opt in parsed_args.extra_dhcp_opts:
opt_ele.update(utils.str2dict(opt))
if "opt_name" in opt_ele and ("opt_value" in opt_ele or "ip_version" in opt_ele):
if opt_ele.get("opt_value") == "null":
opt_ele["opt_value"] = None
ops.append(opt_ele)
opt_ele = {}
else:
raise exceptions.CommandError(edo_err_msg)
if ops:
port["extra_dhcp_opts"] = ops
示例7: run
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
neutron_client = self.get_client()
neutron_client.format = parsed_args.request_format
_router_id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, self.resource, parsed_args.router)
_ext_net_id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, 'network', parsed_args.external_network)
router_dict = {'network_id': _ext_net_id}
if parsed_args.disable_snat:
router_dict['enable_snat'] = False
if parsed_args.fixed_ip:
ips = []
for ip_spec in parsed_args.fixed_ip:
ip_dict = utils.str2dict(ip_spec)
subnet_name_id = ip_dict.get('subnet_id')
if subnet_name_id:
subnet_id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, 'subnet', subnet_name_id)
ip_dict['subnet_id'] = subnet_id
ips.append(ip_dict)
router_dict['external_fixed_ips'] = ips
neutron_client.add_gateway_router(_router_id, router_dict)
print(_('Set gateway for router %s') % parsed_args.router,
file=self.app.stdout)
示例8: args2body
def args2body(self, parsed_args):
_network_id = neutronV20.find_resourceid_by_name_or_id(self.get_client(), "network", parsed_args.network_id)
body = {"port": {"admin_state_up": parsed_args.admin_state, "network_id": _network_id}}
if parsed_args.mac_address:
body["port"].update({"mac_address": parsed_args.mac_address})
if parsed_args.device_id:
body["port"].update({"device_id": parsed_args.device_id})
if parsed_args.tenant_id:
body["port"].update({"tenant_id": parsed_args.tenant_id})
if parsed_args.name:
body["port"].update({"name": parsed_args.name})
ips = []
if parsed_args.fixed_ip:
for ip_spec in parsed_args.fixed_ip:
ip_dict = utils.str2dict(ip_spec)
if "subnet_id" in ip_dict:
subnet_name_id = ip_dict["subnet_id"]
_subnet_id = neutronV20.find_resourceid_by_name_or_id(self.get_client(), "subnet", subnet_name_id)
ip_dict["subnet_id"] = _subnet_id
ips.append(ip_dict)
if ips:
body["port"].update({"fixed_ips": ips})
self.args2body_secgroup(parsed_args, body["port"])
self.args2body_extradhcpopt(parsed_args, body["port"])
return body
示例9: args2body
def args2body(self, parsed_args):
body = {'name': parsed_args.name}
devices = []
if parsed_args.device:
for device in parsed_args.device:
devices.append(utils.str2dict(device))
if devices:
body['devices'] = devices
if parsed_args.tenant_id:
body['tenant_id'] = parsed_args.tenant_id
return {self.resource: body}
示例10: args2body
def args2body(self, parsed_args):
body = {self.resource: {"name": parsed_args.name}}
devices = []
if parsed_args.device:
for device in parsed_args.device:
devices.append(utils.str2dict(device))
if devices:
body[self.resource].update({"devices": devices})
if parsed_args.tenant_id:
body[self.resource].update({"tenant_id": parsed_args.tenant_id})
return body
示例11: args2body
def args2body(self, parsed_args):
if parsed_args.session_persistence:
parsed_args.session_persistence = utils.str2dict(parsed_args.session_persistence)
_listener_id = neutronV20.find_resourceid_by_name_or_id(self.get_client(), "listener", parsed_args.listener)
body = {
"admin_state_up": parsed_args.admin_state,
"protocol": parsed_args.protocol,
"lb_algorithm": parsed_args.lb_algorithm,
"listener_id": _listener_id,
}
neutronV20.update_dict(parsed_args, body, ["description", "name", "session_persistence", "tenant_id"])
return {self.resource: body}
示例12: _updatable_args2body
def _updatable_args2body(parsed_args, body, client):
neutronV20.update_dict(parsed_args, body, ["device_id", "device_owner", "name"])
ips = []
if parsed_args.fixed_ip:
for ip_spec in parsed_args.fixed_ip:
ip_dict = utils.str2dict(ip_spec)
if "subnet_id" in ip_dict:
subnet_name_id = ip_dict["subnet_id"]
_subnet_id = neutronV20.find_resourceid_by_name_or_id(client, "subnet", subnet_name_id)
ip_dict["subnet_id"] = _subnet_id
ips.append(ip_dict)
if ips:
body["fixed_ips"] = ips
示例13: args2body
def args2body(self, parsed_args):
if parsed_args.session_persistence:
parsed_args.session_persistence = utils.str2dict(
parsed_args.session_persistence)
_listener_id = neutronV20.find_resourceid_by_name_or_id(
self.get_client(), 'listener', parsed_args.listener)
body = {'admin_state_up': parsed_args.admin_state,
'protocol': parsed_args.protocol,
'lb_algorithm': parsed_args.lb_algorithm,
'listener_id': _listener_id}
neutronV20.update_dict(parsed_args, body,
['description', 'name',
'session_persistence', 'tenant_id'])
return {self.resource: body}
示例14: _updatable_args2body
def _updatable_args2body(parsed_args, body, client):
neutronV20.update_dict(parsed_args, body,
['device_id', 'device_owner', 'name'])
ips = []
if parsed_args.fixed_ip:
for ip_spec in parsed_args.fixed_ip:
ip_dict = utils.str2dict(ip_spec)
if 'subnet_id' in ip_dict:
subnet_name_id = ip_dict['subnet_id']
_subnet_id = neutronV20.find_resourceid_by_name_or_id(
client, 'subnet', subnet_name_id)
ip_dict['subnet_id'] = _subnet_id
ips.append(ip_dict)
if ips:
body['fixed_ips'] = ips
示例15: _updatable_args2body
def _updatable_args2body(parsed_args, body, client):
if parsed_args.device_id:
body['port'].update({'device_id': parsed_args.device_id})
if parsed_args.device_owner:
body['port'].update({'device_owner': parsed_args.device_owner})
if parsed_args.name:
body['port'].update({'name': parsed_args.name})
ips = []
if parsed_args.fixed_ip:
for ip_spec in parsed_args.fixed_ip:
ip_dict = utils.str2dict(ip_spec)
if 'subnet_id' in ip_dict:
subnet_name_id = ip_dict['subnet_id']
_subnet_id = neutronV20.find_resourceid_by_name_or_id(
client, 'subnet', subnet_name_id)
ip_dict['subnet_id'] = _subnet_id
ips.append(ip_dict)
if ips:
body['port'].update({'fixed_ips': ips})