|
79 | 79 | """, |
80 | 80 | 'calculate': """Usage: deis calculate |
81 | 81 | """, |
82 | | - 'create': """Usage: deis create --flavor=<flavor> --image=<image> [--id=<id>] |
| 82 | + 'create': """Usage: deis create --flavor=<flavor> [--image=<image> --id=<id>] |
83 | 83 | """, |
84 | 84 | 'converge': """Usage: deis converge |
85 | 85 | """, |
|
105 | 105 | """, |
106 | 106 | 'flavors:list': """Usage: deis flavors:list |
107 | 107 | """, |
108 | | - 'formations:create': """Usage: deis formations:create --flavor=<flavor> --image=<image> [--id=<id>] |
| 108 | + 'formations:create': """Usage: deis formations:create --flavor=<flavor> [--image=<image> --id=<id>] |
109 | 109 | """, |
110 | 110 | 'formations:list': """Usage: deis formations:list |
111 | 111 | """, |
@@ -460,66 +460,6 @@ def containers_list(self, args): |
460 | 460 | else: |
461 | 461 | print('Error!', response.text) |
462 | 462 |
|
463 | | - def keys_add(self, args): |
464 | | - """Add SSH keys for the logged in user.""" |
465 | | - path = args.get('<key>') |
466 | | - if not path: |
467 | | - ssh_dir = os.path.expanduser('~/.ssh') |
468 | | - pubkeys = glob.glob(os.path.join(ssh_dir, '*.pub')) |
469 | | - print('Found the following SSH public keys:') |
470 | | - for i, k in enumerate(pubkeys): |
471 | | - key = k.split(os.path.sep)[-1] |
472 | | - print('{0}) {1}'.format(i+1, key)) |
473 | | - inp = raw_input('Which would you like to use with Deis? ') |
474 | | - try: |
475 | | - path = pubkeys[int(inp)-1] |
476 | | - key_id = path.split(os.path.sep)[-1].replace('.pub', '') |
477 | | - except: |
478 | | - print 'Aborting' |
479 | | - return |
480 | | - with open(path) as f: |
481 | | - data = f.read() |
482 | | - match = re.match(r'^(ssh-...) ([^ ]+) (.+)', data) |
483 | | - if not match: |
484 | | - print 'Could not parse public key material' |
485 | | - return |
486 | | - key_type, key_str, _key_comment = match.groups() |
487 | | - body = {'id': key_id, 'public': '{0} {1}'.format(key_type, key_str)} |
488 | | - sys.stdout.write('Uploading {0} to Deis... '.format(path)) |
489 | | - sys.stdout.flush() |
490 | | - response = self._dispatch('post', '/api/keys', json.dumps(body)) |
491 | | - if response.status_code == requests.codes.created: # @UndefinedVariable |
492 | | - print('done') |
493 | | - else: |
494 | | - print('Error!', response.text) |
495 | | - |
496 | | - def keys_list(self, args): |
497 | | - """List SSH keys for the logged in user.""" |
498 | | - response = self._dispatch('get', '/api/keys') |
499 | | - if response.status_code == requests.codes.ok: # @UndefinedVariable |
500 | | - data = response.json() |
501 | | - if data['count'] == 0: |
502 | | - print 'No keys found' |
503 | | - return |
504 | | - print('=== {0} Keys'.format(data['results'][0]['owner'])) |
505 | | - for key in data['results']: |
506 | | - public = key['public'] |
507 | | - print('{0} {1}...{2}'.format( |
508 | | - key['id'], public[0:16], public[-10:])) |
509 | | - else: |
510 | | - print('Error!', response.text) |
511 | | - |
512 | | - def keys_remove(self, args): |
513 | | - """Remove a specific SSH key for the logged in user.""" |
514 | | - key = args.get('<key>') |
515 | | - sys.stdout.write('Removing {0} SSH Key... '.format(key)) |
516 | | - sys.stdout.flush() |
517 | | - response = self._dispatch('delete', '/keys/{}'.format(key)) |
518 | | - if response.status_code == requests.codes.no_content: # @UndefinedVariable |
519 | | - print('done') |
520 | | - else: |
521 | | - print('Error!', response.text) |
522 | | - |
523 | 463 | def flavors_create(self, args): |
524 | 464 | """Create a flavor using a provider""" |
525 | 465 | body = {'id': args.get('--id'), 'provider': args.get('--provider')} |
@@ -565,9 +505,11 @@ def flavors_list(self, args): |
565 | 505 |
|
566 | 506 | def formations_create(self, args): |
567 | 507 | """Create a formation.""" |
568 | | - body = {'image': args['--image'], 'flavor': args['--flavor']} |
| 508 | + body = {'flavor': args['--flavor']} |
569 | 509 | if '--id' in args: |
570 | 510 | body.update({'id': args['--id']}) |
| 511 | + if '--image' in args: |
| 512 | + body.update({'image': args['--image']}) |
571 | 513 | response = self._dispatch('post', '/api/formations', |
572 | 514 | json.dumps(body)) |
573 | 515 | if response.status_code == requests.codes.created: # @UndefinedVariable |
@@ -679,6 +621,66 @@ def formations_converge(self, args): |
679 | 621 | else: |
680 | 622 | print('Error!', response.text) |
681 | 623 |
|
| 624 | + def keys_add(self, args): |
| 625 | + """Add SSH keys for the logged in user.""" |
| 626 | + path = args.get('<key>') |
| 627 | + if not path: |
| 628 | + ssh_dir = os.path.expanduser('~/.ssh') |
| 629 | + pubkeys = glob.glob(os.path.join(ssh_dir, '*.pub')) |
| 630 | + print('Found the following SSH public keys:') |
| 631 | + for i, k in enumerate(pubkeys): |
| 632 | + key = k.split(os.path.sep)[-1] |
| 633 | + print('{0}) {1}'.format(i+1, key)) |
| 634 | + inp = raw_input('Which would you like to use with Deis? ') |
| 635 | + try: |
| 636 | + path = pubkeys[int(inp)-1] |
| 637 | + key_id = path.split(os.path.sep)[-1].replace('.pub', '') |
| 638 | + except: |
| 639 | + print 'Aborting' |
| 640 | + return |
| 641 | + with open(path) as f: |
| 642 | + data = f.read() |
| 643 | + match = re.match(r'^(ssh-...) ([^ ]+) (.+)', data) |
| 644 | + if not match: |
| 645 | + print 'Could not parse public key material' |
| 646 | + return |
| 647 | + key_type, key_str, _key_comment = match.groups() |
| 648 | + body = {'id': key_id, 'public': '{0} {1}'.format(key_type, key_str)} |
| 649 | + sys.stdout.write('Uploading {0} to Deis... '.format(path)) |
| 650 | + sys.stdout.flush() |
| 651 | + response = self._dispatch('post', '/api/keys', json.dumps(body)) |
| 652 | + if response.status_code == requests.codes.created: # @UndefinedVariable |
| 653 | + print('done') |
| 654 | + else: |
| 655 | + print('Error!', response.text) |
| 656 | + |
| 657 | + def keys_list(self, args): |
| 658 | + """List SSH keys for the logged in user.""" |
| 659 | + response = self._dispatch('get', '/api/keys') |
| 660 | + if response.status_code == requests.codes.ok: # @UndefinedVariable |
| 661 | + data = response.json() |
| 662 | + if data['count'] == 0: |
| 663 | + print 'No keys found' |
| 664 | + return |
| 665 | + print('=== {0} Keys'.format(data['results'][0]['owner'])) |
| 666 | + for key in data['results']: |
| 667 | + public = key['public'] |
| 668 | + print('{0} {1}...{2}'.format( |
| 669 | + key['id'], public[0:16], public[-10:])) |
| 670 | + else: |
| 671 | + print('Error!', response.text) |
| 672 | + |
| 673 | + def keys_remove(self, args): |
| 674 | + """Remove a specific SSH key for the logged in user.""" |
| 675 | + key = args.get('<key>') |
| 676 | + sys.stdout.write('Removing {0} SSH Key... '.format(key)) |
| 677 | + sys.stdout.flush() |
| 678 | + response = self._dispatch('delete', '/keys/{}'.format(key)) |
| 679 | + if response.status_code == requests.codes.no_content: # @UndefinedVariable |
| 680 | + print('done') |
| 681 | + else: |
| 682 | + print('Error!', response.text) |
| 683 | + |
682 | 684 | def nodes_info(self, args): |
683 | 685 | """Show detail of a provider.""" |
684 | 686 | node = args.get('<node>') |
|
0 commit comments