Skip to content

Commit e5f438b

Browse files
author
Matthew Fisher
committed
refactor(client): remove provider functions
Deis no longer handles provider code, so these functions should not exist in the client.
1 parent 926c8f4 commit e5f438b

1 file changed

Lines changed: 0 additions & 176 deletions

File tree

client/deis.py

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -268,37 +268,6 @@ def dictify(args):
268268
return data
269269

270270

271-
def get_provider_creds(provider, raise_error=False):
272-
"""Query environment variables and return a provider's creds if found.
273-
"""
274-
cred_types = {
275-
'ec2': [[('AWS_ACCESS_KEY_ID', 'access_key', None),
276-
('AWS_SECRET_ACCESS_KEY', 'secret_key', None)],
277-
[('AWS_ACCESS_KEY', 'access_key', None),
278-
('AWS_SECRET_KEY', 'secret_key', None)]],
279-
'rackspace': [[('RACKSPACE_USERNAME', 'username', None),
280-
('RACKSPACE_API_KEY', 'api_key', None),
281-
('CLOUD_ID_TYPE', 'identity_type', 'rackspace')]],
282-
'digitalocean': [[('DIGITALOCEAN_CLIENT_ID', 'client_id', None),
283-
('DIGITALOCEAN_API_KEY', 'api_key', None)]]
284-
}
285-
missing = None
286-
for cred_set in cred_types[provider]:
287-
creds = {}
288-
for envvar, key, default in cred_set:
289-
val = os.environ.get(envvar, default)
290-
if not val:
291-
missing = envvar
292-
break
293-
else:
294-
creds[key] = val
295-
if creds:
296-
return creds
297-
if raise_error:
298-
raise EnvironmentError(
299-
"Missing environment variable: {}".format(missing))
300-
301-
302271
def readable_datetime(datetime_str):
303272
"""
304273
Return a human-readable datetime string from an ECMA-262 (JavaScript)
@@ -1326,151 +1295,6 @@ def _parse_perms_args(self, args):
13261295
url = "/api/apps/{}/perms".format(app)
13271296
return app, url
13281297

1329-
def providers(self, args):
1330-
"""
1331-
Valid commands for providers:
1332-
1333-
providers:list list available providers for the logged in user
1334-
providers:discover discover provider credentials using envvars
1335-
providers:create create a new provider for use by deis
1336-
providers:info print information about a specific provider
1337-
1338-
Use `deis help [command]` to learn more
1339-
"""
1340-
return self.providers_list(args)
1341-
1342-
def providers_create(self, args): # noqa
1343-
"""
1344-
Create a provider for use by Deis
1345-
1346-
This command is only necessary when adding a duplicate set of
1347-
credentials for a provider. User accounts start with empty providers,
1348-
EC2, Rackspace, and DigitalOcean by default, which should be updated
1349-
in place.
1350-
1351-
Use `providers:discover` to update the credentials for the default
1352-
providers created with your account.
1353-
1354-
Usage: deis providers:create <id> <type> <creds>
1355-
"""
1356-
type = args.get('<type>') # @ReservedAssignment
1357-
if type in ['ec2', 'rackspace', 'digitalocean']:
1358-
creds = get_provider_creds(type, raise_error=True)
1359-
else:
1360-
creds = json.loads(args.get('<creds>'))
1361-
id = args.get('<id>') # @ReservedAssignment
1362-
if not id:
1363-
id = type # @ReservedAssignment
1364-
body = {'id': id, 'type': type, 'creds': json.dumps(creds)}
1365-
response = self._dispatch('post', '/api/providers',
1366-
json.dumps(body))
1367-
if response.status_code == requests.codes.created: # @UndefinedVariable
1368-
print("{0[id]}".format(response.json()))
1369-
else:
1370-
raise ResponseError(response)
1371-
1372-
def providers_discover(self, args): # noqa
1373-
"""
1374-
Discover and update provider credentials
1375-
1376-
This command will discover provider credentials using
1377-
standard environment variables like AWS_ACCESS_KEY and
1378-
AWS_SECRET_KEY. It will use those credentials to update
1379-
the existing provider record, allowing you to use
1380-
pre-installed node flavors.
1381-
1382-
Usage: deis providers:discover
1383-
"""
1384-
provider_data = [
1385-
# Provider, human-redable provider name, sample field to display
1386-
('ec2', 'EC2', 'access_key'),
1387-
('rackspace', 'Rackspace', 'api_key'),
1388-
('digitalocean', 'DigitalOcean', 'api_key'),
1389-
]
1390-
for provider, name, field in provider_data:
1391-
creds = get_provider_creds(provider)
1392-
if creds:
1393-
print ("Discovered {} credentials: {}".format(name, creds[field]))
1394-
inp = raw_input("Import {} credentials? (y/n) : ".format(name))
1395-
if inp.lower().strip('\n') != 'y':
1396-
print('Aborting.')
1397-
else:
1398-
body = {'creds': json.dumps(creds)}
1399-
sys.stdout.write("Uploading {} credentials... ".format(name))
1400-
sys.stdout.flush()
1401-
endpoint = "/api/providers/{}".format(provider)
1402-
response = self._dispatch('patch', endpoint, json.dumps(body))
1403-
if response.status_code == requests.codes.ok: # @UndefinedVariable
1404-
print('done')
1405-
else:
1406-
raise ResponseError(response)
1407-
else:
1408-
print("No {} credentials discovered.".format(name))
1409-
1410-
# Check for locally booted Deis Controller VM
1411-
if '//deis-controller.local' in self._settings['controller']:
1412-
print("Discovered locally running Deis Controller VM")
1413-
# In order for the Controller to be able to boot Vagrant VMs it needs to run commands
1414-
# on the host machine. It does this via an SSH server. In order to access that server
1415-
# we need to send the current user's name and host.
1416-
try:
1417-
user = subprocess.check_output(
1418-
"whoami",
1419-
stderr=subprocess.PIPE
1420-
).strip()
1421-
except subprocess.CalledProcessError:
1422-
print("Error detecting username.")
1423-
sys.exit(1)
1424-
creds = {
1425-
'user': user,
1426-
'host': '192.168.61.1'
1427-
}
1428-
body = {'creds': json.dumps(creds)}
1429-
sys.stdout.write('Activating Vagrant as a provider... ')
1430-
sys.stdout.flush()
1431-
response = self._dispatch('patch', '/api/providers/vagrant',
1432-
json.dumps(body))
1433-
if response.status_code == requests.codes.ok: # @UndefinedVariable
1434-
print('done')
1435-
else:
1436-
raise ResponseError(response)
1437-
else:
1438-
print("No Vagrant Deis Controller discovered.")
1439-
1440-
def providers_info(self, args):
1441-
"""
1442-
Print information about a specific provider
1443-
1444-
Usage: deis providers:info <provider>
1445-
"""
1446-
provider = args.get('<provider>')
1447-
response = self._dispatch('get', "/api/providers/{}".format(provider))
1448-
if response.status_code == requests.codes.ok: # @UndefinedVariable
1449-
print(json.dumps(response.json(), indent=2))
1450-
else:
1451-
raise ResponseError(response)
1452-
1453-
def providers_list(self, args):
1454-
"""
1455-
List providers for the logged in user
1456-
1457-
Usage: deis providers:list
1458-
"""
1459-
response = self._dispatch('get', '/api/providers')
1460-
if response.status_code == requests.codes.ok: # @UndefinedVariable
1461-
data = response.json()
1462-
if data['count'] == 0:
1463-
print('No providers found')
1464-
return
1465-
print("=== {owner} Providers".format(**data['results'][0]))
1466-
for item in data['results']:
1467-
creds = json.loads(item['creds'])
1468-
if 'secret_key' in creds:
1469-
creds.pop('secret_key')
1470-
print("{} => {}".format(item['id'], creds))
1471-
else:
1472-
raise ResponseError(response)
1473-
14741298
def releases(self, args):
14751299
"""
14761300
Valid commands for releases:

0 commit comments

Comments
 (0)