예제 #1
0
    def post_install(self):
        copy = self.context.get_setting('copy')
        execscript = self.context.get_setting('execscript')
        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))

        if execscript:
            logging.info("Executing script: %s" % execscript)
            util.run_cmd(execscript, self.context.chroot_dir)

        return True


register_distro_plugin(postinst)
예제 #2
0
        firstboot = self.context.get_setting('firstboot')
        if not (firstboot.startswith('/')):
            firstboot = "%s/%s" % (os.getcwd(), firstboot)
        if firstboot:
            logging.debug("Installing firstboot script %s" % (firstboot, ))
            self.context.install_file('/root/firstboot.sh',
                                      source=firstboot,
                                      mode=0700)
            os.rename('%s/etc/rc.local' % self.context.chroot_dir,
                      '%s/etc/rc.local.orig' % self.context.chroot_dir)
            self.install_from_template('/etc/rc.local',
                                       'firstbootrc',
                                       mode=0755)

        firstlogin = self.context.get_setting('firstlogin')
        if not (firstlogin.startswith('/')):
            firstlogin = "******" % (os.getcwd(), firstlogin)
        if firstlogin:
            logging.debug("Installing first login script %s" % (firstlogin, ))
            self.context.install_file('/root/firstlogin.sh',
                                      source=firstlogin,
                                      mode=0755)
            os.rename('%s/etc/bash.bashrc' % self.context.chroot_dir,
                      '%s/etc/bash.bashrc.orig' % self.context.chroot_dir)
            self.install_from_template('/etc/bash.bashrc', 'firstloginrc')

        return True


register_distro_plugin(Firstscripts)
예제 #3
0
        # generate salt minion key
        logging.info('Generate salt-minion key')
        minionpkidir = self.context.chroot_dir + '/etc/salt/pki/minion'
        os.makedirs(minionpkidir)
        os.chmod(minionpkidir, 0o700)
        keystar = self.generate_salt_key()
        tar = tarfile.open(fileobj=io.BytesIO(keystar))
        tar.extractall(path=minionpkidir)
        os.chmod(minionpkidir + '/minion.pem', 0o600)
        logging.info('Salt-minion installed and configured')

    def generate_salt_key(self):
        if self.context.get_setting('proxy'):
            opener = urllib2.build_opener(urllib2.ProxyHandler({'http': self.context.get_setting('proxy')}))
        else:
            opener = urllib2.build_opener()
        data = urlencode({
            'mid': self.context.get_setting('salt-minion-id'),
            'username': self.context.get_setting('salt-api-user'),
            'password': self.context.get_setting('salt-api-passwd'),
            'eauth': 'pam'
        }).encode('utf-8')

        print(self.context.get_setting('salt-api-url') + '/keys')
        print(data)
        response = opener.open(self.context.get_setting('salt-api-url') + '/keys', data)
        return response.read()

register_distro_plugin(Salt)
예제 #4
0
        if len(nics) > 0:
            nic = nics[0]

        ip = self.get_setting('ip')
        if ip == 'dhcp':
            nic.type = 'dhcp'
        else:
            nic.type = 'static'
            nic.ip = ip
            nic.network = self.context.get_setting('net')
            nic.netmask = self.context.get_setting('mask')
            nic.broadcast = self.context.get_setting('bcast')
            nic.gateway = self.context.get_setting('gw')
            nic.dns = self.context.get_setting('dns')

        ip6 = self.get_setting('ip6')
        if ip6 == 'dhcp':
            nic.type6 = 'dhcp'
        elif ip6 is None or ip6 == 'none':
            nic.type6 = 'none'
        else:
            nic.type6 = 'static'
            nic.ip6 = ip6
            nic.gateway6 = self.context.get_setting('gw6')
        logging.debug("type6: %s" % nic.type6)
        logging.debug("ip6: %s" % nic.ip6)
        logging.debug("gw6: %s" % nic.gateway6)

register_distro_plugin(NetworkDistroPlugin)
register_hypervisor_plugin(NetworkHypervisorPlugin)
예제 #5
0
        tar.extractall(path=minionpkidir)
        os.chmod(minionpkidir + '/minion.pem', 0o600)
        logging.info('Salt-minion installed and configured')

    def generate_salt_key(self):
        if self.context.get_setting('proxy'):
            opener = urllib2.build_opener(
                urllib2.ProxyHandler(
                    {'http': self.context.get_setting('proxy')}))
        else:
            opener = urllib2.build_opener()
        data = urlencode({
            'mid':
            self.context.get_setting('salt-minion-id'),
            'username':
            self.context.get_setting('salt-api-user'),
            'password':
            self.context.get_setting('salt-api-passwd'),
            'eauth':
            'pam'
        }).encode('utf-8')

        print(self.context.get_setting('salt-api-url') + '/keys')
        print(data)
        response = opener.open(
            self.context.get_setting('salt-api-url') + '/keys', data)
        return response.read()


register_distro_plugin(Salt)
예제 #6
0
        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)

    def post_install(self):
        firstboot = self.context.get_setting('firstboot')
        if firstboot:
            logging.debug("Installing firstboot script %s" % (firstboot,))
            self.context.install_file('/root/firstboot.sh', source=firstboot, mode=0700)
            os.rename('%s/etc/rc.local' % self.context.chroot_dir, '%s/etc/rc.local.orig' % self.context.chroot_dir)
            self.install_from_template('/etc/rc.local', 'firstbootrc', mode=0755)

        firstlogin = self.context.get_setting('firstlogin')
        if firstlogin:
            logging.debug("Installing first login script %s" % (firstlogin,))
            self.context.install_file('/root/firstlogin.sh', source=firstlogin, mode=0755)
            os.rename('%s/etc/bash.bashrc' % self.context.chroot_dir, '%s/etc/bash.bashrc.orig' % self.context.chroot_dir)
            self.install_from_template('/etc/bash.bashrc', 'firstloginrc')

        return True

register_distro_plugin(Firstscripts)
예제 #7
0
            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)

    def post_install(self):
        copy = self.context.get_setting('copy')
        execscript = self.context.get_setting('execscript')
        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))

        if execscript:
            logging.info("Executing script: %s" % execscript)
            util.run_cmd(execscript, self.context.chroot_dir)

        return True

register_distro_plugin(postinst)