Пример #1
0
 def args2body(self, parsed_args):
     body = {'nuage_redirect_target': {
         'name': parsed_args.name}}
     if not parsed_args.insertion_mode:
         message = (_('--insertion_mode should be specified'))
         raise exceptions.NeutronClientException(message=message)
     if not parsed_args.subnet and not parsed_args.router:
         message = (_('--subnet or --router should be specified'))
         raise exceptions.NeutronClientException(message=message)
     if parsed_args.description:
         body['nuage_redirect_target'].update(
             {'description': parsed_args.description})
     if parsed_args.redundancy_enabled:
         body['nuage_redirect_target'].update(
             {'redundancy_enabled': parsed_args.redundancy_enabled})
     if parsed_args.insertion_mode:
         body['nuage_redirect_target'].update(
             {'insertion_mode': parsed_args.insertion_mode})
     if parsed_args.subnet:
         _subnet_id = neutronV20.find_resourceid_by_name_or_id(
             self.get_client(), 'subnet', parsed_args.subnet)
         body['nuage_redirect_target'].update(
             {'subnet_id': _subnet_id})
     if parsed_args.router:
         _router_id = neutronV20.find_resourceid_by_name_or_id(
             self.get_client(), 'router', parsed_args.router)
         body['nuage_redirect_target'].update(
             {'router_id': _router_id})
     return body
Пример #2
0
def add_arguments_for_create_update(parser, is_create):
    parser.add_argument(
        '--switch-id',
        dest='switch_id',
        help=_('SystemID of the gateway device.'),
        required=is_create)
    parser.add_argument(
        '--switch-info',
        dest='switch_info',
        help=_('Name of the switch device'),
        required=False)
    parser.add_argument(
        '--port-id',
        dest='port_id',
        help=_('Name of the port of the switch'),
        required=is_create)
    parser.add_argument(
        '--host-id',
        help=_('Nova compute host id, hypervisor_hostname'),
        required=is_create)
    parser.add_argument(
        '--pci-slot',
        dest='pci_slot',
        help=_('PCI id of the VF device.'),
        required=is_create)
Пример #3
0
    def args2body(self, parsed_args):
        body = {self.resource: {'value': parsed_args.id}}

        if parsed_args.gateway and parsed_args.gatewayport:
            body[self.resource].update({'gateway': parsed_args.gateway})
            gw_id = neutronV20.find_resourceid_by_name_or_id(
                self.get_client(), GW_RESOURCE, parsed_args.gateway)
            body[self.resource].update({'gateway': gw_id})

            gw_port_id = get_resource_by_name_or_id(self.get_client(),
                                                    GW_PORT_RESOURCE,
                                                    parsed_args.gatewayport,
                                                    GATEWAY, gw_id)

            body[self.resource].update({'gatewayport': gw_port_id})

        elif parsed_args.gatewayport:
            match = re.match(UUID_PATTERN, parsed_args.gatewayport)
            if not match:
                message = (_('--gatewayport should be a UUID'))
                raise exceptions.CommandError(message=message)

            gw_port_id = neutronV20.find_resourceid_by_name_or_id(
                self.get_client(), GW_PORT_RESOURCE, parsed_args.gatewayport)

            body[self.resource].update({'gatewayport': gw_port_id})
        else:
            message = (_('--gatewayport should be specified'))
            raise exceptions.CommandError(message=message)

        return body
Пример #4
0
 def get_parser(self, prog_name):
     parser = super(ListGatewayVPort, self).get_parser(prog_name)
     parser.add_argument('id', metavar='SUBNET', help=_('ID of the subnet'))
     parser.add_argument('--tenant-id',
                         metavar='TENANT',
                         help=_('ID of the tenant.'))
     return parser
Пример #5
0
 def run(self, parsed_args):
     self.log.debug('run(%s)' % parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     res_id = get_gatway_info(parsed_args, neutron_client)
     body = {
         self.resource: {
             'tenant': parsed_args.tenant_id,
             'action': 'unassign'
         }
     }
     match = re.match(UUID_PATTERN, str(res_id))
     if match:
         neutron_client.update_nuage_gateway_vlan(res_id, body)
         print((_('Unassigned %(resource)s %(res_id)s from tenant '
                  '%(tenant)s') % {
                      'res_id': parsed_args.id,
                      'resource': self.resource,
                      'tenant': parsed_args.tenant_id
                  }),
               file=self.app.stdout)
     else:
         neutron_client.update_nuage_gateway_vlan(parsed_args.id, body)
         print((_('Unassigned %(resource)s %(res_id)s from tenant '
                  '%(tenant)s') % {
                      'res_id': res_id,
                      'resource': self.resource,
                      'tenant': parsed_args.tenant_id
                  }),
               file=self.app.stdout)
Пример #6
0
 def add_known_arguments(self, parser):
     parser.add_argument('gatewayvlan',
                         metavar='GATEWAYVLAN',
                         help=_('ID of the gateway interface'))
     parser.add_argument('--subnet',
                         metavar='SUBNET',
                         help=_('ID of the subnet'))
     parser.add_argument('--port', metavar='PORT', help=_('ID of the port'))
def add_create_update_attributes(parser):
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--stateful',
                       action='store_true',
                       help=_('Specify that the security group is stateful.'))
    group.add_argument('--no-stateful',
                       action='store_true',
                       help=_('Specify that the security group is not '
                              'stateful.'))
Пример #8
0
 def get_parser(self, prog_name):
     parser = super(ShowGatewayPortVlan, self).get_parser(prog_name)
     parser.add_argument('--gateway',
                         metavar='GATEWAY',
                         help=_('Name or ID of the gateway'))
     parser.add_argument('--gatewayport',
                         metavar='GATEWAYPORT',
                         help=_('Name or ID of the gatewayport'))
     return parser
Пример #9
0
 def get_parser(self, prog_name):
     parser = super(NuageFloatingIpList, self).get_parser(prog_name)
     group = parser.add_mutually_exclusive_group(required=False)
     group.add_argument(
         '--for-subnet',
         help=_('ID or name of subnet to find policy_groups for'))
     group.add_argument(
         '--for-port',
         help=_('ID or name of port to find policy_groups for'))
     return parser
Пример #10
0
 def add_known_arguments(self, parser):
     parser.add_argument(
         'redirect_target_id', metavar='REDIRECT_TARGET',
         help=_('Redirect Target ID to apply rule'))
     parser.add_argument(
         '--protocol',
         help=_('Protocol of packet.'))
     parser.add_argument(
         '--port-range-min',
         help=_('Starting port range.'))
     parser.add_argument(
         '--port-range-max',
         help=_('Ending port range.'))
     parser.add_argument(
         '--remote-ip-prefix',
         help=_('CIDR to match on.'))
     parser.add_argument(
         '--remote-group-id', metavar='REMOTE_GROUP',
         help=_('Remote security group name or ID to apply rule.'))
     parser.add_argument(
         '--origin-group-id', metavar='ORIGIN_SECURITY_GROUP',
         help=_('Origin security group name or ID to apply rule.'))
     parser.add_argument(
         '--priority',
         help=_('Priority of the rule that determines the order of'
                ' the rule.'))
     parser.add_argument(
         '--action',
         help=_('The action of the rule FORWARD or REDIRECT.'))
Пример #11
0
    def args2body(self, parsed_args):
        _redirect_target_id = neutronV20.find_resourceid_by_name_or_id(
            self.get_client(), 'nuage_redirect_target',
            parsed_args.redirect_target_id)
        if parsed_args.origin_group_id:
            _origin_group_id = neutronV20.find_resourceid_by_name_or_id(
                self.get_client(), 'security_group',
                parsed_args.origin_group_id)
        else:
            message = (_('--origin-group-id should be specified'))
            raise exceptions.NeutronClientException(message=message)
        if parsed_args.action:
            _action = parsed_args.action
            if _action not in ['FORWARD', 'REDIRECT']:
                message = (_('valid rule action values are'
                             ' FORWARD or REDIRECT'))
                raise exceptions.NeutronClientException(message=message)
        else:
            message = (_('--action should be specified'))
            raise exceptions.NeutronClientException(message=message)

        body = {'nuage_redirect_target_rule': {
            'redirect_target_id': _redirect_target_id,
            'origin_group_id': _origin_group_id,
            'action': _action}}
        if parsed_args.priority:
            body['nuage_redirect_target_rule'].update(
                {'priority': parsed_args.priority})
        if parsed_args.protocol:
            body['nuage_redirect_target_rule'].update(
                {'protocol': parsed_args.protocol})
        if parsed_args.port_range_min:
            body['nuage_redirect_target_rule'].update(
                {'port_range_min': parsed_args.port_range_min})
        if parsed_args.port_range_max:
            body['nuage_redirect_target_rule'].update(
                {'port_range_max': parsed_args.port_range_max})
        if parsed_args.remote_ip_prefix:
            body['nuage_redirect_target_rule'].update(
                {'remote_ip_prefix': parsed_args.remote_ip_prefix})
        if parsed_args.remote_group_id:
            _remote_group_id = neutronV20.find_resourceid_by_name_or_id(
                self.get_client(), 'security_group',
                parsed_args.remote_group_id)
            body['nuage_redirect_target_rule'].update(
                {'remote_group_id': _remote_group_id})
        if parsed_args.remote_group_id and parsed_args.remote_ip_prefix:
            message = (_('Only remote_ip_prefix or remote_group_id may '
                         'be provided.'))
            raise exceptions.NeutronClientException(message=message)
        if parsed_args.tenant_id:
            body['nuage_redirect_target_rule'].update(
                {'tenant_id': parsed_args.tenant_id})

        return body
Пример #12
0
 def add_known_arguments(self, parser):
     parser.add_argument('id',
                         metavar='VLAN_VALUE',
                         type=check_vlan_value,
                         help=_('Vlan value in 0-4094 range'))
     parser.add_argument('--gateway',
                         metavar='GATEWAY',
                         help=_('Name or ID of the gateway'))
     parser.add_argument('--gatewayport',
                         metavar='GATEWAYPORT',
                         help=_('Name or ID of the gatewayport'))
 def get_parser(self, prog_name):
     parser = super(CreateNuageProjectNetpartitionMapping,
                    self).get_parser(prog_name)
     parser.add_argument(
         'net_partition',
         metavar='<netpartition>',
         help=_('ID or name of the netpartition to associate.'))
     parser.add_argument('project',
                         metavar='<project>',
                         help=_('ID or name of the project'))
     return parser
Пример #14
0
def _add_known_arguments(parser):
    parser.add_argument(
        '--nuage-floatingip',
        help=_('ID or IP of the floatingip on VSD to link with this port.'))
    parser.add_argument(
        '--nuage-policy-groups', action='append',
        help=_('IDs or names of the policy groups to attach to this port.'))
    parser.add_argument(
        '--nuage-redirect-targets',
        help=_('ID(s) or name(s) of the redirect target(s)'
               ' to assign to this port.'))
Пример #15
0
 def get_parser(self, prog_name):
     parser = super(ListNuageFloatingIP, self).get_parser(prog_name)
     group = parser.add_mutually_exclusive_group(required=False)
     group.add_argument(
         '--for-subnet',
         help=_('ID or name of subnet for which to find available floating '
                'ips.'))
     group.add_argument(
         '--for-port',
         help=_('ID or name of port for which to find available floating '
                'ips.'))
     return parser
Пример #16
0
    def get_parser(self, prog_name):
        parser = super(ProjectNetpartitionMappingCreate,
                       self).get_parser(prog_name)
        parser.add_argument(
            'net_partition',
            metavar='NETPARTITION',
            help=_('ID or name of the net_partition to associate.'))
        parser.add_argument('project',
                            metavar='PROJECT',
                            help=_('ID of the project'))

        return parser
 def add_known_arguments(self, parser):
     super(CreateFloatingIP, self).add_known_arguments(parser)
     parser.add_argument(
         '--nuage-ingress-fip-rate-kbps',
         help=_('Rate limiting applied to the floating IP in kbps and'
                ' ingress direction. '
                'Can be -1 for unlimited.'))
     parser.add_argument(
         '--nuage-egress-fip-rate-kbps',
         help=_('Rate limiting applied to the floating IP in kbps and '
                'egress direction. '
                'Can be -1 for unlimited.'))
Пример #18
0
def check_vlan_value(value):
    try:
        vlan_val = int(value)
    except ValueError:
        message = (_('Vlan value should be a valid integer '
                     'in 0-4094 range'))
        raise exceptions.CommandError(message=message)

    if vlan_val not in range(0, 4095):
        message = (_('Vlan value should be in 0-4094 range'))
        raise exceptions.CommandError(message=message)

    return vlan_val
Пример #19
0
 def get_parser(self, prog_name):
     parser = super(ListGatewayPortVlan, self).get_parser(prog_name)
     parser.add_argument('--gateway',
                         metavar='gateway',
                         help=_('ID or name of gateway to look up.'))
     parser.add_argument(
         '--tenant-id',
         metavar='TENANT_ID',
         help=_('The owner tenant ID.'),
     )
     parser.add_argument('--gatewayport',
                         metavar='GATEWAYPORT',
                         help=_('ID or name of gatewayport to look up.'))
     return parser
Пример #20
0
 def get_parser(self, prog_name):
     parser = super(UnassignGatewayPortVlan, self).get_parser(prog_name)
     parser.add_argument(
         'tenant_id',
         metavar='TENANT_ID',
         help=_('The owner tenant ID.'),
     )
     parser.add_argument('--gateway',
                         metavar='GATEWAY',
                         help=_('Name or ID of the gateway'))
     parser.add_argument('--gatewayport',
                         metavar='GATEWAYPORT',
                         help=_('Name or ID of the gatewayport'))
     return parser
Пример #21
0
 def add_known_arguments(self, parser):
     super(CreateSubnet, self).add_known_arguments(parser)
     parser.add_argument('--net-partition',
                         help=_('ID or name of the net partition.'))
     parser.add_argument('--nuagenet',
                         help=_('ID of the subnet or l2domain on the VSD.'))
     parser.add_argument(
         '--nuage-uplink',
         help=_('ID of the shared resource zone on the VSD.'))
     utils.add_boolean_argument(
         parser,
         '--underlay',
         help=_('Whether to enable or disable underlay for shared '
                'networks'))
Пример #22
0
 def add_known_arguments(self, parser):
     super(UpdatePort, self).add_known_arguments(parser)
     parser.add_argument(
         '--no-nuage-floatingip',
         action='store_true',
         help=_('Disassociate the floating ip on VSD.'))
     parser.add_argument(
         '--no-nuage-policy-groups',
         action='store_true',
         help=_('Disassociate the policy groups on VSD.'))
     parser.add_argument(
         '--no-nuage-redirect-targets',
         action='store_true',
         help=_('Disassociate the redirect target on VSD.'))
     _add_known_arguments(parser)
 def add_known_arguments(self, parser):
     parser.add_argument('--switch-id',
                         dest='switch_id',
                         help=_('SystemID of the gateway device.'))
     parser.add_argument('--switch-info',
                         dest='switch_info',
                         help=_('Name of the gateway device'))
     parser.add_argument('--port_id',
                         dest='port_id',
                         help=_('Port mnemoniq of phys port of gateway'))
     parser.add_argument(
         '--host-id', help=_('Nova compute host id. hypervisor_hostname'))
     parser.add_argument('--pci-slot',
                         dest='pci_slot',
                         help=_('PCI id of the device.'))
 def get_parser(self, prog_name):
     parser = super(NuagePolicyGroupList, self).get_parser(prog_name)
     group = parser.add_mutually_exclusive_group(required=False)
     group.add_argument(
         '--for-subnet',
         help=_('ID or name of subnet to find policy_groups for'))
     group.add_argument(
         '--for-port',
         help=_('ID or name of port to find policy_groups for'))
     group.add_argument(
         '--ports',
         action='append',
         help=_('ID or name of port(s) which the policy groups are '
                'associated with'))
     return parser
Пример #25
0
def get_resource_by_name_or_id(neutron_client, resource, resource_id,
                               parent_resource, parent_id):
    obj_lister = getattr(neutron_client, "list_%s" % resource + 's')

    params = {'id': resource_id, parent_resource: parent_id}
    data = obj_lister(**params)
    resource += 's'
    resp_dict = None
    if data[resource]:
        resp_dict = data[resource][0]
        _id = resp_dict['id']
    if not resp_dict:
        params = {'name': resource_id, parent_resource: parent_id}
        data = obj_lister(**params)
        if data[resource]:
            resp_dict = data[resource][0]
            _id = resp_dict['id']

    if not resp_dict:
        not_found_message = (_("Unable to find %(resource)s with name "
                               "'%(name)s'") % {
                                   'resource': resource,
                                   'name': resource_id
                               })
        # 404 is used to simulate server side behavior
        raise exceptions.NeutronClientException(message=not_found_message,
                                                status_code=404)

    return _id
    def args2body(self, parsed_args):
        _external_group_id = neutronV20.find_resourceid_by_name_or_id(
            self.get_client(), 'nuage_external_security_group',
            parsed_args.remote_external_group_id)
        if parsed_args.origin_group_id:
            _origin_group_id = neutronV20.find_resourceid_by_name_or_id(
                self.get_client(), 'security_group',
                parsed_args.origin_group_id)
        else:
            message = (_('--origin-group-id should be specified'))
            raise exceptions.NeutronClientException(message=message)

        body = {
            'nuage_external_security_group_rule': {
                'direction': parsed_args.direction,
                'remote_external_group_id': _external_group_id,
                'origin_group_id': _origin_group_id
            }
        }
        if parsed_args.protocol:
            body['nuage_external_security_group_rule'].update(
                {'protocol': parsed_args.protocol})
        if parsed_args.port_range_min:
            body['nuage_external_security_group_rule'].update(
                {'port_range_min': parsed_args.port_range_min})
        if parsed_args.port_range_max:
            body['nuage_external_security_group_rule'].update(
                {'port_range_max': parsed_args.port_range_max})
        if parsed_args.tenant_id:
            body['nuage_redirect_target_rule'].update(
                {'tenant_id': parsed_args.tenant_id})

        return body
Пример #27
0
def add_arguments_for_set_create(parser):
    """Add arguments for port create and port set commands"""
    parser.add_argument(
        '--nuage-floatingip',
        metavar='<nuage-floatingip>',
        help=_('ID or IP of the floatingip on VSD to link with this port.'))
    parser.add_argument(
        '--nuage-policy-group',
        metavar='<nuage-policy-group>',
        action='append',
        help=_('Desired Nuage Policygroup for this port (Name or ID) '
               '(repeat option to set multiple Nuage policygroups)'))
    parser.add_argument(
        '--nuage-redirect-target',
        metavar='<nuage-redirect-target>',
        help=_('ID or IP of the redirect target on VSD to link with this '
               'port.'))
Пример #28
0
 def get_parser(self, prog_name):
     parser = super(SetNuageL2Bridge, self).get_parser(prog_name)
     parser.add_argument(
         'nuage_l2bridge',
         metavar="<nuage_l2bridge>",
         help=_("nuage_l2bridge to set (name or ID)")
     )
     add_name_argument(parser, is_required=False)
     add_physnet_argument(parser)
     parser.add_argument(
         '--no-physnet',
         action='store_true',
         help=_("Clear existing information of physnets."
                "Specify both --physnet and --no-physnet "
                "to overwrite the current physnet(s).")
     )
     return parser
    def get_parser(self, prog_name):
        parser = super(CreateNuageNetpartition, self).get_parser(prog_name)

        parser.add_argument('name',
                            metavar='<name>',
                            help=_("New netparition name"))

        return parser
 def get_parser(self, prog_name):
     parser = super(DeleteNuageNetpartition, self).get_parser(prog_name)
     parser.add_argument(
         'nuage_netpartition',
         metavar='<nuage-netpartition>',
         nargs='+',
         help=_('Nuage Netpartitions to delete (name or ID)'))
     return parser