本文整理汇总了Python中neutron.api.v2.attributes.convert_to_boolean函数的典型用法代码示例。如果您正苦于以下问题:Python convert_to_boolean函数的具体用法?Python convert_to_boolean怎么用?Python convert_to_boolean使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convert_to_boolean函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_agents
def get_agents(self, context, filters=None, fields=None):
agents = self._get_collection(context, Agent, self._make_agent_dict, filters=filters, fields=fields)
alive = filters and filters.get("alive", None)
if alive:
# alive filter will be a list
alive = attributes.convert_to_boolean(alive[0])
agents = [agent for agent in agents if agent["alive"] == alive]
return agents
示例2: test_convert_to_boolean_str
def test_convert_to_boolean_str(self):
self.assertIs(attributes.convert_to_boolean("True"), True)
self.assertIs(attributes.convert_to_boolean("true"), True)
self.assertIs(attributes.convert_to_boolean("False"), False)
self.assertIs(attributes.convert_to_boolean("false"), False)
self.assertIs(attributes.convert_to_boolean("0"), False)
self.assertIs(attributes.convert_to_boolean("1"), True)
self.assertRaises(n_exc.InvalidInput, attributes.convert_to_boolean, "7")
示例3: test_convert_to_boolean_str
def test_convert_to_boolean_str(self):
self.assertIs(attributes.convert_to_boolean('True'), True)
self.assertIs(attributes.convert_to_boolean('true'), True)
self.assertIs(attributes.convert_to_boolean('False'), False)
self.assertIs(attributes.convert_to_boolean('false'), False)
self.assertIs(attributes.convert_to_boolean('0'), False)
self.assertIs(attributes.convert_to_boolean('1'), True)
self.assertRaises(n_exc.InvalidInput,
attributes.convert_to_boolean,
'7')
示例4: test_convert_to_boolean_int
def test_convert_to_boolean_int(self):
self.assertIs(attributes.convert_to_boolean(0), False)
self.assertIs(attributes.convert_to_boolean(1), True)
self.assertRaises(n_exc.InvalidInput,
attributes.convert_to_boolean,
7)
示例5: test_convert_to_boolean_bool
def test_convert_to_boolean_bool(self):
self.assertIs(attributes.convert_to_boolean(True), True)
self.assertIs(attributes.convert_to_boolean(False), False)
示例6: convert_to_boolean_if_not_none
def convert_to_boolean_if_not_none(data):
if data is not None:
return attributes.convert_to_boolean(data)
return data
示例7: update
def update(self, request, id, **kwargs):
context = request.context
self._check_admin(context)
body = validators.validate_request(request)
key_list = ['access_protocol', 'access_parameters',
'enable', 'rediscover']
validators.validate_attributes(body.keys(), key_list)
validate_snmp_creds = False
phys_switch = db.get_bnp_phys_switch(context, id)
if not phys_switch:
raise webob.exc.HTTPNotFound(
_("Switch %s does not exist") % id)
if body.get('access_parameters'):
validate_snmp_creds = True
access_parameters = body.pop("access_parameters")
for key, value in access_parameters.iteritems():
body[key] = value
else:
access_parameters = {
'write_community': phys_switch['write_community'],
'security_name': phys_switch['security_name'],
'auth_protocol': phys_switch['auth_protocol'],
'priv_protocol': phys_switch['priv_protocol'],
'auth_key': phys_switch['auth_key'],
'priv_key': phys_switch['priv_key'],
'security_level': phys_switch['security_level']}
if body.get('access_protocol'):
validate_snmp_creds = True
protocol = body['access_protocol']
if protocol.lower() not in const.SUPPORTED_PROTOCOLS:
raise webob.exc.HTTPBadRequest(
_("access protocol %s is not supported") % body[
'access_protocol'])
else:
protocol = phys_switch['access_protocol']
switch_dict = self._update_dict(body, dict(phys_switch))
switch_to_show = self._switch_to_show(switch_dict)
switch = switch_to_show[0]
if validate_snmp_creds:
if protocol.lower() == const.SNMP_V3:
validators.validate_snmpv3_parameters(access_parameters)
else:
validators.validate_snmp_parameters(access_parameters)
try:
snmp_driver = discovery_driver.SNMPDiscoveryDriver(switch_dict)
snmp_driver.get_sys_name()
db.update_bnp_phys_switch_access_params(context,
id, switch_dict)
except Exception as e:
LOG.error(_LE("Exception in validating credentials '%s' "), e)
raise webob.exc.HTTPBadRequest(
_("Validation of credentials failed"))
if body.get('enable'):
enable = attributes.convert_to_boolean(body['enable'])
if not enable:
switch_status = const.SWITCH_STATUS['disable']
db.update_bnp_phys_switch_status(context, id, switch_status)
else:
switch_status = const.SWITCH_STATUS['enable']
db.update_bnp_phys_switch_status(context, id, switch_status)
switch['status'] = switch_status
if body.get('rediscover'):
bnp_switch = self._discover_switch(switch_dict)
db_switch_ports = db.get_bnp_phys_switch_ports_by_switch_id(
context, id)
self._update_switch_ports(context, id,
bnp_switch.get('ports'),
db_switch_ports)
return switch