@@ -1657,6 +1657,14 @@ def providers_create(self, args):
16571657 'api_key' : os .environ ['RACKSPACE_API_KEY' ],
16581658 'identity_type' : os .environ .get ('CLOUD_ID_TYPE' , 'rackspace' ),
16591659 }
1660+ elif type == 'digitalocean' :
1661+ # read creds from envvars
1662+ for k in ('DIGITALOCEAN_CLIENT_ID' , 'DIGITALOCEAN_API_KEY' ):
1663+ if not k in os .environ :
1664+ msg = "Missing environment variable: {}" .format (k )
1665+ raise EnvironmentError (msg )
1666+ creds = {'client_id' : os .environ ['DIGITALOCEAN_CLIENT_ID' ],
1667+ 'api_key' : os .environ ['DIGITALOCEAN_API_KEY' ]}
16601668 else :
16611669 creds = json .loads (args .get ('<creds>' ))
16621670 id = args .get ('<id>' ) # @ReservedAssignment
@@ -1701,7 +1709,7 @@ def providers_discover(self, args):
17011709 else :
17021710 raise ResponseError (response )
17031711 else :
1704- print ('No credentials discovered, did you install the EC2 Command Line tools?' )
1712+ print ('No EC2 credentials discovered. Did you install the EC2 Command Line tools?' )
17051713 if 'RACKSPACE_API_KEY' in os .environ and 'RACKSPACE_USERNAME' in os .environ :
17061714 print ("Found Rackspace credentials: {}" .format (os .environ ['RACKSPACE_API_KEY' ]))
17071715 inp = raw_input ('Import these credentials? (y/n) : ' )
@@ -1721,7 +1729,27 @@ def providers_discover(self, args):
17211729 else :
17221730 raise ResponseError (response )
17231731 else :
1724- print ('No Rackspace credentials discovered' )
1732+ print ('No Rackspace credentials discovered.' )
1733+ if 'DIGITALOCEAN_API_KEY' in os .environ and 'DIGITALOCEAN_CLIENT_ID' in os .environ :
1734+ print ("Found Digitalocean credentials: {}" .format (os .environ ['DIGITALOCEAN_CLIENT_ID' ]))
1735+ inp = raw_input ('Import these credentials? (y/n) : ' )
1736+ if inp .lower ().strip ('\n ' ) != 'y' :
1737+ print ('Aborting.' )
1738+ else :
1739+ creds = {'client_id' : os .environ ['DIGITALOCEAN_CLIENT_ID' ],
1740+ 'api_key' : os .environ ['DIGITALOCEAN_API_KEY' ],
1741+ }
1742+ body = {'creds' : json .dumps (creds )}
1743+ sys .stdout .write ('Uploading Digitalocean credentials... ' )
1744+ sys .stdout .flush ()
1745+ response = self ._dispatch ('patch' , 'api/providers/digitalocean' ,
1746+ json .dumps (body ))
1747+ if response .status_code == requests .codes .ok : # @UndefinedVariable
1748+ print ('done' )
1749+ else :
1750+ raise ResponseError (response )
1751+ else :
1752+ print ('No Digitalocean credentials discovered.' )
17251753
17261754 def providers_info (self , args ):
17271755 """
0 commit comments