def test_exclusive(self): s = ExclusiveSet() assert_that(len(s), is_(0)) assert_that('1' in s, is_(False)) assert_that('2' in s, is_(False)) s.add('1') assert_that(len(s), is_(1)) assert_that('1' in s, is_(True)) assert_that('2' in s, is_(False)) self.assertRaises(DuplicatedValue, s.add, '1') s.remove('1') assert_that(len(s), is_(0))
def get_occupied_vnc_ports(self): vms = self.vim_client.get_vms() ports = ExclusiveSet() for vm in vms: if vm.config and vm.config.extraConfig: enabled = False port = None for option in vm.config.extraConfig: if option.key == self.EXTRA_CONFIG_VNC_ENABLED: enabled = option.value.upper() == 'TRUE' elif option.key == self.EXTRA_CONFIG_VNC_PORT: port = int(option.value) if enabled: try: ports.add(port) except DuplicatedValue: self._logger.warning("port %d already occupied" % port) return ports