Exemplo n.º 1
0
 def test_get_occupied_ports(self):
     # Make sure we have at least 1 mapped port.
     machine = VmInstance.objects.get(name='test_vm')
     machine.current_state = 'Running'
     machine.has_ssh = True
     machine.map_port('ssh', 10020)
     machine.save()
     # Test the routine.
     occupied_ports = VmInstance.get_all_occupied_ports()
     assert len(occupied_ports) > 0
Exemplo n.º 2
0
 def get_next_unmapped_port(self):
     '''
     Get a next port form the mapping range that was not mapped by any
     instances.
     '''
     # Get a list of ports, occupied by running instances
     already_mapped_ports = VmInstance.get_all_occupied_ports()
     # Continue until unmapped port is found.
     for next_port in self.mapping_port_range:
         if next_port in already_mapped_ports:
             continue
         # Found unmapped port.
         self.__next_unmapped_port = next_port
         return next_port
     raise Exception('Failed to find unmapped/unoccupied port.')
Exemplo n.º 3
0
 def get_next_unmapped_port(self):
     '''
     Get a next port form the mapping range that was not mapped by any
     instances.
     '''
     # Get a list of ports, occupied by running instances
     already_mapped_ports = VmInstance.get_all_occupied_ports()
     # Continue until unmapped port is found.
     for next_port in self.mapping_port_range:
         if next_port in already_mapped_ports:
             continue
         # Found unmapped port.
         self.__next_unmapped_port = next_port
         return next_port
     raise Exception('Failed to find unmapped/unoccupied port.')