|
| 1 | +# Copyright 2012-2013 OpenStack, LLC. |
| 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 | + |
| 16 | +import logging |
| 17 | + |
| 18 | +from cliff import command |
| 19 | +from cliff import lister |
| 20 | +from cliff import show |
| 21 | + |
| 22 | + |
| 23 | +class CreateCommand(show.ShowOne): |
| 24 | + |
| 25 | + log = logging.getLogger(__name__ + '.CreateCommand') |
| 26 | + |
| 27 | + def get_client(self): |
| 28 | + return self.app.client_manager.network |
| 29 | + |
| 30 | + def get_parser(self, prog_name): |
| 31 | + parser = super(CreateCommand, self).get_parser(prog_name) |
| 32 | + parser.add_argument( |
| 33 | + '--project', |
| 34 | + dest='tenant_id', |
| 35 | + help='the owner project id') |
| 36 | + return parser |
| 37 | + |
| 38 | + def take_action(self, parsed_args): |
| 39 | + self.log.debug('take_action(%s)' % parsed_args) |
| 40 | + neuter = self.clazz(self.app, self.app_args) |
| 41 | + neuter.get_client = self.get_client |
| 42 | + parsed_args.request_format = 'json' |
| 43 | + return neuter.take_action(parsed_args) |
| 44 | + |
| 45 | + |
| 46 | +class DeleteCommand(command.Command): |
| 47 | + |
| 48 | + log = logging.getLogger(__name__ + '.DeleteCommand') |
| 49 | + name = "id" |
| 50 | + metavar = "<id>" |
| 51 | + help_text = "Identifier of object to delete" |
| 52 | + |
| 53 | + def get_client(self): |
| 54 | + return self.app.client_manager.network |
| 55 | + |
| 56 | + def get_parser(self, prog_name): |
| 57 | + parser = super(DeleteCommand, self).get_parser(prog_name) |
| 58 | + parser.add_argument( |
| 59 | + self.name, |
| 60 | + metavar=self.metavar, |
| 61 | + help=self.help_text, |
| 62 | + ) |
| 63 | + return parser |
| 64 | + |
| 65 | + def take_action(self, parsed_args): |
| 66 | + self.log.debug('take_action(%s)' % parsed_args) |
| 67 | + neuter = self.clazz(self.app, self.app_args) |
| 68 | + neuter.get_client = self.get_client |
| 69 | + parsed_args.request_format = 'json' |
| 70 | + return neuter.run(parsed_args) |
| 71 | + |
| 72 | + |
| 73 | +class ListCommand(lister.Lister): |
| 74 | + |
| 75 | + log = logging.getLogger(__name__ + '.ListCommand') |
| 76 | + |
| 77 | + def get_client(self): |
| 78 | + return self.app.client_manager.network |
| 79 | + |
| 80 | + def get_parser(self, prog_name): |
| 81 | + parser = super(ListCommand, self).get_parser(prog_name) |
| 82 | + parser.add_argument( |
| 83 | + '--long', |
| 84 | + dest='show_details', |
| 85 | + action='store_true', |
| 86 | + default=False, |
| 87 | + help='Long listing', |
| 88 | + ) |
| 89 | + return parser |
| 90 | + |
| 91 | + def take_action(self, parsed_args): |
| 92 | + self.log.debug('take_action(%s)' % parsed_args) |
| 93 | + neuter = self.clazz(self.app, self.app_args) |
| 94 | + neuter.get_client = self.get_client |
| 95 | + parsed_args.request_format = 'json' |
| 96 | + parsed_args.page_size = None |
| 97 | + parsed_args.sort_key = [] |
| 98 | + parsed_args.sort_dir = [] |
| 99 | + parsed_args.fields = [] |
| 100 | + return neuter.take_action(parsed_args) |
| 101 | + |
| 102 | + |
| 103 | +class SetCommand(command.Command): |
| 104 | + |
| 105 | + log = logging.getLogger(__name__ + '.SetCommand') |
| 106 | + name = "id" |
| 107 | + metavar = "<id>" |
| 108 | + help_text = "Identifier of object to set" |
| 109 | + |
| 110 | + def get_client(self): |
| 111 | + return self.app.client_manager.network |
| 112 | + |
| 113 | + def get_parser(self, prog_name): |
| 114 | + parser = super(SetCommand, self).get_parser(prog_name) |
| 115 | + parser.add_argument( |
| 116 | + '--project', |
| 117 | + dest='tenant_id', |
| 118 | + help='the owner project id') |
| 119 | + parser.add_argument( |
| 120 | + self.name, |
| 121 | + metavar=self.metavar, |
| 122 | + help=self.help_text, |
| 123 | + ) |
| 124 | + return parser |
| 125 | + |
| 126 | + def take_action(self, parsed_args): |
| 127 | + self.log.debug('take_action(%s)' % parsed_args) |
| 128 | + neuter = self.clazz(self.app, self.app_args) |
| 129 | + neuter.get_client = self.get_client |
| 130 | + parsed_args.request_format = 'json' |
| 131 | + return neuter.take_action(parsed_args) |
| 132 | + |
| 133 | + |
| 134 | +class ShowCommand(show.ShowOne): |
| 135 | + |
| 136 | + log = logging.getLogger(__name__ + '.ShowCommand') |
| 137 | + name = "id" |
| 138 | + metavar = "<id>" |
| 139 | + help_text = "Identifier of object to delete" |
| 140 | + |
| 141 | + def get_client(self): |
| 142 | + return self.app.client_manager.network |
| 143 | + |
| 144 | + def get_parser(self, prog_name): |
| 145 | + parser = super(ShowCommand, self).get_parser(prog_name) |
| 146 | + parser.add_argument( |
| 147 | + self.name, |
| 148 | + metavar=self.metavar, |
| 149 | + help=self.help_text, |
| 150 | + ) |
| 151 | + return parser |
| 152 | + |
| 153 | + def take_action(self, parsed_args): |
| 154 | + self.log.debug('take_action(%s)' % parsed_args) |
| 155 | + neuter = self.clazz(self.app, self.app_args) |
| 156 | + neuter.get_client = self.get_client |
| 157 | + parsed_args.show_details = True |
| 158 | + parsed_args.request_format = 'json' |
| 159 | + parsed_args.fields = [] |
| 160 | + return neuter.take_action(parsed_args) |
| 161 | + |
| 162 | + |
| 163 | +class AddCommand(command.Command): |
| 164 | + |
| 165 | + log = logging.getLogger(__name__ + '.AddCommand') |
| 166 | + container_name = "container_id" |
| 167 | + container_metavar = "<container_id>" |
| 168 | + container_help_text = "Identifier of container" |
| 169 | + name = "id" |
| 170 | + metavar = "<id>" |
| 171 | + help_text = "Identifier of object to be added" |
| 172 | + |
| 173 | + def get_client(self): |
| 174 | + return self.app.client_manager.network |
| 175 | + |
| 176 | + def get_parser(self, prog_name): |
| 177 | + parser = super(AddCommand, self).get_parser(prog_name) |
| 178 | + parser.add_argument( |
| 179 | + self.container_name, |
| 180 | + metavar=self.container_metavar, |
| 181 | + help=self.container_help_text, |
| 182 | + ) |
| 183 | + parser.add_argument( |
| 184 | + self.name, |
| 185 | + metavar=self.metavar, |
| 186 | + help=self.help_text, |
| 187 | + ) |
| 188 | + return parser |
| 189 | + |
| 190 | + def take_action(self, parsed_args): |
| 191 | + self.log.debug('take_action(%s)' % parsed_args) |
| 192 | + neuter = self.clazz(self.app, self.app_args) |
| 193 | + neuter.get_client = self.get_client |
| 194 | + parsed_args.request_format = 'json' |
| 195 | + return neuter.run(parsed_args) |
| 196 | + |
| 197 | + |
| 198 | +class RemoveCommand(command.Command): |
| 199 | + |
| 200 | + log = logging.getLogger(__name__ + '.RemoveCommand') |
| 201 | + container_name = "container_id" |
| 202 | + container_metavar = "<container_id>" |
| 203 | + container_help_text = "Identifier of container" |
| 204 | + name = "id" |
| 205 | + metavar = "<id>" |
| 206 | + help_text = "Identifier of object to be removed" |
| 207 | + |
| 208 | + def get_client(self): |
| 209 | + return self.app.client_manager.network |
| 210 | + |
| 211 | + def get_parser(self, prog_name): |
| 212 | + parser = super(RemoveCommand, self).get_parser(prog_name) |
| 213 | + if self.container_name: |
| 214 | + parser.add_argument( |
| 215 | + self.container_name, |
| 216 | + metavar=self.container_metavar, |
| 217 | + help=self.container_help_text, |
| 218 | + ) |
| 219 | + parser.add_argument( |
| 220 | + self.name, |
| 221 | + metavar=self.metavar, |
| 222 | + help=self.help_text, |
| 223 | + ) |
| 224 | + return parser |
| 225 | + |
| 226 | + def take_action(self, parsed_args): |
| 227 | + self.log.debug('take_action(%s)' % parsed_args) |
| 228 | + neuter = self.clazz(self.app, self.app_args) |
| 229 | + neuter.get_client = self.get_client |
| 230 | + parsed_args.request_format = 'json' |
| 231 | + return neuter.run(parsed_args) |
0 commit comments