Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F OpenNebula/one-aiops#70: opennebula backend #1

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8872fc6
F OpenNebula/one-aiops#70: opennebula backend basic skeleton
MarioRobres May 30, 2024
9cd053f
F OpenNebula/one-aiops#70: basic opennebula backend skeleton
MarioRobres May 30, 2024
5ca5fac
F OpenNebula/one-aiops#70: refactor skeleton
MarioRobres Jun 4, 2024
7d2885c
F OpenNebula/one-aiops#70: basic initialization
MarioRobres Jun 5, 2024
e4848cd
F OpenNebula/one-aiops#70: add optionals parameters to instantiate OneKE
MarioRobres Jun 6, 2024
0070050
F OpenNebula/one-aiops#70: instantiate OneKE basic version
MarioRobres Jun 6, 2024
422c81f
F OpenNebula/one-aiops#70: add pyone and start wait for OneKE
MarioRobres Jun 6, 2024
013b38b
F OpenNebula/one-aiops#70: wait for OneKE implemented
MarioRobres Jun 6, 2024
76c17c4
F OpenNebula/one-aiops#70: get kubecfg from master node
MarioRobres Jun 7, 2024
b3256fd
F OpenNebula/one-aiops#70: fix kubecfg path
MarioRobres Jun 7, 2024
f1ef645
F OpenNebula/one-aiops#70: method _chek_oneke and add new params
MarioRobres Jun 7, 2024
9df5c93
F OpenNebula/one-aiops#70: minor fix
MarioRobres Jun 7, 2024
d5d91c4
F OpenNebula/one-aiops#70: ONE_AUTH can directly contain the credenti…
MarioRobres Jun 11, 2024
a61e458
F OpenNebula/one-aiops#70: fix service status + refactor code
MarioRobres Jun 21, 2024
7983dd7
F OpenNebula/one-aiops#70: basic scaling for one backend
MarioRobres Jun 28, 2024
b92b712
F OpenNebula/one-aiops#70: fix missing k8s config key
MarioRobres Jul 2, 2024
7455898
F OpenNebula/one-aiops#70: add new one params
MarioRobres Jul 2, 2024
a166b6f
F OpenNebula/one-aiops#70: improve scaling functionality
MarioRobres Jul 2, 2024
2ebae22
F OpenNebula/one-aiops#70: fix scaling functionality
MarioRobres Jul 2, 2024
f9234e3
F OpenNebula/one-aiops#70: get host and vm_template resources + refactor
MarioRobres Jul 3, 2024
a5b9f13
F OpenNebula/one-aiops#70: get runtime meta if oneke has 0 workers
MarioRobres Jul 4, 2024
7625f12
F OpenNebula/one-aiops#70: fix divide by 0 & runtime metadata
MarioRobres Jul 10, 2024
9ea2f09
F OpenNebula/one-aiops#70: duplicate clears and not detected kubernet…
MarioRobres Jul 10, 2024
90e12b1
F OpenNebula/one-aiops#70: add scale on demand, pod resources, fix ca…
MarioRobres Jul 24, 2024
a5d7a71
F OpenNebula/one-aiops#70: set node and vcpu limit
MarioRobres Jul 25, 2024
198170b
F OpenNebula/one-aiops#70: wait until kubernetes detect all workers n…
MarioRobres Jul 26, 2024
5eb427e
F OpenNebula/one-aiops#70: wait for nodes after scaling
MarioRobres Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lithops/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
'azure_containers',
'aliyun_fc',
'oracle_f',
'k8s'
'k8s',
'one'
]

STANDALONE_BACKENDS = [
Expand Down Expand Up @@ -140,6 +141,7 @@
'azure_vms',
'aws_batch',
'k8s',
'code_engine'
'one',
'code_engine',
'vm'
]
3 changes: 3 additions & 0 deletions lithops/serverless/backends/one/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .one import OpenNebula as ServerlessBackend

__all__ = ['ServerlessBackend']
197 changes: 197 additions & 0 deletions lithops/serverless/backends/one/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import os
import json


from lithops.serverless.backends.k8s.config import (
DEFAULT_CONFIG_KEYS,
load_config as original_load_config
)


class OneConfigError(Exception):
pass


MANDATORY_CONFIG_KEYS = {
"public_network_id",
"private_network_id"
}

OPTIONAL_CONFIG_KEYS = {
"ONEAPP_VROUTER_ETH0_VIP0": "",
"ONEAPP_VROUTER_ETH1_VIP0": "",
"ONEAPP_RKE2_SUPERVISOR_EP": "ep0.eth0.vr:9345",
"ONEAPP_K8S_CONTROL_PLANE_EP": "ep0.eth0.vr:6443",
"ONEAPP_K8S_EXTRA_SANS": "localhost,127.0.0.1,ep0.eth0.vr,${vnf.TEMPLATE.CONTEXT.ETH0_IP},k8s.yourdomain.it",
"ONEAPP_K8S_MULTUS_ENABLED": "NO",
"ONEAPP_K8S_MULTUS_CONFIG": "",
"ONEAPP_K8S_CNI_PLUGIN": "cilium",
"ONEAPP_K8S_CNI_CONFIG": "",
"ONEAPP_K8S_CILIUM_RANGE": "",
"ONEAPP_K8S_METALLB_ENABLED": "NO",
"ONEAPP_K8S_METALLB_CONFIG": "",
"ONEAPP_K8S_METALLB_RANGE": "",
"ONEAPP_K8S_LONGHORN_ENABLED": "YES",
"ONEAPP_STORAGE_DEVICE": "/dev/vdb",
"ONEAPP_STORAGE_FILESYSTEM": "xfs",
"ONEAPP_K8S_TRAEFIK_ENABLED": "YES",
"ONEAPP_VNF_HAPROXY_INTERFACES": "eth0",
"ONEAPP_VNF_HAPROXY_REFRESH_RATE": "30",
"ONEAPP_VNF_HAPROXY_LB0_PORT": "9345",
"ONEAPP_VNF_HAPROXY_LB1_PORT": "6443",
"ONEAPP_VNF_HAPROXY_LB2_PORT": "443",
"ONEAPP_VNF_HAPROXY_LB3_PORT": "80",
"ONEAPP_VNF_DNS_ENABLED": "YES",
"ONEAPP_VNF_DNS_INTERFACES": "eth1",
"ONEAPP_VNF_DNS_NAMESERVERS": "1.1.1.1,8.8.8.8",
"ONEAPP_VNF_NAT4_ENABLED": "YES",
"ONEAPP_VNF_NAT4_INTERFACES_OUT": "eth0",
"ONEAPP_VNF_ROUTER4_ENABLED": "YES",
"ONEAPP_VNF_ROUTER4_INTERFACES": "eth0,eth1"
}

DEFAULT_PRIVATE_VNET = """
NAME = "private-oneke"
VN_MAD = "bridge"
AUTOMATIC_VLAN_ID = "YES"
AR = [TYPE = "IP4", IP = "192.168.150.0", SIZE = "51"]
"""

STATE = {
0: "INIT",
1: "PENDING",
2: "HOLD",
3: "ACTIVE",
4: "STOPPED",
5: "SUSPENDED",
6: "DONE",
8: "POWEROFF",
9: "UNDEPLOYED",
10: "CLONING",
11: "CLONING_FAILURE"
}

LCM_STATE = {
0: "LCM_INIT",
1: "PROLOG",
2: "BOOT",
3: "RUNNING",
4: "MIGRATE",
5: "SAVE_STOP",
6: "SAVE_SUSPEND",
7: "SAVE_MIGRATE",
8: "PROLOG_MIGRATE",
9: "PROLOG_RESUME",
10: "EPILOG_STOP",
11: "EPILOG",
12: "SHUTDOWN",
15: "CLEANUP_RESUBMIT",
16: "UNKNOWN",
17: "HOTPLUG",
18: "SHUTDOWN_POWEROFF",
19: "BOOT_UNKNOWN",
20: "BOOT_POWEROFF",
21: "BOOT_SUSPENDED",
22: "BOOT_STOPPED",
23: "CLEANUP_DELETE",
24: "HOTPLUG_SNAPSHOT",
25: "HOTPLUG_NIC",
26: "HOTPLUG_SAVEAS",
27: "HOTPLUG_SAVEAS_POWEROFF",
28: "HOTPLUG_SAVEAS_SUSPENDED",
29: "SHUTDOWN_UNDEPLOY",
30: "EPILOG_UNDEPLOY",
31: "PROLOG_UNDEPLOY",
32: "BOOT_UNDEPLOY",
33: "HOTPLUG_PROLOG_POWEROFF",
34: "HOTPLUG_EPILOG_POWEROFF",
35: "BOOT_MIGRATE",
36: "BOOT_FAILURE",
37: "BOOT_MIGRATE_FAILURE",
38: "PROLOG_MIGRATE_FAILURE",
39: "PROLOG_FAILURE",
40: "EPILOG_FAILURE",
41: "EPILOG_STOP_FAILURE",
42: "EPILOG_UNDEPLOY_FAILURE",
43: "PROLOG_MIGRATE_POWEROFF",
44: "PROLOG_MIGRATE_POWEROFF_FAILURE",
45: "PROLOG_MIGRATE_SUSPEND",
46: "PROLOG_MIGRATE_SUSPEND_FAILURE",
47: "BOOT_UNDEPLOY_FAILURE",
48: "BOOT_STOPPED_FAILURE",
49: "PROLOG_RESUME_FAILURE",
50: "PROLOG_UNDEPLOY_FAILURE",
51: "DISK_SNAPSHOT_POWEROFF",
52: "DISK_SNAPSHOT_REVERT_POWEROFF",
53: "DISK_SNAPSHOT_DELETE_POWEROFF",
54: "DISK_SNAPSHOT_SUSPENDED",
55: "DISK_SNAPSHOT_REVERT_SUSPENDED",
56: "DISK_SNAPSHOT_DELETE_SUSPENDED",
57: "DISK_SNAPSHOT",
59: "DISK_SNAPSHOT_DELETE",
60: "PROLOG_MIGRATE_UNKNOWN",
61: "PROLOG_MIGRATE_UNKNOWN_FAILURE",
62: "DISK_RESIZE",
63: "DISK_RESIZE_POWEROFF",
64: "DISK_RESIZE_UNDEPLOYED",
65: "HOTPLUG_NIC_POWEROFF",
66: "HOTPLUG_RESIZE",
67: "HOTPLUG_SAVEAS_UNDEPLOYED",
68: "HOTPLUG_SAVEAS_STOPPED",
69: "BACKUP",
70: "BACKUP_POWEROFF"
}

# Add OpenNebula defaults
DEFAULT_CONFIG_KEYS.update({
'timeout': 600,
'kubecfg_path': '/tmp/kube_config',
'oneke_config_path': None,
'delete': False,
'minimum_nodes': 0,
'maximum_nodes': -1,
'average_job_execution': 1,
'auto_scale': 'all',
})


def load_config(config_data):
if 'oneke_config' in config_data['one']:
oneke_config = config_data['one']['oneke_config']

# Validate mandatory params
for key in MANDATORY_CONFIG_KEYS:
if key not in oneke_config:
raise OneConfigError(f"'{key}' is missing in 'oneke_config'")
public_network_id = oneke_config['public_network_id']
private_network_id = oneke_config['private_network_id']

# Optional params
name = oneke_config.get('name', 'OneKE for lithops')
custom_attrs_values = {key: oneke_config.get(key, default_value)
for key, default_value in OPTIONAL_CONFIG_KEYS.items()}

oneke_update = {
"name": name,
"networks_values": [
{"Public": {"id": str(public_network_id)}},
{"Private": {"id": str(private_network_id)}}
],
"custom_attrs_values": custom_attrs_values
}
# Override oneke_config with a valid JSON to update the service
config_data['one']['oneke_config'] = json.dumps(oneke_update)

# Load default config
for key in DEFAULT_CONFIG_KEYS:
if key not in config_data['one']:
config_data['one'][key] = DEFAULT_CONFIG_KEYS[key]

# Ensure 'k8s' key exists and is a dictionary
if 'k8s' not in config_data or config_data['k8s'] is None:
config_data['k8s'] = {}
config_data['k8s']['docker_user'] = config_data['one']['docker_user']
config_data['k8s']['docker_password'] = config_data['one']['docker_password']

# Load k8s default config
original_load_config(config_data)
Loading
Loading