Skip to content

Commit 5aed1ee

Browse files
author
Gabriel Monroy
committed
add layers:destroy, change layers:create args
1 parent 2cfa340 commit 5aed1ee

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

client/deis/client.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,22 @@
119119
""",
120120
'keys:remove': """Usage: deis keys:remove <key>
121121
""",
122-
'layers:create': """Usage: deis layers:create <id> --flavor=<flavor> [options]
122+
'layers:create': """Usage: deis layers:create <id> <flavor> --run_list=<run_list> [options]
123123
124124
Chef Options:
125125
126-
--run_list=RUN_LIST run-list to use when bootstrapping nodes
127-
--environment=ENVIRONMENT chef environment to place nodes
128-
--initial_attributes=INITIAL_ATTRS initial attributes for nodes
126+
--run_list=RUN_LIST run-list to use when bootstrapping nodes
127+
--environment=ENVIRONMENT chef environment to place nodes [default: _default]
128+
--attributes=INITIAL_ATTRS initial attributes for nodes
129129
130130
SSH Options:
131131
132132
--ssh_username=USERNAME username for ssh connections [default: ubuntu]
133133
--ssh_private_key=PRIVATE_KEY private key for ssh comm (default: auto-gen)
134134
--ssh_public_key=PUBLIC_KEY public key for ssh comm (default: auto-gen)
135135
136+
""",
137+
'layers:destroy': """Usage: deis layers:destroy <id>
136138
""",
137139
'layers:scale': """Usage: deis layers:scale <type=num>...
138140
""",
@@ -533,13 +535,11 @@ def flavors_list(self, args):
533535

534536
def formations_create(self, args):
535537
"""Create a formation."""
536-
body = {'flavor': args['--flavor']}
537-
formation_id = args.get('--id')
538-
if formation_id:
539-
body.update({'id': formation_id})
540-
image = args.get('--image')
541-
if image:
542-
body.update({'image': image})
538+
body = {}
539+
for opt in ('--id', '--image'):
540+
o = args.get(opt)
541+
if o:
542+
body.update({opt.strip('-'): o})
543543
response = self._dispatch('post', '/api/formations',
544544
json.dumps(body))
545545
if response.status_code == requests.codes.created: # @UndefinedVariable
@@ -699,21 +699,36 @@ def layers_create(self, args):
699699
formation = args.get('--formation')
700700
if not formation:
701701
formation = self._session.formation
702-
body = {'id': args['<id>'], 'flavor': args['<flavor>']}
703-
for opt in ('--run_list', '--environment', '--initial_attributes',
702+
body = {'id': args['<id>'], 'flavor': args['<flavor>'], 'run_list': args['--run_list']}
703+
for opt in ('--environment', '--initial_attributes',
704704
'--ssh_username', '--ssh_private_key', '--ssh_public_key'):
705705
o = args.get(opt)
706706
if o:
707707
body.update({opt.strip('-'): o})
708-
response = self._dispatch('post', '/api/formations/{}/layers'.format(formation),
709-
json.dumps(body))
710708
sys.stdout.write('Creating layer {}...'.format(args['<id>']))
711709
sys.stdout.flush()
710+
response = self._dispatch('post', '/api/formations/{}/layers'.format(formation),
711+
json.dumps(body))
712712
if response.status_code == requests.codes.created: # @UndefinedVariable
713713
print('done')
714714
else:
715715
print('Error!', response.text)
716716

717+
def layers_destroy(self, args):
718+
"""Destroy a layer of nodes."""
719+
formation = args.get('--formation')
720+
if not formation:
721+
formation = self._session.formation
722+
layer = args['<id>']
723+
sys.stdout.write('Destroying layer {layer}...'.format(**locals()))
724+
sys.stdout.flush()
725+
response = self._dispatch('delete',
726+
'/api/formations/{formation}/layers/{layer}'.format(**locals()))
727+
if response.status_code == requests.codes.no_content: # @UndefinedVariable
728+
print('done')
729+
else:
730+
print('Error!', response.text)
731+
717732
def layers_list(self, args):
718733
"""List layers for this formation."""
719734
formation = args.get('--formation')

0 commit comments

Comments
 (0)