Esempio n. 1
0
    def preflight_check(self):
        libvirt_uri = self.get_setting('libvirt')
        if not libvirt_uri:
            return True

        if not self.context.name == 'KVM' and not self.context.name == 'QEMu':
            raise VMBuilderUserError(
                'The libvirt plugin is only equiped to work with KVM and QEMu at the moment.'
            )

        import libvirt
        import xml.etree.ElementTree

        self.conn = libvirt.open(libvirt_uri)

        e = xml.etree.ElementTree.fromstring(self.conn.getCapabilities())

        if not 'hvm' in [x.text for x in e.getiterator('os_type')]:
            raise VMBuilderUserError(
                'libvirt does not seem to want to accept hvm domains')

        hostname = self.context.distro.get_setting('hostname')
        if hostname in self.all_domains() and not self.context.overwrite:
            raise VMBuilderUserError('Domain %s already exists at %s' %
                                     (hostname, libvirt_uri))
Esempio n. 2
0
 def preflight_check(self):
     if self.vm.copy:
         logging.debug("Checking if --copy PATH exists: %s" % self.vm.copy)
         if not(os.path.isfile(self.vm.copy)):
             raise VMBuilderUserError('The path to the --copy directives is invalid: %s. Make sure you are providing a full path.' % self.vm.copy)
             
     if self.vm.execscript:
         logging.debug("Checking if --exec PATH exists: %s" % self.vm.execscript)
         if not(os.path.isfile(self.vm.execscript)):
             raise VMBuilderUserError('The path to the --execscript file is invalid: %s. Make sure you are providing a full path.' % self.vm.execscript) 
Esempio n. 3
0
    def preflight_check(self):
        firstboot = self.context.get_setting('firstboot')
        if firstboot:
            logging.debug("Checking if firstboot script %s exists" % (firstboot,))
            if not(os.path.isfile(firstboot) and firstboot.startswith('/')):
                raise VMBuilderUserError('The path to the first-boot script is invalid: %s. Make sure you are providing a full path.' % firstboot)

        firstlogin = self.context.get_setting('firstlogin')
        if firstlogin:
            logging.debug("Checking if first login script %s exists" % (firstlogin,))
            if not(os.path.isfile(firstlogin) and firstlogin.startswith('/')):
                raise VMBuilderUserError('The path to the first-login script is invalid: %s.  Make sure you are providing a full path.' % firstlogin)
Esempio n. 4
0
    def deploy(self, destdir):
        libvirt_uri = self.get_setting('libvirt')
        if not libvirt_uri:
            # Not for us
            return False

        hostname = self.context.distro.get_setting('hostname')
        tmpl_ctxt = {
            'mem': self.context.get_setting('mem'),
            'cpus': self.context.get_setting('cpus'),
            'bridge': self.context.get_setting('bridge'),
            'mac': self.context.get_setting('mac'),
            'network': self.context.get_setting('network'),
            'mac': self.context.get_setting('mac'),
            'virtio_net': self.context.distro.use_virtio_net(),
            'disks': self.context.disks,
            'filesystems': self.context.filesystems,
            'hostname': hostname,
            'domain_type': self.context.libvirt_domain_type_name()
        }
        if self.context.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
            vmxml = VMBuilder.util.render_template('libvirt', self.context,
                                                   'libvirtxml_fsimage',
                                                   tmpl_ctxt)
        else:
            vmxml = VMBuilder.util.render_template('libvirt', self.context,
                                                   'libvirtxml', tmpl_ctxt)

        if hostname in self.all_domains() and not self.context.overwrite:
            raise VMBuilderUserError('Domain %s already exists at %s' %
                                     (hostname, libvirt_uri))
        else:
            self.conn.defineXML(vmxml)

        return True
Esempio n. 5
0
    def preflight_check(self):
        
        if self.vm.firstboot:
            logging.debug("Checking if firstboot script %s exists" % (self.vm.firstboot,))
	    if not(os.access(self.vm.firstboot, os.X_OK)):
	        raise MBuilderUserError("The first-boot script is not executable")

            if not(os.path.isfile(self.vm.firstboot)):
                raise VMBuilderUserError('The path to the first-boot script is invalid: %s. Make sure you are providing a full path.' % self.vm.firstboot)
                
        if self.vm.firstlogin:
            logging.debug("Checking if first login script %s exists" % (self.vm.firstlogin,))
            if not(os.access(self.vm.firstlogin, os.X_OK)):
                raise VMBuilderUserError("The first-login script is not executable")

            if not(os.path.isfile(self.vm.firstlogin)):
                raise VMBuilderUserError('The path to the first-login script is invalid: %s.  Make sure you are providing a full path.' % self.vm.firstlogin)
Esempio n. 6
0
    def post_install(self):
        if self.vm.copy:
            logging.info("Copying files specified by --copy in: %s" % self.vm.copy)
            try:
                for line in file(self.vm.copy):
                    pair = line.strip().split(' ')
                    util.run_cmd('cp', '-LpR', pair[0], '%s%s' % (self.vm.installdir, pair[1]))

            except IOError, (errno, strerror):
                raise VMBuilderUserError("%s executing --copy directives: %s" % (errno, strerror))
Esempio n. 7
0
    def preflight_check(self):
        if not self.vm.libvirt:
            return True

        import libvirt

        self.conn = libvirt.open(self.vm.libvirt)
        if self.vm.hostname in self.all_domains() and not self.vm.overwrite:
            raise VMBuilderUserError('Domain %s already exists at %s' %
                                     (self.vm.hostname, self.vm.libvirt))

        if not self.vm.hypervisor.name == 'KVM':
            raise VMBuilderUserError(
                'The libvirt plugin is only equiped to work with KVM at the moment.'
            )

        if not self.vm.hypervisor.name == 'KVM':
            raise VMBuilderUserError(
                'The libvirt plugin is only equiped to work with KVM at the moment.'
            )
Esempio n. 8
0
    def preflight_check(self):
        copy = self.context.get_setting('copy')
        if copy:
            logging.debug("Checking if copy PATH exists: %s" % copy)
            if not (os.path.isfile(copy)):
                raise VMBuilderUserError(
                    'The path to the copy directive is invalid: %s. Make sure you are providing a full path.'
                    % copy)

        execscript = self.context.get_setting('execscript')
        if execscript:
            logging.debug("Checking if exec PATH exists: %s" % execscript)
            if not (os.path.isfile(execscript)):
                raise VMBuilderUserError(
                    'The path to the execscript file is invalid: %s. Make sure you are providing a full path.'
                    % execscript)

            logging.debug("Checking permissions of exec PATH: %s" % execscript)
            if not os.access(execscript, os.X_OK | os.R_OK):
                raise VMBuilderUserError(
                    'The path to the execscript file has invalid permissions: %s. Make sure the path is readable and executable.'
                    % execscript)
Esempio n. 9
0
    def preflight_check(self):
        if not getattr(self.vm, 'ec2', False):
            return True

        #NOW, actually check if we can do EC2. Also check if we can take advantage of Euca's KVM support
        if not isinstance(self.vm.hypervisor, VMBuilder.plugins.xen.Xen):
            if not self.vm.ec2_is_eucalyptus:
                raise VMBuilderUserError("You must use Xen on EC2")
            elif not isinstance(self.vm.hypervisor,
                                VMBuilder.plugins.kvm.vm.KVM):
                raise VMBuilderUserError(
                    "You must use either Xen or KVM on Eucalyptus")

        if self.vm.ec2_no_amazon_tools:
            logging.info("Not using Amazon ec2-tools.")
            awsec2_installed = False
        else:
            try:
                run_cmd('ec2-ami-tools-version')
            except OSError, VMBuilderException:
                awsec2_installed = False
            else:
Esempio n. 10
0
    def preflight_check(self):
        if self.vm.copy:
            logging.debug("Checking if --copy PATH exists: %s" % self.vm.copy)
            if not (os.path.isfile(self.vm.copy)):
                raise VMBuilderUserError(
                    'The path to the --copy directives is invalid: %s. Make sure you are providing a full path.'
                    % self.vm.copy)

        if self.vm.execscript:
            logging.debug("Checking if --exec PATH exists: %s" %
                          self.vm.execscript)
            if not (os.path.isfile(self.vm.execscript)):
                raise VMBuilderUserError(
                    'The path to the --execscript file is invalid: %s. Make sure you are providing a full path.'
                    % self.vm.execscript)

            logging.debug("Checking permissions of --exec PATH: %s" %
                          self.vm.execscript)
            if not os.access(self.vm.execscript, os.X_OK | os.R_OK):
                raise VMBuilderUserError(
                    'The path to the --execscript file has invalid permissions: %s. Make sure the path is readable and executable.'
                    % self.vm.execscript)
Esempio n. 11
0
    def post_install(self):
        copy = self.context.get_setting('copy')
        if copy:
            logging.info("Copying files specified by copy in: %s" % copy)
            try:
                for line in file(copy):
                    pair = line.strip().split(' ')
                    if len(pair) < 2:  # skip blank and incomplete lines
                        continue
                    directory = '%s%s' % (self.context.chroot_dir,
                                          os.path.dirname(pair[1]))
                    if not os.path.exists(directory):
                        os.makedirs(directory)
                    util.run_cmd('cp', '-LpR', pair[0],
                                 '%s%s' % (self.context.chroot_dir, pair[1]))

            except IOError, (errno, strerror):
                raise VMBuilderUserError("%s executing copy directives: %s" %
                                         (errno, strerror))
Esempio n. 12
0
    def deploy(self):
        if not self.vm.libvirt:
            # Not for us
            return False

        if self.vm.hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
            vmxml = VMBuilder.util.render_template('libvirt', self.vm,
                                                   'libvirtxml_fsimage')
        else:
            vmxml = VMBuilder.util.render_template('libvirt', self.vm,
                                                   'libvirtxml')

        if self.vm.hostname in self.all_domains() and not self.vm.overwrite:
            raise VMBuilderUserError('Domain %s already exists at %s' %
                                     (self.vm.hostname, self.vm.libvirt))
        else:
            self.conn.defineXML(vmxml)

        return True
Esempio n. 13
0
        else:
            try:  #TODO: Fix this so that it doesn't use running d-a-z as a we-have-euca2ools check
                run_cmd('euca-describe-availability-zones')
            except OSError, VMBuilderException:
                euca_installed = False
            else:
                euca_installed = True

        if euca_installed:
            self.ec2_tools_prefix = "euca-"
        elif awsec2_installed:
            self.ec2_tools_prefix = "ec2-"
        else:
            if self.vm.ec2_bundle or self.vm.ec2_upload:
                raise VMBuilderUserError(
                    'When bundling or uploading for EC2 you must have ec2-tools or euca2ools installed.'
                )
            else:
                logging.warn(
                    'You do not have a suitable AMI tools suite installed, however, the current operation does not require it.'
                )
                self.ec2_tools_prefix = None

        if self.ec2_tools_prefix:
            logging.info("Using EC2 tools prefix: %s" % self.ec2_tools_prefix)

        if self.vm.ec2_bundle:
            if not self.vm.ec2_name:
                raise VMBuilderUserError(
                    'When building for EC2 you must supply the name for the image.'
                )
Esempio n. 14
0
    def preflight_check(self):
        if not getattr(self.vm, 'ec2', False):
            return True

        if not self.context.hypervisor.name == 'Xen':
            raise VMBuilderUserError(
                'When building for EC2 you must use the xen hypervisor.')

        if self.context.ec2_bundle:
            try:
                run_cmd('ec2-ami-tools-version')
            except VMBuilderException, e:
                raise VMBuilderUserError(
                    'You need to have the Amazon EC2 AMI tools installed')

            if not self.context.ec2_name:
                raise VMBuilderUserError(
                    'When building for EC2 you must supply the name for the image.'
                )

            if not self.context.ec2_cert:
                if "EC2_CERT" in os.environ:
                    self.context.ec2_cert = os.environ["EC2_CERT"]
                else:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your PEM encoded public key certificate'
                    )

            if not self.context.ec2_key:
                if "EC2_PRIVATE_KEY" in os.environ:
                    self.context.ec2_key = os.environ["EC2_PRIVATE_KEY"]
                else:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your PEM encoded private key file'
                    )

            if not self.context.ec2_user:
                raise VMBuilderUserError(
                    'When building for EC2 you must provide your EC2 user ID (your AWS account number, not your AWS access key ID)'
                )

            if not self.context.ec2_kernel:
                self.context.ec2_kernel = self.vm.distro.get_ec2_kernel()
                logging.debug('%s - to be used for AKI.' %
                              (self.context.ec2_kernel))

            if not self.context.ec2_ramdisk:
                self.context.ec2_ramdisk = self.vm.distro.ec2_ramdisk_id()
                logging.debug('%s - to be use for the ARI.' %
                              (self.context.ec2_ramdisk))

            if self.context.ec2_upload:
                if not self.context.ec2_bucket:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide an S3 bucket to hold the AMI'
                    )

                if not self.context.ec2_access_key:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your AWS access key ID.'
                    )

                if not self.context.ec2_secret_key:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your AWS secret access key.'
                    )
Esempio n. 15
0
class EC2(Plugin):
    name = 'EC2 integration'

    def register_options(self):
        # Don't pretend like we can do EC2
        if not isinstance(self.context.hypervisor, VMBuilder.plugins.xen.Xen):
            return
        group = self.context.setting_group('EC2 integation')
        group.add_option('--ec2', action='store_true', help='Build for EC2')
        group.add_option('--ec2-name',
                         '--ec2-prefix',
                         metavar='EC2_NAME',
                         help='Name for the EC2 image.')
        group.add_option('--ec2-cert',
                         metavar='CERTFILE',
                         help='PEM encoded public certificate for EC2.')
        group.add_option('--ec2-key',
                         metavar='KEYFILE',
                         help='PEM encoded private key for EC2.')
        group.add_option(
            '--ec2-user',
            metavar='AWS_ACCOUNT',
            help=
            'EC2 user ID (a.k.a. AWS account number, not AWS access key ID).')
        group.add_option('--ec2-bucket',
                         metavar='BUCKET',
                         help='S3 bucket to hold the AMI.')
        group.add_option('--ec2-access-key',
                         metavar='ACCESS_ID',
                         help='AWS access key ID.')
        group.add_option('--ec2-secret-key',
                         metavar='SECRET_ID',
                         help='AWS secret access key.')
        group.add_option('--ec2-kernel',
                         '--ec2-aki',
                         metavar='AKI',
                         help='EC2 AKI (kernel) to use.')
        group.add_option('--ec2-ramdisk',
                         '--ec2-ari',
                         metavar='ARI',
                         help='EC2 ARI (ramdisk) to use.')
        group.add_option('--ec2-version',
                         metavar='EC2_VER',
                         help='Specify the EC2 image version.')
        group.add_option('--ec2-landscape',
                         action='store_true',
                         help='Install landscape client support')
        group.add_option('--ec2-bundle',
                         action='store_true',
                         help='Bundle the instance')
        group.add_option('--ec2-upload',
                         action='store_true',
                         help='Upload the instance')
        group.add_option('--ec2-register',
                         action='store_true',
                         help='Register the instance')
        self.context.register_setting_group(group)

    def preflight_check(self):
        if not getattr(self.vm, 'ec2', False):
            return True

        if not self.context.hypervisor.name == 'Xen':
            raise VMBuilderUserError(
                'When building for EC2 you must use the xen hypervisor.')

        if self.context.ec2_bundle:
            try:
                run_cmd('ec2-ami-tools-version')
            except VMBuilderException, e:
                raise VMBuilderUserError(
                    'You need to have the Amazon EC2 AMI tools installed')

            if not self.context.ec2_name:
                raise VMBuilderUserError(
                    'When building for EC2 you must supply the name for the image.'
                )

            if not self.context.ec2_cert:
                if "EC2_CERT" in os.environ:
                    self.context.ec2_cert = os.environ["EC2_CERT"]
                else:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your PEM encoded public key certificate'
                    )

            if not self.context.ec2_key:
                if "EC2_PRIVATE_KEY" in os.environ:
                    self.context.ec2_key = os.environ["EC2_PRIVATE_KEY"]
                else:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your PEM encoded private key file'
                    )

            if not self.context.ec2_user:
                raise VMBuilderUserError(
                    'When building for EC2 you must provide your EC2 user ID (your AWS account number, not your AWS access key ID)'
                )

            if not self.context.ec2_kernel:
                self.context.ec2_kernel = self.vm.distro.get_ec2_kernel()
                logging.debug('%s - to be used for AKI.' %
                              (self.context.ec2_kernel))

            if not self.context.ec2_ramdisk:
                self.context.ec2_ramdisk = self.vm.distro.ec2_ramdisk_id()
                logging.debug('%s - to be use for the ARI.' %
                              (self.context.ec2_ramdisk))

            if self.context.ec2_upload:
                if not self.context.ec2_bucket:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide an S3 bucket to hold the AMI'
                    )

                if not self.context.ec2_access_key:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your AWS access key ID.'
                    )

                if not self.context.ec2_secret_key:
                    raise VMBuilderUserError(
                        'When building for EC2 you must provide your AWS secret access key.'
                    )

        if not self.context.ec2_version:
            raise VMBuilderUserError(
                'When building for EC2 you must provide version info.')

        if not self.context.addpkg:
            self.context.addpkg = []

        if self.context.ec2_landscape:
            logging.info('Installing landscape support')
            self.context.addpkg += ['landscape-client']