-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm_deploy.py
More file actions
73 lines (61 loc) · 2.57 KB
/
vm_deploy.py
File metadata and controls
73 lines (61 loc) · 2.57 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env python
# Python script for the Interoute Virtual Data Centre API:
# Name: vm_deploy.py
# Purpose: Deploy a virtual machine
# Requires: class VDCApiCall in the file vdc_api_call.py
# For download and information:
# https://github.com/Interoute/VDC-API-examples-Python
#
# Copyright (C) Interoute Communications Limited, 2016
from __future__ import print_function
import vdc_api_call as vdc
import getpass
import json
import os
import pprint
if __name__ == '__main__':
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']
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 desired hostname of the VM
vm_hostname = raw_input('Enter the desired VM hostname:')
# Get the VM description
vm_description = raw_input('Enter the desired VM description:')
# Get the zone ID- you can find these IDs using the zone_get_all.py script
zone_id = raw_input('Enter the zone ID (from zone_get_all.py script):')
# Get the template ID- you can find these IDs using the template_get_by_zone.py
# script
template_id = raw_input('Enter the template ID' +
' (from the template_get_by_zone.py script):')
# Get the service offering ID- you can find these using the
# service_offering_get_all.py script
service_offering_id = raw_input('Enter the service offering ID' +
' (from the service_offering_get_all.py' +
' script):')
# Get the network ID (or IDs if more than one network)
network_ids = raw_input('Enter the network ID, or enter more than one separated by commas' +
' (from the output of networks_get_by_zone.py):')
# Deploy the VM
request = {
'serviceofferingid': service_offering_id,
'templateid': template_id,
'networkids': network_ids,
'zoneid': zone_id,
'displayname': vm_description,
'name': vm_hostname
}
result = api.deployVirtualMachine(request)
pprint.pprint(api.wait_for_job(result['jobid']))