Example #1
0
    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> ...'))
Example #2
0
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).'))
Example #3
0
    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
Example #7
0
 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
Example #8
0
 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)
Example #10
0
    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.'))
Example #11
0
    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)
Example #12
0
    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.'))
Example #13
0
 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
Example #14
0
 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
Example #15
0
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
Example #16
0
    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'))
Example #17
0
    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'))
Example #18
0
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
              })
Example #19
0
 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)
Example #20
0
 def add_known_arguments(self, parser):
     parser.add_argument('bgpvpn', metavar='BGPVPN',
                         help=_('ID or name of the BGPVPN.'))
Example #21
0
class BGPVPNDriverError(n_exc.NeutronException):
    message = _("%(method)s failed.")
Example #22
0
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")
Example #23
0
class BGPVPNMultipleRouterAssocNotSupported(n_exc.BadRequest):
    message = _("BGPVPN %(driver)s driver does not support multiple "
                "router association with a bgpvpn")
Example #24
0
class BGPVPNRouterAssocAlreadyExists(n_exc.BadRequest):
    message = _("router %(router_id)s is already associated to "
                "BGPVPN %(bgpvpn_id)s")
Example #25
0
class BGPVPNFindFromNetNotSupported(n_exc.BadRequest):
    message = _("BGPVPN %(driver)s driver does not support to fetch BGPVPNs "
                "associated to network id %(net_id)")
Example #26
0
class BGPVPNRDNotSupported(n_exc.BadRequest):
    message = _("BGPVPN %(driver)s driver does not support to manually set "
                "route distinguisher")
Example #27
0
class BGPVPNTypeNotSupported(n_exc.BadRequest):
    message = _("BGPVPN %(driver)s driver does not support %(type)s type")
Example #28
0
class BGPVPNRouterAssocNotFound(n_exc.NotFound):
    message = _("BGPVPN router association %(id)s could not be found "
                "for BGPVPN %(bgpvpn_id)s")
Example #29
0
class BGPVPNNetAssocNotFound(n_exc.NotFound):
    message = _("BGPVPN network association %(id)s could not be found "
                "for BGPVPN %(bgpvpn_id)s")
Example #30
0
class BGPVPNNotFound(n_exc.NotFound):
    message = _("BGPVPN %(id)s could not be found")
Example #31
0
class BGPVPNNetAssocAlreadyExists(n_exc.BadRequest):
    message = _("network %(net_id)s is already associated to "
                "BGPVPN %(bgpvpn_id)s")
Example #32
0
 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.'))
Example #33
0
class BGPVPNRouterAssociationNotSupported(n_exc.BadRequest):
    message = _("BGPVPN %(driver)s driver does not support router "
                "associations")
Example #34
0
class OpenContrailMalformedUUID(n_exc.BadRequest):
    message = _("Malformed UUID: %(uuid)s")
Example #35
0
class OpenContrailAPIBadRequest(n_exc.BadRequest):
    message = _("OpenContrail API bad request: %(reason)s")