コード例 #1
0
ファイル: utils.py プロジェクト: AsherBond/openvz-nova-driver
def execute(*cmd, **kwargs):
    """
    This is a wrapper for utils.execute so as to reduce the amount of
    duplicated code in the driver.
    """
    if 'raise_on_error' in kwargs:
        raise_on_error = kwargs.pop('raise_on_error')
    else:
        raise_on_error = True

    try:
        out, err = utils.execute(*cmd, **kwargs)
        if out:
            LOG.debug(_('Stdout from %(command)s: %(out)s') %
                      {'command': cmd[0], 'out': out})
        if err:
            LOG.debug(_('Stderr from %(command)s: %(out)s') %
                      {'command': cmd[0], 'out': err})
        return out
    except processutils.ProcessExecutionError as err:
        msg = (_('Stderr from %(command)s: %(out)s') %
               {'command': cmd[0], 'out': err})
        if raise_on_error:
            LOG.error(msg)
            raise exception.InstanceUnacceptable(
                _('Error running %(command)s: %(out)s') %
                {'command': cmd[0], 'out': err})
        else:
            LOG.warn(msg)
            return None
コード例 #2
0
 def quota_init(self):
     """
     Initialize quotas for instance
     """
     LOG.debug(_('Initializing quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'quotainit', self.instance['id'])
     LOG.debug(_('Initialized quotas for %s') % self.instance['id'])
コード例 #3
0
    def dump_and_transfer_instance(self):
        """
        Put all the pieces together to dump the instance and make the dump
        ready for transfer to the destination host.
        """
        self.make_dump_dir()

        # Begin the dumping process
        if self.live_migration:
            # this is a live migration so dump current memory and network
            # state.
            LOG.debug(_('Making container backup for %s') %
                      self.instance['id'])
            self.dump()

        if self.unprivileged_user:
            # we are transferring the instance by using an unprivileged user
            # so we need to tar the instance to preserve ownerships and
            # permissions
            LOG.debug(_('self.unprivileged_user is True'))
            self.tar_instance()

        # Take all instance scripts from /etc/vz/conf and put them in a
        # tarball for transfer.
        LOG.debug(_('Making action script backups for %s') %
                  self.instance['id'])
        self.backup_action_scripts()
        LOG.debug(_('Archiving misc files: %s') % self.instance['id'])
        self.tar_dumpdir()
        LOG.debug(_('Migration image created'))
コード例 #4
0
 def untar_instance(self):
     """
     Expand the tarball from the instance and expand it into place
     """
     LOG.debug(_('Untarring instance: %s') % self.instance_source)
     ovz_utils.untar(self.instance_tarfile, self.instance_parent)
     LOG.debug(_('Untarred instance: %s') % self.instance_source)
コード例 #5
0
 def untar_dumpdir(self):
     """
     Expand the dumpdir into place on the destination machine
     """
     LOG.debug(_('Untarring instance dumpdir: %s') % self.dumpdir)
     ovz_utils.untar(self.dumpdir_tarfile, self.dumpdir_parent)
     LOG.debug(_('Untarred instance dumpdir: %s') % self.dumpdir)
コード例 #6
0
    def _find(cls, *params):
        vzlist_cmd = ['vzlist', '--no-header', '--all',
                      '--output', 'ctid,status,description']
        vzlist_cmd.extend(params)
        out = ovz_utils.execute(*vzlist_cmd, raise_on_error=False,
                                run_as_root=True)

        # for testing, we allow multiple nova hosts per node.  We don't want
        # to load containers for the other hosts, so pretend they don't exist
        found = None
        if out is not None:
            lines = out.splitlines()
            for line in lines:
                possible = cls._load_from_vzlist(line)
                if CONF.host == possible.host:
                    found = possible
                    break

        if found is None:
            raise exception.InstanceNotFound(
                _('Instance %s does not exist') % str(params))

        LOG.debug(_('Loading container from vzlist %(params)s: %(ovz_data)s') %
            {'params': params, 'ovz_data': found.ovz_data})

        return found
コード例 #7
0
    def dump_and_transfer_instance(self):
        """
        Put all the pieces together to dump the instance and make the dump
        ready for transfer to the destination host.
        """

        self.container.prep_for_migration()
        self.make_dump_dir()

        # Begin the dumping process
        if self.live_migration:
            # this is a live migration so dump current memory and network
            # state.
            LOG.debug(_('Making container backup for %s') %
                      self.container.ovz_id)
            self.dump()
        else:
            LOG.debug(_('Archiving container to tar: %s') %
                      self.container.ovz_id)
            self.tar_instance()

        # Take all instance scripts from /etc/vz/conf and put them in a
        # tarball for transfer.
        LOG.debug(_('Making action script backups for %s') %
                  self.container.ovz_id)
        self.backup_action_scripts()
        LOG.debug(_('Archiving misc files: %s') % self.container.ovz_id)
        self.tar_dumpdir()
        LOG.debug(_('Migration image created'))
コード例 #8
0
ファイル: tc.py プロジェクト: AsherBond/openvz-nova-driver
    def _list_existing_ids(self):
        LOG.debug(_('Attempting to list existing IDs'))
        out = ovz_utils.execute('tc', 'filter', 'show', 'dev',
                                CONF.ovz_tc_host_slave_device,
                                run_as_root=True)
        ids = list()
        for line in out.splitlines():
            line = line.split()
            if line[0] == 'filter':
                tc_id = int(line[6])
                if tc_id not in ids:
                    ids.append(int(tc_id))

        # get the metadata for instances from the database
        # this will provide us with any ids of instances that aren't
        # currently running so that we can remove active and provisioned
        # but inactive ids from the available list
        instances_metadata = ovz_utils.read_all_instance_metadata()
        LOG.debug(_('Instances metadata: %s') % instances_metadata)
        if instances_metadata:
            for instance_id, meta in instances_metadata.iteritems():
                tc_id = meta.get('tc_id')
                if tc_id:
                    if tc_id not in ids:
                        LOG.debug(
                            _('TC id "%(tc_id)s" for instance '
                              '"%(instance_id)s" found') % locals())
                        ids.append(int(tc_id))
        return ids
コード例 #9
0
ファイル: utils.py プロジェクト: AsherBond/openvz-nova-driver
def get_cpuunits_capability():
    """
    Use openvz tools to discover the total processing capability of the
    host node.  This is done using the vzcpucheck utility.

    Run the command:

    vzcpucheck

    If this fails to run an exception is raised because the output of this
    method is required to calculate the overall bean count available on the
    host to be carved up for guests to use.
    """
    result = {}
    out = execute('vzcpucheck', run_as_root=True)
    for line in out.splitlines():
        line = line.split()
        if len(line) > 0:
            if line[0] == 'Power':
                LOG.debug(_('Power of host: %s') % line[4])
                result['total'] = int(line[4])
            elif line[0] == 'Current':
                LOG.debug(_('Current cpuunits subscribed: %s') % line[3])
                result['subscribed'] = int(line[3])

    if len(result.keys()) == 2:
        return result
    else:
        raise exception.InvalidCPUInfo(
            _("Cannot determine the CPUUNITS for host"))
コード例 #10
0
 def quotaload(self):
     """
     Load quotas from quota file
     """
     LOG.debug(_('Loading quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzdqload', self.instance['id'], '-U', '-G', '-T',
                       '<', self.qdumpfile, run_as_root=True)
     LOG.debug(_('Loaded quotas for %s') % self.instance['id'])
コード例 #11
0
 def quotadump(self):
     """
     Dump the quotas for containers
     """
     LOG.debug(_('Dumping quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzdqdump', self.instance['id'], '-U', '-G',
                       '-T', '>', self.qdumpfile, run_as_root=True)
     LOG.debug(_('Dumped quotas for %s') % self.instance['id'])
コード例 #12
0
 def resume(self):
     """
     Resume a container from an undumped migration
     """
     LOG.debug(_('Resuming instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'restore', self.instance['id'],
                       '--resume', run_as_root=True)
     LOG.debug(_('Resumed instance %s') % self.instance['id'])
コード例 #13
0
 def quotaload(self):
     """
     Load quotas from quota file
     """
     LOG.debug(_('Loading quotas for %s') % self.container.ovz_id)
     ovz_utils.execute('vzdqload', self.container.ovz_id, '-U', '-G', '-T',
                       '<', self.qdumpfile, run_as_root=True)
     LOG.debug(_('Loaded quotas for %s') % self.container.ovz_id)
コード例 #14
0
 def quotaenable(self):
     """
     enable quotas for a given container
     """
     LOG.debug(_('Enabling quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzquota', 'reload2',
                       self.instance['id'], run_as_root=True)
     LOG.debug(_('Enabled quotas for %s') % self.instance['id'])
コード例 #15
0
 def tar_dumpdir(self):
     """
     Archive the instance action scripts
     """
     LOG.debug(_('Tarring up instance dumpdir: %s') % self.dumpdir)
     ovz_utils.tar(self.dumpdir_name, self.dumpdir_tarfile,
                   self.dumpdir_parent)
     LOG.debug(_('Tarred up instance dumpdir: %s') % self.dumpdir)
コード例 #16
0
 def quota_on(self):
     """
     Turn on quotas for instance
     """
     LOG.debug(_('Turning on quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'quotaon', self.instance['id'],
                       run_as_root=True)
     LOG.debug(_('Turned on quotas for %s') % self.instance['id'])
コード例 #17
0
ファイル: rsync.py プロジェクト: hanjinze/openvz-nova-driver
 def send(self):
     """
     Send image/files to a destination.  This should be run on the source
     host.
     """
     LOG.debug(_('Running _rsync()'))
     self._rsync(self.src_path, self.dest_path)
     LOG.debug(_('Ran _rsync()'))
     super(OVZMigrationRsyncTransport, self).send()
コード例 #18
0
 def kill(self):
     """
     This is used to stop a container once it's suspended without having to
     resume it to properly destroy it
     """
     LOG.debug(_('Killing instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'chkpnt', self.instance['id'],
                       '--kill', run_as_root=True)
     LOG.debug(_('Killed instance %s') % self.instance['id'])
コード例 #19
0
 def make_dump_dir(self):
     """
     Make our dump locations
     """
     LOG.debug(_('Making dump location for %s') % self.instance['id'])
     ovz_utils.make_dir(self.dumpdir)
     ovz_utils.make_dir(self.i_dumpdir)
     ovz_utils.make_dir(self.q_dumpdir)
     ovz_utils.make_dir(self.as_dumpdir)
     LOG.debug(_('Done making location for %s') % self.instance['id'])
コード例 #20
0
ファイル: tc.py プロジェクト: AsherBond/openvz-nova-driver
 def _reserve_id(self, tc_id):
     """
     This removes the id from the _ovz_tc_available_ids and adds it to the
     _ovz_tc_inflight_ids
     """
     LOG.debug(_('Beginning reservation process'))
     OVZTcRules._ovz_tc_inflight_ids.append(tc_id)
     LOG.debug(_('Added id "%s" to _ovz_tc_inflight_ids') % tc_id)
     OVZTcRules._ovz_tc_available_ids.remove(tc_id)
     LOG.debug(_('Removed id "%s" from _ovz_tc_available_ids') % tc_id)
コード例 #21
0
 def make_dump_dir(self):
     """
     Make our dump locations
     """
     LOG.debug(_('Making dump location for %s') % self.container.ovz_id)
     ovz_utils.make_dir(self.dumpdir)
     ovz_utils.make_dir(self.i_dumpdir)
     ovz_utils.make_dir(self.q_dumpdir)
     ovz_utils.make_dir(self.as_dumpdir)
     LOG.debug(_('Done making location for %s') % self.container.ovz_id)
コード例 #22
0
ファイル: file.py プロジェクト: AsherBond/openvz-nova-driver
 def remove_line(self, line):
     """
     Simple helper method to actually do the removal of a line from an array
     """
     LOG.debug(_('Removing line if present: %s') % line)
     if line in self.contents:
         LOG.debug(_('Line found: %s') % line)
         self.contents.remove(line)
         LOG.debug(_('Line removed: %(line)s \t%(contents)s') %
                   {'line': line, 'contents': self.contents})
コード例 #23
0
 def undump(self):
     """
     Restore a VZ from a dump file
     """
     LOG.debug(_('Undumping instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'restore', self.instance['id'], '--undump',
                       '--dumpfile', self.dumpfile, '--skip_arpdetect',
                       run_as_root=True)
     LOG.debug(_('Undumped instance %(instance_id)s from %(dumpfile)s') %
               {'instance_id': self.instance['id'],
                'dumpfile': self.dumpfile})
コード例 #24
0
 def tar_instance(self):
     """
     Not an optimal way to do this but if you aren't using the root user
     to rsync the files from host to host you need to preserve the
     permissions and ownerships thus tar is your only hope.
     """
     # Create our batch volume operations object
     LOG.debug(_('Tarring up instance: %s') % self.instance['id'])
     ovz_utils.tar(self.instance['id'], self.instance_tarfile,
                   self.instance_parent)
     LOG.debug(_('Tarred up instance: %s') % self.instance['id'])
コード例 #25
0
 def dump(self):
     """
     Create a vz dump file from a container.  This is the file that we
     transfer to do a full migration
     """
     LOG.debug(_('Dumping instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'chkpnt', self.instance['id'],
                       '--dump', '--dumpfile', self.dumpfile,
                       run_as_root=True)
     LOG.debug(_('Dumped instance %(instance_id)s to %(dumpfile)s') %
               {'instance_id': self.instance['id'],
                'dumpfile': self.dumpfile})
コード例 #26
0
ファイル: tc.py プロジェクト: AsherBond/openvz-nova-driver
 def _remove_used_ids(self):
     """
     Clean ids that are currently provisioned on the host from the
     list of _ovz_tc_available_ids
     """
     LOG.debug(_('Beginning cleanup of used ids'))
     used_ids = self._list_existing_ids()
     LOG.debug(_('Used ids found, removing from _ovz_tc_available_ids'))
     for tc_id in used_ids:
         if tc_id in OVZTcRules._ovz_tc_available_ids:
             OVZTcRules._ovz_tc_available_ids.remove(tc_id)
     LOG.debug(_('Removed all ids in use'))
コード例 #27
0
 def cleanup_files(self):
     """
     Remove the files in the OpenVz temp dir
     """
     LOG.debug(_('Cleaning migration files for %s') % self.instance['id'])
     ovz_utils.execute('rm', '-rf', self.dumpdir, run_as_root=True)
     ovz_utils.execute('rm', '-f', self.dumpdir_tarfile, run_as_root=True)
     if self.instance_tarfile:
         ovz_utils.execute('rm', '-f', self.instance_tarfile,
                           run_as_root=True)
     LOG.debug(
         _('Cleaned up migration files for %s') % self.instance['id'])
コード例 #28
0
ファイル: file.py プロジェクト: AsherBond/openvz-nova-driver
 def read(self):
     """
     Open the file for reading only and read it's contents into the instance
     attribute self.contents
     """
     try:
         with open(self.filename, 'r') as fh:
             self.contents = fh.read().split('\n')
     except Exception as err:
         LOG.error(_('Output from open: %s') % err)
         raise exception.FileNotFound(
             _('Failed to read %s') % self.filename)
コード例 #29
0
 def get_cpulimit(self):
     """
     Fetch the total possible cpu processing limit in percentage to be
     divided up across all containers.  This is expressed in percentage
     being added up by logical processor.  If there are 24 logical
     processors then the total cpulimit for the host node will be
     2400.
     """
     self.utility['CPULIMIT'] = ovz_utils.get_vcpu_total() * 100
     LOG.debug(_('Updated cpulimit in utility'))
     LOG.debug(
         _('Current cpulimit in utility: %s') % self.utility['CPULIMIT'])
コード例 #30
0
ファイル: file.py プロジェクト: AsherBond/openvz-nova-driver
 def delete(self, contents):
     """
     Delete the argument contents from self.contents if they exist.
     """
     if isinstance(contents, list):
         LOG.debug(_('A list was passed to delete: %s') % contents)
         for line in contents:
             LOG.debug(_('Line: %(line)s \tFound in: %(contents)s') %
                       locals())
             self.remove_line(line)
     else:
         LOG.debug(_('A string was passed to delete: %s') % contents)
         self.remove_line(contents)