Exemplo n.º 1
0
    def deactivate(self):
        """ Delete pool in hypervisor
            Preconditions:
            - pool is activated
            - no running VMs in pool
            Actions:
            - call hypervisor for deletion
            - remove path of pool in xenstore
        """
        self.pool_lock.acquire()
        try:
            if not self.get_activated():
                raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'deactivated')
            if len(self.get_started_VMs()) != 0:
                raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'in use')

            pool_id = self.query_pool_id()
            # remove cpus from pool
            cpus = []
            for pool_rec in xc.cpupool_getinfo():
                if pool_rec['cpupool'] == pool_id:
                    cpus = pool_rec['cpulist']
            for cpu_number in cpus:
                xc.cpupool_removecpu(pool_id, cpu_number)
            xc.cpupool_destroy(pool_id)

            # update XenStore
            xs_path = XS_POOLROOT + "%s/" % pool_id
            xstransact.Remove(xs_path)
        finally:
            self.pool_lock.release()
Exemplo n.º 2
0
    def deactivate(self):
        """ Delete pool in hypervisor
            Preconditions:
            - pool is activated
            - no running VMs in pool
            Actions:
            - call hypervisor for deletion
            - remove path of pool in xenstore
        """
        self.pool_lock.acquire()
        try:
            if not self.get_activated():
                raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'deactivated')
            if len(self.get_started_VMs()) != 0:
                raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'in use')

            pool_id = self.query_pool_id()
            # remove cpus from pool
            cpus = []
            for pool_rec in xc.cpupool_getinfo():
                if pool_rec['cpupool'] == pool_id:
                    cpus = pool_rec['cpulist']
            for cpu_number in cpus:
                xc.cpupool_removecpu(pool_id, cpu_number)
            xc.cpupool_destroy(pool_id)

            # update XenStore
            xs_path = XS_POOLROOT + "%s/" % pool_id
            xstransact.Remove(xs_path)
        finally:
            self.pool_lock.release()
Exemplo n.º 3
0
    def remove_host_CPU_live(self, cpu_ref):
        """ Remove cpu from pool.
            After successfull call, the cpu is free.
            Remove of the last cpu of the pool is rejected.
            @param cpu_ref: reference of host_cpu instance to remove
            @type  cpu_ref: str
        """
        if not self.get_activated():
            raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'deactivated')
        node = XendNode.instance()
        number = node.get_host_cpu_field(cpu_ref, 'number')

        self.pool_lock.acquire()
        try:
            pool_id = self.query_pool_id()
            pool_rec = {}
            for pool in xc.cpupool_getinfo():
                if pool['cpupool'] == pool_id:
                    pool_rec = pool
                    break

            if number in pool_rec['cpulist']:
                if len(pool_rec['cpulist']) < 2 and pool_rec['n_dom'] > 0:
                    raise PoolError(XEND_ERROR_LAST_CPU_NOT_REM,
                                    'could not remove last cpu')
                xc.cpupool_removecpu(pool_id, number)
            else:
                raise PoolError(XEND_ERROR_INVALID_CPU,
                                'CPU not assigned to pool')
        finally:
            self.pool_lock.release()

        if number in self.proposed_cpus:
            self.proposed_cpus.remove(number)
        self._update_ncpu(pool_id)
        if self._managed:
            XendNode.instance().save_cpu_pools()
Exemplo n.º 4
0
    def remove_host_CPU_live(self, cpu_ref):
        """ Remove cpu from pool.
            After successfull call, the cpu is free.
            Remove of the last cpu of the pool is rejected.
            @param cpu_ref: reference of host_cpu instance to remove
            @type  cpu_ref: str
        """
        if not self.get_activated():
            raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'deactivated')
        node = XendNode.instance()
        number = node.get_host_cpu_field(cpu_ref, 'number')

        self.pool_lock.acquire()
        try:
            pool_id = self.query_pool_id()
            pool_rec = {}
            for pool in xc.cpupool_getinfo():
                if pool['cpupool'] == pool_id:
                    pool_rec = pool
                    break

            if number in pool_rec['cpulist']:
                if len(pool_rec['cpulist']) < 2 and pool_rec['n_dom'] > 0:
                    raise PoolError(XEND_ERROR_LAST_CPU_NOT_REM,
                                    'could not remove last cpu')
                xc.cpupool_removecpu(pool_id, number)
            else:
                raise PoolError(XEND_ERROR_INVALID_CPU,
                                'CPU not assigned to pool')
        finally:
            self.pool_lock.release()

        if number in self.proposed_cpus:
            self.proposed_cpus.remove(number)
        self._update_ncpu(pool_id)
        if self._managed:
            XendNode.instance().save_cpu_pools()