Example #1
0
 def get_parser(self, prog_name):
     parser = super(FirewallPolicyInsertRule, self).get_parser(prog_name)
     parser.add_argument("--insert-before", metavar="FIREWALL_RULE", help=_("Insert before this rule."))
     parser.add_argument("--insert-after", metavar="FIREWALL_RULE", help=_("Insert after this rule."))
     parser.add_argument("firewall_rule_id", metavar="FIREWALL_RULE", help=_("New rule to insert."))
     self.add_known_arguments(parser)
     return parser
 def add_known_arguments(self, parser):
     # adding admin_state_up here so that it is available for update only
     # as it is True by default and not meaningful in the create operation
     parser.add_argument(
         "--admin-state-up",
         dest="admin_state_up",
         action="store_true",
         help=_("Set hosting device administratively up."),
         default=argparse.SUPPRESS,
     )
     parser.add_argument(
         "--admin_state_up",
         dest="admin_state_up",
         action="store_true",
         help=argparse.SUPPRESS,
         default=argparse.SUPPRESS,
     )
     # adding no_auto_delete here so that it is available for update only
     # as auto_delete is False by default and not meaningful in the create
     # operation
     parser.add_argument(
         "--no-auto-delete",
         dest="auto_delete",
         action="store_false",
         help=_("Exempt hosting device from automated life cycle " "management."),
         default=argparse.SUPPRESS,
     )
     parser.add_argument(
         "--no_auto_delete",
         dest="auto_delete",
         action="store_false",
         help=argparse.SUPPRESS,
         default=argparse.SUPPRESS,
     )
     _add_updatable_args(parser)
 def get_parser(self, prog_name):
     parser = super(DisassociateHealthMonitor, self).get_parser(prog_name)
     parser.add_argument("health_monitor_id", metavar="HEALTH_MONITOR_ID", help=_("Health monitor to associate."))
     parser.add_argument(
         "pool_id", metavar="POOL", help=_("ID of the pool to be associated with the health monitor.")
     )
     return parser
Example #4
0
 def run(self, parsed_args):
     self.log.debug("run(%s)", parsed_args)
     self.set_extra_attrs(parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     _extra_values = parse_args_to_dict(self.values_specs)
     _merge_args(self, parsed_args, _extra_values, self.values_specs)
     body = self.args2body(parsed_args)
     if self.resource in body:
         body[self.resource].update(_extra_values)
     else:
         body[self.resource] = _extra_values
     if not body[self.resource]:
         raise exceptions.CommandError(_("Must specify new values to update %s") % self.cmd_resource)
     if self.allow_names:
         _id = find_resourceid_by_name_or_id(
             neutron_client, self.resource, parsed_args.id, cmd_resource=self.cmd_resource, parent_id=self.parent_id
         )
     else:
         _id = find_resourceid_by_id(
             neutron_client, self.resource, parsed_args.id, self.cmd_resource, self.parent_id
         )
     obj_updater = getattr(neutron_client, "update_%s" % self.cmd_resource)
     if self.parent_id:
         obj_updater(_id, self.parent_id, body)
     else:
         obj_updater(_id, body)
     print(
         (_("Updated %(resource)s: %(id)s") % {"id": parsed_args.id, "resource": self.resource}),
         file=self.app.stdout,
     )
     return
 def add_known_arguments(self, parser):
     # adding ha_disabled here so that it is available for update only as
     # HA is disabled by default and not meaningful in the create operation
     parser.add_argument(
         "--ha-disabled",
         dest="ha_enabled_by_default",
         action="store_false",
         help=_("Make HA disabled for the router type."),
         default=argparse.SUPPRESS,
     )
     parser.add_argument(
         "--ha_disabled",
         dest="ha_enabled_by_default",
         action="store_false",
         help=argparse.SUPPRESS,
         default=argparse.SUPPRESS,
     )
     # adding shared here so that it is available for update only as it is
     # True by default and not meaningful in the create operation
     parser.add_argument(
         "--shared",
         dest="shared",
         action="store_true",
         help=_("Make router type shared among tenants."),
         default=argparse.SUPPRESS,
     )
     _add_updatable_args(parser)
Example #6
0
 def get_parser(self, prog_name):
     parser = super(CreatePortChain, self).get_parser(prog_name)
     parser.add_argument("name", metavar="NAME", help=_("Name of the Port Chain."))
     parser.add_argument("--description", help=_("Description for the Port Chain."))
     parser.add_argument(
         "--port-pair-group",
         metavar="PORT-PAIR-GROUP",
         dest="port_pair_groups",
         required=True,
         action="append",
         help=_("ID or name of the Port Pair Group. " "This option can be repeated."),
     )
     parser.add_argument(
         "--flow-classifier",
         default=[],
         metavar="FLOW-CLASSIFIER",
         dest="flow_classifiers",
         action="append",
         help=_("ID or name of the Flow Classifier." "This option can be repeated."),
     )
     parser.add_argument(
         "--chain-parameters",
         metavar="[correlation=CORRELATION_TYPE, symmetric=BOOLEAN_TYPE]",
         type=nc_utils.str2dict_type(optional_keys=["correlation", "symmetric"]),
         help=_("Dictionary of chain parameters. Supports " "correlation=mpls and symmetric=true|false"),
     )
     return parser
def _add_updatable_args(parser):
    parser.add_argument("--name", help=_("Name of this router type."))
    parser.add_argument("--description", help=_("Description of this router type."))
    parser.add_argument(
        "--ha-enabled",
        dest="ha_enabled_by_default",
        action="store_true",
        help=_("Make HA enabled for the router type."),
        default=argparse.SUPPRESS,
    )
    parser.add_argument(
        "--ha_enabled",
        dest="ha_enabled_by_default",
        action="store_true",
        help=argparse.SUPPRESS,
        default=argparse.SUPPRESS,
    )
    parser.add_argument(
        "--unshared",
        dest="shared",
        action="store_false",
        help=_("Make router type NOT shared among tenants."),
        default=argparse.SUPPRESS,
    )
    parser.add_argument("--slot-need", help=_("Number of slots routers of this type consumes."))
    parser.add_argument("--slot_need", help=argparse.SUPPRESS)
 def add_known_arguments(self, parser):
     parser.add_argument(
         "--nodes",
         type=string.split,
         help=_("List of Service Chain Node IDs or names of the Service " "Chain Nodes"),
     )
     parser.add_argument("--shared", type=bool, help=_("Shared flag"))
Example #9
0
 def add_known_arguments(self, parser):
     add_updatable_arguments(parser)
     parser.add_argument(
         '--ip-version',
         type=int,
         default=4, choices=[4, 6],
         help=_('IP version to use, default is 4.'))
     parser.add_argument(
         '--ip_version',
         type=int,
         choices=[4, 6],
         help=argparse.SUPPRESS)
     parser.add_argument(
         'network_id', metavar='NETWORK',
         help=_('Network ID or name this subnet belongs to.'))
     parser.add_argument(
         'cidr', metavar='CIDR',
         help=_('CIDR of subnet to create.'))
     parser.add_argument(
         '--ipv6-ra-mode',
         choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
         help=_('IPv6 RA (Router Advertisement) mode.'))
     parser.add_argument(
         '--ipv6-address-mode',
         choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
         help=_('IPv6 address mode.'))
Example #10
0
def validate_lifetime_dict(lifetime_dict):

    for key, value in lifetime_dict.items():
        if key not in lifetime_keys:
            message = _(
                "Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s "
            ) % {"key": key, "supported_key": lifetime_keys}
            raise exceptions.CommandError(message)
        if key == "units" and value not in lifetime_units:
            message = _(
                "Lifetime Dictionary ValueError: "
                "Reason-Invalid units : "
                "'%(key_value)s' not in %(supported_units)s "
            ) % {"key_value": key, "supported_units": lifetime_units}
            raise exceptions.CommandError(message)
        if key == "value":
            try:
                if int(value) < 60:
                    raise ValueError()
            except ValueError:
                message = _(
                    "Lifetime Dictionary ValueError: "
                    "Reason-Invalid value should be at least 60:"
                    "'%(key_value)s' = %(value)s "
                ) % {"key_value": key, "value": value}
                raise exceptions.CommandError(message)
            else:
                lifetime_dict["value"] = int(value)
    return
Example #11
0
def validate_dpd_dict(dpd_dict):
    for key, value in dpd_dict.items():
        if key not in dpd_supported_keys:
            message = _(
                "DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s "
            ) % {"key": key, "supported_key": dpd_supported_keys}
            raise exceptions.CommandError(message)
        if key == "action" and value not in dpd_supported_actions:
            message = _(
                "DPD Dictionary ValueError: "
                "Reason-Invalid DPD action : "
                "'%(key_value)s' not in %(supported_action)s "
            ) % {"key_value": value, "supported_action": dpd_supported_actions}
            raise exceptions.CommandError(message)
        if key in ("interval", "timeout"):
            try:
                if int(value) <= 0:
                    raise ValueError()
            except ValueError:
                message = _(
                    "DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s "
                ) % {"key": key, "value": value}
                raise exceptions.CommandError(message)
            else:
                dpd_dict[key] = int(value)
    return
Example #12
0
 def add_known_arguments(self, parser):
     parser.add_argument("name", metavar="NAME", help=_("Name of the Port Chain."))
     parser.add_argument("--description", help=_("Description for the Port Chain."))
     parser.add_argument(
         "--port-pair-group",
         metavar="PORT-PAIR-GROUP",
         dest="port_pair_groups",
         default=[],
         required=True,
         action="append",
         help=_("ID or name of the Port Pair Group. " "This option can be repeated."),
     )
     parser.add_argument(
         "--flow-classifier",
         default=[],
         metavar="FLOW-CLASSIFIER",
         dest="flow_classifiers",
         action="append",
         help=_("ID or name of the Flow Classifier." "This option can be repeated."),
     )
     parser.add_argument(
         "--chain-parameters",
         metavar="type=TYPE[,correlation=CORRELATION_TYPE]",
         type=utils.str2dict,
         help=_("Dictionary of chain parameters. Currently, only " "correlation=mpls is supported by default."),
     )
 def add_known_arguments(self, parser):
     parser.add_argument("--name", help=_("Name for the firewall rule."))
     parser.add_argument("--description", help=_("Description for the firewall rule."))
     parser.add_argument(
         "--shared",
         dest="shared",
         action="store_true",
         help=_("Set shared to True (default is False)."),
         default=argparse.SUPPRESS,
     )
     parser.add_argument("--source-ip-address", help=_("Source IP address or subnet."))
     parser.add_argument("--destination-ip-address", help=_("Destination IP address or subnet."))
     parser.add_argument("--source-port", help=_("Source port (integer in [1, 65535] or range in a:b)."))
     parser.add_argument(
         "--destination-port", help=_("Destination port (integer in [1, 65535] or range in " "a:b).")
     )
     parser.add_argument(
         "--enabled",
         dest="enabled",
         choices=["True", "False"],
         help=_("Whether to enable or disable this rule."),
         default=argparse.SUPPRESS,
     )
     parser.add_argument(
         "--protocol",
         choices=["tcp", "udp", "icmp", "any"],
         required=True,
         help=_("Protocol for the firewall rule."),
     )
     parser.add_argument(
         "--action", required=True, choices=["allow", "deny"], help=_("Action for the firewall rule.")
     )
 def run_subcommand(self, argv):
     subcommand = self.command_manager.find_command(argv)
     cmd_factory, cmd_name, sub_argv = subcommand
     cmd = cmd_factory(self, self.options)
     err = None
     result = 1
     try:
         self.prepare_to_run_command(cmd)
         full_name = cmd_name if self.interactive_mode else " ".join([self.NAME, cmd_name])
         cmd_parser = cmd.get_parser(full_name)
         return run_command(cmd, cmd_parser, sub_argv)
     except Exception as err:
         if self.options.verbose_level >= self.DEBUG_LEVEL:
             self.log.exception(unicode(err))
         else:
             self.log.error(unicode(err))
         try:
             self.clean_up(cmd, result, err)
         except Exception as err2:
             if self.options.verbose_level >= self.DEBUG_LEVEL:
                 self.log.exception(unicode(err2))
             else:
                 self.log.error(_("Could not clean up: %s"), unicode(err2))
         if self.options.verbose_level >= self.DEBUG_LEVEL:
             raise
     else:
         try:
             self.clean_up(cmd, result, None)
         except Exception as err3:
             if self.options.verbose_level >= self.DEBUG_LEVEL:
                 self.log.exception(unicode(err3))
             else:
                 self.log.error(_("Could not clean up: %s"), unicode(err3))
     return result
Example #15
0
def updatable_args2body(parsed_args, body, for_create=True, ip_version=None):
    if parsed_args.disable_dhcp and parsed_args.enable_dhcp:
        raise exceptions.CommandError(_("You cannot enable and disable DHCP at the same time."))

    if parsed_args.no_gateway:
        body["gateway_ip"] = None
    elif parsed_args.gateway:
        body["gateway_ip"] = parsed_args.gateway
    if parsed_args.name:
        body["name"] = parsed_args.name
    if parsed_args.disable_dhcp:
        body["enable_dhcp"] = False
    if parsed_args.enable_dhcp:
        body["enable_dhcp"] = True
    if parsed_args.allocation_pools:
        body["allocation_pools"] = parsed_args.allocation_pools
    if parsed_args.host_routes:
        body["host_routes"] = parsed_args.host_routes
    if parsed_args.dns_nameservers:
        body["dns_nameservers"] = parsed_args.dns_nameservers
    if for_create and parsed_args.ipv6_ra_mode:
        if ip_version == 4:
            raise exceptions.CommandError(_("--ipv6-ra-mode is invalid " "when --ip-version is 4"))
        body["ipv6_ra_mode"] = parsed_args.ipv6_ra_mode
    if for_create and parsed_args.ipv6_address_mode:
        if ip_version == 4:
            raise exceptions.CommandError(_("--ipv6-address-mode is " "invalid when --ip-version " "is 4"))
        body["ipv6_address_mode"] = parsed_args.ipv6_address_mode
Example #16
0
 def get_parser(self, prog_name):
     parser = super(CreatePortPair, self).get_parser(prog_name)
     parser.add_argument(
         'name',
         metavar='NAME',
         help=_('Name of the Port Pair.'))
     parser.add_argument(
         '--description',
         help=_('Description for the Port Pair.'))
     parser.add_argument(
         '--ingress',
         required=True,
         help=_('ID or name of the ingress neutron port.'))
     parser.add_argument(
         '--egress',
         required=True,
         help=_('ID or name of the egress neutron port.'))
     parser.add_argument(
         '--service-function-parameter',
         metavar='[correlation=CORRELATION_TYPE, weight=WEIGHT]',
         type=nc_utils.str2dict_type(optional_keys=['correlation',
                                                    'weight']),
         help=_('Dictionary of Service function parameters. '
                'Currently, only correlation=None and weight '
                'is supported. Weight is an integer that influences '
                'the selection of a port pair within a port pair group '
                'for a flow. The higher the weight, the more flows will '
                'hash to the port pair. The default weight is 1.'))
     return parser
def add_updatable_arguments(parser):
    parser.add_argument("--min-prefixlen", type=int, help=_("Subnetpool minimum prefix length."))
    parser.add_argument("--max-prefixlen", type=int, help=_("Subnetpool maximum prefix length."))
    parser.add_argument("--default-prefixlen", type=int, help=_("Subnetpool default prefix length."))
    parser.add_argument(
        "--pool-prefix", action="append", dest="prefixes", help=_("Subnetpool prefixes (This option can be repeated).")
    )
Example #18
0
def updatable_args2body(parsed_args, body, for_create=True):
    if parsed_args.gateway and parsed_args.no_gateway:
        raise exceptions.CommandError(_("--gateway option and " "--no-gateway option can " "not be used same time"))
    if parsed_args.disable_dhcp and parsed_args.enable_dhcp:
        raise exceptions.CommandError(_("--enable-dhcp and --disable-dhcp can " "not be used in the same command."))

    if parsed_args.no_gateway:
        body["subnet"].update({"gateway_ip": None})
    if parsed_args.gateway:
        body["subnet"].update({"gateway_ip": parsed_args.gateway})
    if parsed_args.name:
        body["subnet"].update({"name": parsed_args.name})
    if parsed_args.disable_dhcp:
        body["subnet"].update({"enable_dhcp": False})
    if parsed_args.enable_dhcp:
        body["subnet"].update({"enable_dhcp": True})
    if parsed_args.allocation_pools:
        body["subnet"]["allocation_pools"] = parsed_args.allocation_pools
    if parsed_args.host_routes:
        body["subnet"]["host_routes"] = parsed_args.host_routes
    if parsed_args.dns_nameservers:
        body["subnet"]["dns_nameservers"] = parsed_args.dns_nameservers
    if for_create and parsed_args.ipv6_ra_mode:
        if parsed_args.ip_version == 4:
            raise exceptions.CommandError(_("--ipv6-ra-mode is invalid " "when --ip-version is 4"))
        body["subnet"]["ipv6_ra_mode"] = parsed_args.ipv6_ra_mode
    if for_create and parsed_args.ipv6_address_mode:
        if parsed_args.ip_version == 4:
            raise exceptions.CommandError(_("--ipv6-address-mode is " "invalid when --ip-version " "is 4"))
        body["subnet"]["ipv6_address_mode"] = parsed_args.ipv6_address_mode
Example #19
0
 def add_known_arguments(self, parser):
     parser.add_argument("--name", help=_("Name of this router."))
     utils.add_boolean_argument(
         parser,
         "--admin-state-up",
         dest="admin_state",
         help=_("Specify the administrative state of the router" ' (True meaning "Up")'),
     )
     utils.add_boolean_argument(parser, "--admin_state_up", dest="admin_state", help=argparse.SUPPRESS)
     utils.add_boolean_argument(
         parser,
         "--distributed",
         dest="distributed",
         help=_("True means this router should operate in" " distributed mode."),
     )
     routes_group = parser.add_mutually_exclusive_group()
     routes_group.add_argument(
         "--route",
         metavar="destination=CIDR,nexthop=IP_ADDR",
         action="append",
         dest="routes",
         type=utils.str2dict,
         help=_("Route to associate with the router." " You can repeat this option."),
     )
     routes_group.add_argument(
         "--no-routes", action="store_true", help=_("Remove routes associated with the router.")
     )
Example #20
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 #21
0
 def add_known_arguments(self, parser):
     _add_updatable_args(parser)
     parser.add_argument("--admin-state-up", choices=["True", "False"], help=_("Set admin state up for the port."))
     parser.add_argument("--admin_state_up", choices=["True", "False"], help=argparse.SUPPRESS)
     parser.add_argument("--qos-policy", help=_("Attach QoS policy ID or name to the port."))
     parser.add_argument("--no-qos-policy", action="store_true", help=_("Detach QoS policy from the port."))
     self.add_arguments_secgroup(parser)
     self.add_arguments_extradhcpopt(parser)
Example #22
0
 def add_known_arguments(self, parser):
     parser.add_argument("name", metavar="NAME", help=_("Name of QoS policy to create."))
     parser.add_argument("--description", help=_("Description of the QoS policy."))
     parser.add_argument(
         "--shared",
         action="store_true",
         help=_("Accessible by other tenants. " "Set shared to True (default is False)."),
     )
 def add_known_arguments(self, parser):
     parser.add_argument(
         "--admin-state-down", dest="admin_state", action="store_false", help=_("Set admin state up to false.")
     )
     parser.add_argument("--admin_state_down", dest="admin_state", action="store_false", help=argparse.SUPPRESS)
     parser.add_argument("name", metavar="NAME", help=_("Name of router to create."))
     utils.add_boolean_argument(parser, "--distributed", dest="distributed", help=_("Create a distributed router."))
     utils.add_boolean_argument(parser, "--ha", dest="ha", help=_("Create a highly available router."))
Example #24
0
def check_non_negative_int(value):
    try:
        value = int(value)
    except ValueError:
        raise argparse.ArgumentTypeError(_("invalid int value: %r") % value)
    if value < 0:
        raise argparse.ArgumentTypeError(_("input value %d is negative") % value)
    return value
Example #25
0
 def get_parser(self, prog_name):
     parser = super(SetGatewayRouter, self).get_parser(prog_name)
     parser.add_argument("router_id", metavar="router-id", help=_("ID of the router."))
     parser.add_argument(
         "external_network_id", metavar="external-network-id", help=_("ID of the external network for the gateway.")
     )
     parser.add_argument("--disable-snat", action="store_true", help=_("Disable source NAT on the router gateway."))
     return parser
 def add_known_arguments(self, parser):
     parser.add_argument("name", metavar="NAME", help=_("Name of network gateway to create."))
     parser.add_argument(
         "--device",
         metavar="id=ID,interface_name=NAME_OR_ID",
         action="append",
         help=_("Device info for this gateway. You can repeat this " "option for multiple devices for HA gateways."),
     )
Example #27
0
 def get_parser(self, prog_name):
     parser = super(DeleteCommand, self).get_parser(prog_name)
     if self.allow_names:
         help_str = _("ID or name of %s to delete.")
     else:
         help_str = _("ID of %s to delete.")
     parser.add_argument("id", metavar=self.resource.upper(), help=help_str % self.resource)
     return parser
Example #28
0
 def add_known_arguments(self, parser):
     parser.add_argument(
         "--admin-state-down",
         dest="admin_state",
         action="store_false",
         help=_("Set admin state up of the agent to false."),
     )
     parser.add_argument("--description", help=_("Description for the agent."))
 def get_parser(self, prog_name):
     parser = super(UpdatePolicyProfile, self).get_parser(prog_name)
     parser.add_argument(
         "--add-tenant", action="append", dest="add_tenant", help=_("Add tenant to the policy profile.")
     )
     parser.add_argument(
         "--remove-tenant", action="append", dest="remove_tenant", help=_("Remove tenant from the policy profile.")
     )
     return parser
Example #30
0
 def add_known_arguments(self, parser):
     parser.add_argument(
         "--admin-state-down", dest="admin_state", action="store_false", help=_("Set admin state up to false.")
     )
     parser.add_argument("--admin_state_down", dest="admin_state", action="store_false", help=argparse.SUPPRESS)
     parser.add_argument(
         "--shared", action="store_true", help=_("Set the network as shared."), default=argparse.SUPPRESS
     )
     parser.add_argument("name", metavar="NAME", help=_("Name of network to create."))