Example #1
0
 def test_create_server(self):
     """
     Create a VM via nova
     """
     self.nova.flavors.find.return_value = 'test-flavor'
     self.nova.images.find.return_value = 'test-image'
     openstack.create_server(self.nova, 'test-vm', {"ram": 4096, "disk": 40}, {"name": "Ubuntu 12.04"})
     self.assertEqual(self.nova.mock_calls, [
         call.flavors.find(disk=40, ram=4096),
         call.images.find(name='Ubuntu 12.04'),
         call.servers.create('test-vm', 'test-image', 'test-flavor', key_name=None)
     ])
Example #2
0
 def test_create_server(self):
     """
     Create a VM via nova
     """
     self.nova.flavors.find.return_value = 'test-flavor'
     self.nova.images.find.return_value = 'test-image'
     openstack.create_server(self.nova, 'test-vm', {
         "ram": 4096,
         "disk": 40
     }, {"name": "Ubuntu 12.04"})
     self.assertEqual(self.nova.mock_calls, [
         call.flavors.find(disk=40, ram=4096),
         call.images.find(name='Ubuntu 12.04'),
         call.servers.create(
             'test-vm', 'test-image', 'test-flavor', key_name=None)
     ])
Example #3
0
    def start(self):
        """
        Get a server instance started and an openstack_id assigned

        TODO: Add handling of quota limitations & waiting list
        TODO: Create the key dynamically
        """
        self.logger.info("Starting server (status=%s)...", self.status)
        self._status_to_building()
        try:
            os_server = openstack.create_server(
                self.nova,
                self.name,
                settings.OPENSTACK_SANDBOX_FLAVOR,
                settings.OPENSTACK_SANDBOX_BASE_IMAGE,
                key_name=settings.OPENSTACK_SANDBOX_SSH_KEYNAME,
            )
        except novaclient.exceptions.ClientException as e:
            self.logger.error("Failed to start server: %s", e)
            self._status_to_build_failed()
        else:
            self.openstack_id = os_server.id
            self.logger.info("Server got assigned OpenStack id %s", self.openstack_id)
            # Persist OpenStack ID
            self.save()
Example #4
0
    def start(self):
        """
        Get a server instance started and an openstack_id assigned

        TODO: Add handling of quota limitations & waiting list
        TODO: Create the key dynamically
        """
        self.logger.info('Starting server (status=%s)...', self.status)
        if self.status == self.NEW:
            self._set_status(self.STARTED, self.PROGRESS_RUNNING)
            os_server = openstack.create_server(
                self.nova,
                self.instance.sub_domain,
                settings.OPENSTACK_SANDBOX_FLAVOR,
                settings.OPENSTACK_SANDBOX_BASE_IMAGE,
                key_name=settings.OPENSTACK_SANDBOX_SSH_KEYNAME,
            )
            self.openstack_id = os_server.id
            self.logger.info('Server got assigned OpenStack id %s', self.openstack_id)
            self._set_status(self.STARTED, self.PROGRESS_SUCCESS)
        else:
            raise NotImplementedError