Skip to content
Snippets Groups Projects
vm.py 2.75 KiB
Newer Older
Seblu's avatar
Seblu committed

'''
CloudControl VM related commands
'''

from cccli.exception import *
from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
Seblu's avatar
Seblu committed
from cccli.command.command import TqlCommand
Seblu's avatar
Seblu committed

class Command_start(TqlCommand):
    '''Start a stopped vm'''
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
    def __init__(self, cli, argv0):
Seblu's avatar
Seblu committed
        TqlCommand.__init__(self, cli, argv0)
        self.tql_filter += "&r=vm&status=stopped"
Seblu's avatar
Seblu committed

    def __call__(self, argv):
        # arg parse
Seblu's avatar
Seblu committed
        self.parse_args(argv)
        if len(self.args) != 1:
Seblu's avatar
Seblu committed
            raise cmdBadArgument()
        # rpc call
        self.rpccall("start", self.args[0])
class Command_stop(TqlCommand):
Seblu's avatar
Seblu committed
    '''Stop a running vm'''

    def __init__(self, cli, argv0):
        TqlCommand.__init__(self, cli, argv0)
        self.tql_filter += "&r=vm&status=running"

Seblu's avatar
Seblu committed
    def __call__(self, argv):
        # arg parse
        self.parse_args(argv)
        if len(self.args) != 1:
            raise cmdBadArgument()
        # rpc call
        self.rpccall("stop", self.args[0])
class Command_destroy(TqlCommand):
Seblu's avatar
Seblu committed
    '''Force a vm to stop'''

    def __init__(self, cli, argv0):
        TqlCommand.__init__(self, cli, argv0)
        self.tql_filter += "&r=vm&status!=stopped"

Seblu's avatar
Seblu committed
    def __call__(self, argv):
        # arg parse
        self.parse_args(argv)
        if len(self.args) != 1:
            raise cmdBadArgument()
        # rpc call
        self.rpccall("destroy", self.args[0])

Seblu's avatar
Seblu committed

class Command_pause(TqlCommand):
Seblu's avatar
Seblu committed
    '''Pause a running vm'''

    def __init__(self, cli, argv0):
        TqlCommand.__init__(self, cli, argv0)
        self.tql_filter += "&r=vm&status=stopped"

Seblu's avatar
Seblu committed
    def __call__(self, argv):
        # arg parse
        self.parse_args(argv)
        if len(self.args) != 1:
            raise cmdBadArgument()
        # rpc call
        self.rpccall("pause", self.args[0])
class Command_resume(TqlCommand):
Seblu's avatar
Seblu committed
    '''Resume a paused vm'''

    def __init__(self, cli, argv0):
        TqlCommand.__init__(self, cli, argv0)
        self.tql_filter += "&r=vm&status=paused"

Seblu's avatar
Seblu committed
    def __call__(self, argv):
        # arg parse
        self.parse_args(argv)
        if len(self.args) != 1:
            raise cmdBadArgument()
        # rpc call
        self.rpccall("resume", self.args[0])
Seblu's avatar
Seblu committed

class Command_undefine(TqlCommand):
    '''Undefine a stopped vm'''

    def __init__(self, cli, argv0):
        TqlCommand.__init__(self, cli, argv0)
        self.tql_filter += "&r=vm&status=stopped"
        self.add_option("-c", "--clean", action="store_true", dest="clean", default=False,
                        help="Remove storage")

    def __call__(self, argv):
        # arg parse
        self.parse_args(argv)
        if len(self.args) != 1:
            raise cmdBadArgument()
        # rpc call
        self.rpccall("undefine", self.args[0], self.options.clean)