コード例 #1
0
ファイル: core.py プロジェクト: baseboxorg/machination
 def start(self):
   # Fire up the vagrant machine
   self.pack()
   p = subprocess.Popen("vagrant up", shell=True, stderr=subprocess.PIPE, cwd=self.getPath())
   err = p.communicate()[1]
   if p.returncode != 0:
     CORELOGGER.critical(err)
     raise RuntimeError("Error while starting machine instance: '{0}'".format(self.getName()));
コード例 #2
0
ファイル: core.py プロジェクト: baseboxorg/machination
 def pack(self):
   # If the machine does not exist yet
   if os.path.exists(self.getPath()):
     if self.getProvider().needsProvision(self):
       CORELOGGER.debug("Image needs provisioning, starting packer...")
       cmd = "packer build ./{0}".format(MACHINATION_PACKERFILE_NAME)
       
       # Fire up the vagrant machine
       p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, cwd=self.getPath())
       p.communicate()[0]
       returnCode = p.returncode
       if returnCode != 0:
         raise RuntimeError("Error while creating packing '{0}'".format(self.getName()));
   else:
         raise RuntimeError("Error while packing machine '{0}'".format(self.getName()));
コード例 #3
0
ファイル: core.py プロジェクト: baseboxorg/machination
 def create(self):
   # If the machine does not exist yet
   if not os.path.exists(self.getPath()):
     # Create its folder and copy the Vagrant file
     os.makedirs(self.getPath())
     shutil.copy(os.path.join(MACHINATION_INSTALLDIR, "share", "machination", "vagrant", "Vagrantfile"), os.path.join(self.getPath(), "Vagrantfile"))
     try:
       # Create the machine config file
       configFile = yaml.dump(self)
       openedFile = open(os.path.join(self.getPath(), MACHINATION_CONFIGFILE_NAME), "w+")
       openedFile.write(configFile)
       openedFile.close()
       # Generate the file related to the provisioner and the provider
       variables = {}
       variables["os_version"] = self.getOsVersion()
       variables["architecture"] = str(self.getArch())
       variables["template_name"] = self.getTemplate().getName()
       variables["template_version"] = str(self.getTemplate().getVersion())
       self.getPackerFile()["variables"] = variables
       self.getPackerFile()["builders"] = []
       self.getPackerFile()["provisioners"] = []
       self.getPackerFile()["post-processors"] = []
 
       self.getProvider().generateFilesFor(self)
       self.getProvisioner().generateFilesFor(self)
       
       outfile = open(os.path.join(self.getPath(),MACHINATION_PACKERFILE_NAME),"w")
       json.dump(self.getPackerFile(),outfile,indent=2)
       outfile.close()
       self.pack()
       
     except Exception as e:
       shutil.rmtree(self.getPath())
       CORELOGGER.debug(traceback.format_exc())
       raise e
   else:
     shutil.rmtree(self.getPath())
     # Raise an error about the fact the machine already exists
     raise RuntimeError("MachineInstance instance '{0}' already exists".format(self.getPath()))