def identify_file(input_file):
     """
     Return True if the given file is of this format.
     """
     try:
         ImageParser.parse_file(input_file)
     except ImageParser.ParserException:
         return False
     return True
Exemple #2
0
    def run(self,appliance, settings):
        img = ImageParser.parse_file(self.virt_image_path(appliance, settings))
        count = 0
        target = self.resolve_appliance(appliance)
        for name, disk in img.storage.iteritems():
    	    if count >= 1:
                raise ValueError, ("EC2 only supports one disk image")
                logging.error("EC2 only allows one disk, please edit your kickstart file")
            else:
                count += 1

        directory = self.output_dir(appliance, settings)
        ec2_disk = self.converted_file(0, appliance, settings)
        aws_cert = settings["aws_cert"]
        aws_private_key = settings["aws_private_key"]
        aws_account_number = settings["aws_account_number"]
        cmd = "ec2-bundle-image -i %s -c %s -k %s -u %s -r i386 -d %s " % (ec2_disk,aws_cert,aws_private_key,aws_account_number, directory)
        if target.ec2kernel is not None:
            cmd += " --kernel %s" % target.ec2kernel
        if target.ec2ramdisk is not None:
            cmd += " --ramdisk %s" % target.ec2ramdisk
        print cmd
        os.system(cmd)
        
        return True
 def import_file(input_file):
     """
     Import a configuration file.  Raises if the file couldn't be
     opened, or parsing otherwise failed.
     """
     vm = vmcfg.vm()
     try:
         config  = ImageParser.parse_file(input_file)
     except Exception, e:
         raise ValueError(_("Couldn't import file '%s': %s") %
                          (input_file, e))
Exemple #4
0
 def run(self,appliance, settings):
     success = True 
     img = ImageParser.parse_file(self.virt_image_path(appliance, settings))
     count = 0
     directory = self.output_dir(appliance, settings)
     self.create_directory(directory)
     for name, disk in img.storage.iteritems():
         source_path = os.path.join(self.output_path(appliance, settings), disk.file)
         print source_path         
         success = ec2config.convert(source_path, "diskimage", \
             settings["temp_directory"], "yes", "yes", self.converted_file(count, appliance, settings))            
         count += 1                
Exemple #5
0
 def run(self,appliance, settings):
     img = ImageParser.parse_file(self.virt_image_path(appliance, settings))
     count = 0
     for name, disk in img.storage.iteritems():
 	    if count >= 1:
             raise ValueError, ("EC2 only supports one disk image")
             logging.error("EC2 only allows one disk, please edit your kickstart file")
         else:
             count += 1
             
     target = self.resolve_appliance(appliance)
     manifest_file = self.manifest_file(appliance, settings)
     s3_bucket = target.s3bucket
     aws_key = settings["aws_key"]
     aws_secret_key = settings["aws_secret_key"]
     self.exec_cmd("ec2-upload-bundle -b %s -m %s -a %s -s %s --retry" % (s3_bucket,manifest_file,aws_key,aws_secret_key))    
Exemple #6
0
 def run(self,appliance, settings):
     # Get the disk files     
     image = ImageParser.parse_file(self.virt_image_path(appliance, settings))
     disks = []
     for name, disk in image.storage.iteritems():
         imagefile = os.path.join(self.output_path(appliance, settings), disk.file)
         disks.append(imagefile)
     all_disks = ",".join(disks)
     
     # Convert the memory to megebytes
     memory_in_mb = image.domain.memory / 1024
     
     # Translate the architecture
     arch = image.domain.boots[0].arch
     if arch == 'i686':
         arch = 'x86'
         
     # Log into cobbler
     server = settings["cobbler_hostname"]
     login = settings["cobbler_user"]
     password = settings["cobbler_password"]        
     
     cobbler_uri = "http://%s/cobbler_api_rw" % server
     remote =  xmlrpclib.Server(cobbler_uri)
     token = remote.login(login,password)
     
     # Create and update the image
     image_id = remote.new_image(token)
     remote.modify_image(image_id, "name",appliance,token)
     remote.modify_image(image_id, "virt_ram",memory_in_mb,token) 
     remote.modify_image(image_id, "virt_cpus",image.domain.vcpu,token)         
     remote.modify_image(image_id, "virt_type","auto",token)                 
     remote.modify_image(image_id, "image_type","virt-clone",token)                         
     remote.modify_image(image_id, "file",all_disks,token)         
     remote.modify_image(image_id, "virt_bridge","",token)   
     remote.modify_image(image_id, "network_count",image.domain.interface,token)           
     remote.modify_image(image_id, "arch",arch,token)               
     remote.save_image(image_id,token)