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
Beispiel #2
0
 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 = attributes.convert_to_boolean(alive[0])
         agents = [agent for agent in agents if agent['alive'] == alive]
     return agents
 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")
Beispiel #4
0
 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')
 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')
Beispiel #6
0
def convert_to_boolean_if_not_none(data):
    if data is not None:
        return attributes.convert_to_boolean(data)
    return data
Beispiel #7
0
 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)
Beispiel #8
0
 def test_convert_to_boolean_bool(self):
     self.assertIs(attributes.convert_to_boolean(True), True)
     self.assertIs(attributes.convert_to_boolean(False), False)
 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)
 def test_convert_to_boolean_bool(self):
     self.assertIs(attributes.convert_to_boolean(True), True)
     self.assertIs(attributes.convert_to_boolean(False), False)
Beispiel #11
0
def convert_to_boolean_if_not_none(data):
    if data is not None:
        return attributes.convert_to_boolean(data)
    return data
 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
Beispiel #13
0
               help=_("mgmt interface of mgmt subnet"
                      " anti spoofing feature")),
    cfg.StrOpt('mgmt_security_group',
               default='servicevm_mgmt_security_group',
               help=_("security group for servicevm manager port")),
    cfg.StrOpt('internal_security_group',
               default='servicevm_internal_port_security_group',
               help=_("security group for servicevm manager port")),
    cfg.StrOpt('mgmt_pps_limit',
               default='tcp:syn::100,udp:::100,icmp:::50',
               help=_("pps limit for servicevm manager port")),
]

cfg.CONF.register_opts(SVM_OPTS, "servicevm")

anti_spoofing = attributes.convert_to_boolean(
    cfg.CONF.servicevm.servicevm_anti_spoofing)
mgmt_anti_spoofing = attributes.convert_to_boolean(
    cfg.CONF.servicevm.servicevm_mgmt_anti_spoofing)
shadow_net_anti_spoofing = attributes.convert_to_boolean(True)

mgmt_subnet = cfg.CONF.servicevm.mgmt_subnet_name_id
mgmt_network = cfg.CONF.servicevm.mgmt_network_name_id
shadow_subnet = cfg.CONF.unitedstack.external_shadow_subnet
mgmt_pps_limit = cfg.CONF.servicevm.mgmt_pps_limit

MGMT = l3_constants.SERVICEVM_OWNER_MGMT
ROUTER_GW = l3_constants.SERVICEVM_OWNER_ROUTER_GW
ROUTER_INTF = l3_constants.SERVICEVM_OWNER_ROUTER_INTF

_NICS = 'nics'  # converted by novaclient => 'networks'
_NET_ID = 'net-id'  # converted by novaclient => 'uuid'