7676 'config:unset' : """Usage: deis config:unset <key>...
7777""" ,
7878 'containers:list' : """Usage: deis containers:list
79+ """ ,
80+ 'containers:scale' : """Usage: deis containers:scale <type=num>...
7981""" ,
8082 'calculate' : """Usage: deis calculate
8183""" ,
110112 'formations:list' : """Usage: deis formations:list
111113""" ,
112114 'formations:destroy' : """Usage: deis formations:destroy [<formation>] [--confirm=<confirm>]
113- """ ,
114- 'formations:scale' : """Usage: deis formations:scale <type=num>...
115115""" ,
116116 'formations:converge' : """Usage: deis formations:converge
117117""" ,
124124 'keys:list' : """Usage: deis keys:list
125125""" ,
126126 'keys:remove' : """Usage: deis keys:remove <key>
127+ """ ,
128+ 'layers:create' : """Usage: deis layers:create <id> [--run_list=<run_list> --initial_attributes=<initial_attributes>]
129+ """ ,
130+ 'layers:scale' : """Usage: deis layers:scale <type=num>...
127131""" ,
128132 'login' : """Usage: deis login <controller> [--username=<username> --password=<password>]
129133""" ,
133137""" ,
134138 'nodes:list' : """Usage: deis nodes:list
135139""" ,
136- 'nodes:delete' : """Usage: deis nodes:delete --id= <id>
140+ 'nodes:delete' : """Usage: deis nodes:delete <id>
137141""" ,
138142 'providers:create' : """Usage: deis providers:create --type=<type> [--id=<id> --creds=<creds>]
139143""" ,
@@ -460,6 +464,23 @@ def containers_list(self, args):
460464 else :
461465 print ('Error!' , response .text )
462466
467+ def containers_scale (self , args ):
468+ formation = args .get ('--formation' )
469+ if not formation :
470+ formation = self ._session .formation
471+ body = {}
472+ for type_num in args .get ('<type=num>' ):
473+ typ , count = type_num .split ('=' )
474+ body .update ({typ : int (count )})
475+ response = self ._dispatch ('post' ,
476+ '/api/formations/{}/scale/containers' .format (formation ),
477+ json .dumps (body ))
478+ if response .status_code == requests .codes .ok : # @UndefinedVariable
479+ databag = json .loads (response .content )
480+ print (json .dumps (databag , indent = 2 ))
481+ else :
482+ print ('Error!' , response .text )
483+
463484 def flavors_create (self , args ):
464485 """Create a flavor using a provider"""
465486 body = {'id' : args .get ('--id' ), 'provider' : args .get ('--provider' )}
@@ -506,10 +527,12 @@ def flavors_list(self, args):
506527 def formations_create (self , args ):
507528 """Create a formation."""
508529 body = {'flavor' : args ['--flavor' ]}
509- if '--id' in args :
510- body .update ({'id' : args ['--id' ]})
511- if '--image' in args :
512- body .update ({'image' : args ['--image' ]})
530+ formation_id = args .get ('--id' )
531+ if formation_id :
532+ body .update ({'id' : formation_id })
533+ image = args .get ('--image' )
534+ if image :
535+ body .update ({'image' : image })
513536 response = self ._dispatch ('post' , '/api/formations' ,
514537 json .dumps (body ))
515538 if response .status_code == requests .codes .created : # @UndefinedVariable
@@ -568,23 +591,6 @@ def formations_destroy(self, args):
568591 else :
569592 print ('Error!' , response .text )
570593
571- def formations_scale (self , args ):
572- formation = args .get ('--formation' )
573- if not formation :
574- formation = self ._session .formation
575- body = {}
576- for type_num in args .get ('<type=num>' ):
577- typ , count = type_num .split ('=' )
578- body .update ({typ : int (count )})
579- response = self ._dispatch ('post' ,
580- '/api/formations/{}/scale' .format (formation ),
581- json .dumps (body ))
582- if response .status_code == requests .codes .ok : # @UndefinedVariable
583- databag = json .loads (response .content )
584- print (json .dumps (databag , indent = 2 ))
585- else :
586- print ('Error!' , response .text )
587-
588594 def formations_calculate (self , args ):
589595 formation = args .get ('--formation' )
590596 if not formation :
@@ -681,6 +687,58 @@ def keys_remove(self, args):
681687 else :
682688 print ('Error!' , response .text )
683689
690+ def layers_create (self , args ):
691+ """Create a layer of nodes."""
692+ formation = args .get ('--formation' )
693+ if not formation :
694+ formation = self ._session .formation
695+ body = {'id' : args ['<id>' ]}
696+ if '--run_list' in args :
697+ body .update ({'run_list' : args ['--run_list' ]})
698+ if '--initial_attributes' in args :
699+ body .update ({'initial_attributes' : args ['--initial_attributes' ]})
700+ response = self ._dispatch ('post' , '/api/formations/{}/layers' .format (formation ),
701+ json .dumps (body ))
702+ sys .stdout .write ('Creating layer {}...' .format (args ['<id>' ]))
703+ sys .stdout .flush ()
704+ if response .status_code == requests .codes .created : # @UndefinedVariable
705+ print ('done' )
706+ else :
707+ print ('Error!' , response .text )
708+
709+ def layers_list (self , args ):
710+ """List layers for this formation."""
711+ formation = args .get ('--formation' )
712+ if not formation :
713+ formation = self ._session .formation
714+ response = self ._dispatch ('get' ,
715+ '/api/formations/{}/layers' .format (formation ))
716+ if response .status_code == requests .codes .ok : # @UndefinedVariable
717+ print ('=== {0}' .format (formation ))
718+ data = response .json ()
719+ format_str = '{0[id]} => {0[run_list]}'
720+ for item in data ['results' ]:
721+ print (format_str .format (item ))
722+ else :
723+ print ('Error!' , response .text )
724+
725+ def layers_scale (self , args ):
726+ formation = args .get ('--formation' )
727+ if not formation :
728+ formation = self ._session .formation
729+ body = {}
730+ for type_num in args .get ('<type=num>' ):
731+ typ , count = type_num .split ('=' )
732+ body .update ({typ : int (count )})
733+ response = self ._dispatch ('post' ,
734+ '/api/formations/{}/scale/layers' .format (formation ),
735+ json .dumps (body ))
736+ if response .status_code == requests .codes .ok : # @UndefinedVariable
737+ databag = json .loads (response .content )
738+ print (json .dumps (databag , indent = 2 ))
739+ else :
740+ print ('Error!' , response .text )
741+
684742 def nodes_info (self , args ):
685743 """Show detail of a provider."""
686744 node = args .get ('<node>' )
@@ -700,15 +758,15 @@ def nodes_list(self, args):
700758 if response .status_code == requests .codes .ok : # @UndefinedVariable
701759 print ('=== {0}' .format (formation ))
702760 data = response .json ()
703- format_str = '{0[id]:<23} {0[type ]} {0[provider_id]} {0[fqdn]}'
761+ format_str = '{0[id]:<23} {0[layer ]} {0[provider_id]} {0[fqdn]}'
704762 for item in data ['results' ]:
705763 print (format_str .format (item ))
706764 else :
707765 print ('Error!' , response .text )
708766
709767 def nodes_delete (self , args ):
710768 """Delete a node by ID."""
711- node = args . get ( '--id' )
769+ node = args [ '<id>' ]
712770 response = self ._dispatch ('delete' ,
713771 '/api/nodes/{}' .format (node ))
714772 if response .status_code == requests .codes .no_content : # @UndefinedVariable
@@ -819,7 +877,7 @@ def main():
819877 'logout' : cli .auth_logout ,
820878 'create' : cli .formations_create ,
821879 'destroy' : cli .formations_destroy ,
822- 'scale' : cli .formations_scale ,
880+ 'scale' : cli .containers_scale ,
823881 'calculate' : cli .formations_calculate ,
824882 'balance' : cli .formations_balance ,
825883 'converge' : cli .formations_converge }
0 commit comments