Browse Source

Merge "Cleanup some flavor commands"

Jenkins 6 years ago
parent
commit
64e43fde43
4 changed files with 29 additions and 33 deletions
  1. 8
    2
      README.rst
  2. 3
    16
      novaclient/utils.py
  3. 12
    10
      novaclient/v1_1/flavors.py
  4. 6
    5
      novaclient/v1_1/shell.py

+ 8
- 2
README.rst View File

@@ -109,10 +109,16 @@ You'll find complete documentation on the shell by running
109 109
         endpoints           Discover endpoints that get returned from the
110 110
                             authenticate services
111 111
         evacuate            Evacuate a server from failed host
112
-        flavor-create       Create a new flavor
113
-        flavor-delete       Delete a specific flavor
112
+        flavor-create       Create a new flavor.
113
+        flavor-delete       Delete a specific flavor.
114 114
         flavor-list         Print a list of available 'flavors' (sizes of
115 115
                             servers).
116
+        flavor-show         Show details about the given flavor.
117
+        flavor-key          Set or unset extra_spec for a flavor.
118
+        flavor-access-list  Print access information about the given flavor.
119
+        flavor-access-add   Add flavor access for the given tenant.
120
+        flavor-access-remove
121
+                            Remove flavor access for the given tenant.
116 122
         floating-ip-create  Allocate a floating IP for the current tenant.
117 123
         floating-ip-delete  De-allocate a floating IP.
118 124
         floating-ip-list    List floating ips for this tenant.

+ 3
- 16
novaclient/utils.py View File

@@ -196,15 +196,9 @@ def find_resource(manager, name_or_id):
196 196
     """Helper for the _find_* methods."""
197 197
     # first try to get entity as integer id
198 198
     try:
199
-        is_intid = isinstance(name_or_id, int) or name_or_id.isdigit()
200
-    except AttributeError:
201
-        is_intid = False
202
-
203
-    if is_intid:
204
-        try:
205
-            return manager.get(int(name_or_id))
206
-        except exceptions.NotFound:
207
-            pass
199
+        return manager.get(int(name_or_id))
200
+    except (TypeError, ValueError, exceptions.NotFound):
201
+        pass
208 202
 
209 203
     # now try to get entity as uuid
210 204
     try:
@@ -365,13 +359,6 @@ def is_uuid_like(val):
365 359
         return False
366 360
 
367 361
 
368
-def check_uuid_like(val):
369
-    if not is_uuid_like(val):
370
-        raise exceptions.CommandError(
371
-                     "error: Invalid tenant-id %s supplied"
372
-                       % val)
373
-
374
-
375 362
 def _load_entry_point(ep_name, name=None):
376 363
     """Try to load the entry point ep_name that matches name."""
377 364
     for ep in pkg_resources.iter_entry_points(ep_name, name=name):

+ 12
- 10
novaclient/v1_1/flavors.py View File

@@ -134,35 +134,37 @@ class FlavorManager(base.ManagerWithFind):
134 134
 
135 135
         try:
136 136
             ram = int(ram)
137
-        except:
137
+        except (TypeError, ValueError):
138 138
             raise exceptions.CommandError("Ram must be an integer.")
139
-
140 139
         try:
141 140
             vcpus = int(vcpus)
142
-        except:
141
+        except (TypeError, ValueError):
143 142
             raise exceptions.CommandError("VCPUs must be an integer.")
144
-
145 143
         try:
146 144
             disk = int(disk)
147
-        except:
145
+        except (TypeError, ValueError):
148 146
             raise exceptions.CommandError("Disk must be an integer.")
149 147
 
150 148
         if flavorid == "auto":
151 149
             flavorid = None
150
+        elif not utils.is_uuid_like(flavorid):
151
+            try:
152
+                flavorid = int(flavorid)
153
+            except (TypeError, ValueError):
154
+                raise exceptions.CommandError("Flavor ID must be an integer "
155
+                                              "or a UUID or auto.")
152 156
 
153 157
         try:
154 158
             swap = int(swap)
155
-        except:
159
+        except (TypeError, ValueError):
156 160
             raise exceptions.CommandError("Swap must be an integer.")
157
-
158 161
         try:
159 162
             ephemeral = int(ephemeral)
160
-        except:
163
+        except (TypeError, ValueError):
161 164
             raise exceptions.CommandError("Ephemeral must be an integer.")
162
-
163 165
         try:
164 166
             rxtx_factor = float(rxtx_factor)
165
-        except:
167
+        except (TypeError, ValueError):
166 168
             raise exceptions.CommandError("rxtx_factor must be a float.")
167 169
 
168 170
         try:

+ 6
- 5
novaclient/v1_1/shell.py View File

@@ -416,7 +416,7 @@ def _print_flavor_extra_specs(flavor):
416 416
         return "N/A"
417 417
 
418 418
 
419
-def _print_flavor_list(cs, flavors, show_extra_specs=False):
419
+def _print_flavor_list(flavors, show_extra_specs=False):
420 420
     _translate_flavor_keys(flavors)
421 421
 
422 422
     headers = [
@@ -456,7 +456,7 @@ def do_flavor_list(cs, args):
456 456
         flavors = cs.flavors.list(is_public=None)
457 457
     else:
458 458
         flavors = cs.flavors.list()
459
-    _print_flavor_list(cs, flavors, args.extra_specs)
459
+    _print_flavor_list(flavors, args.extra_specs)
460 460
 
461 461
 
462 462
 @utils.arg('flavor',
@@ -466,6 +466,7 @@ def do_flavor_delete(cs, args):
466 466
     """Delete a specific flavor"""
467 467
     flavorid = _find_flavor(cs, args.flavor)
468 468
     cs.flavors.delete(flavorid)
469
+    _print_flavor_list([flavorid])
469 470
 
470 471
 
471 472
 @utils.arg('flavor',
@@ -474,7 +475,7 @@ def do_flavor_delete(cs, args):
474 475
 def do_flavor_show(cs, args):
475 476
     """Show details about the given flavor."""
476 477
     flavor = _find_flavor(cs, args.flavor)
477
-    _print_flavor(cs, flavor)
478
+    _print_flavor(flavor)
478 479
 
479 480
 
480 481
 @utils.arg('name',
@@ -515,7 +516,7 @@ def do_flavor_create(cs, args):
515 516
     f = cs.flavors.create(args.name, args.ram, args.vcpus, args.disk, args.id,
516 517
                           args.ephemeral, args.swap, args.rxtx_factor,
517 518
                           args.is_public)
518
-    _print_flavor_list(cs, [f])
519
+    _print_flavor_list([f])
519 520
 
520 521
 
521 522
 @utils.arg('flavor',
@@ -848,7 +849,7 @@ def _print_image(image):
848 849
     utils.print_dict(info)
849 850
 
850 851
 
851
-def _print_flavor(cs, flavor):
852
+def _print_flavor(flavor):
852 853
     info = flavor._info.copy()
853 854
     # ignore links, we don't need to present those
854 855
     info.pop('links')

Loading…
Cancel
Save