Exemplo n.º 1
0
    def _create_config_drive(self, context, instance_path, instance,
                             injected_files, admin_password):
        if CONF.config_drive_format not in ['tgz', 'iso9660']:
            msg = (_("Invalid config drive format %s") %
                   CONF.config_drive_format)
            LOG.debug(msg)
            raise exception.ConfigDriveUnsupportedFormat(
                format=CONF.config_drive_format)

        LOG.debug('Using config drive', instance=instance)

        extra_md = {}
        if admin_password:
            extra_md['admin_pass'] = admin_password

        inst_md = instance_metadata.InstanceMetadata(instance,
                                                     content=injected_files,
                                                     extra_md=extra_md,
                                                     request_context=context)
        # network_metadata will prevent the hostname of the instance from
        # being set correctly, so clean the value
        inst_md.network_metadata = None

        configdrive_tgz = os.path.join(instance_path, 'cfgdrive.tgz')

        LOG.debug('Creating config drive at %s',
                  configdrive_tgz,
                  instance=instance)
        with zvmconfigdrive.ZVMConfigDriveBuilder(instance_md=inst_md) as cdb:
            cdb.make_drive(configdrive_tgz)

        return configdrive_tgz
Exemplo n.º 2
0
 def test_make_drive_unknown_format(self):
     self.flags(config_drive_format='vfat')
     try:
         with zvmconfigdrive.ZVMConfigDriveBuilder(
                 instance_md=self.inst_md) as c:
             self.assertRaises(exception.ConfigDriveUnknownFormat,
                               c.make_drive, self._file_name)
     finally:
         fileutils.remove_path_on_error(self._file_path)
Exemplo n.º 3
0
    def test_create_configdrive_tgz(self):
        self._file_path = CONF.tempdir
        fileutils.ensure_tree(self._file_path)
        try:
            with zvmconfigdrive.ZVMConfigDriveBuilder(
                    instance_md=self.inst_md) as c:
                c.make_drive(self._file_name)

            self.assertTrue(os.path.exists(self._file_name))

        finally:
            fileutils.remove_path_on_error(self._file_path)
Exemplo n.º 4
0
    def _create_config_drive(self, context, instance_path, instance,
                             injected_files, admin_password, commands,
                             linuxdist):
        if CONF.config_drive_format not in ['tgz', 'iso9660']:
            msg = (_("Invalid config drive format %s") %
                   CONF.config_drive_format)
            raise exception.ZVMConfigDriveError(msg=msg)

        LOG.debug('Using config drive', instance=instance)

        extra_md = {}
        if admin_password:
            extra_md['admin_pass'] = admin_password

        udev_settle = linuxdist.get_znetconfig_contents()
        if udev_settle:
            if len(commands) == 0:
                znetconfig = '\n'.join(('#!/bin/bash', udev_settle))
            else:
                znetconfig = '\n'.join(('#!/bin/bash', commands, udev_settle))
            znetconfig += '\nrm -rf /tmp/znetconfig.sh\n'
            # Create a temp file in instance to execute above commands
            net_cmd_file = []
            net_cmd_file.append(('/tmp/znetconfig.sh', znetconfig))  # nosec
            injected_files.extend(net_cmd_file)
            # injected_files.extend(('/tmp/znetconfig.sh', znetconfig))

        inst_md = instance_metadata.InstanceMetadata(instance,
                                                     content=injected_files,
                                                     extra_md=extra_md,
                                                     request_context=context)
        # network_metadata will prevent the hostname of the instance from
        # being set correctly, so clean the value
        inst_md.network_metadata = None

        configdrive_tgz = os.path.join(instance_path, 'cfgdrive.tgz')

        LOG.debug('Creating config drive at %s' % configdrive_tgz,
                  instance=instance)
        with zvmconfigdrive.ZVMConfigDriveBuilder(instance_md=inst_md) as cdb:
            cdb.make_drive(configdrive_tgz)

        return configdrive_tgz