Revision 60a71437

b/snf-cyclades-app/synnefo/api/management/commands/server-modify.py
35 35

  
36 36
from django.db import transaction
37 37
from django.core.management.base import BaseCommand, CommandError
38
from synnefo.management.common import get_vm
38
from synnefo.management.common import get_vm, get_flavor, convert_api_faults
39 39
from synnefo.webproject.management.utils import parse_bool
40
from synnefo.logic import servers
40
from synnefo.logic import servers, backend as backend_mod
41 41

  
42 42

  
43 43
class Command(BaseCommand):
......
62 62
            choices=["True", "False"],
63 63
            metavar="True|False",
64 64
            help="Mark a server as suspended/non-suspended."),
65
        make_option(
66
            "--flavor",
67
            dest="flavor",
68
            metavar="FLAVOR_ID",
69
            help="Resize a server by modifying its flavor. The new flavor"
70
                 " must have the same disk size and disk template."),
65 71
    )
66 72

  
67 73
    @transaction.commit_on_success
74
    @convert_api_faults
68 75
    def handle(self, *args, **options):
69 76
        if len(args) != 1:
70 77
            raise CommandError("Please provide a server ID")
......
95 102
            server.save()
96 103
            msg = "Changed the owner of server '%s' from '%s' to '%s'.\n"
97 104
            self.stdout.write(msg % (server, old_owner, new_owner))
105

  
106
        new_flavor_id = options.get("flavor")
107
        if new_flavor_id is not None:
108
            new_flavor = get_flavor(new_flavor_id)
109
            old_flavor = server.flavor
110
            msg = "Resizing server '%s' from flavor '%s' to '%s'.\n"
111
            self.stdout.write(msg % (server, old_flavor, new_flavor))
112
            server = servers.resize(server, new_flavor)
113
            jobID = server.task_job_id
114
            msg = "Issued job '%s'. Waiting to complete...\n"
115
            self.stdout.write(msg % jobID)
116
            client = server.get_client()
117
            status, error = backend_mod.wait_for_job(client, jobID)
118
            if status == "success":
119
                self.stdout.write("Job finished successfully.\n")
120
            else:
121
                self.stdout.write("Job failed! Error: %s\n" % error)

Also available in: Unified diff