Beispiel #1
0
def edit_duplicate_domain(hostname):
    vgname = None
    vglist = volume.list_vgs()
    if len(vglist) == 0:
        if dialogbox.messagebox.execute(gui.res.string_create_region, dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) == "ok":
            vgname = volume.create_vg()
        if vgname == None: return None
    else:
        vgname = vglist[0]["name"]

    fields = [{"id":"hostname","label":gui.res.string_machine_name,"value":hostname},{"id":"vgname","label":gui.res.string_domain_area,"value":vgname}]
    while True:
        values = gui.propertybox.execute(gui.res.string_duplicate,fields)
        if values == None: break
        #else
        hostname = values["hostname"]
        vgname = values["vgname"]

        fields[0]["value"] = hostname
        fields[1]["value"] = vgname

        if domain.exists(hostname):
            dialogbox.messagebox.execute(gui.res.string_vm_already_exists % (hostname), None, gui.res.caution_sign)
            continue

        if not volume.vg_exists(vgname):
            dialogbox.messagebox.execute(gui.res.string_domain_desc % (vgname), None, gui.res.caution_sign)
            continue

        return {"hostname":hostname, "vgname":vgname}

    return None
Beispiel #2
0
def edit_new_domain(title, hostname, default_memory, min_disk, min_memory = None):
    vgname = None
    vglist = volume.list_vgs()
    if len(vglist) == 0:
        if dialogbox.messagebox.execute(gui.res.string_create_region, dialogbox.DialogBox.OKCANCEL(), gui.res.caution_sign) == "ok":
            vgname = volume.create_vg()
        if vgname == None: return None
    else:
        vgname = vglist[0]["name"]

    fields = [{"id":"hostname","label":gui.res.string_machine_name,"value":hostname},{"id":"memory","label":gui.res.string_allocated_memory,"value":default_memory,"type":"int"},{"id":"vgname","label":gui.res.string_domain_area,"value":vgname},{"id":"disk","label":gui.res.string_allocation_hd,"value":min_disk,"type":"int"}]
    while True:
        values = gui.propertybox.execute(title,fields)
        if values == None: break
        #else
        hostname = values["hostname"]
        memory = values["memory"]
        vgname = values["vgname"]
        disk = values["disk"]

        fields[0]["value"] = hostname
        fields[1]["value"] = memory
        fields[2]["value"] = vgname
        fields[3]["value"] = disk

        if domain.exists(hostname):
            dialogbox.messagebox.execute(gui.res.string_vm_already_exists % (hostname), None, gui.res.caution_sign)
            continue

        if min_memory != None and memory < min_memory:
            dialogbox.messagebox.execute(gui.res.string_vm_creation_description % (min_memory), None, gui.res.caution_sign)
            continue
        if memory < 32:
            dialogbox.messagebox.execute(gui.res.string_vm_allocation_desc, None, gui.res.caution_sign)
            continue

        if disk < min_disk:
            dialogbox.messagebox.execute(gui.res.string_vm_space_desc % (min_disk), None, gui.res.caution_sign)
            continue

        if not volume.vg_exists(vgname):
            dialogbox.messagebox.execute(gui.res.string_domain_desc % (vgname), None, gui.res.caution_sign)
            continue

        return {"hostname":hostname, "vgname":vgname, "memory":memory, "disk":disk}

    return None
Beispiel #3
0
def edit_duplicate_domain(hostname):
    vgname = None
    vglist = volume.list_vgs()
    if len(vglist) == 0:
        if dialogbox.messagebox.execute(gui.res.string_create_region,
                                        dialogbox.DialogBox.OKCANCEL(),
                                        gui.res.caution_sign) == "ok":
            vgname = volume.create_vg()
        if vgname == None: return None
    else:
        vgname = vglist[0]["name"]

    fields = [{
        "id": "hostname",
        "label": gui.res.string_machine_name,
        "value": hostname
    }, {
        "id": "vgname",
        "label": gui.res.string_domain_area,
        "value": vgname
    }]
    while True:
        values = gui.propertybox.execute(gui.res.string_duplicate, fields)
        if values == None: break
        #else
        hostname = values["hostname"]
        vgname = values["vgname"]

        fields[0]["value"] = hostname
        fields[1]["value"] = vgname

        if domain.exists(hostname):
            dialogbox.messagebox.execute(
                gui.res.string_vm_already_exists % (hostname), None,
                gui.res.caution_sign)
            continue

        if not volume.vg_exists(vgname):
            dialogbox.messagebox.execute(gui.res.string_domain_desc % (vgname),
                                         None, gui.res.caution_sign)
            continue

        return {"hostname": hostname, "vgname": vgname}

    return None
Beispiel #4
0
def edit_new_domain(title,
                    hostname,
                    default_memory,
                    min_disk,
                    min_memory=None):
    vgname = None
    vglist = volume.list_vgs()
    if len(vglist) == 0:
        if dialogbox.messagebox.execute(gui.res.string_create_region,
                                        dialogbox.DialogBox.OKCANCEL(),
                                        gui.res.caution_sign) == "ok":
            vgname = volume.create_vg()
        if vgname == None: return None
    else:
        vgname = vglist[0]["name"]

    fields = [{
        "id": "hostname",
        "label": gui.res.string_machine_name,
        "value": hostname
    }, {
        "id": "memory",
        "label": gui.res.string_allocated_memory,
        "value": default_memory,
        "type": "int"
    }, {
        "id": "vgname",
        "label": gui.res.string_domain_area,
        "value": vgname
    }, {
        "id": "disk",
        "label": gui.res.string_allocation_hd,
        "value": min_disk,
        "type": "int"
    }]
    while True:
        values = gui.propertybox.execute(title, fields)
        if values == None: break
        #else
        hostname = values["hostname"]
        memory = values["memory"]
        vgname = values["vgname"]
        disk = values["disk"]

        fields[0]["value"] = hostname
        fields[1]["value"] = memory
        fields[2]["value"] = vgname
        fields[3]["value"] = disk

        if domain.exists(hostname):
            dialogbox.messagebox.execute(
                gui.res.string_vm_already_exists % (hostname), None,
                gui.res.caution_sign)
            continue

        if min_memory != None and memory < min_memory:
            dialogbox.messagebox.execute(
                gui.res.string_vm_creation_description % (min_memory), None,
                gui.res.caution_sign)
            continue
        if memory < 32:
            dialogbox.messagebox.execute(gui.res.string_vm_allocation_desc,
                                         None, gui.res.caution_sign)
            continue

        if disk < min_disk:
            dialogbox.messagebox.execute(
                gui.res.string_vm_space_desc % (min_disk), None,
                gui.res.caution_sign)
            continue

        if not volume.vg_exists(vgname):
            dialogbox.messagebox.execute(gui.res.string_domain_desc % (vgname),
                                         None, gui.res.caution_sign)
            continue

        return {
            "hostname": hostname,
            "vgname": vgname,
            "memory": memory,
            "disk": disk
        }

    return None
Beispiel #5
0
def create():
    code = dialogbox.inputbox.TextInputBox(gui.res.string_app_code, "", 5, 32, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").execute()
    if code == None: return None
    json_url = "http://goo.gl/" + code # e.g. lLj8Q

    try:
        with dialogbox.messagebox.open(gui.res.string_app_code_check):
            rst = http_client.nonblockHttpGet(json_url)
            app = json.loads(rst)
            for key in ["id", "title","type"]: 
                if not key in app: raise ValueError("Invalid data")
            if app["type"] != "app":
                raise ValueError("type must be app")
    except ValueError:
        dialogbox.messagebox.execute(gui.res.string_code_invalid, None, gui.res.caution_sign)
        return None
    except http_client.Cancelled:
        dialogbox.messagebox.execute(gui.res.string_app_canceled)
        return None
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(gui.res.string_app_comm_error % (e.getError(), e.getURL()), None, gui.res.caution_sign)
        return None

    images = app["images"] if "images" in app else None
    tarball = app["tarball"] if "tarball" in app else None
    minimum_hd = app["minimum_hd"] if "minimum_hd" in app else None
    title = app["title"] if "title" in app else None
    description = app["description"] if "description" in app else None

    s = system.getSystem()
    if not s.checkIfArchitectureIsSupported(app["arch"] if "arch" in app else "i686"):
         dialogbox.messagebox.execute(gui.res.string_app_not_supported % s.getArchitectureString(), None, gui.res.caution_sign)
         return False

    try:
        with dialogbox.messagebox.open(gui.res.string_apps_details):
            image_url = images[0]["url"] if images != None and len(images) > 0 and "url" in images[0] else None

            if image_url != None: 
                rst = http_client.nonblockHttpGet(image_url)
                image = pygame.image.load(io.BytesIO(rst)).convert_alpha()
            else:
                image = None

            contentLength = None
            if tarball != None:
                headers = http_client.nonblockingHttpHead(tarball)
                if "content-length" in headers:
                    contentLength = headers["content-length"]
    except http_client.Cancelled:
        dialogbox.messagebox.execute(gui.res.string_app_canceled)
        return False
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(gui.res.string_app_comm_error % (e.getError(), e.getURL()), None, gui.res.caution_sign)
        return False

    buttons = []
    if tarball != None: buttons.append({ "id":"download", "icon":gui.res.icon_ok, "text":gui.res.string_app_download })
    buttons.append({ "id":"cancel", "icon":gui.res.icon_cancel, "text":gui.res.string_app_can})
    specs = []
    if contentLength != None: specs.append(gui.res.string_downl_capacity % (float(contentLength) / 1024 / 1024))
    if minimum_hd != None: specs.append(gui.res.string_app_minimum_hd % minimum_hd)

    apd = domain.create.VirtualApplianceDescription(title, image, description, " ".join(specs))

    if dialogbox.DialogBox(apd, buttons).execute() != "download": return False

    if exists(app["id"]):
        dialogbox.messagebox.execute(gui.res.string_app_exists % app["id"], None, gui.res.caution_sign)
        return False

    
    vgname = None

    while vgname == None:
        options = []
        for vg in volume.list_vgs():
            options.append({"id":vg["name"], "label":vg["name"]})
        vgname = gui.selectbox.execute(gui.res.string_app__select_area, options)
        if vgname == None: return False

        lvname = app["id"]
        try:
            device_name = s.createLogicalVolumeInMB(vgname, lvname, int(minimum_hd), "@wbapp")
        except Exception, e:
            traceback.print_exc(file=sys.stderr)
            dialogbox.messagebox.execute(gui.res.string_app_area_creation_failed_desc, None, gui.res.caution_sign)
            vgname = None