Example #1
0
def delete_node():
    data = j.data.serializers.json.loads(request.body.read())
    wid = data.get("wid")
    releases_to_delete = data.get("releases_to_delete")
    if not wid:
        abort(400, "Error: Not all required params was passed.")
    vdc = get_vdc()
    if not vdc:
        return HTTPResponse(status=404,
                            headers={"Content-Type": "application/json"})
    deployer = vdc.get_deployer()

    # Delete all releases which have pods on this node
    if releases_to_delete:
        deployer.vdc_k8s_manager.delete_namespaces(releases_to_delete)

    # Delete the node
    try:
        j.logger.info(f"Deleting node with wid: {wid}")
        deployer.delete_k8s_node(wid, True)
    except Exception as e:
        j.logger.error(
            f"Error: Failed to delete workload due to the following {str(e)}")
        abort(500, "Error: Failed to delete workload")
    return j.data.serializers.json.dumps({"result": True})
Example #2
0
def vdc_capacity():
    vdc = get_vdc()
    vdc_dict = vdc.to_dict()
    for node in vdc_dict["kubernetes"]:
        if node["role"] == "master":
            node["status"] = j.sals.nettools.tcp_connection_test(
                node["public_ip"], 6443, 10)
    return HTTPResponse(j.data.serializers.json.dumps(vdc_dict),
                        status=200,
                        headers={"Content-Type": "application/json"})
Example #3
0
def list_all_deployments() -> str:
    deployments = []
    vdc = get_vdc()
    data = j.data.serializers.json.loads(request.body.read())
    solution_types = data.get("solution_types")
    try:
        deployments = get_all_vdc_deployments(vdc.vdc_name,
                                              solution_types=solution_types)
    except Exception as e:
        j.logger.exception(message=str(e), exception=e)

    return j.data.serializers.json.dumps({"data": deployments})
Example #4
0
def expose_s3() -> str:
    vdc = get_vdc()
    if not vdc:
        return HTTPResponse(status=404,
                            headers={"Content-Type": "application/json"})

    vdc_deployer = vdc.get_deployer()
    s3_domain = vdc_deployer.expose_s3()
    if not s3_domain:
        return HTTPResponse(status=400,
                            message="Failed to expose S3",
                            headers={"Content-Type": "application/json"})
    return j.data.serializers.json.dumps({"data": s3_domain})
Example #5
0
def _get_zstor_config(ip_version=6):
    vdc = get_vdc(True)
    vdc_zdb_monitor = vdc.get_zdb_monitor()
    password = vdc_zdb_monitor.get_password()
    encryption_key = password[:32].encode().zfill(32).hex()
    data = {
        "data_shards": 2,
        "parity_shards": 1,
        "redundant_groups": 0,
        "redundant_nodes": 0,
        "encryption": {
            "algorithm": "AES",
            "key": encryption_key
        },
        "compression": {
            "algorithm": "snappy"
        },
        "meta": {
            "type": "etcd",
            "config": {
                "endpoints": [
                    "http://127.0.0.1:2379", "http://127.0.0.1:22379",
                    "http://127.0.0.1:32379"
                ],
                "prefix":
                "someprefix",
            },
        },
        "groups": [],
    }
    if ip_version == 4:
        deployer = vdc.get_deployer()
        vdc.load_info(load_proxy=True)
        deployer.s3.expose_zdbs()

    for zdb in vdc.s3.zdbs:
        if ip_version == 6:
            zdb_url = f"[{zdb.ip_address}]:{zdb.port}"
        elif ip_version == 4:
            zdb_url = zdb.proxy_address
        else:
            return
        data["groups"].append({
            "backends": [{
                "address": zdb_url,
                "namespace": zdb.namespace,
                "password": password
            }]
        })
    return data
Example #6
0
def delete_zdb():
    data = j.data.serializers.json.loads(request.body.read())
    wid = data.get("wid")
    if not wid:
        abort(400, "Error: Not all required params was passed.")
    vdc = get_vdc()
    if not vdc:
        return HTTPResponse(status=404,
                            headers={"Content-Type": "application/json"})
    deployer = vdc.get_deployer()
    try:
        j.logger.info(f"Deleting zdb with wid: {wid}")
        deployer.delete_s3_zdb(wid)
    except Exception as e:
        j.logger.error(
            f"Error: Failed to delete workload due to the following {str(e)}")
        abort(500, "Error: Failed to delete workload")
    return j.data.serializers.json.dumps({"result": True})
Example #7
0
def check_before_delete_node():
    data = j.data.serializers.json.loads(request.body.read())
    wid = data.get("wid")
    if not wid:
        abort(400, "Error: Not all required params was passed.")
    vdc = get_vdc()
    if not vdc:
        return HTTPResponse(status=404,
                            headers={"Content-Type": "application/json"})
    deployer = vdc.get_deployer()
    try:
        releases_to_delete = deployer.kubernetes.list_node_releases(wid)
    except Exception as e:
        j.logger.error(
            f"Error: Failed to check before delete workload due to the following {str(e)}"
        )
        abort(500, "Error: Failed to check before delete workload")
    return j.data.serializers.json.dumps(
        {"releases_to_delete": releases_to_delete})
Example #8
0
def redeploy_master():
    data = j.data.serializers.json.loads(request.body.read())
    wid = data.get("wid")
    vdc = get_vdc()
    if not wid:
        deployer = vdc.get_deployer()
        w = deployer.kubernetes._get_latest_master_workload()
    else:
        zos = j.sals.zos.get()
        w = zos.workloads.get(wid)
    network_farm = j.sals.marketplace.deployer.get_pool_farm_name(
        w.info.pool_id)
    deployer = vdc.get_deployer(network_farm=network_farm)
    try:
        deployer.kubernetes.redeploy_master(w)
    except Exception as e:
        j.logger.exception("Failed to redeploy master", exception=e)
        return HTTPResponse(f"Failed to redeploy master",
                            status=500,
                            headers={"Content-Type": "application/json"})
Example #9
0
def enable_quantumstorage():
    vdc = get_vdc()
    if not vdc:
        return HTTPResponse(status=404,
                            headers={"Content-Type": "application/json"})

    qs = vdc.get_quantumstorage_manager()
    try:
        file_content = qs.apply()
        return HTTPResponse(
            j.data.serializers.json.dumps({"data": file_content}),
            status=200,
            headers={"Content-Type": "application/json"},
        )
    except Exception as e:
        j.logger.error(
            f"Failed to enable quantum storage on your vdc due to {str(e)}")
        return HTTPResponse("Failed to enable quantum storage on your vdc",
                            status=500,
                            headers={"Content-Type": "application/json"})
Example #10
0
def cancel_deployment():
    data = j.data.serializers.json.loads(request.body.read())
    user_info = j.data.serializers.json.loads(get_user_info())
    username = user_info["username"]
    vdc_name = data.get("vdc_name")
    namespace = data.get("namespace", "default")
    if not vdc_name:
        abort(400, "Error: Not all required params was passed.")
    config_path = j.sals.fs.expanduser("~/.kube/config")
    k8s_client = j.sals.kubernetes.Manager(config_path=config_path)
    vdc = get_vdc()
    if namespace == "default":
        k8s_client.delete_deployed_release(release=data["release"],
                                           vdc_instance=vdc,
                                           namespace=namespace)
    else:
        k8s_client.execute_native_cmd(f"kubectl delete ns {namespace}")
    j.logger.info(f"Cancelling deployment for {data['solution_id']}")
    j.sals.marketplace.solutions.cancel_solution_by_uuid(data["solution_id"])
    return j.data.serializers.json.dumps({"result": True})
Example #11
0
def get_zdb_secret():
    vdc = get_vdc()
    vdc_zdb_monitor = vdc.get_zdb_monitor()
    password = vdc_zdb_monitor.get_password()
    return j.data.serializers.json.dumps({"data": password})
Example #12
0
def vdc_expiration():
    vdc = get_vdc()
    data = {"price": math.ceil(vdc.calculate_spec_price())}
    return HTTPResponse(j.data.serializers.json.dumps(data),
                        status=200,
                        headers={"Content-Type": "application/json"})