Ejemplo n.º 1
0
 def setUp(self):
     vm_image = VmImage.objects.create(
         name='test_image',
         image_filename='test.img',
         disk_size=10,
     )
     vm_image.save()
     flavour = Flavour.objects.create(name='tiny')
     flavour.save()
     machine = VmInstance(
         name='test_vm',
         image=vm_image,
         flavour=flavour,
     )
     machine.save()
Ejemplo n.º 2
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
Ejemplo 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.')
Ejemplo n.º 4
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.')