diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-06-12 12:50:30 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-06-15 17:23:39 +0800 |
| commit | 8e2f49fbf22c242270c8162254fc83fbb4580a24 (patch) | |
| tree | 8885ba7e468cc5ff625a1919f7a95199fb1c0ef0 /openstackclient/network/v2 | |
| parent | 0ec711c640120539e4968c81fd6ee158257845d4 (diff) | |
| download | python-openstackclient-8e2f49fbf22c242270c8162254fc83fbb4580a24.tar.gz | |
Support bulk deletion for commands that exist in both network and compute.
Some delete commands in networkv2 are exist in both network
and compute, They can use NetworkAndComputeDeleteclass to
supprot bulk deletion and error handling and the codes are
similar, so I change them all in this patch. The changed
commands including:
1.floating ip delete
2.security group delete
3.security group rule delete
Also, I update unit tests and docs for these commands in this patch.
Change-Id: I6c94c3d10ba579ddd9b14d17673c821e3481fd8a
Partially-Implements: blueprint multi-argument-network
Diffstat (limited to 'openstackclient/network/v2')
| -rw-r--r-- | openstackclient/network/v2/floating_ip.py | 18 | ||||
| -rw-r--r-- | openstackclient/network/v2/security_group.py | 18 | ||||
| -rw-r--r-- | openstackclient/network/v2/security_group_rule.py | 16 |
3 files changed, 31 insertions, 21 deletions
diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index c734c2ed..8fbf049e 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -110,26 +110,28 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne): return (columns, data) -class DeleteFloatingIP(common.NetworkAndComputeCommand): - """Delete floating IP""" +class DeleteFloatingIP(common.NetworkAndComputeDelete): + """Delete floating IP(s)""" + + # Used by base class to find resources in parsed_args. + resource = 'floating_ip' + r = None def update_parser_common(self, parser): parser.add_argument( 'floating_ip', metavar="<floating-ip>", - help=_("Floating IP to delete (IP address or ID)") + nargs="+", + help=_("Floating IP(s) to delete (IP address or ID)") ) return parser def take_action_network(self, client, parsed_args): - obj = client.find_ip(parsed_args.floating_ip) + obj = client.find_ip(self.r, ignore_missing=False) client.delete_ip(obj) def take_action_compute(self, client, parsed_args): - obj = utils.find_resource( - client.floating_ips, - parsed_args.floating_ip, - ) + obj = utils.find_resource(client.floating_ips, self.r) client.floating_ips.delete(obj.id) diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index 95971800..f832f721 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -164,26 +164,28 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne): return (display_columns, data) -class DeleteSecurityGroup(common.NetworkAndComputeCommand): - """Delete a security group""" +class DeleteSecurityGroup(common.NetworkAndComputeDelete): + """Delete security group(s)""" + + # Used by base class to find resources in parsed_args. + resource = 'group' + r = None def update_parser_common(self, parser): parser.add_argument( 'group', metavar='<group>', - help=_("Security group to delete (name or ID)") + nargs="+", + help=_("Security group(s) to delete (name or ID)"), ) return parser def take_action_network(self, client, parsed_args): - obj = client.find_security_group(parsed_args.group) + obj = client.find_security_group(self.r, ignore_missing=False) client.delete_security_group(obj) def take_action_compute(self, client, parsed_args): - data = utils.find_resource( - client.security_groups, - parsed_args.group, - ) + data = utils.find_resource(client.security_groups, self.r) client.security_groups.delete(data.id) diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py index 7c810786..18863223 100644 --- a/openstackclient/network/v2/security_group_rule.py +++ b/openstackclient/network/v2/security_group_rule.py @@ -333,23 +333,29 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne): return _format_security_group_rule_show(obj._info) -class DeleteSecurityGroupRule(common.NetworkAndComputeCommand): - """Delete a security group rule""" +class DeleteSecurityGroupRule(common.NetworkAndComputeDelete): + """Delete security group rule(s)""" + + # Used by base class to find resources in parsed_args. + resource = 'rule' + r = None def update_parser_common(self, parser): parser.add_argument( 'rule', metavar='<rule>', - help=_("Security group rule to delete (ID only)") + nargs="+", + help=_("Security group rule(s) to delete (ID only)") ) return parser def take_action_network(self, client, parsed_args): - obj = client.find_security_group_rule(parsed_args.rule) + obj = client.find_security_group_rule( + self.r, ignore_missing=False) client.delete_security_group_rule(obj) def take_action_compute(self, client, parsed_args): - client.security_group_rules.delete(parsed_args.rule) + client.security_group_rules.delete(self.r) class ListSecurityGroupRule(common.NetworkAndComputeLister): |
