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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
'''
Created on Aug 13, 2014
__author__ = "California Sullivan"
__copyright__ = "Copyright 2014, Intel Corp."
__credits__ = ["California Sullivan"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = "Elizabeth Flanagan"
__email__ = "pidge@toganlabs.com"
'''
from autobuilder.config import *
from buildbot.steps.shell import ShellCommand
class ProvisionGoogleVMs(ShellCommand):
haltOnFailure = True
flunkOnFailure = True
name = "Provision Google VMs"
def __init__(self, factory, argdict=None, **kwargs):
self.vmname=None
self.vmnames=""
self.vmcount=1
self.startupscript=None
self.metadata=None
self.zone="us-central1-a"
self.image=None
self.machine=None
self.network=None
self.disksize=None
self.factory = factory
self.description = "Provision Google VMs"
for k, v in argdict.iteritems():
if type(v) is bool:
setattr(self, k, str(v))
else:
setattr(self, k, v)
if self.vmname is None or self.vmname == "":
self.finished(FAILURE)
else:
self.command = ""
if self.zone is None or self.zone not in ["us-central1-a", "us-central1-b", "us-central1-f", "europe-west1-a", "europe-west1-b", "asia-east1-a", "asia-east1-b", "asia-east1-b"]:
self.zone = "us-central1-a"
for x in range(0, self.vmcount):
self.vmnames += " " + self.vmname + "-" + str(x)
self.command += " gcloud compute instances delete"
self.command += self.vmnames
self.command += " --zone " + self.zone + " --quiet;"
self.command += " gcloud compute instances create"
self.command += self.vmnames
self.command += " --zone " + self.zone
if self.disksize is not None and self.disksize != "":
self.command += " --boot-disk-size " + self.disksize
else:
self.command += " --boot-disk-size 200GB"
if self.image is None:
self.command += " --image debian-7"
else:
self.command += " --image " + self.image
if self.machine is not None and self.machine in ["g1-small", "f1-micro", "n1-standard-1", "n1-standard-2", "n1-standard-4", "n1-standard-8", "n1-standard-16", "n1-highmem-2", "n1-highmem-4"]:
self.command += " --machine-type " + self.machine
else:
self.command += " --machine-type n1-standard-1"
if self.network is not None and self.network != "":
self.command += " --network " + self.network
if self.startupscript is not None and self.startupscript != "":
self.command += " --metadata-from-file startup-script="+YOCTO_ABBASE+"/bin/"+self.startupscript
if self.metadata is not None and self.metadata != "":
self.command += " --metadata " + self.metadata
self.command += " 1> /dev/null";
# Timeout needs to be passed to LoggingBuildStep as a kwarg
self.timeout = 1000
kwargs['timeout']=self.timeout
ShellCommand.__init__(self, **kwargs)
def describe(self, done=False):
description = ShellCommand.describe(self,done)
return description
def commandComplete(self, cmd):
if not cmd.didFail():
self.setProperty("vmnames", self.vmnames)
self.setProperty("zone", self.zone)
self.setProperty("vmcount", self.vmcount)
|