本文整理汇总了Python中neutronclient.common.utils.str2dict函数的典型用法代码示例。如果您正苦于以下问题:Python str2dict函数的具体用法?Python str2dict怎么用?Python str2dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str2dict函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:ChameleonCloud,项目名称:python-neutronclient,代码行数:7,代码来源:test_utils.py
示例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))
开发者ID:ChameleonCloud,项目名称:python-neutronclient,代码行数:14,代码来源:test_utils.py
示例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))
开发者ID:ChameleonCloud,项目名称:python-neutronclient,代码行数:14,代码来源:test_utils.py
示例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})
开发者ID:cboling,项目名称:SDNdbg,代码行数:26,代码来源:port.py
示例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
开发者ID:ralphwort,项目名称:chef-repo,代码行数:30,代码来源:port.py
示例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
开发者ID:nmagnezi,项目名称:python-neutronclient,代码行数:25,代码来源:port.py
示例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)
开发者ID:Gvkrishna,项目名称:python-neutronclient,代码行数:25,代码来源:router.py
示例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
开发者ID:kbijon,项目名称:OpenStack-CVRM,代码行数:27,代码来源:port.py
示例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}
开发者ID:rjain-iitr,项目名称:python-neutronclient,代码行数:11,代码来源:networkgateway.py
示例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
开发者ID:wputra,项目名称:MOS-centos,代码行数:11,代码来源:networkgateway.py
示例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}
开发者ID:Gvkrishna,项目名称:python-neutronclient,代码行数:12,代码来源:pool.py
示例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
开发者ID:nmagnezi,项目名称:python-neutronclient,代码行数:13,代码来源:port.py
示例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}
开发者ID:rjain-iitr,项目名称:python-neutronclient,代码行数:14,代码来源:pool.py
示例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
开发者ID:TonyChengTW,项目名称:OpenStack_Liberty_Control,代码行数:15,代码来源:port.py
示例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})
开发者ID:yizhongyin,项目名称:OpenstackLiberty,代码行数:19,代码来源:port.py
示例16: 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)
开发者ID:yizhongyin,项目名称:OpenstackLiberty,代码行数:21,代码来源:router.py
示例17: test_validate_lifetime_dictionary_under_minimum_integer_value
def test_validate_lifetime_dictionary_under_minimum_integer_value(self):
input_str = utils.str2dict('units=seconds,value=59')
self._test_validate_lifetime_negative_test_case(input_str)
开发者ID:niuzhenguo,项目名称:python-neutronclient,代码行数:3,代码来源:test_utils.py
示例18: test_validate_lifetime_dictionary_seconds
def test_validate_lifetime_dictionary_seconds(self):
input_str = utils.str2dict("units=seconds,value=3600")
self.assertIsNone(vpn_utils.validate_lifetime_dict(input_str))
开发者ID:niuzhenguo,项目名称:python-neutronclient,代码行数:3,代码来源:test_utils.py
示例19: test_validate_dpd_dictionary_negative_timeout_value
def test_validate_dpd_dictionary_negative_timeout_value(self):
input_str = utils.str2dict('action=hold,interval=30,timeout=-1')
self._test_validate_lifetime_negative_test_case(input_str)
开发者ID:niuzhenguo,项目名称:python-neutronclient,代码行数:3,代码来源:test_utils.py
示例20: test_string_to_dictionary
def test_string_to_dictionary(self):
input_str = 'key1=value1,key2=value2'
expected = {'key1': 'value1', 'key2': 'value2'}
self.assertEqual(expected, utils.str2dict(input_str))
开发者ID:ChameleonCloud,项目名称:python-neutronclient,代码行数:4,代码来源:test_utils.py
注:本文中的neutronclient.common.utils.str2dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论