Skip to content

Commit 50df654

Browse files
author
Gabriel Monroy
committed
add deis providers:discover with a more explicit discovery workflow that uses default providers, fixes #23
1 parent 485df36 commit 50df654

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

client/deis/client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
'nodes:delete': """Usage: deis nodes:delete --id=<id>
137137
""",
138138
'providers:create': """Usage: deis providers:create --type=<type> [--id=<id> --creds=<creds>]
139+
""",
140+
'providers:discover': """Usage: deis providers:discover
139141
""",
140142
'providers:list': """Usage: deis providers:list
141143
""",
@@ -734,6 +736,30 @@ def providers_create(self, args):
734736
else:
735737
print('Error!', response.text)
736738

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+
737763
def providers_list(self, args):
738764
"""List providers."""
739765
response = self._dispatch('get', '/api/providers')

0 commit comments

Comments
 (0)