@@ -43,32 +43,31 @@ class BMCCreateOptions(CLIRunnable):
4343 action = 'create-options'
4444 options = ['datacenter' , 'cpu' , 'memory' , 'os' , 'disk' , 'nic' ]
4545
46- @classmethod
47- def execute (cls , client , args ):
46+ def execute (self , args ):
4847 t = KeyValueTable (['Name' , 'Value' ])
4948 t .align ['Name' ] = 'r'
5049 t .align ['Value' ] = 'l'
5150
5251 show_all = True
53- for opt_name in cls .options :
52+ for opt_name in self .options :
5453 if args .get ("--" + opt_name ):
5554 show_all = False
5655 break
5756
58- mgr = HardwareManager (client )
57+ mgr = HardwareManager (self . client )
5958
6059 bmi_options = mgr .get_bare_metal_create_options ()
6160
6261 if args ['--all' ]:
6362 show_all = True
6463
6564 if args ['--datacenter' ] or show_all :
66- results = cls .get_create_options (bmi_options , 'datacenter' )[0 ]
65+ results = self .get_create_options (bmi_options , 'datacenter' )[0 ]
6766
6867 t .add_row ([results [0 ], listing (sorted (results [1 ]))])
6968
7069 if args ['--cpu' ] or args ['--memory' ] or show_all :
71- results = cls .get_create_options (bmi_options , 'cpu' )
70+ results = self .get_create_options (bmi_options , 'cpu' )
7271 memory_cpu_table = Table (['memory' , 'cpu' ])
7372 for result in results :
7473 memory_cpu_table .add_row ([
@@ -80,7 +79,7 @@ def execute(cls, client, args):
8079 t .add_row (['memory/cpu' , memory_cpu_table ])
8180
8281 if args ['--os' ] or show_all :
83- results = cls .get_create_options (bmi_options , 'os' )
82+ results = self .get_create_options (bmi_options , 'os' )
8483
8584 for result in results :
8685 t .add_row ([
@@ -91,22 +90,21 @@ def execute(cls, client, args):
9190 )])
9291
9392 if args ['--disk' ] or show_all :
94- results = cls .get_create_options (bmi_options , 'disk' )[0 ]
93+ results = self .get_create_options (bmi_options , 'disk' )[0 ]
9594
9695 t .add_row ([results [0 ], listing (
9796 [item [0 ] for item in sorted (results [1 ])])])
9897
9998 if args ['--nic' ] or show_all :
100- results = cls .get_create_options (bmi_options , 'nic' )
99+ results = self .get_create_options (bmi_options , 'nic' )
101100
102101 for result in results :
103102 t .add_row ([result [0 ], listing (
104103 [item [0 ] for item in sorted (result [1 ],)])])
105104
106105 return t
107106
108- @classmethod
109- def get_create_options (cls , bmi_options , section , pretty = True ):
107+ def get_create_options (self , bmi_options , section , pretty = True ):
110108 """ This method can be used to parse the bare metal instance creation
111109 options into different sections. This can be useful for data validation
112110 as well as printing the options on a help screen.
@@ -257,7 +255,8 @@ def _generate_windows_code(description):
257255 dual .append ((str (int (item ['capacity' ])) + '_DUAL' ,
258256 item ['price_id' ]))
259257 else :
260- single .append ((str (int (item ['capacity' ])), item ['price_id' ]))
258+ single .append ((str (int (item ['capacity' ])),
259+ item ['price_id' ]))
261260
262261 return [('single nic' , single ), ('dual nic' , dual )]
263262
@@ -304,10 +303,9 @@ class CreateBMCInstance(CLIRunnable):
304303 options = ['confirm' ]
305304 required_params = ['--hostname' , '--domain' , '--cpu' , '--memory' , '--os' ]
306305
307- @classmethod
308- def execute (cls , client , args ):
306+ def execute (self , args ):
309307 update_with_template_args (args )
310- mgr = HardwareManager (client )
308+ mgr = HardwareManager (self . client )
311309
312310 # Disks will be a comma-separated list. Let's make it a real list.
313311 if isinstance (args .get ('--disk' ), str ):
@@ -317,7 +315,7 @@ def execute(cls, client, args):
317315 if isinstance (args .get ('--key' ), str ):
318316 args ['--key' ] = args .get ('--key' ).split (',' )
319317
320- cls ._validate_args (args )
318+ self ._validate_args (args )
321319
322320 bmi_options = mgr .get_bare_metal_create_options ()
323321
@@ -328,9 +326,9 @@ def execute(cls, client, args):
328326 }
329327
330328 # Validate the CPU/Memory combination and get the price ID
331- server_core = cls ._get_cpu_and_memory_price_ids (bmi_options ,
332- args ['--cpu' ],
333- args ['--memory' ])
329+ server_core = self ._get_cpu_and_memory_price_ids (bmi_options ,
330+ args ['--cpu' ],
331+ args ['--memory' ])
334332
335333 if server_core :
336334 order ['server' ] = server_core
@@ -340,8 +338,8 @@ def execute(cls, client, args):
340338 order ['hourly' ] = args ['--hourly' ]
341339
342340 # Convert the OS code back into a price ID
343- os_price = cls ._get_price_id_from_options (bmi_options , 'os' ,
344- args ['--os' ])
341+ os_price = self ._get_price_id_from_options (bmi_options , 'os' ,
342+ args ['--os' ])
345343
346344 if os_price :
347345 order ['os' ] = os_price
@@ -353,22 +351,22 @@ def execute(cls, client, args):
353351 # Set the disk size
354352 disk_prices = []
355353 for disk in args .get ('--disk' ):
356- disk_price = cls ._get_price_id_from_options (bmi_options , 'disk' ,
357- disk )
354+ disk_price = self ._get_price_id_from_options (bmi_options , 'disk' ,
355+ disk )
358356
359357 if disk_price :
360358 disk_prices .append (disk_price )
361359
362360 if not disk_prices :
363- disk_prices .append (cls ._get_default_value (bmi_options , 'disk0' ))
361+ disk_prices .append (self ._get_default_value (bmi_options , 'disk0' ))
364362
365363 order ['disks' ] = disk_prices
366364
367365 # Set the port speed
368366 port_speed = args .get ('--network' ) or 10
369367
370- nic_price = cls ._get_price_id_from_options (bmi_options , 'nic' ,
371- port_speed )
368+ nic_price = self ._get_price_id_from_options (bmi_options , 'nic' ,
369+ port_speed )
372370
373371 if nic_price :
374372 order ['port_speed' ] = nic_price
@@ -379,8 +377,8 @@ def execute(cls, client, args):
379377 if args .get ('--key' ):
380378 keys = []
381379 for key in args .get ('--key' ):
382- key_id = resolve_id (SshKeyManager (client ).resolve_ids , key ,
383- 'SshKey' )
380+ key_id = resolve_id (SshKeyManager (self . client ).resolve_ids ,
381+ key , 'SshKey' )
384382 keys .append (key_id )
385383 order ['ssh_keys' ] = keys
386384
@@ -441,9 +439,8 @@ def execute(cls, client, args):
441439
442440 return output
443441
444- @classmethod
445- def _validate_args (cls , args ):
446- invalid_args = [k for k in cls .required_params if args .get (k ) is None ]
442+ def _validate_args (self , args ):
443+ invalid_args = [k for k in self .required_params if args .get (k ) is None ]
447444 if invalid_args :
448445 raise ArgumentError ('Missing required options: %s'
449446 % ',' .join (invalid_args ))
@@ -460,8 +457,7 @@ def _validate_args(cls, args):
460457 if not any ([args ['--hourly' ], args ['--monthly' ]]):
461458 raise ArgumentError ('One of [--hourly | --monthly] is required' )
462459
463- @classmethod
464- def _get_cpu_and_memory_price_ids (cls , bmi_options , cpu_value ,
460+ def _get_cpu_and_memory_price_ids (self , bmi_options , cpu_value ,
465461 memory_value ):
466462 bmi_obj = BMCCreateOptions ()
467463 price_id = None
@@ -477,8 +473,7 @@ def _get_cpu_and_memory_price_ids(cls, bmi_options, cpu_value,
477473
478474 return price_id
479475
480- @classmethod
481- def _get_default_value (cls , bmi_options , option ):
476+ def _get_default_value (self , bmi_options , option ):
482477 if option not in bmi_options ['categories' ]:
483478 return
484479
@@ -492,12 +487,11 @@ def _get_default_value(cls, bmi_options, option):
492487 ]):
493488 return item ['price_id' ]
494489
495- @classmethod
496- def _get_price_id_from_options (cls , bmi_options , option , value ):
490+ def _get_price_id_from_options (self , bmi_options , option , value ):
497491 bmi_obj = BMCCreateOptions ()
498492 price_id = None
499493
500- for k , v in bmi_obj .get_create_options (bmi_options , option , False ):
494+ for _ , v in bmi_obj .get_create_options (bmi_options , option , False ):
501495 for item_options in v :
502496 if item_options [0 ] == value :
503497 price_id = item_options [1 ]
@@ -519,9 +513,8 @@ class CancelInstance(CLIRunnable):
519513 action = 'cancel'
520514 options = ['confirm' ]
521515
522- @staticmethod
523- def execute (client , args ):
524- hw = HardwareManager (client )
516+ def execute (self , args ):
517+ hw = HardwareManager (self .client )
525518 hw_id = resolve_id (
526519 hw .resolve_ids , args .get ('<identifier>' ), 'hardware' )
527520
0 commit comments