Ejemplo n.º 1
0
 def test_rescue_stopped_rescued_vm(self):
     """Test rescue a stopped VM while in rescue mode"""
     with mocked_quotaholder():
         self.vm.task = None
         self.vm.operstate = "STOPPED"
         self.vm.rescue = True
         with self.assertRaises(faults.BadRequest):
             servers.rescue(self.vm, credentials=self.credentials)
Ejemplo n.º 2
0
 def test_rescue_stopped_rescued_vm(self):
     """Test rescue a stopped VM while in rescue mode"""
     with mocked_quotaholder():
         self.vm.task = None
         self.vm.operstate = "STOPPED"
         self.vm.rescue = True
         with self.assertRaises(faults.BadRequest):
             servers.rescue(self.vm, credentials=self.credentials)
Ejemplo n.º 3
0
 def test_rescue_started_vm(self):
     """Test rescue a started VM"""
     with mocked_quotaholder():
         self.vm.task = None
         self.vm.operstate = "STARTED"
         print(self.credentials)
         with self.assertRaises(faults.BadRequest):
             servers.rescue(self.vm, credentials=self.credentials)
Ejemplo n.º 4
0
 def test_rescue_started_vm(self):
     """Test rescue a started VM"""
     with mocked_quotaholder():
         self.vm.task = None
         self.vm.operstate = "STARTED"
         print(self.credentials)
         with self.assertRaises(faults.BadRequest):
             servers.rescue(self.vm, credentials=self.credentials)
Ejemplo n.º 5
0
 def test_rescue_vm_rescue_properties(self, mrapi):
     """Test rescue a VM using rescue properties"""
     mrapi().ModifyInstance.return_value = 1
     vm = mfactory.VirtualMachineFactory(
         rescue_properties__os_family='linux',
         rescue_properties__os='debian')
     with mocked_quotaholder():
         vm.task = None
         vm.operstate = "STOPPED"
         servers.rescue(vm, credentials=self.credentials)
         self.assertEqual(vm.task_job_id, 1)
         self.assertEqual(vm.rescue_image, self.debian_rescue_image)
Ejemplo n.º 6
0
 def test_rescue_vm_rescue_properties(self, mrapi):
     """Test rescue a VM using rescue properties"""
     mrapi().ModifyInstance.return_value = 1
     vm = mfactory.VirtualMachineFactory(
          rescue_properties__os_family='linux',
          rescue_properties__os='debian')
     with mocked_quotaholder():
         vm.task = None
         vm.operstate = "STOPPED"
         servers.rescue(vm, credentials=self.credentials)
         self.assertEqual(vm.task_job_id, 1)
         self.assertEqual(vm.rescue_image, self.debian_rescue_image)
Ejemplo n.º 7
0
 def test_rescue_stopped_vm(self, mrapi):
     """Test rescue a stopped VM"""
     mrapi().ModifyInstance.return_value = 1
     # Since we are not using rescue properties, the default
     # image should be used.
     with mocked_quotaholder():
         self.vm.task = None
         self.vm.rescue = False
         self.vm.operstate = "STOPPED"
         servers.rescue(self.vm, credentials=self.credentials)
         self.assertEqual(self.vm.task_job_id, 1)
         self.assertFalse(self.vm.rescue_image is None)
         self.assertTrue(self.vm.rescue_image.is_default)
Ejemplo n.º 8
0
 def test_rescue_stopped_vm(self, mrapi):
     """Test rescue a stopped VM"""
     mrapi().ModifyInstance.return_value = 1
     # Since we are not using rescue properties, the default
     # image should be used.
     with mocked_quotaholder():
         self.vm.task = None
         self.vm.rescue = False
         self.vm.operstate = "STOPPED"
         servers.rescue(self.vm, credentials=self.credentials)
         self.assertEqual(self.vm.task_job_id, 1)
         self.assertFalse(self.vm.rescue_image is None)
         self.assertTrue(self.vm.rescue_image.is_default)
Ejemplo n.º 9
0
def rescue(request, server_id, args):
    # Normal Response Code: 202
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       serverCapacityUnavailable (503),
    log.info("User %s initiated rescue mode on VM %s", request.user_uniq,
             server_id)
    credentials = request.credentials
    rescue_image_ref = args.get("rescue_image_ref")
    servers.rescue(server_id, rescue_image_ref, credentials=credentials)

    return HttpResponse(status=202)
Ejemplo n.º 10
0
def rescue(request, server_id, args):
    # Normal Response Code: 202
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       serverCapacityUnavailable (503),
    log.info("User %s initiated rescue mode on VM %s", request.user_uniq,
             server_id)
    credentials = request.credentials
    rescue_image_ref = args.get("rescue_image_ref")
    servers.rescue(server_id, rescue_image_ref, credentials=credentials)

    return HttpResponse(status=202)
Ejemplo n.º 11
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a server ID")

        server_id = args[0]
        server = get_resource("server", server_id)

        credentials = Credentials("snf-manage", is_admin=True)
        new_name = options.get("name", None)
        if new_name is not None:
            old_name = server.name
            server = servers.rename(server_id, new_name, credentials)
            self.stdout.write("Renamed server '%s' from '%s' to '%s'\n" %
                              (server, old_name, new_name))

        suspended = options.get("suspended", None)
        if suspended is not None:
            suspended = parse_bool(suspended)
            server = servers.suspend(server_id, suspended, credentials)
            self.stdout.write("Set server '%s' as suspended=%s\n" %
                              (server, suspended))

        new_owner = options.get('user')
        if new_owner is not None:
            if "@" in new_owner:
                raise CommandError("Invalid user UUID.")
            if new_owner == server.userid:
                self.stdout.write("%s is already server owner.\n" % new_owner)
            else:
                servers.change_owner(server_id, new_owner, credentials)
                self.stdout.write(
                    "WARNING: User quotas should be out of sync now,"
                    " run `snf-manage reconcile-resources-cyclades'"
                    " to review and update them.\n")

        wait = parse_bool(options["wait"])
        new_flavor_id = options.get("flavor")
        if new_flavor_id is not None:
            new_flavor = get_resource("flavor", new_flavor_id)
            old_flavor = server.flavor
            msg = "Resizing server '%s' from flavor '%s' to '%s'.\n"
            self.stdout.write(msg % (server, old_flavor, new_flavor))
            server = servers.resize(server_id, new_flavor, credentials)
            wait_server_task(server, wait, stdout=self.stdout)

        action = options.get("action")
        if action is not None:
            if action == "start":
                server = servers.start(server_id, credentials=credentials)
            elif action == "stop":
                server = servers.stop(server_id, credentials=credentials)
            elif action == "reboot_hard":
                server = servers.reboot(server_id,
                                        reboot_type="HARD",
                                        credentials=credentials)
            elif action == "reboot_soft":
                server = servers.reboot(server_id,
                                        reboot_type="SOFT",
                                        credentials=credentials)
            elif action == "rescue":
                server = servers.rescue(server_id, credentials=credentials)
            elif action == "unrescue":
                server = servers.unrescue(server_id, credentials=credentials)
            else:
                raise CommandError("Unknown action.")
            wait_server_task(server, wait, stdout=self.stdout)
Ejemplo n.º 12
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a server ID")

        server_id = args[0]
        server = get_resource("server", server_id)

        credentials = Credentials("snf-manage", is_admin=True)
        new_name = options.get("name", None)
        if new_name is not None:
            old_name = server.name
            server = servers.rename(server_id, new_name, credentials)
            self.stdout.write("Renamed server '%s' from '%s' to '%s'\n" %
                              (server, old_name, new_name))

        suspended = options.get("suspended", None)
        if suspended is not None:
            suspended = parse_bool(suspended)
            server = servers.suspend(server_id, suspended, credentials)
            self.stdout.write("Set server '%s' as suspended=%s\n" %
                              (server, suspended))

        new_owner = options.get('user')
        if new_owner is not None:
            if "@" in new_owner:
                raise CommandError("Invalid user UUID.")
            if new_owner == server.userid:
                self.stdout.write("%s is already server owner.\n" % new_owner)
            else:
                servers.change_owner(server_id, new_owner, credentials)
                self.stdout.write(
                    "WARNING: User quotas should be out of sync now,"
                    " run `snf-manage reconcile-resources-cyclades'"
                    " to review and update them.\n")

        wait = parse_bool(options["wait"])
        new_flavor_id = options.get("flavor")
        if new_flavor_id is not None:
            new_flavor = get_resource("flavor", new_flavor_id)
            old_flavor = server.flavor
            msg = "Resizing server '%s' from flavor '%s' to '%s'.\n"
            self.stdout.write(msg % (server, old_flavor, new_flavor))
            server = servers.resize(server_id, new_flavor, credentials)
            wait_server_task(server, wait, stdout=self.stdout)

        action = options.get("action")
        if action is not None:
            if action == "start":
                server = servers.start(server_id, credentials=credentials)
            elif action == "stop":
                server = servers.stop(server_id, credentials=credentials)
            elif action == "reboot_hard":
                server = servers.reboot(server_id, reboot_type="HARD",
                                        credentials=credentials)
            elif action == "reboot_soft":
                server = servers.reboot(server_id, reboot_type="SOFT",
                                        credentials=credentials)
            elif action == "rescue":
                server = servers.rescue(server_id, credentials=credentials)
            elif action == "unrescue":
                server = servers.unrescue(server_id, credentials=credentials)
            else:
                raise CommandError("Unknown action.")
            wait_server_task(server, wait, stdout=self.stdout)