| 1 |
# Copyright (C) 2013 eNovance SAS <[email protected]> |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 |
# not use this file except in compliance with the License. You may obtain |
| 5 |
# a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 |
# License for the specific language governing permissions and limitations |
| 13 |
# under the License. |
| 14 |
|
| 15 |
from neutronclient._i18n import _ |
| 16 |
from neutronclient.common import utils |
| 17 |
from neutronclient.neutron import v2_0 as neutronv20 |
| 18 |
|
| 19 |
|
| 20 |
class ListMeteringLabel(neutronv20.ListCommand): |
| 21 |
"""List metering labels that belong to a given tenant.""" |
| 22 |
|
| 23 |
resource = 'metering_label' |
| 24 |
list_columns = ['id', 'name', 'description', 'shared'] |
| 25 |
pagination_support = True |
| 26 |
sorting_support = True |
| 27 |
|
| 28 |
|
| 29 |
class ShowMeteringLabel(neutronv20.ShowCommand): |
| 30 |
"""Show information of a given metering label.""" |
| 31 |
|
| 32 |
resource = 'metering_label' |
| 33 |
allow_names = True |
| 34 |
|
| 35 |
|
| 36 |
class CreateMeteringLabel(neutronv20.CreateCommand): |
| 37 |
"""Create a metering label for a given tenant.""" |
| 38 |
|
| 39 |
resource = 'metering_label' |
| 40 |
|
| 41 |
def add_known_arguments(self, parser): |
| 42 |
parser.add_argument( |
| 43 |
'name', metavar='NAME', |
| 44 |
help=_('Name of the metering label to be created.')) |
| 45 |
parser.add_argument( |
| 46 |
'--description', |
| 47 |
help=_('Description of the metering label to be created.')) |
| 48 |
parser.add_argument( |
| 49 |
'--shared', |
| 50 |
action='store_true', |
| 51 |
help=_('Set the label as shared.')) |
| 52 |
|
| 53 |
def args2body(self, parsed_args): |
| 54 |
body = {'name': parsed_args.name} |
| 55 |
neutronv20.update_dict(parsed_args, body, |
| 56 |
['tenant_id', 'description', 'shared']) |
| 57 |
return {'metering_label': body} |
| 58 |
|
| 59 |
|
| 60 |
class DeleteMeteringLabel(neutronv20.DeleteCommand): |
| 61 |
"""Delete a given metering label.""" |
| 62 |
|
| 63 |
resource = 'metering_label' |
| 64 |
allow_names = True |
| 65 |
|
| 66 |
|
| 67 |
class ListMeteringLabelRule(neutronv20.ListCommand): |
| 68 |
"""List metering labels that belong to a given label.""" |
| 69 |
|
| 70 |
resource = 'metering_label_rule' |
| 71 |
list_columns = ['id', 'excluded', 'direction', 'remote_ip_prefix'] |
| 72 |
pagination_support = True |
| 73 |
sorting_support = True |
| 74 |
|
| 75 |
|
| 76 |
class ShowMeteringLabelRule(neutronv20.ShowCommand): |
| 77 |
"""Show information of a given metering label rule.""" |
| 78 |
|
| 79 |
resource = 'metering_label_rule' |
| 80 |
allow_names = False |
| 81 |
|
| 82 |
|
| 83 |
class CreateMeteringLabelRule(neutronv20.CreateCommand): |
| 84 |
"""Create a metering label rule for a given label.""" |
| 85 |
|
| 86 |
resource = 'metering_label_rule' |
| 87 |
|
| 88 |
def add_known_arguments(self, parser): |
| 89 |
parser.add_argument( |
| 90 |
'label_id', metavar='LABEL', |
| 91 |
help=_('ID or name of the label.')) |
| 92 |
parser.add_argument( |
| 93 |
'remote_ip_prefix', metavar='REMOTE_IP_PREFIX', |
| 94 |
help=_('CIDR to match on.')) |
| 95 |
parser.add_argument( |
| 96 |
'--direction', |
| 97 |
default='ingress', choices=['ingress', 'egress'], |
| 98 |
type=utils.convert_to_lowercase, |
| 99 |
help=_('Direction of traffic, default: ingress.')) |
| 100 |
parser.add_argument( |
| 101 |
'--excluded', |
| 102 |
action='store_true', |
| 103 |
help=_('Exclude this CIDR from the label, default: not excluded.')) |
| 104 |
|
| 105 |
def args2body(self, parsed_args): |
| 106 |
neutron_client = self.get_client() |
| 107 |
label_id = neutronv20.find_resourceid_by_name_or_id( |
| 108 |
neutron_client, 'metering_label', parsed_args.label_id) |
| 109 |
|
| 110 |
body = {'metering_label_id': label_id, |
| 111 |
'remote_ip_prefix': parsed_args.remote_ip_prefix} |
| 112 |
neutronv20.update_dict(parsed_args, body, |
| 113 |
['direction', 'excluded']) |
| 114 |
return {'metering_label_rule': body} |
| 115 |
|
| 116 |
|
| 117 |
class DeleteMeteringLabelRule(neutronv20.DeleteCommand): |
| 118 |
"""Delete a given metering label.""" |
| 119 |
|
| 120 |
resource = 'metering_label_rule' |
| 121 |
allow_names = False |