-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_get_by_zone.py
More file actions
58 lines (51 loc) · 1.97 KB
/
template_get_by_zone.py
File metadata and controls
58 lines (51 loc) · 1.97 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env python
# Python script for the Interoute Virtual Data Centre API:
# Name: template_get_by_zone.py
# Purpose: List available templates to create a VM, in a specified zone
# 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)
# Get the zone ID- you can find these IDs with the zone_get_all.py script
zone_id = raw_input('ID of zone to filter the list of templates' +
' (you can find these IDs with the zone_get_all.py' +
' script):')
request = {
'templatefilter': 'executable', 'zoneid': zone_id
}
result = api.listTemplates(request)
for template in result['template']:
print('%s: %s (NAME: %s, TYPE: %s)' % (
template['id'],
template['displaytext'],
template['name'],
template['ostypename'],
))