示例#1
0
 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
示例#2
0
    def identify_file(input_file):
        """
        Return True if the given file is of this format.
        """
        try:
            f = file(input_file, "r")
            output = f.read()
            f.close()

            ImageParser.parse(output, input_file)
        except ImageParser.ParserException:
            return False
        return True
示例#3
0
    def identify_file(input_file):
        """
        Return True if the given file is of this format.
        """
        try:
            f = file(input_file, "r")
            output = f.read()
            f.close()

            ImageParser.parse(output, input_file)
        except ImageParser.ParserException:
            return False
        return True
示例#4
0
def process_disk(image, boot, file, location, target):
    image_location = copy_image(file, location)
    # Create the disk
    disk = ImageParser.Disk()
    disk.format = "raw"
    disk.file = image_location
    disk.use = "user"
    disk.id = image_location
    image.storage[disk.id] = disk

    #Create the drive
    drive = ImageParser.Drive()
    drive.id = image_location
    drive.target = target
    drive.disk = disk
    boot.disks.append(drive)
示例#5
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
示例#6
0
 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))
示例#7
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                
示例#8
0
    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:
            f = file(input_file, "r")
            output = f.read()
            f.close()

            logging.debug("Importing virt-image XML:\n%s", output)
            config = ImageParser.parse(output, input_file)
        except Exception, e:
            raise ValueError(_("Couldn't import file '%s': %s") %
                             (input_file, e))
示例#9
0
    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:
            f = file(input_file, "r")
            output = f.read()
            f.close()

            logging.debug("Importing virt-image XML:\n%s", output)
            config = ImageParser.parse(output, input_file)
        except Exception, e:
            raise ValueError(
                _("Couldn't import file '%s': %s") % (input_file, e))
示例#10
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))    
示例#11
0
文件: cobbler.py 项目: bkearney/adk2
 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)
示例#12
0
def start_install(name=None,
                  ram=None,
                  disks=None,
                  uuid=None,
                  extra=None,
                  vcpus=None,
                  profile_data=None,
                  arch=None,
                  no_gfx=False,
                  fullvirt=False,
                  bridge=None,
                  virt_type=None,
                  virt_auto_boot=None):

    #FIXME how to do a non-default connection
    #Can we drive off of virt-type?
    connection = None

    if (virt_type is None) or (virt_type == "auto"):
        connection = virtinst.util.default_connection()
    elif virt_type.lower()[0:3] == "xen":
        connection = "xen"
    else:
        connection = "qemu:///system"

    connection = libvirt.open(connection)
    capabilities = virtinst.CapabilitiesParser.parse(
        connection.getCapabilities())
    image_arch = transform_arch(arch)

    image = ImageParser.Image()
    #dev api
    #image = ImageParser.Image(filename="") #FIXME, ImageParser should take in None
    image.name = name

    domain = ImageParser.Domain()
    domain.vcpu = vcpus
    domain.memory = ram
    image.domain = domain

    boot = ImageParser.Boot()
    boot.type = "hvm"  #FIXME HARDCODED
    boot.loader = "hd"  #FIXME HARDCODED
    boot.arch = image_arch
    domain.boots.append(boot)

    #FIXME Several issues. Single Disk, type is hardcoded
    #And there is no way to provision with access to "file"
    process_disk(image, boot, profile_data["file"], disks[0][0], "hda")

    #FIXME boot_index??
    installer = virtinst.ImageInstaller(boot_index=0,
                                        image=image,
                                        capabilities=capabilities)
    guest = virtinst.FullVirtGuest(connection=connection,
                                   installer=installer,
                                   arch=image_arch)

    extra = extra.replace("&", "&")

    guest.extraargs = extra
    guest.set_name(name)
    guest.set_memory(ram)
    guest.set_vcpus(vcpus)

    if not no_gfx:
        guest.set_graphics("vnc")
    else:
        guest.set_graphics(False)

    if uuid is not None:
        guest.set_uuid(uuid)

    process_networks(domain, guest, profile_data, bridge)

    guest.start_install()

    return "use virt-manager or reconnect with virsh console %s" % name