예제 #1
0
 def __init__(self, screen, title, settings):
     self.settings = settings
     self.memory = FloatField("memory", float(settings["memory"]) / 1024)
     self.swap = FloatField("swap", float(settings["swap"]) / 1024)
     self.vcpu = IntegerField("vcpu", settings["vcpu"])
     self.bootorder = IntegerField("bootorder",
                                   settings.get("bootorder"),
                                   required=False)
     self.disk = FloatField("diskspace",
                            float(settings["diskspace"]["/"]) / 1024)
     self.ioprio = RadioBarField("ioprio", screen,
                                 [('Low    ', 0, settings["ioprio"] == 0),
                                  ('Default', 4, settings["ioprio"] == 4),
                                  ('High   ', 7, settings["ioprio"] == 7)])
     self.bind_mounts = BindMountsField("bind_mounts",
                                        settings["bind_mounts"],
                                        required=False)
     self.vcpulimit = IntegerField("vcpulimit",
                                   settings["vcpulimit"],
                                   min_value=0,
                                   max_value=100)
     self.onboot = CheckboxField("onboot",
                                 settings.get("onboot", 0),
                                 display_name="Start on boot")
     self.ctid = IntegerField('ctid',
                              settings['ctid'],
                              display_name='VEID',
                              required=False)
     self.hostname = StringField("hostname", settings.get("name", ""))
     Form.__init__(self, screen, title, [
         self.memory, self.vcpu, self.disk, self.ioprio, self.hostname,
         self.bind_mounts, self.swap, self.onboot, self.bootorder,
         self.vcpulimit, self.ctid
     ])
예제 #2
0
 def __init__(self, screen, title, settings):
     self.memory = FloatField("memory", settings["memory"], settings["memory_min"],
                              settings["memory_max"])
     self.swap = FloatField("swap", settings["swap"], settings["swap_min"], settings["swap_max"])
     self.vcpu = FloatField("vcpu", settings["vcpu"], settings["vcpu_min"], settings["vcpu_max"])
     self.vcpulimit = IntegerField("vcpulimit", settings["vcpulimit"], settings["vcpulimit_min"],
                                   settings["vcpulimit_max"])
     self.disk = FloatField("disk", settings["disk"], settings["disk_min"], settings["disk_max"])
     self.ioprio = RadioBarField("ioprio", screen, [('Low    ', 0, settings["ioprio"] == 0),
                                                    ('Default', 4, settings["ioprio"] == 4),
                                                    ('High   ', 7, settings["ioprio"] == 7)])
     self.bind_mounts = BindMountsField("bind_mounts", settings["bind_mounts"], required=False)
     self.hostname = StringField("hostname", settings.get("hostname", ""))
     self.ip_address = IpField("ip_address", settings["ip_address"], display_name="IP address")
     self.nameserver = IpField("nameserver", settings["nameserver"])
     self.password = PasswordField("passwd", settings["passwd"], display_name="password")
     self.password2 = PasswordField("passw2", settings["passwd"], display_name="password")
     self.ostemplate = StringField("ostemplate", settings["ostemplate"], display_name="OS template")
     self.startvm = CheckboxField("startvm", settings.get("startvm", 0), display_name="Start VM")
     self.onboot = CheckboxField("onboot", settings.get("onboot", 0), display_name="Start on boot")
     Form.__init__(self, screen, title, [self.memory, self.swap, self.vcpu,
                                         self.vcpulimit, self.disk, self.ioprio,
                                         self.bind_mounts, self.hostname,
                                         self.ip_address, self.nameserver,
                                         self.password, self.password2,
                                         self.ostemplate, self.startvm,
                                         self.onboot])
     self.settings = settings  # save passed parameters for convenience
예제 #3
0
 def __init__(self, screen, title, settings):
     self.memory = FloatField("memory", settings["memory"],
                              settings["memory_min"],
                              settings["memory_max"])
     self.swap = FloatField("swap", settings["swap"], settings["swap_min"],
                            settings["swap_max"])
     self.vcpu = FloatField("vcpu", settings["vcpu"], settings["vcpu_min"],
                            settings["vcpu_max"])
     self.vcpulimit = IntegerField("vcpulimit", settings["vcpulimit"],
                                   settings["vcpulimit_min"],
                                   settings["vcpulimit_max"])
     self.disk = FloatField("disk", settings["disk"], settings["disk_min"],
                            settings["disk_max"])
     self.ioprio = RadioBarField("ioprio", screen,
                                 [('Low    ', 0, settings["ioprio"] == 0),
                                  ('Default', 4, settings["ioprio"] == 4),
                                  ('High   ', 7, settings["ioprio"] == 7)])
     self.bind_mounts = BindMountsField("bind_mounts",
                                        settings["bind_mounts"],
                                        required=False)
     self.hostname = StringField("hostname", settings.get("hostname", ""))
     self.ip_address = IpField("ip_address",
                               settings["ip_address"],
                               display_name="IP address")
     self.nameserver = IpField("nameserver", settings["nameserver"])
     self.password = PasswordField("passwd",
                                   settings["passwd"],
                                   display_name="password")
     self.password2 = PasswordField("passw2",
                                    settings["passwd"],
                                    display_name="password")
     self.ostemplate = StringField("ostemplate",
                                   settings["ostemplate"],
                                   display_name="OS template")
     self.startvm = CheckboxField("startvm",
                                  settings.get("startvm", 0),
                                  display_name="Start VM")
     self.onboot = CheckboxField("onboot",
                                 settings.get("onboot", 0),
                                 display_name="Start on boot")
     Form.__init__(self, screen, title, [
         self.memory, self.swap, self.vcpu, self.vcpulimit, self.disk,
         self.ioprio, self.bind_mounts, self.hostname, self.ip_address,
         self.nameserver, self.password, self.password2, self.ostemplate,
         self.startvm, self.onboot
     ])
     self.settings = settings  # save passed parameters for convenience
예제 #4
0
 def __init__(self, screen, title, settings):
     self.settings = settings
     self.memory = FloatField("memory", float(settings["memory"]) / 1024)
     self.swap = FloatField("swap", float(settings["swap"]) / 1024)
     self.vcpu = IntegerField("vcpu", settings["vcpu"])
     self.bootorder = IntegerField("bootorder", settings.get("bootorder"), required=False)
     self.disk = FloatField("diskspace", float(settings["diskspace"]["/"]) / 1024)
     self.ioprio = RadioBarField("ioprio", screen, [('Low    ', 0, settings["ioprio"] == 0),
                                                    ('Default', 4, settings["ioprio"] == 4),
                                                    ('High   ', 7, settings["ioprio"] == 7)])
     self.bind_mounts = BindMountsField("bind_mounts", settings["bind_mounts"], required=False)
     self.vcpulimit = IntegerField("vcpulimit", settings["vcpulimit"],
                                   min_value=0, max_value=100)
     self.onboot = CheckboxField("onboot", settings.get("onboot", 0), display_name="Start on boot")
     self.ctid = IntegerField('ctid', settings['ctid'],
                              display_name='VEID', required=False)
     self.hostname = StringField("hostname", settings.get("name", ""))
     Form.__init__(self, screen, title, [self.memory, self.vcpu, self.disk, self.ioprio, self.hostname,
                                         self.bind_mounts, self.swap, self.onboot, self.bootorder,
                                         self.vcpulimit, self.ctid])
예제 #5
0
class OpenvzForm(Form):
    def __init__(self, screen, title, settings):
        self.memory = FloatField("memory", settings["memory"],
                                 settings["memory_min"],
                                 settings["memory_max"])
        self.swap = FloatField("swap", settings["swap"], settings["swap_min"],
                               settings["swap_max"])
        self.vcpu = FloatField("vcpu", settings["vcpu"], settings["vcpu_min"],
                               settings["vcpu_max"])
        self.vcpulimit = IntegerField("vcpulimit", settings["vcpulimit"],
                                      settings["vcpulimit_min"],
                                      settings["vcpulimit_max"])
        self.disk = FloatField("disk", settings["disk"], settings["disk_min"],
                               settings["disk_max"])
        self.ioprio = RadioBarField("ioprio", screen,
                                    [('Low    ', 0, settings["ioprio"] == 0),
                                     ('Default', 4, settings["ioprio"] == 4),
                                     ('High   ', 7, settings["ioprio"] == 7)])
        self.bind_mounts = BindMountsField("bind_mounts",
                                           settings["bind_mounts"],
                                           required=False)
        self.hostname = StringField("hostname", settings.get("hostname", ""))
        self.ip_address = IpField("ip_address",
                                  settings["ip_address"],
                                  display_name="IP address")
        self.nameserver = IpField("nameserver", settings["nameserver"])
        self.password = PasswordField("passwd",
                                      settings["passwd"],
                                      display_name="password")
        self.password2 = PasswordField("passw2",
                                       settings["passwd"],
                                       display_name="password")
        self.ostemplate = StringField("ostemplate",
                                      settings["ostemplate"],
                                      display_name="OS template")
        self.startvm = CheckboxField("startvm",
                                     settings.get("startvm", 0),
                                     display_name="Start VM")
        self.onboot = CheckboxField("onboot",
                                    settings.get("onboot", 0),
                                    display_name="Start on boot")
        Form.__init__(self, screen, title, [
            self.memory, self.swap, self.vcpu, self.vcpulimit, self.disk,
            self.ioprio, self.bind_mounts, self.hostname, self.ip_address,
            self.nameserver, self.password, self.password2, self.ostemplate,
            self.startvm, self.onboot
        ])
        self.settings = settings  # save passed parameters for convenience

    def display(self):
        button_exit, button_save = Button("Back"), Button("Create VM")
        separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0))
        rows = [
            (Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory),
            (Textbox(20, 1, "Memory min/max:", 0, 0),
             Textbox(
                 20, 1,
                 "%s / %s" % (self.memory.min_value, self.memory.max_value), 0,
                 0)), (Textbox(20, 1, "VSwap size (GB):", 0, 0), self.swap),
            (Textbox(20, 1, "VSwap min/max:", 0, 0),
             Textbox(20, 1,
                     "%s / %s" % (self.swap.min_value, self.swap.max_value), 0,
                     0)), (Textbox(20, 1, "Number of CPUs:", 0, 0), self.vcpu),
            (Textbox(20, 1, "CPU number min/max:", 0, 0),
             Textbox(20, 1,
                     "%s / %s" % (self.vcpu.min_value, self.vcpu.max_value), 0,
                     0)),
            (Textbox(20, 1, "CPU usage limit (%):", 0, 0), self.vcpulimit),
            (Textbox(20, 1, "CPU usage min/max:", 0, 0),
             Textbox(
                 20, 1, "%s / %s" %
                 (self.vcpulimit.min_value, self.vcpulimit.max_value), 0, 0)),
            (Textbox(20, 1, "Disk size (GB):", 0, 0), self.disk),
            (Textbox(20, 1, "Disk size min/max:", 0, 0),
             Textbox(20, 1,
                     "%s / %s" % (self.disk.min_value, self.disk.max_value), 0,
                     0)), (Textbox(20, 1, "IO Priority:", 0, 0), self.ioprio),
            (Textbox(20, 1, "Bind mounts:", 0, 0), self.bind_mounts),
            (Textbox(20, 1, "", 0,
                     0), Textbox(20, 1, "/src1,/dst1;/srcN,..", 0, 0)),
            (Textbox(20, 1, "Hostname:", 0, 0), self.hostname),
            (Textbox(20, 1, "IP-address:", 0, 0), self.ip_address),
            (Textbox(20, 2, "Nameserver:", 0, 0), self.nameserver),
            (Textbox(20, 1, "Root password:"******"Root password x2:", 0, 0), self.password2),
            (Textbox(20, 2, "OS Template:", 0, 0), self.ostemplate),
            (self.startvm, self.onboot), separator, (button_save, button_exit)
        ]
        form = GridForm(self.screen, self.title, 2, len(rows))
        for i, row in enumerate(rows):
            for j, cell in enumerate(row):
                form.add(cell, j, i)
        return form.runOnce() != button_exit

    def validate(self):
        Form.validate(self)
        if (self.password.validate() and self.password2.validate()
                and self.password.value() != self.password2.value()):
            self.errors.append(("passwd", "Passwords don't match."))

        bm_valid = self.bind_mounts.validate()
        if bm_valid:
            error_str = "\n".join([s[1] for s in bm_valid])
            self.errors.append(("bind_mounts", "%s" % error_str))

        return not self.errors
예제 #6
0
class OpenvzModificationForm(Form):
    def __init__(self, screen, title, settings):
        self.settings = settings
        self.memory = FloatField("memory", float(settings["memory"]) / 1024)
        self.swap = FloatField("swap", float(settings["swap"]) / 1024)
        self.vcpu = IntegerField("vcpu", settings["vcpu"])
        self.bootorder = IntegerField("bootorder",
                                      settings.get("bootorder"),
                                      required=False)
        self.disk = FloatField("diskspace",
                               float(settings["diskspace"]["/"]) / 1024)
        self.ioprio = RadioBarField("ioprio", screen,
                                    [('Low    ', 0, settings["ioprio"] == 0),
                                     ('Default', 4, settings["ioprio"] == 4),
                                     ('High   ', 7, settings["ioprio"] == 7)])
        self.bind_mounts = BindMountsField("bind_mounts",
                                           settings["bind_mounts"],
                                           required=False)
        self.vcpulimit = IntegerField("vcpulimit",
                                      settings["vcpulimit"],
                                      min_value=0,
                                      max_value=100)
        self.onboot = CheckboxField("onboot",
                                    settings.get("onboot", 0),
                                    display_name="Start on boot")
        self.ctid = IntegerField('ctid',
                                 settings['ctid'],
                                 display_name='VEID',
                                 required=False)
        self.hostname = StringField("hostname", settings.get("name", ""))
        Form.__init__(self, screen, title, [
            self.memory, self.vcpu, self.disk, self.ioprio, self.hostname,
            self.bind_mounts, self.swap, self.onboot, self.bootorder,
            self.vcpulimit, self.ctid
        ])

    def display(self):
        button_save, button_exit = Button("Update"), Button("Back")
        separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0))
        rows = [(Textbox(20, 1, "Memory size (GB):", 0,
                         0), self.memory), separator,
                (Textbox(20, 1, "Swap size (GB):", 0,
                         0), self.swap), separator,
                (Textbox(20, 1, "Nr. of CPUs:", 0, 0), self.vcpu), separator,
                (Textbox(20, 1, "CPU usage limit (%):", 0, 0), self.vcpulimit),
                separator, (Textbox(20, 1, "Disk size (GB):", 0,
                                    0), self.disk), separator,
                (Textbox(20, 1, "IO Priority:", 0, 0), self.ioprio), separator,
                (Textbox(20, 1, "Bind mounts:", 0, 0), self.bind_mounts),
                (Textbox(20, 1, "", 0,
                         0), Textbox(20, 1, "/src1,/dst1;/srcN,..", 0,
                                     0)), separator,
                (Textbox(20, 1, "Hostname:", 0, 0), self.hostname), separator,
                (Textbox(20, 1, "", 0, 0), self.onboot), separator,
                (Textbox(20, 1, "Boot order:", 0,
                         0), self.bootorder), separator,
                (Textbox(20, 1, "VEID:", 0, 0), self.ctid), separator,
                (button_exit, button_save)]
        form = GridForm(self.screen, self.title, 2, len(rows))
        for i, row in enumerate(rows):
            for j, cell in enumerate(row):
                form.add(cell, j, i)
        return form.runOnce() != button_exit

    def validate(self):
        # TODO disallow decrease of disk size, which would break OS
        Form.validate(self)
        bm_valid = self.bind_mounts.validate()
        if bm_valid:
            error_str = "\n".join([s[1] for s in bm_valid])
            self.errors.append(("bind_mounts", "%s" % error_str))
        if self.memory.value() < self.settings["memory_min"]:
            err_msg = (
                "Memory size can not be lower than minimum defined in template: %s GB"
                % self.settings["memory_min"])
            self.errors.append(("memory", err_msg))
        return not self.errors
예제 #7
0
class OpenvzForm(Form):

    def __init__(self, screen, title, settings):
        self.memory = FloatField("memory", settings["memory"], settings["memory_min"],
                                 settings["memory_max"])
        self.swap = FloatField("swap", settings["swap"], settings["swap_min"], settings["swap_max"])
        self.vcpu = FloatField("vcpu", settings["vcpu"], settings["vcpu_min"], settings["vcpu_max"])
        self.vcpulimit = IntegerField("vcpulimit", settings["vcpulimit"], settings["vcpulimit_min"],
                                      settings["vcpulimit_max"])
        self.disk = FloatField("disk", settings["disk"], settings["disk_min"], settings["disk_max"])
        self.ioprio = RadioBarField("ioprio", screen, [('Low    ', 0, settings["ioprio"] == 0),
                                                       ('Default', 4, settings["ioprio"] == 4),
                                                       ('High   ', 7, settings["ioprio"] == 7)])
        self.bind_mounts = BindMountsField("bind_mounts", settings["bind_mounts"], required=False)
        self.hostname = StringField("hostname", settings.get("hostname", ""))
        self.ip_address = IpField("ip_address", settings["ip_address"], display_name="IP address")
        self.nameserver = IpField("nameserver", settings["nameserver"])
        self.password = PasswordField("passwd", settings["passwd"], display_name="password")
        self.password2 = PasswordField("passw2", settings["passwd"], display_name="password")
        self.ostemplate = StringField("ostemplate", settings["ostemplate"], display_name="OS template")
        self.startvm = CheckboxField("startvm", settings.get("startvm", 0), display_name="Start VM")
        self.onboot = CheckboxField("onboot", settings.get("onboot", 0), display_name="Start on boot")
        Form.__init__(self, screen, title, [self.memory, self.swap, self.vcpu,
                                            self.vcpulimit, self.disk, self.ioprio,
                                            self.bind_mounts, self.hostname,
                                            self.ip_address, self.nameserver,
                                            self.password, self.password2,
                                            self.ostemplate, self.startvm,
                                            self.onboot])
        self.settings = settings  # save passed parameters for convenience

    def display(self):
        button_exit, button_save = Button("Back"), Button("Create VM")
        separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0))
        rows = [
            (Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory),
            (Textbox(20, 1, "Memory min/max:", 0, 0),
             Textbox(20, 1, "%s / %s" % (self.memory.min_value, self.memory.max_value), 0, 0)),
            (Textbox(20, 1, "VSwap size (GB):", 0, 0), self.swap),
            (Textbox(20, 1, "VSwap min/max:", 0, 0),
             Textbox(20, 1, "%s / %s" % (self.swap.min_value, self.swap.max_value), 0, 0)),
            (Textbox(20, 1, "Number of CPUs:", 0, 0), self.vcpu),
            (Textbox(20, 1, "CPU number min/max:", 0, 0),
             Textbox(20, 1, "%s / %s" % (self.vcpu.min_value, self.vcpu.max_value), 0, 0)),
            (Textbox(20, 1, "CPU usage limit (%):", 0, 0), self.vcpulimit),
            (Textbox(20, 1, "CPU usage min/max:", 0, 0),
             Textbox(20, 1, "%s / %s" % (self.vcpulimit.min_value, self.vcpulimit.max_value), 0, 0)),
            (Textbox(20, 1, "Disk size (GB):", 0, 0), self.disk),
            (Textbox(20, 1, "Disk size min/max:", 0, 0),
             Textbox(20, 1, "%s / %s" % (self.disk.min_value, self.disk.max_value), 0, 0)),
            (Textbox(20, 1, "IO Priority:", 0, 0), self.ioprio),
            (Textbox(20, 1, "Bind mounts:", 0, 0), self.bind_mounts),
            (Textbox(20, 1, "", 0, 0),
             Textbox(20, 1, "/src1,/dst1;/srcN,..", 0, 0)),
            (Textbox(20, 1, "Hostname:", 0, 0), self.hostname),
            (Textbox(20, 1, "IP-address:", 0, 0), self.ip_address),
            (Textbox(20, 2, "Nameserver:", 0, 0), self.nameserver),
            (Textbox(20, 1, "Root password:"******"Root password x2:", 0, 0), self.password2),
            (Textbox(20, 2, "OS Template:", 0, 0), self.ostemplate),
            (self.startvm, self.onboot),
            separator,
            (button_save, button_exit)
        ]
        form = GridForm(self.screen, self.title, 2, len(rows))
        for i, row in enumerate(rows):
            for j, cell in enumerate(row):
                form.add(cell, j, i)
        return form.runOnce() != button_exit

    def validate(self):
        Form.validate(self)
        if (self.password.validate() and self.password2.validate() and
                self.password.value() != self.password2.value()):
            self.errors.append(("passwd", "Passwords don't match."))

        bm_valid = self.bind_mounts.validate()
        if bm_valid:
            error_str = "\n".join([s[1] for s in bm_valid])
            self.errors.append(("bind_mounts", "%s" % error_str))

        return not self.errors
예제 #8
0
class OpenvzModificationForm(Form):

    def __init__(self, screen, title, settings):
        self.settings = settings
        self.memory = FloatField("memory", float(settings["memory"]) / 1024)
        self.swap = FloatField("swap", float(settings["swap"]) / 1024)
        self.vcpu = IntegerField("vcpu", settings["vcpu"])
        self.bootorder = IntegerField("bootorder", settings.get("bootorder"), required=False)
        self.disk = FloatField("diskspace", float(settings["diskspace"]["/"]) / 1024)
        self.ioprio = RadioBarField("ioprio", screen, [('Low    ', 0, settings["ioprio"] == 0),
                                                       ('Default', 4, settings["ioprio"] == 4),
                                                       ('High   ', 7, settings["ioprio"] == 7)])
        self.bind_mounts = BindMountsField("bind_mounts", settings["bind_mounts"], required=False)
        self.vcpulimit = IntegerField("vcpulimit", settings["vcpulimit"],
                                      min_value=0, max_value=100)
        self.onboot = CheckboxField("onboot", settings.get("onboot", 0), display_name="Start on boot")
        self.ctid = IntegerField('ctid', settings['ctid'],
                                 display_name='VEID', required=False)
        self.hostname = StringField("hostname", settings.get("name", ""))
        Form.__init__(self, screen, title, [self.memory, self.vcpu, self.disk, self.ioprio, self.hostname,
                                            self.bind_mounts, self.swap, self.onboot, self.bootorder,
                                            self.vcpulimit, self.ctid])

    def display(self):
        button_save, button_exit = Button("Update"), Button("Back")
        separator = (Textbox(20, 1, "", 0, 0), Textbox(20, 1, "", 0, 0))
        rows = [
            (Textbox(20, 1, "Memory size (GB):", 0, 0), self.memory),
            separator,
            (Textbox(20, 1, "Swap size (GB):", 0, 0), self.swap),
            separator,
            (Textbox(20, 1, "Nr. of CPUs:", 0, 0), self.vcpu),
            separator,
            (Textbox(20, 1, "CPU usage limit (%):", 0, 0), self.vcpulimit),
            separator,
            (Textbox(20, 1, "Disk size (GB):", 0, 0), self.disk),
            separator,
            (Textbox(20, 1, "IO Priority:", 0, 0), self.ioprio),
            separator,
            (Textbox(20, 1, "Bind mounts:", 0, 0), self.bind_mounts),
            (Textbox(20, 1, "", 0, 0),
             Textbox(20, 1, "/src1,/dst1;/srcN,..", 0, 0)),
            separator,
            (Textbox(20, 1, "Hostname:", 0, 0), self.hostname),
            separator,
            (Textbox(20, 1, "", 0, 0), self.onboot),
            separator,
            (Textbox(20, 1, "Boot order:", 0, 0), self.bootorder),
            separator,
            (Textbox(20, 1, "VEID:", 0, 0), self.ctid),
            separator,
            (button_exit, button_save)
        ]
        form = GridForm(self.screen, self.title, 2, len(rows))
        for i, row in enumerate(rows):
            for j, cell in enumerate(row):
                form.add(cell, j, i)
        return form.runOnce() != button_exit

    def validate(self):
        # TODO disallow decrease of disk size, which would break OS
        Form.validate(self)
        bm_valid = self.bind_mounts.validate()
        if bm_valid:
            error_str = "\n".join([s[1] for s in bm_valid])
            self.errors.append(("bind_mounts", "%s" % error_str))
        if self.memory.value() < self.settings["memory_min"]:
            err_msg = ("Memory size can not be lower than minimum defined in template: %s GB" %
                       self.settings["memory_min"])
            self.errors.append(("memory", err_msg))
        return not self.errors