''' 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)