Exemplo n.º 1
0
def main(remoteAddress):
  """ Main function
      Keyword arguments:
      remoteAddress -- remote address of the host that sent the request
  """
  try:
    if remoteData.has_key("vmAction"):
      remoteAction = remoteData["vmAction"].value
      logging.info("received a request from " + str(os.getenv('REMOTE_ADDR')) + " with remote action " + remoteAction)
      if remoteAction == "remoteDeploy":
        checkRequestComesFromServer(remoteAddress)
        deploy()
      elif remoteAction == "remoteTerminate":
        checkRequestComesFromServer(remoteAddress)
        terminate()
      else:
        logging.info("received a unkown request from " + str(os.getenv('REMOTE_ADDR')))
    else:
      logging.info("received a invalid request from " + str(os.getenv('REMOTE_ADDR'))) 
  except:
    logging.info('Exception raised')
    if (not remoteData.has_key("vmHostname")):
      logging.info("No key vmHostname")
    else:
      vmHostname = remoteData["vmHostname"].value;
      forkworker.startForked(reportStateMessage, args=[vmHostname, str(sys.exc_info()[1]),os.getenv('REMOTE_ADDR')])
      forkworker.startForked(reportState , args=[vmHostname, 'failed',os.getenv('REMOTE_ADDR')])
Exemplo n.º 2
0
def terminate():
  """Function to process the request of the Server to terminate a virtual machine.
  """
  logging.info("terminating a machine for " + str(os.getenv('REMOTE_ADDR')))
  if (not remoteData.has_key("vmHostname")):
    logging.info("No key vmHostname")
    raise Exception('No key vmHostname')
  else:
    vmHostname = remoteData["vmHostname"].value; 
  try:
    vmUsername = remoteData["vmUsername"].value;
    vmName = remoteData["vmName"].value;
    saveImage = remoteData["saveImage"].value;
    machinename = vmUsername + '_' + vmHostname
    vmImage = remoteData["vmImage"].value;
    vmImageType = vmImage
    vgDeployer = deployer.VNodeDeployer.getDeployerForImage(vmImageType)
    vmImageFilename = None
    logging.info("Terminate details for:  " + str(os.getenv('REMOTE_ADDR')))
    logging.info("Username:"******"Name:" + vmName)
    logging.info("Save Image:" + saveImage)
    logging.info("Machine Nname:" + vmUsername + '_' + vmHostname)
    logging.info("Image:" + vmImage)
    logging.info("ImageType:" + vmImageType)
    if (saveImage == 'yes'):
       imageDir = vnConfigNode.getImageDirectory()
       vmImageFilename = imageDir + vmUsername + '_' + vmName + ".tar.gz"
    logging.info("Destroying the virtual machine")
    vgDeployer.destroyVirtualMachine(vmHostname, machinename, vmImageFilename)
  except SystemExit:
  #  raise Exception('Raised by sys.exit()')
     pass
  except:
    forkworker.startForked(reportStateMessage, args=[vmHostname, str(sys.exc_info()[1])])
    forkworker.startForked(reportState , args=[vmHostname, 'failed'])
    logging.info("Could not terminate the virtual machine")
    raise Exception('Could not terminate the virtual machine')
Exemplo n.º 3
0
 def destroyVirtualMachine(self, vmHostname, machinename, imagename = None):
     forkworker.startForked(VNodeXenDeployer.__destroyVirtualMachine,
                            args=[self, vmHostname, machinename, imagename])
Exemplo n.º 4
0
 def createVirtualMachine(self, configFile, vmHostname, machinename, imagename, partitionSize, imageType, sitename):
     forkworker.startForked(VNodeXenDeployer.__createVirtualMachine,
                           args=[self, configFile, vmHostname, machinename, imagename, partitionSize, imageType, sitename])
Exemplo n.º 5
0
def deploy():
  """Function to process the request of the Server to deploy a virtual machine.
  """
  logging.info("deploying a machine for " + str(os.getenv('REMOTE_ADDR')))
  if (not remoteData.has_key("vmHostname")):
    logging.info("No key vmHostname")
    raise Exception('No vmHostname key')
  else:
    vmHostname = remoteData["vmHostname"].value; 
  try:
    vmUsername = remoteData["vmUsername"].value;
    vmName = remoteData["vmName"].value;
    vmPhysicalHost = remoteData["vmPhysicalHost"].value;
    vmMemory = remoteData["vmMemory"].value;
    vmPartition = remoteData["vmPartition"].value;
    vmSitename = remoteData["vmSitename"].value;
    vmRepo = remoteData["vmRepo"].value;
    vmGliteServices = remoteData["vmGliteServices"].value;
    imageDir = vnConfigNode.getImageDirectory()
    vmImage = remoteData["vmImage"].value;
    imageFilename = vnConfigNode.getVMImageFile(vmImage)
    logging.info("Deploying details for " + str(os.getenv('REMOTE_ADDR')))
    logging.info("Username:"******"Name:" + vmName)
    logging.info("PhysicalHost:" + vmPhysicalHost)
    logging.info("Memory:" + vmMemory)
    logging.info("Partition:" + vmPartition)
    logging.info("Sitename:" + vmSitename)
    logging.info("Repo:" + vmRepo)
    logging.info("Glite Services" + vmGliteServices)
    logging.info("Image:" + vmImage)
    logging.info("Image Filename:" + str(imageFilename))
    if (imageFilename == None and len(vmImage) != 0):
      imageFilename = vmImage
    elif (imageFilename == None and len(vmImage) == 0):
      logging.info("No was image defined")
      raise Exception('No Image')
    vmImageType = vmImage
    if (not imageFilename.startswith('/')):
      imageFilename = imageDir + imageFilename
    logging.info("Image Filename with append path:" + imageFilename)
    if (not os.path.exists(imageFilename)):
      logging.info("Cannot find path to image")
      raise Exception('Cannot find path to image')
    machinename = vmUsername + '_' + vmHostname
    configFilename = "/tmp/vnode_" + machinename + ".cfg"
    vgDeployer = deployer.VNodeDeployer.getDeployerForImage(vmImageType)
    logging.info("Verifying if physical host has enough resources to deploy the machine")
    vgDeployer.checkAvailability(vmMemory, vmPartition, vmImageType)
    logging.info("Creating the configuration file")
    vnConfigNode.createVMConfigFile(vmUsername, machinename, vmPhysicalHost, vmHostname, vmName, vmMemory, vmPartition, vmImageType, configFilename)
    logging.info("Creating the yaimgen configuration file")
    vnConfigNode.createVMYaimgenFile(vmSitename,vmRepo,vmUsername,vmGliteServices)
    logging.info("Creating the virtual machine with the previous defined parameters")
    vgDeployer.createVirtualMachine(configFilename, vmHostname, machinename, imageFilename, vmPartition, vmImageType, vmSitename)
  except SystemExit:
    #raise Exception('Raised by sys.exit()')\
    pass
  except:
    forkworker.startForked(reportStateMessage, args=[vmHostname, str(sys.exc_info()[1])])
    forkworker.startForked(reportState , args=[vmHostname, 'failed'])
    logging.info('Could not deploy the virtual machine')
    raise Exception('Could not deploy the virtual machine')