-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_offering_get_all.py
46 lines (40 loc) · 1.57 KB
/
service_offering_get_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env python
# Python script for the Interoute Virtual Data Centre API:
# Name: service_offering_get_all.py
# Purpose: List all the available service offerings (CPU and RAM for a VM)
# Requires: class VDCApiCall in the file vdc_api_call.py
# For download and information:
# http://cloudstore.interoute.com/main/knowledge-centre/library/vdc-api-python-scripts
#
# Copyright (C) Interoute Communications Limited, 2014
from __future__ import print_function
import vdc_api_call as vdc
import getpass
import json
import os
if __name__ == '__main__':
cloudinit_scripts_dir = 'cloudinit-scripts'
config_file = os.path.join(os.path.expanduser('~'), '.vdcapi')
if os.path.isfile(config_file):
with open(config_file) as fh:
data = fh.read()
config = json.loads(data)
api_url = config['api_url']
apiKey = config['api_key']
secret = config['api_secret']
try:
cloudinit_scripts_dir = config['cloudinit_scripts_dir']
except KeyError:
pass
else:
print('API url (e.g. http://10.220.18.115:8080/client/api):', end='')
api_url = raw_input()
print('API key:', end='')
apiKey = raw_input()
secret = getpass.getpass(prompt='API secret:')
# Create the api access object
api = vdc.VDCApiCall(api_url, apiKey, secret)
request = {}
result = api.listServiceOfferings(request)
for serviceoffering in result['serviceoffering']:
print('%s: %s' % (serviceoffering['id'], serviceoffering['displaytext']))