-
Notifications
You must be signed in to change notification settings - Fork 3
/
createinstance.py
59 lines (55 loc) · 1.99 KB
/
createinstance.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
47
48
49
50
51
52
53
54
55
56
57
58
59
import random
import string
from googleapiclient.discovery import build
from google.oauth2 import service_account
creds = service_account.Credentials.from_service_account_file('service-account.json')
compute = build('compute','v1',credentials = creds)
l = string.ascii_lowercase
name = "sf-crawl-" + ''.join(random.choice(l) for i in range(4))
machine = "zones/us-central1-a/machineTypes/n1-standard-2"
snapshot = "global/snapshots/sf-cli-api"
startupscript = "bash /home/****/bin/cloudcrawlclose example.com"
config = {
'name': name,
'machineType': machine,
'disks': [
{
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceSnapshot': snapshot,
}
}
],
'networkInterfaces': [{
'network': 'global/networks/default',
'accessConfigs': [
{'type': 'ONE_TO_ONE_NAT', 'name': 'External NAT'}
]
}],
'serviceAccounts': [{
"email": "***************@developer.gserviceaccount.com",
"scopes": [
"https://www.googleapis.com/auth/bigquery",
"https://www.googleapis.com/auth/datastore",
"https://www.googleapis.com/auth/devstorage.full_control",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/sqlservice.admin",
"https://www.googleapis.com/auth/trace.append"
]
}],
'metadata': {
'items': [{
'key': 'startup-script',
'value': startupscript
}]
}
}
instance = compute.instances().insert(
project=project,
zone=zone,
body=config).execute()
print(instance)