示例#1
0
    def _doOpenNebula(contextDiskFile, cdromFiles):
        tmpdir = None
        image = None
        try:
            tmpdir = mkdtemp()
            for f in cdromFiles:
                shutil.copy(f, tmpdir)

            _, image = mkstemp()

            cmd = ["mkisofs", "-V", "_STRATUSLAB", "-o", image, "-J", "-R", tmpdir]
            rc = execute(cmd)
            if (rc != 0):
                raise Exception("error creating cdrom")

            os.chmod(image, TMContext.DISK_PERMS)

            scp(image, contextDiskFile)

        finally:
            if tmpdir:
                shutil.rmtree(tmpdir, True)
            if image:
                os.remove(image)
示例#2
0
    def _nodeCopy(self, source, dest, **kwargs):
        stdout = kwargs.get('stdout', self.stdout)
        stderr = kwargs.get('stderr', self.stderr)

        if kwargs.has_key('stdout'):
            del kwargs['stdout']
        if kwargs.has_key('stderr'):
            del kwargs['stderr']

        return scp(source,
                   'root@%s:%s' % (self.nodeAddr, dest),
                   self.nodePrivateKey,
                   stdout=stdout,
                   stderr=stderr,
                   verboseLevel=self.verboseLevel,
                   verboseThreshold=Util.VERBOSE_LEVEL_DETAILED,
                   **kwargs)
示例#3
0
    def _doCloudInit(contextDiskFile, params):
        content_dir = None
        image = None
        vfat_script = params['vfat_script']
        try:
            content_dir = mkdtemp()

            try:
                b64_content = params['network']

                net_dir = os.path.join(content_dir, 'etc', 'network')
                os.makedirs(net_dir)

                net_file = os.path.join(net_dir, 'interfaces')

                with open(net_file, 'wb') as f:
                    content = base64.b64decode(b64_content)
                    f.write(content)

            except KeyError:
                pass

            try:
                b64_content = params['authorized_keys']

                ssh_dir = os.path.join(content_dir, 'root', '.ssh')
                os.makedirs(ssh_dir)

                keys_file = os.path.join(ssh_dir, 'authorized_keys')

                with open(keys_file, 'wb') as f:
                    content = base64.b64decode(b64_content)
                    f.write(content)

            except KeyError:
                pass

            try:
                encoded_content = params['user_data']
            except KeyError:
                encoded_content = None

            meta_content = decode_multipart_as_json('local', encoded_content)

            meta_file = os.path.join(content_dir, 'meta.js')

            with open(meta_file, 'wb') as f:
                f.write(meta_content)

            #
            # This must be run as root because the VFAT file must be
            # mounted and unmounted from the file system.
            #
            image = TMContext._makeEmptyFile()
            cmd = ['sudo', vfat_script, content_dir, image]
            rc = execute(cmd)
            if (rc != 0):
                raise Exception('cannot create VFAT file system for cloud-init')

            scp(image, contextDiskFile)

        finally:
            if content_dir:
                shutil.rmtree(content_dir, True)
            if image:
                os.remove(image)