示例#1
0
文件: servers.py 项目: vgerak/synnefo
 def test_task_after(self, mrapi):
     return
     vm = mfactory.VirtualMachineFactory()
     mrapi().StartupInstance.return_value = 1
     mrapi().ShutdownInstance.return_value = 2
     mrapi().RebootInstance.return_value = 2
     with mocked_quotaholder():
         vm.task = None
         vm.operstate = "STOPPED"
         vm.save()
         servers.start(vm.id, credentials=self.credentials)
         self.assertEqual(vm.task, "START")
         self.assertEqual(vm.task_job_id, 1)
     with mocked_quotaholder():
         vm.task = None
         vm.operstate = "STARTED"
         vm.save()
         servers.stop(vm.id, credentials=self.credentials)
         self.assertEqual(vm.task, "STOP")
         self.assertEqual(vm.task_job_id, 2)
     with mocked_quotaholder():
         vm.task = None
         vm.save()
         servers.reboot(vm.id, credentials=self.credentials)
         self.assertEqual(vm.task, "REBOOT")
         self.assertEqual(vm.task_job_id, 3)
示例#2
0
文件: servers.py 项目: grnet/synnefo
 def test_task_after(self, mrapi):
     return
     vm = mfactory.VirtualMachineFactory()
     mrapi().StartupInstance.return_value = 1
     mrapi().ShutdownInstance.return_value = 2
     mrapi().RebootInstance.return_value = 2
     with mocked_quotaholder():
         vm.task = None
         vm.operstate = "STOPPED"
         vm.save()
         servers.start(vm.id, credentials=self.credentials)
         self.assertEqual(vm.task, "START")
         self.assertEqual(vm.task_job_id, 1)
     with mocked_quotaholder():
         vm.task = None
         vm.operstate = "STARTED"
         vm.save()
         servers.stop(vm.id, credentials=self.credentials)
         self.assertEqual(vm.task, "STOP")
         self.assertEqual(vm.task_job_id, 2)
     with mocked_quotaholder():
         vm.task = None
         vm.save()
         servers.reboot(vm.id, credentials=self.credentials)
         self.assertEqual(vm.task, "REBOOT")
         self.assertEqual(vm.task_job_id, 3)
示例#3
0
文件: servers.py 项目: vgerak/synnefo
def shutdown(request, server_id, args):
    # Normal Response Code: 202
    # Error Response Codes: serviceUnavailable (503),
    #                       itemNotFound (404)
    credentials = request.credentials
    servers.stop(server_id, credentials=credentials)
    log.info("User %s stopped VM %s", credentials.userid, server_id)
    return HttpResponse(status=202)
示例#4
0
文件: servers.py 项目: grnet/synnefo
def shutdown(request, server_id, args):
    # Normal Response Code: 202
    # Error Response Codes: serviceUnavailable (503),
    #                       itemNotFound (404)
    credentials = request.credentials
    servers.stop(server_id, credentials=credentials)
    log.info("User %s stopped VM %s", credentials.userid, server_id)
    return HttpResponse(status=202)
示例#5
0
    def stop_server(self, vm, wait):
        """Stop a helper VM.

        First, we need to wait for the server to finish building. Then, we can
        send a shutdown job to Ganeti and optionally wait once more.
        """
        vm = self.wait_building_server(vm)
        servers.stop(vm)
        common.wait_server_task(vm, wait, self.stdout)
示例#6
0
def shutdown(request, vm, args):
    # Normal Response Code: 202
    # Error Response Codes: serviceUnavailable (503),
    #                       itemNotFound (404)
    vm = servers.stop(vm)
    log.info("User %s stopped VM %s", request.user_uniq, vm.id)
    return HttpResponse(status=202)
示例#7
0
文件: views.py 项目: apyrgio/synnefo
def vm_shutdown(request, vm_id):
    logging.info("VM %s shutdown by %s", vm_id, request.user_uniq)
    vm = VirtualMachine.objects.get(pk=vm_id)
    account = vm.userid
    error = None
    try:
        jobId = servers_backend.stop(vm)
    except Exception, e:
        error = e.message
示例#8
0
文件: views.py 项目: kins299/mycloud
def vm_shutdown(request, vm_id):
    logging.info("VM %s shutdown by %s", vm_id, request.user_uniq)
    vm = VirtualMachine.objects.get(pk=vm_id)
    account = vm.userid
    error = None
    try:
        jobId = servers_backend.stop(vm)
    except Exception, e:
        error = e.message
示例#9
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a server ID")

        server = get_resource("server", args[0], for_update=True)

        new_name = options.get("name", None)
        if new_name is not None:
            old_name = server.name
            server = servers.rename(server, new_name)
            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.suspended = suspended
            server.save()
            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, new_owner)
                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, new_flavor)
            wait_server_task(server, wait, stdout=self.stdout)

        action = options.get("action")
        if action is not None:
            if action == "start":
                server = servers.start(server)
            elif action == "stop":
                server = servers.stop(server)
            elif action == "reboot_hard":
                server = servers.reboot(server, reboot_type="HARD")
            elif action == "reboot_soft":
                server = servers.reboot(server, reboot_type="SOFT")
            else:
                raise CommandError("Unknown action.")
            wait_server_task(server, wait, stdout=self.stdout)
示例#10
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a server ID")

        server = get_resource("server", args[0], for_update=True)

        new_name = options.get("name", None)
        if new_name is not None:
            old_name = server.name
            server = servers.rename(server, new_name)
            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.suspended = suspended
            server.save()
            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.")
            old_owner = server.userid
            server.userid = new_owner
            server.save()
            msg = "Changed the owner of server '%s' from '%s' to '%s'.\n"
            self.stdout.write(msg % (server, old_owner, new_owner))

        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, new_flavor)
            wait_server_task(server, wait, stdout=self.stdout)

        action = options.get("action")
        if action is not None:
            if action == "start":
                server = servers.start(server)
            elif action == "stop":
                server = servers.stop(server)
            elif action == "reboot_hard":
                server = servers.reboot(server, reboot_type="HARD")
            elif action == "reboot_stof":
                server = servers.reboot(server, reboot_type="SOFT")
            else:
                raise CommandError("Unknown action.")
            wait_server_task(server, wait, stdout=self.stdout)
示例#11
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a server ID")

        server = get_vm(args[0], for_update=True)

        new_name = options.get("name", None)
        if new_name is not None:
            old_name = server.name
            server = servers.rename(server, new_name)
            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.suspended = suspended
            server.save()
            self.stdout.write("Set server '%s' as suspended=%s\n" %
                              (server, suspended))

        new_owner = options.get('owner')
        if new_owner is not None:
            if "@" in new_owner:
                raise CommandError("Invalid owner UUID.")
            old_owner = server.userid
            server.userid = new_owner
            server.save()
            msg = "Changed the owner of server '%s' from '%s' to '%s'.\n"
            self.stdout.write(msg % (server, old_owner, new_owner))

        wait = parse_bool(options["wait"])
        new_flavor_id = options.get("flavor")
        if new_flavor_id is not None:
            new_flavor = get_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, new_flavor)
            wait_server_task(server, wait, stdout=self.stdout)

        action = options.get("action")
        if action is not None:
            if action == "start":
                server = servers.start(server)
            elif action == "stop":
                server = servers.stop(server)
            elif action == "reboot_hard":
                server = servers.reboot(server, reboot_type="HARD")
            elif action == "reboot_stof":
                server = servers.reboot(server, reboot_type="SOFT")
            else:
                raise CommandError("Unknown action.")
            wait_server_task(server, wait, stdout=self.stdout)
示例#12
0
def shutdown(request, vm, args):
    # Normal Response Code: 202
    # Error Response Codes: serviceUnavailable (503),
    #                       itemNotFound (404)
    vm = servers.stop(vm)
    return HttpResponse(status=202)
示例#13
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a server ID")

        server = get_resource("server", args[0], for_update=True)

        new_name = options.get("name", None)
        if new_name is not None:
            old_name = server.name
            server = servers.rename(server, new_name)
            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.suspended = suspended
            server.save()
            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.")
            old_owner = server.userid
            server.userid = new_owner
            old_project = server.project
            server.project = new_owner
            server.save()
            msg = "Changed the owner of server '%s' from '%s' to '%s'.\n"
            self.stdout.write(msg % (server, old_owner, new_owner))
            msg = "Changed the project of server '%s' from '%s' to '%s'.\n"
            self.stdout.write(msg % (server, old_project, new_owner))
            for vol in server.volumes.filter(
                    userid=old_owner).select_for_update():
                vol.userid = new_owner
                vol_old_project = vol.project
                vol.project = new_owner
                vol.save()
                msg = "Changed the owner of volume '%s' from '%s' to '%s'.\n"
                self.stdout.write(msg % (vol, old_owner, new_owner))
                msg = "Changed the project of volume '%s' from '%s' to '%s'.\n"
                self.stdout.write(msg % (vol, vol_old_project, new_owner))
            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, new_flavor)
            wait_server_task(server, wait, stdout=self.stdout)

        action = options.get("action")
        if action is not None:
            if action == "start":
                server = servers.start(server)
            elif action == "stop":
                server = servers.stop(server)
            elif action == "reboot_hard":
                server = servers.reboot(server, reboot_type="HARD")
            elif action == "reboot_stof":
                server = servers.reboot(server, reboot_type="SOFT")
            else:
                raise CommandError("Unknown action.")
            wait_server_task(server, wait, stdout=self.stdout)
示例#14
0
def shutdown(request, vm, args):
    # Normal Response Code: 202
    # Error Response Codes: serviceUnavailable (503),
    #                       itemNotFound (404)
    vm = servers.stop(vm)
    return HttpResponse(status=202)
示例#15
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)