|
136 | 136 | 'nodes:delete': """Usage: deis nodes:delete --id=<id> |
137 | 137 | """, |
138 | 138 | 'providers:create': """Usage: deis providers:create --type=<type> [--id=<id> --creds=<creds>] |
| 139 | +""", |
| 140 | + 'providers:discover': """Usage: deis providers:discover |
139 | 141 | """, |
140 | 142 | 'providers:list': """Usage: deis providers:list |
141 | 143 | """, |
@@ -734,6 +736,30 @@ def providers_create(self, args): |
734 | 736 | else: |
735 | 737 | print('Error!', response.text) |
736 | 738 |
|
| 739 | + def providers_discover(self, args): |
| 740 | + """Discover and update providers""" |
| 741 | + # look for ec2 credentials |
| 742 | + if 'AWS_ACCESS_KEY' in os.environ and 'AWS_SECRET_KEY' in os.environ: |
| 743 | + print('Found EC2 credentials: {0}'.format(os.environ['AWS_ACCESS_KEY'])) |
| 744 | + inp = raw_input('Import these credentials? (y/n) : ') |
| 745 | + if inp.lower().strip('\n') != 'y': |
| 746 | + print 'Aborting.' |
| 747 | + return |
| 748 | + creds = {'access_key': os.environ['AWS_ACCESS_KEY'], |
| 749 | + 'secret_key': os.environ['AWS_SECRET_KEY']} |
| 750 | + body = {'creds': json.dumps(creds)} |
| 751 | + sys.stdout.write('Uploading EC2 credentials... ') |
| 752 | + sys.stdout.flush() |
| 753 | + response = self._dispatch('patch', '/api/providers/ec2', |
| 754 | + json.dumps(body)) |
| 755 | + if response.status_code == requests.codes.ok: # @UndefinedVariable |
| 756 | + print 'done' |
| 757 | + else: |
| 758 | + print('Error!', response.text) |
| 759 | + else: |
| 760 | + print 'No credentials discovered, did you install the EC2 Command Line tools?' |
| 761 | + return |
| 762 | + |
737 | 763 | def providers_list(self, args): |
738 | 764 | """List providers.""" |
739 | 765 | response = self._dispatch('get', '/api/providers') |
|
0 commit comments