def add_known_arguments(self, parser): """Adds to parser arguments common to create and update commands.""" parser.add_argument( '--name', help=_('Name of the BGP VPN')) parser.add_argument( '--route-targets', help=_('Route Targets list to import/export for this BGP ' 'VPN. Usage: -- --route-targets ' 'list=true <asn1>:<nn1> <asn2>:<nn2> ...')) parser.add_argument( '--import-targets', help=_('List of additional Route Targets to import from.' ' Usage: -- --import-targets list=true ' '<asn1>:<nn1> <asn2>:<nn2> ...')) parser.add_argument( '--export-targets', help=_('List of additional Route Targets to export to. Usage: -- ' '--export-targets list=true <asn1>:<nn1> <asn2>:<nn2> ...')) parser.add_argument( '--route-distinguishers', help=_('List of RDs that will be used to advertize VPN routes.' 'Usage: -- --route-distinguishers list=true ' '<asn1>:<nn1> <asn2>:<nn2> ...'))
def _add_create_update_common_arguments(parser): """Adds to parser arguments common to create and update commands.""" parser.add_argument('--name', metavar='<name>', help=_('Name of the BGP VPN')) parser.add_argument('--route-target', dest='route_targets', action='append', metavar='<route-target>', help=_( 'Route Target to import/export for this BGP VPN ' '(repeat option to set multiple Route Targets).')) parser.add_argument('--import-target', dest='import_targets', action='append', metavar='<import-target>', help=_( 'Additional Route Target to import from ' '(repeat option to set multiple Route Targets).')) parser.add_argument('--export-target', dest='export_targets', action='append', metavar='<export-target>', help=_( 'Additional Route Target to export to ' '(repeat option to set multiple Route Targets).')) parser.add_argument( '--route-distinguisher', dest='route_distinguishers', action='append', metavar='<route-distinguisher>', help=_('Set of Route Distinguisher in which the Route Distinguisher' 'for advertized VPN routes will be picked from (repeat option ' 'to set multiple Route Distinguishers).'))
def add_known_arguments(self, parser): """Adds to parser arguments common to create and update commands.""" parser.add_argument( '--name', help=_('Name of the BGP VPN')) parser.add_argument( '--route-targets', help=_('Route Targets list to import/export for this BGP ' 'VPN. Usage: -- --route-targets ' 'list=true <asn1>:<nn1> <asn2>:<nn2> ...')) parser.add_argument( '--import-targets', help=_('List of additional Route Targets to import from.' ' Usage: -- --import-targets list=true ' '<asn1>:<nn1> <asn2>:<nn2> ...')) parser.add_argument( '--export-targets', help=_('List of additional Route Targets to export to. Usage: -- ' '--export-targets list=true <asn1>:<nn1> <asn2>:<nn2> ...')) parser.add_argument( '--route-distinguishers', help=_('List of RDs that will be used to advertize VPN routes.' 'Usage: -- --route-distinguishers list=true ' '<asn1>:<nn1> <asn2>:<nn2> ...'))
def get_parser(self, prog_name): parser = super(UpdateBgpvpnResAssoc, self).get_parser(prog_name) parser.add_argument('resource_association', metavar="<%s association>" % self._assoc_res_name, help=(_("ID of the %s association to update.") % self._assoc_res_name)) parser.add_argument('bgpvpn', metavar="<bgpvpn>", help=_("ID or name of BGP VPN.")) return parser
def get_parser(self, prog_name): parser = super(ListBgpvpnResAssoc, self).get_parser(prog_name) parser.add_argument('bgpvpn', metavar="<bgpvpn>", help=_("ID or name of BGP VPN.")) parser.add_argument( '--property', metavar='<key=value>', default=dict(), help=_('Filter property to apply on returned bgpvpns (repeat to ' 'filter on multiple properties)'), action=KeyValueAction) return parser
def get_parser(self, prog_name): parser = super(CreateBgpvpnResAssoc, self).get_parser(prog_name) parser.add_argument('--project', metavar='<project>', help=_("Owner's project (name or ID)")) identity_common.add_project_domain_option_to_parser(parser) parser.add_argument('bgpvpn', metavar="<bgpvpn>", help=_("ID or name of the BGP VPN.")) parser.add_argument('resource', metavar="<%s>" % self._assoc_res_name, help=(_("ID or name of the %s.") % self._assoc_res_name)) return parser
def get_parser(self, prog_name): parser = super(ListBgpvpn, self).get_parser(prog_name) parser.add_argument('--project', metavar='<project>', help=_("Owner's project (name or ID)")) identity_common.add_project_domain_option_to_parser(parser) parser.add_argument( '--property', metavar='<key=value>', default=dict(), help=_('Filter property to apply on returned BGP VPNs (repeat to ' 'filter on multiple properties)'), action=KeyValueAction) return parser
def get_parser(self, prog_name): parser = super(CreateBgpvpn, self).get_parser(prog_name) parser.add_argument('--project', metavar='<project>', help=_("Owner's project (name or ID)")) identity_common.add_project_domain_option_to_parser(parser) _add_create_update_common_arguments(parser) parser.add_argument( '--type', default='l3', choices=['l2', 'l3'], help=_('BGP VPN type selection between IP VPN (l3) and Ethernet ' 'VPN (l2) (default:%(default)s)')) return parser
def take_action(self, parsed_args): client = self.app.client_manager.neutronclient bgpvpn = client.find_resource(bgpvpn_resource, parsed_args.bgpvpn) fails = 0 for id in parsed_args.resource_associations: try: client.delete_ext(self._resource_path % bgpvpn['id'], id) LOG.warn( _LW("%(assoc_res_name)s association %(id)s deleted"), { 'assoc_res_name': self._assoc_res_name.capitalize(), 'id': id }) except Exception as e: fails += 1 LOG.error( _LE("Failed to delete %(assoc_res_name)s " "association with ID '%(id)s': %(e)s"), { 'assoc_res_name': self._assoc_res_name, 'id': id, 'e': e }) if fails > 0: msg = (_("Failed to delete %(fails)s of %(total)s " "%(assoc_res_name)s BGP VPN association(s).") % { 'fails': fails, 'total': len(parsed_args.resource_associations), 'assoc_res_name': self._assoc_res_name }) raise exceptions.CommandError(msg)
def add_known_arguments(self, parser): BGPVPNNetAssoc.add_known_arguments(self, parser) parser.add_argument('--network', required=True, help=_('ID or name of the network.'))
def _notify_adding_interface_to_router(self, resource, event, trigger, **kwargs): context = kwargs.get('context') network_id = kwargs.get('network_id') router_id = kwargs.get('router_id') try: routers_bgpvpns = self.driver.get_bgpvpns( context, filters={ 'routers': [router_id], }, ) except bgpvpn.BGPVPNRouterAssociationNotSupported: return nets_bgpvpns = self.driver.get_bgpvpns( context, filters={ 'networks': [network_id], 'type': [constants.BGPVPN_L3], }, ) if routers_bgpvpns and nets_bgpvpns: msg = _('It is not allowed to add an interface to a router if ' 'both the router and the network are bound to an ' 'L3 BGPVPN.') raise n_exc.BadRequest(resource='bgpvpn', msg=msg)
def add_known_arguments(self, parser): BGPVPNNetAssoc.add_known_arguments(self, parser) parser.add_argument( '--network', required=True, help=_('ID or name of the network.'))
def get_parser(self, prog_name): parser = super(DeleteBgpvpn, self).get_parser(prog_name) parser.add_argument('bgpvpns', metavar="<bgpvpn>", nargs="+", help=_("BGP VPN(s) to delete (name or ID)")) return parser
def get_parser(self, prog_name): parser = super(UpdateBgpvpn, self).get_parser(prog_name) parser.add_argument('bgpvpn', metavar="<bgpvpn>", help=_("ID or name of BGP VPN to update.")) _add_create_update_common_arguments(parser) return parser
def _validate_rt_list(data, valid_values=None): if data is None or data is "": return if not isinstance(data, list): msg = _("'%s' is not a list") % data LOG.debug(msg) return msg for item in data: msg = api.validators.validate_regex(item, constants.RT_REGEX) if msg: LOG.debug(msg) return msg if len(set(data)) != len(data): msg = _("Duplicate items in the list: '%s'") % ', '.join(data) LOG.debug(msg) return msg
def add_known_arguments(self, parser): BGPVPNCreateUpdateCommon.add_known_arguments(self, parser) # type is read-only, hence specific to create parser.add_argument( '--type', default='l3', choices=['l2', 'l3'], help=_('BGP VPN type selection between L3VPN (l3) and ' 'EVPN (l2), default:l3'))
def add_known_arguments(self, parser): BGPVPNCreateUpdateCommon.add_known_arguments(self, parser) # type is read-only, hence specific to create parser.add_argument( '--type', default='l3', choices=['l2', 'l3'], help=_('BGP VPN type selection between L3VPN (l3) and ' 'EVPN (l2), default:l3'))
def get_auth_token(): DEFAULT_HEADERS = { 'Content-type': 'application/json; charset="UTF-8"', 'X-Contrail-Useragent': 'bgppn_opencontrail_client', } admin_user = cfg.CONF.keystone_authtoken.admin_user admin_password = cfg.CONF.keystone_authtoken.admin_password admin_tenant_name = cfg.CONF.keystone_authtoken.admin_tenant_name auth_body = { "auth": { "passwordCredentials": { "username": admin_user, "password": admin_password }, "tenantName": admin_tenant_name } } try: auth_type = CONF.keystone_authtoken.auth_type except cfg.NoSuchOptError: auth_type = "keystone" if auth_type != "keystone": return try: auth_url = cfg.CONF.keystone_authtoken.auth_url except cfg.NoSuchOptError: try: auth_host = cfg.CONF.keystone_authtoken.auth_host except cfg.NoSuchOptError: auth_host = "127.0.0.1" try: auth_protocol = cfg.CONF.keystone_authtoken.auth_protocol except cfg.NoSuchOptError: auth_protocol = "http" try: auth_port = cfg.CONF.keystone_authtoken.auth_port except cfg.NoSuchOptError: auth_port = "35357" auth_url = "%s://%s:%s" % (auth_protocol, auth_host, auth_port) url = auth_url + '/v2.0/tokens' response = requests.post(url, data=jsonutils.dumps(auth_body), headers=DEFAULT_HEADERS) if response.status_code == 200: auth_content = jsonutils.loads(response.text) return auth_content['access']['token']['id'] else: raise RuntimeError( _("Authentication failure. Code: %(code)d, " "reason: %(reason)s") % { 'code': response.status_code, 'reason': response.reason })
def take_action(self, parsed_args): client = self.app.client_manager.neutronclient fails = 0 for id_or_name in parsed_args.bgpvpns: try: id = client.find_resource(resource, id_or_name)['id'] client.delete_ext(resource_path, id) LOG.warn(_LW("BGP VPN %(id)s deleted"), {'id': id}) except Exception as e: fails += 1 LOG.error( _LE("Failed to delete BGP VPN with name or ID " "'%(id_or_name)s': %(e)s"), { 'id_or_name': id_or_name, 'e': e }) if fails > 0: msg = (_("Failed to delete %(fails)s of %(total)s BGP VPN.") % { 'fails': fails, 'total': len(parsed_args.bgpvpns) }) raise exceptions.CommandError(msg)
def add_known_arguments(self, parser): parser.add_argument('bgpvpn', metavar='BGPVPN', help=_('ID or name of the BGPVPN.'))
class BGPVPNDriverError(n_exc.NeutronException): message = _("%(method)s failed.")
class BGPVPNNetworkAssocExistsAnotherBgpvpn(n_exc.BadRequest): message = _("Network %(network)s already associated with %(bgpvpn)s. " "BGPVPN %(driver)s driver does not support same network" " associated to multiple bgpvpns")
class BGPVPNMultipleRouterAssocNotSupported(n_exc.BadRequest): message = _("BGPVPN %(driver)s driver does not support multiple " "router association with a bgpvpn")
class BGPVPNRouterAssocAlreadyExists(n_exc.BadRequest): message = _("router %(router_id)s is already associated to " "BGPVPN %(bgpvpn_id)s")
class BGPVPNFindFromNetNotSupported(n_exc.BadRequest): message = _("BGPVPN %(driver)s driver does not support to fetch BGPVPNs " "associated to network id %(net_id)")
class BGPVPNRDNotSupported(n_exc.BadRequest): message = _("BGPVPN %(driver)s driver does not support to manually set " "route distinguisher")
class BGPVPNTypeNotSupported(n_exc.BadRequest): message = _("BGPVPN %(driver)s driver does not support %(type)s type")
class BGPVPNRouterAssocNotFound(n_exc.NotFound): message = _("BGPVPN router association %(id)s could not be found " "for BGPVPN %(bgpvpn_id)s")
class BGPVPNNetAssocNotFound(n_exc.NotFound): message = _("BGPVPN network association %(id)s could not be found " "for BGPVPN %(bgpvpn_id)s")
class BGPVPNNotFound(n_exc.NotFound): message = _("BGPVPN %(id)s could not be found")
class BGPVPNNetAssocAlreadyExists(n_exc.BadRequest): message = _("network %(net_id)s is already associated to " "BGPVPN %(bgpvpn_id)s")
def add_known_arguments(self, parser): BGPVPNRouterAssoc.add_known_arguments(self, parser) parser.add_argument( '--router', required=True, help=_('ID or name of the router.'))
class BGPVPNRouterAssociationNotSupported(n_exc.BadRequest): message = _("BGPVPN %(driver)s driver does not support router " "associations")
class OpenContrailMalformedUUID(n_exc.BadRequest): message = _("Malformed UUID: %(uuid)s")
class OpenContrailAPIBadRequest(n_exc.BadRequest): message = _("OpenContrail API bad request: %(reason)s")