From db35c133092a30234241d8bd19ad3d21e8628fca Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Tue, 22 Mar 2022 17:20:19 +0200 Subject: [PATCH 01/20] clean code "flake8" --- mysql_as_service.py | 353 +++++++++++++++++++++++++------------------- setup.py | 3 +- 2 files changed, 202 insertions(+), 154 deletions(-) diff --git a/mysql_as_service.py b/mysql_as_service.py index 8a18481..1de704a 100644 --- a/mysql_as_service.py +++ b/mysql_as_service.py @@ -1,24 +1,15 @@ #!/usr/bin/env/python -from dataclasses import replace -import json -from multiprocessing.spawn import old_main_modules from requests.structures import CaseInsensitiveDict import requests import os -import subprocess -import sys # for input args from minio import Minio -from minio.error import S3Error - menu_options = { 1: 'Install MySQL-Operator', 2: 'Create MySQL-Cluster', 3: 'Create Cluster from existing backup', -# 4: 'Create Database inside your cluster', 4: 'List Your Clusters', - 5: 'Edit Cluster', # change backup , change replica + 5: 'Edit Cluster', # change backup , change replica 6: 'Remove Cluster', -# 6: 'List Databases', 7: 'List Backups', 8: 'Exit', } @@ -29,16 +20,19 @@ menu_edit_cluster = { 2: 'Change backup schedule', } + def print_menu(): for key in menu_options.keys(): - print (key, '--', menu_options[key] ) + print(key, '--', menu_options[key]) def print_edit_cluster_menu(): for key in menu_edit_cluster.keys(): - print (key, '--', menu_edit_cluster[key] ) + print(key, '--', menu_edit_cluster[key]) -def create_server_pool_lb(api_url,customer_id,cloudspace_id,cluster_name,node_port,jwt): + +def create_server_pool_lb(api_url, customer_id, cloudspace_id, + cluster_name, node_port, jwt): # Create server pool and Loadbalancer using API # make session headers = CaseInsensitiveDict() @@ -46,9 +40,10 @@ def create_server_pool_lb(api_url,customer_id,cloudspace_id,cluster_name,node_po headers["Authorization"] = "Bearer {}".format(jwt) ################################################## - print ("Creating serverpool...") + print("Creating serverpool...") # Create ServerPool - serverpool_api = f"https://{api_url}/alpha/customers/{customer_id}/cloudspaces/{cloudspace_id}/ingress/server-pools?name={cluster_name}" + serverpool_api = f"https://{api_url}/alpha/customers/{customer_id}/cloudspaces/{cloudspace_id}\ +/ingress/server-pools?name={cluster_name}" # Make API request to create Serverpool create_serverpool = requests.post(serverpool_api, headers=headers) @@ -56,11 +51,12 @@ def create_server_pool_lb(api_url,customer_id,cloudspace_id,cluster_name,node_po # save serverpool id to var "serverpool_id" serverpool_id = serverpool['id'] - print (f"ServerPool Status {create_serverpool.status_code}") + print(f"ServerPool Status {create_serverpool.status_code}") print("Add kubernetes hosts to serverpool...") - # get workers IPs - k8s_node_ip = f"kubectl get node -o json | jq '.items[] | .status.addresses[0].address'" + # get workers IPs + k8s_node_ip = "kubectl get node -o json | jq '.items[] |\ +.status.addresses[0].address'" output = os.popen(k8s_node_ip).read() # Save output to lines "split them line by line" lines = output.splitlines() @@ -68,68 +64,72 @@ def create_server_pool_lb(api_url,customer_id,cloudspace_id,cluster_name,node_po for ip_count in range(len(lines)): # remove "" from output ip = lines[ip_count].replace('"', "") - #print (ip) + # print (ip) # API URL for post request to add host to server pool - add_host_to_serverpool_api = f"https://{api_url}/alpha/customers/{customer_id}/cloudspaces/{cloudspace_id}/ingress/server-pools/{serverpool_id}/hosts?address={ip}" - + add_host_to_serverpool_api = f"https://{api_url}/alpha/customers/\ +{customer_id}/cloudspaces/{cloudspace_id}/\ +ingress/server-pools/{serverpool_id}/\ +hosts?address={ip}" # Create API request to add host to server pool add_host = requests.post(add_host_to_serverpool_api, headers=headers) - print (add_host.json()) + print(add_host.json()) - print (f"Add hosts to ServerPool Status {add_host.status_code}") + print(f"Add hosts to ServerPool Status {add_host.status_code}") ################################################## # Create LB - print ("Creating LoadBalancer...") - lb_api = f"https://{api_url}/alpha/customers/{customer_id}/cloudspaces/{cloudspace_id}/ingress/load-balancers" + print("Creating LoadBalancer...") + lb_api = f"https://{api_url}/alpha/customers/{customer_id}/cloudspaces/\ +{cloudspace_id}/ingress/load-balancers" # Create MySQL LB create_mysql_lb = requests.post(lb_api, headers=headers, json={ - "name": f"{cluster_name}", - "description": "string", - "type": "TCP", - "front_end": { - "port": node_port, - "tls": { - "is_enabled": False, - "domain": "string", - "tls_termination": False + "name": f"{cluster_name}", + "description": "string", + "type": "TCP", + "front_end": { + "port": node_port, + "tls": { + "is_enabled": False, + "domain": "string", + "tls_termination": False + } + }, + "back_end": { + "serverpool_id": f"{serverpool_id}", + "target_port": node_port } - }, - "back_end": { - "serverpool_id": f"{serverpool_id}", - "target_port": node_port - } - }) + }) print(create_mysql_lb.json()) -def create_bucket(s3_url,s3_port,s3_access_key,s3_secret_key,mybucket): + +def create_bucket(s3_url, s3_port, s3_access_key, s3_secret_key, mybucket): endpoint_url = f"{s3_url}:{s3_port}" s3_access = f"{s3_access_key}" s3_secret = f"{s3_secret_key}" client = Minio( - endpoint=endpoint_url, - secure=True, - access_key=s3_access, - secret_key=s3_secret + endpoint=endpoint_url, + secure=True, + access_key=s3_access, + secret_key=s3_secret ) found = client.bucket_exists(mybucket) if not found: client.make_bucket(mybucket) - print(f"Bucket {mybucket} has been created") + print(f"Bucket {mybucket} has been created") else: print(f"Bucket {mybucket} already exists") -def test_s3_connection(s3_url,s3_port,s3_access_key,s3_secret_key): +def test_s3_connection(s3_url, s3_port, s3_access_key, s3_secret_key): endpoint_url = f"{s3_url}:{s3_port}" s3_access = f"{s3_access_key}" s3_secret = f"{s3_secret_key}" client = Minio( - endpoint=endpoint_url, - secure=True, - access_key=s3_access, - secret_key=s3_secret + endpoint=endpoint_url, + secure=True, + access_key=s3_access, + secret_key=s3_secret ) try: client.list_buckets() @@ -139,16 +139,19 @@ def test_s3_connection(s3_url,s3_port,s3_access_key,s3_secret_key): print("Object storage not reachable") exit(0) + def install_mysql_operator(): print('Installing MySQL-Operator...') - add_helm_repo = f'helm repo add bitpoke https://helm-charts.bitpoke.io' - output = os.popen(add_helm_repo).read() - update_helm_repo = f'helm repo update' - output = os.popen(update_helm_repo).read() - install_mysql_operator = f"helm install mysql-operator bitpoke/mysql-operator" - output = os.popen(install_mysql_operator).read() - #print (output) - print ("MySQL-Operator is installed") + add_helm_repo = 'helm repo add bitpoke https://helm-charts.bitpoke.io' + os.popen(add_helm_repo).read() + update_helm_repo = 'helm repo update' + os.popen(update_helm_repo).read() + install_mysql_operator = "helm install mysql-operator\ +bitpoke/mysql-operator" + os.popen(install_mysql_operator).read() + # print (output) + print("MySQL-Operator is installed") + def create_cluster(): print('Create MySQL-Cluster') @@ -163,24 +166,28 @@ def create_cluster(): node_port = int(input("MySQL NodePort [30000-32767]: ")) pvc_size = input("Cluster Size (Gi): ") answer = None - while answer not in ("yes", "no", "y", "Y", "n", "N"): + while answer not in ("yes", "no", "y", "Y", "n", "N"): answer = input("Enable Auto backup ? [yes/no]: ") - if answer == "yes" or answer == "y" or answer == "Y": + if answer == "yes" or answer == "y" or answer == "Y": backup_schedule = None - while backup_schedule not in ("daily", "weekly", "monthly", "yearly", "d", "D", "w", "W", "m", "M", "y", "Y", "custom", "c", "C"): - backup_schedule = input("Backup Schedule [daily/weekly/monthly/yearly/custom]: ") - if backup_schedule == "daily" or backup_schedule == "d" or backup_schedule == "D" : + while backup_schedule not in ("daily", "weekly", "monthly", + "yearly", "d", "D", "w", "W", "m", + "M", "y", "Y", "custom", "c", "C"): + backup_schedule = input("Backup Schedule [daily/weekly/\ +monthly/yearly/custom]: ") + if backup_schedule == "daily" or backup_schedule == "d" or\ + backup_schedule == "D": my_backup_schedule = "0 0 * * * *" backup_history_limit = input("Number of backups limit: ") - #print(f'"{my_backup_schedule}"') + # print(f'"{my_backup_schedule}"') s3_url = input("Object storage URL: ") s3_port = input("Object storage port: ") s3_access_key = input("Object storage access key: ") s3_secret_key = input("Object storage secret key: ") mybucket = input("Bucket Name: ") - #test_s3_connection(s3_url,s3_port,s3_access_key,s3_secret_key) - #break - elif backup_schedule == "weekly" or backup_schedule == "w" or backup_schedule == "W" : + # break + elif backup_schedule == "weekly" or backup_schedule == "w" or\ + backup_schedule == "W": my_backup_schedule = "0 0 0 * * 0" backup_history_limit = input("Number of backups limit: ") s3_url = input("Object storage URL: ") @@ -188,26 +195,29 @@ def create_cluster(): s3_access_key = input("Object storage access key: ") s3_secret_key = input("Object storage secret key: ") mybucket = input("Bucket Name: ") - #break - elif backup_schedule == "monthly" or backup_schedule == "m" or backup_schedule == "M" : - my_backup_schedule= "0 0 0 1 * *" + # break + elif backup_schedule == "monthly" or backup_schedule == "m" or\ + backup_schedule == "M": + my_backup_schedule = "0 0 0 1 * *" backup_history_limit = input("Number of backups limit: ") s3_url = input("Object storage URL: ") s3_port = input("Object storage port: ") s3_access_key = input("Object storage access key: ") s3_secret_key = input("Object storage secret key: ") mybucket = input("Bucket Name: ") - #break - elif backup_schedule == "yearly" or backup_schedule == "y" or backup_schedule == "Y": - my_backup_schedule= "15 0 0 1 1 *" + # break + elif backup_schedule == "yearly" or backup_schedule == "y" or\ + backup_schedule == "Y": + my_backup_schedule = "15 0 0 1 1 *" backup_history_limit = input("Number of backups limit: ") s3_url = input("Object storage URL: ") s3_port = input("Object storage port: ") s3_access_key = input("Object storage access key: ") s3_secret_key = input("Object storage secret key: ") mybucket = input("Bucket Name: ") - #break - elif backup_schedule == "custom" or backup_schedule == "c" or backup_schedule == "C": + # break + elif backup_schedule == "custom" or backup_schedule == "c" or\ + backup_schedule == "C": my_backup_schedule = input("Custom backup cronjob: ") backup_history_limit = input("Number of backups limit: ") s3_url = input("Object storage URL: ") @@ -215,35 +225,54 @@ def create_cluster(): s3_access_key = input("Object storage access key: ") s3_secret_key = input("Object storage secret key: ") mybucket = input("Bucket Name: ") - #break + # break else: print("Error please enter correct value") - ## Test S3 - test_s3_connection(s3_url,s3_port,s3_access_key,s3_secret_key) - create_bucket(s3_url,s3_port,s3_access_key,s3_secret_key,mybucket) - #### DEF CREATE SERVER POOL & LB - create_server_pool_lb(api_url,customer_id,cloudspace_id,cluster_name,node_port,jwt) + # Test S3 + test_s3_connection(s3_url, s3_port, s3_access_key, s3_secret_key) + create_bucket(s3_url, s3_port, s3_access_key, + s3_secret_key, mybucket) + # DEF CREATE SERVER POOL & LB + create_server_pool_lb(api_url, customer_id, cloudspace_id, + cluster_name, node_port, jwt) # Deploy cluster with backup print("Deploying your cluster with auto backup...") - command2 = f'helm install {cluster_name} ./mysql-cluster --set replicas={replica} --set rootPassword={root_password} --set mysqlnodeport={node_port} --set backupSchedule="{my_backup_schedule}" --set backupScheduleJobsHistoryLimit={backup_history_limit} --set backupRemoteDeletePolicy=delete --set backupURL="s3://{mybucket}/" --set backupCredentials.AWS_ACCESS_KEY_ID="{s3_access_key}" --set backupCredentials.AWS_SECRET_ACCESS_KEY="{s3_secret_key}" --set backupCredentials.S3_PROVIDER=Minio --set backupCredentials.S3_ENDPOINT=https://{s3_url} --set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi ' + command2 = f'helm install {cluster_name} ./mysql-cluster --set replicas={replica} \ +--set rootPassword={root_password} \ +--set mysqlnodeport={node_port} \ +--set backupSchedule="{my_backup_schedule}" \ +--set backupScheduleJobsHistoryLimit={backup_history_limit} \ +--set backupRemoteDeletePolicy=delete \ +--set backupURL="s3://{mybucket}/" \ +--set backupCredentials.AWS_ACCESS_KEY_ID="{s3_access_key}" \ +--set backupCredentials.AWS_SECRET_ACCESS_KEY="{s3_secret_key}" \ +--set backupCredentials.S3_PROVIDER=Minio \ +--set backupCredentials.S3_ENDPOINT=https://{s3_url} \ +--set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi' output2 = os.popen(command2).read() - print (output2) - print(f"Please wait until the cluster becomes ready...") + print(output2) + print("Please wait until the cluster becomes ready...") print(f"Access your cluster with port {node_port} \n") elif answer == "no" or answer == "n" or answer == "N": - #print(f"OUT") - #### Deploy cluster without backup - #### DEF CREATE SERVER POOL & LB - create_server_pool_lb(api_url,customer_id,cloudspace_id,cluster_name,node_port,jwt) + # print(f"OUT") + # Deploy cluster without backup + # DEF CREATE SERVER POOL & LB + create_server_pool_lb(api_url, customer_id, cloudspace_id, + cluster_name, node_port, jwt) # Deploy mysql cluster without backup print("Deploying your cluster...") - command = f"helm install {cluster_name} ./mysql-cluster --set replicas={replica} --set rootPassword={root_password} --set mysqlnodeport={node_port} --set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi" + command = f"helm install {cluster_name} ./mysql-cluster \ +--set replicas={replica} \ +--set rootPassword={root_password} \ +--set mysqlnodeport={node_port} \ +--set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi" output = os.popen(command).read() - print (output) - print(f"Please wait until the cluster becomes ready...") + print(output) + print("Please wait until the cluster becomes ready...") print(f"Access your cluster with port {node_port} \n") - else: - print("Please enter yes or no.") + else: + print("Please enter yes or no.") + def create_cluster_from_backup(): print('Create Cluster from existing backup') @@ -259,27 +288,37 @@ def create_cluster_from_backup(): node_port = int(input("MySQL NodePort [30000-32767]: ")) pvc_size = input("Cluster Size (Gi): ") list_backups() - #mybucket = input("Bucket Name: ") -# backup_file_name = input("Backup File Name: ") + # mybucket = input("Bucket Name: ") + # backup_file_name = input("Backup File Name: ") backup_number = int(input("Enter your backup number: ")) - #print (mydict[backup_number]) + # print (mydict[backup_number]) backup_file_name = mydict[backup_number] - print (f"You select {backup_file_name}") + print(f"You select {backup_file_name}") backup_bucket_url = f's3://{mybucket}/{backup_file_name}' - #s3_access_key = input("Object storage access key: ") - #s3_secret_key = input("Object storage secret key: ") - #s3_url = input("Object storage URL: ") + # s3_access_key = input("Object storage access key: ") + # s3_secret_key = input("Object storage secret key: ") + # s3_url = input("Object storage URL: ") s3_url = s3_endpoint - #### DEF CREATE SERVER POOL & LB - create_server_pool_lb(api_url,customer_id,cloudspace_id,cluster_name,node_port,jwt) + # DEF CREATE SERVER POOL & LB + create_server_pool_lb(api_url, customer_id, cloudspace_id, + cluster_name, node_port, jwt) # Deploy your cluster .. print("Deploying your cluster...") - command = f'helm install {cluster_name} ./mysql-cluster --set replicas={replica} --set rootPassword={root_password} --set mysqlnodeport={node_port} --set initBucketURL={backup_bucket_url} --set backupCredentials.AWS_ACCESS_KEY_ID="{s3_access_key}" --set backupCredentials.AWS_SECRET_ACCESS_KEY="{s3_secret_key}" --set backupCredentials.S3_PROVIDER=Minio --set backupCredentials.S3_ENDPOINT=https://{s3_url} --set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi ' + command = f'helm install {cluster_name} ./mysql-cluster \ +--set replicas={replica} --set rootPassword={root_password} \ +--set mysqlnodeport={node_port} \ +--set initBucketURL={backup_bucket_url} \ +--set backupCredentials.AWS_ACCESS_KEY_ID="{s3_access_key}" \ +--set backupCredentials.AWS_SECRET_ACCESS_KEY="{s3_secret_key}" \ +--set backupCredentials.S3_PROVIDER=Minio \ +--set backupCredentials.S3_ENDPOINT=https://{s3_url} \ +--set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi' output = os.popen(command).read() - print (output) - print(f"Please wait until the cluster becomes ready...") + print(output) + print("Please wait until the cluster becomes ready...") print(f"Access your cluster with port {node_port}") + def edit_cluster(): print('Edit your cluster') cluster_name = input("Cluster Name: ") @@ -290,87 +329,95 @@ def edit_cluster(): option = int(input('Choice: ')) except: print('Wrong input. Please enter a number ...') - #Check what choice was entered and act accordingly + # Check what choice was entered and act accordingly if option == 1: - #print('1') - replica_num = input("Number of replicas:" ) - command = f'kubectl scale --replicas={replica_num} mysqlcluster {cluster_name}' + # print('1') + replica_num = input("Number of replicas:") + command = f'kubectl scale --replicas={replica_num}\ + mysqlcluster {cluster_name}' output = os.popen(command).read() - print (output) - break; + print(output) + break elif option == 2: - #print('2') - get_cluster_yaml = f'kubectl get mysqlcluster {cluster_name} -o yaml > {cluster_name}.yaml ' + # print('2') + get_cluster_yaml = f'kubectl get mysqlcluster {cluster_name}\ + -o yaml > {cluster_name}.yaml ' output = os.popen(get_cluster_yaml).read() - cronjob_input = input("Custom Cronjob:" ) - cronjob = f"'\{cronjob_input}'" - # replace cronjob - replace_cronjob = f'sed -i "s/backupSchedule.*/backupSchedule: {cronjob}/g" {cluster_name}.yaml' + cronjob_input = input("Custom Cronjob:") + cronjob = f"'{cronjob_input}'" + # replace cronjob + replace_cronjob = f'sed -i "s/backupSchedule.*/backupSchedule: {cronjob}/g"\ + {cluster_name}.yaml' output = os.popen(replace_cronjob).read() apply_changes = f'kubectl apply -f {cluster_name}.yaml' output = os.popen(apply_changes).read() - print (output) - break; + print(output) + break else: print('Invalid option. Please enter a number between 1 and 2.') + def list_clusters(): - print ("List clusters....") - list_helm_deployment = f'helm list -A | grep cluster-0.3.1' + print("List clusters....") + list_helm_deployment = 'helm list -A | grep cluster-0.3.1' output = os.popen(list_helm_deployment).read() firstline = True # Print only first column "deployment name" for line in output.splitlines(): - if firstline: #skip first line + if firstline: # skip first line firstline = False - #continue + # continue fields = line.split() deployment_name = fields[0] - print (f'helm deployment name: {deployment_name}') - list_deployment_resources = f'helm get all {deployment_name} | grep -e mysql.presslabs.org/cluster -e nodePort | sed "s/mysql.presslabs.org\///g" | sed "s/node//g"' + print(f'helm deployment name: {deployment_name}') + list_deployment_resources = f'helm get all {deployment_name} | \ + grep -e mysql.presslabs.org/cluster -e nodePort | \ + sed "s/mysql.presslabs.org.*:/Cluster:/g" | sed "s/node//g"' output = os.popen(list_deployment_resources).read() - print (output) + print(output) + def remove_cluster(): - list_helm_deployment = f'helm list -A | grep cluster-0.3.1' + list_helm_deployment = 'helm list -A | grep cluster-0.3.1' output = os.popen(list_helm_deployment).read() # Print only first column "deployment name" for line in output.splitlines(): fields = line.split() if len(fields) >= 1: - print (fields[0]) + print(fields[0]) deployment_name = input("Deployment Name to be remove: ") if input("are you sure to delete? (y/n) ") != "y": exit() - delete_deployment = f'helm delete {deployment_name}' + delete_deployment = f'helm delete {deployment_name}' output = os.popen(delete_deployment).read() - print (output) + print(output) + def list_backups(): print('List Backups from Object Storage...') - global mybucket,s3_endpoint,s3_port,s3_access_key,s3_secret_key + global mybucket, s3_endpoint, s3_port, s3_access_key, s3_secret_key s3_endpoint = input("Object storage endpoint: ") - s3_port = input("Object storage port: ") + s3_port = input("Object storage port: ") s3_access_key = input("Object storage access key: ") s3_secret_key = input("Object storage secret key: ") mybucket = input("Bucket Name: ") endpoint_url = f"{s3_endpoint}:{s3_port}" s3_access = f"{s3_access_key}" s3_secret = f"{s3_secret_key}" - #print (endpoint_url,s3_access,s3_secret) - #list_buckets = f"'{mybucket}', prefix=None, recursive=True" - #print (list_buckets) + # print (endpoint_url,s3_access,s3_secret) + # list_buckets = f"'{mybucket}', prefix=None, recursive=True" + # print (list_buckets) client = Minio( - endpoint=endpoint_url, - secure=True, - access_key=s3_access, - secret_key=s3_secret + endpoint=endpoint_url, + secure=True, + access_key=s3_access, + secret_key=s3_secret ) - index = 0 # start index with 0 + index = 0 # start index with 0 global mydict - mydict= {} # empty dic - ## List Objects + mydict = {} # empty dic + # List Objects objects = client.list_objects(mybucket, prefix=None, recursive=True) for obj in objects: # Save index and file backup name @@ -380,8 +427,9 @@ def list_backups(): # Print index, file backup name print(backup_list) index += 1 - #backup_number = int(input("Enter your backup number: ")) - #return (mydict[backup_number]) + # backup_number = int(input("Enter your backup number: ")) + # return (mydict[backup_number]) + if __name__ == '__main__': while(True): @@ -391,20 +439,20 @@ if __name__ == '__main__': option = int(input('Enter your choice: ')) except: print('Wrong input. Please enter a number ...') - #Check what choice was entered and act accordingly + # Check what choice was entered and act accordingly if option == 1: - install_mysql_operator() - #break; + install_mysql_operator() + # break; elif option == 2: create_cluster() elif option == 3: create_cluster_from_backup() -# elif option == 4: -# create_database() + # elif option == 4: + # create_database() elif option == 4: list_clusters() -# elif option == 6: -# list_databases() + # elif option == 6: + # list_databases() elif option == 5: edit_cluster() elif option == 6: @@ -416,4 +464,3 @@ if __name__ == '__main__': exit() else: print('Invalid option. Please enter a number between 1 and 8.') - diff --git a/setup.py b/setup.py index d7c660c..cabb733 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,8 @@ from setuptools import setup, find_packages NAME = "kmm" VERSION = subprocess.run( - "cat VERSION || git describe --tags 2>/dev/null || git branch | grep \\* | cut -d ' ' -f2", + "cat VERSION || git describe --tags 2>/dev/null || \ + git branch | grep \\* | cut -d ' ' -f2", shell=True, stdout=subprocess.PIPE, ).stdout.decode("utf8") -- GitLab From 0fd33123b82804b6bfbc9255053bf5f76e23b081 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Tue, 22 Mar 2022 17:24:55 +0200 Subject: [PATCH 02/20] test s3 connections --- mysql_as_service.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql_as_service.py b/mysql_as_service.py index 1de704a..a46b5f2 100644 --- a/mysql_as_service.py +++ b/mysql_as_service.py @@ -404,6 +404,7 @@ def list_backups(): endpoint_url = f"{s3_endpoint}:{s3_port}" s3_access = f"{s3_access_key}" s3_secret = f"{s3_secret_key}" + test_s3_connection(s3_endpoint, s3_port, s3_access_key, s3_secret_key) # print (endpoint_url,s3_access,s3_secret) # list_buckets = f"'{mybucket}', prefix=None, recursive=True" # print (list_buckets) -- GitLab From 8fb2c29c6fa4771dd1ad00d63a461d266e9503a5 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Tue, 22 Mar 2022 17:32:01 +0200 Subject: [PATCH 03/20] add except Exception --- mysql_as_service.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mysql_as_service.py b/mysql_as_service.py index a46b5f2..f503483 100644 --- a/mysql_as_service.py +++ b/mysql_as_service.py @@ -1,4 +1,5 @@ #!/usr/bin/env/python +# from optparse import OptionError from requests.structures import CaseInsensitiveDict import requests import os @@ -135,7 +136,7 @@ def test_s3_connection(s3_url, s3_port, s3_access_key, s3_secret_key): client.list_buckets() print("Object storage connected") - except: + except Exception: print("Object storage not reachable") exit(0) @@ -327,7 +328,7 @@ def edit_cluster(): option = '' try: option = int(input('Choice: ')) - except: + except Exception: print('Wrong input. Please enter a number ...') # Check what choice was entered and act accordingly if option == 1: @@ -438,7 +439,7 @@ if __name__ == '__main__': option = '' try: option = int(input('Enter your choice: ')) - except: + except Exception: print('Wrong input. Please enter a number ...') # Check what choice was entered and act accordingly if option == 1: -- GitLab From 2fb2f05d16e1c8049d7c33eea12af86329b4b900 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 11:32:11 +0200 Subject: [PATCH 04/20] add - publish-pypi stage --- .gitlab-ci.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9e6caf5..d5a65e2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ stages: - lint - + - publish-pypi include: - project: "gig-meneja/infrastructure" ref: master @@ -31,3 +31,23 @@ black: - blackcheck only: - merge_requests +publish-pypi: + stage: publish-pypi + image: python:3.8-slim + only: + - tags + script: + - apt-get update + - apt-get install git -y -q + - echo "[distutils]" > ~/.pypirc + - echo "index-servers =" >> ~/.pypirc + - echo " gig" >> ~/.pypirc + - echo "" >> ~/.pypirc + - echo "[gig]" >> ~/.pypirc + - 'echo "repository: https://pypi.gig.tech" >> ~/.pypirc' + - 'echo "username: ${PYPI_USER}" >> ~/.pypirc' + - 'echo "password: ${PYPI_PASSWORD}" >> ~/.pypirc' + - pip install twine + - echo "$CI_COMMIT_TAG" > VERSION + - python setup.py sdist + - twine upload --repository gig dist/* \ No newline at end of file -- GitLab From 98b6ba76b4a1f66fa92a8a82aea4f87db7d2921a Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 11:33:10 +0200 Subject: [PATCH 05/20] chnage pypi repo --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d5a65e2..e341cfd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,7 +44,7 @@ publish-pypi: - echo " gig" >> ~/.pypirc - echo "" >> ~/.pypirc - echo "[gig]" >> ~/.pypirc - - 'echo "repository: https://pypi.gig.tech" >> ~/.pypirc' + - 'echo "repository: https://test.pypi.org" >> ~/.pypirc' - 'echo "username: ${PYPI_USER}" >> ~/.pypirc' - 'echo "password: ${PYPI_PASSWORD}" >> ~/.pypirc' - pip install twine -- GitLab From ada39e5df3f365c57ea355cf4013a9b729150408 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 11:35:27 +0200 Subject: [PATCH 06/20] push --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e341cfd..7ed6a36 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ stages: - lint - publish-pypi + include: - project: "gig-meneja/infrastructure" ref: master -- GitLab From 0536479054e4610ed92c82a0e6792d33d5e13163 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 11:38:52 +0200 Subject: [PATCH 07/20] change pypi api url "test" --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7ed6a36..1208882 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ stages: - lint - publish-pypi - + include: - project: "gig-meneja/infrastructure" ref: master @@ -45,7 +45,7 @@ publish-pypi: - echo " gig" >> ~/.pypirc - echo "" >> ~/.pypirc - echo "[gig]" >> ~/.pypirc - - 'echo "repository: https://test.pypi.org" >> ~/.pypirc' + - 'echo "repository: https://test.pypi.org/legacy/" >> ~/.pypirc' - 'echo "username: ${PYPI_USER}" >> ~/.pypirc' - 'echo "password: ${PYPI_PASSWORD}" >> ~/.pypirc' - pip install twine -- GitLab From b1d84bfa9209373845a7488c211b3fc684c99047 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 12:58:47 +0200 Subject: [PATCH 08/20] create folder kmm --- .gitlab-ci.yml | 1 - {mysql-cluster => kmm/mysql-cluster}/.helmignore | 0 {mysql-cluster => kmm/mysql-cluster}/Chart.yaml | 0 {mysql-cluster => kmm/mysql-cluster}/templates/NodePort.yaml | 0 {mysql-cluster => kmm/mysql-cluster}/templates/_helpers.tpl | 0 .../mysql-cluster}/templates/backup-secret.yaml | 0 {mysql-cluster => kmm/mysql-cluster}/templates/cluster.yaml | 0 {mysql-cluster => kmm/mysql-cluster}/templates/secret.yaml | 0 {mysql-cluster => kmm/mysql-cluster}/values.yaml | 0 mysql_as_service.py => kmm/mysql_as_service.py | 0 10 files changed, 1 deletion(-) rename {mysql-cluster => kmm/mysql-cluster}/.helmignore (100%) rename {mysql-cluster => kmm/mysql-cluster}/Chart.yaml (100%) rename {mysql-cluster => kmm/mysql-cluster}/templates/NodePort.yaml (100%) rename {mysql-cluster => kmm/mysql-cluster}/templates/_helpers.tpl (100%) rename {mysql-cluster => kmm/mysql-cluster}/templates/backup-secret.yaml (100%) rename {mysql-cluster => kmm/mysql-cluster}/templates/cluster.yaml (100%) rename {mysql-cluster => kmm/mysql-cluster}/templates/secret.yaml (100%) rename {mysql-cluster => kmm/mysql-cluster}/values.yaml (100%) rename mysql_as_service.py => kmm/mysql_as_service.py (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1208882..3c866c2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,6 @@ stages: - lint - publish-pypi - include: - project: "gig-meneja/infrastructure" ref: master diff --git a/mysql-cluster/.helmignore b/kmm/mysql-cluster/.helmignore similarity index 100% rename from mysql-cluster/.helmignore rename to kmm/mysql-cluster/.helmignore diff --git a/mysql-cluster/Chart.yaml b/kmm/mysql-cluster/Chart.yaml similarity index 100% rename from mysql-cluster/Chart.yaml rename to kmm/mysql-cluster/Chart.yaml diff --git a/mysql-cluster/templates/NodePort.yaml b/kmm/mysql-cluster/templates/NodePort.yaml similarity index 100% rename from mysql-cluster/templates/NodePort.yaml rename to kmm/mysql-cluster/templates/NodePort.yaml diff --git a/mysql-cluster/templates/_helpers.tpl b/kmm/mysql-cluster/templates/_helpers.tpl similarity index 100% rename from mysql-cluster/templates/_helpers.tpl rename to kmm/mysql-cluster/templates/_helpers.tpl diff --git a/mysql-cluster/templates/backup-secret.yaml b/kmm/mysql-cluster/templates/backup-secret.yaml similarity index 100% rename from mysql-cluster/templates/backup-secret.yaml rename to kmm/mysql-cluster/templates/backup-secret.yaml diff --git a/mysql-cluster/templates/cluster.yaml b/kmm/mysql-cluster/templates/cluster.yaml similarity index 100% rename from mysql-cluster/templates/cluster.yaml rename to kmm/mysql-cluster/templates/cluster.yaml diff --git a/mysql-cluster/templates/secret.yaml b/kmm/mysql-cluster/templates/secret.yaml similarity index 100% rename from mysql-cluster/templates/secret.yaml rename to kmm/mysql-cluster/templates/secret.yaml diff --git a/mysql-cluster/values.yaml b/kmm/mysql-cluster/values.yaml similarity index 100% rename from mysql-cluster/values.yaml rename to kmm/mysql-cluster/values.yaml diff --git a/mysql_as_service.py b/kmm/mysql_as_service.py similarity index 100% rename from mysql_as_service.py rename to kmm/mysql_as_service.py -- GitLab From a96002ad7c1569393ae8be9e30efd689ed0caf9a Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 13:50:31 +0200 Subject: [PATCH 09/20] push to pypi prd --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3c866c2..8fdc576 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,7 +44,7 @@ publish-pypi: - echo " gig" >> ~/.pypirc - echo "" >> ~/.pypirc - echo "[gig]" >> ~/.pypirc - - 'echo "repository: https://test.pypi.org/legacy/" >> ~/.pypirc' + - 'echo "repository: https://upload.pypi.org/legacy/" >> ~/.pypirc' - 'echo "username: ${PYPI_USER}" >> ~/.pypirc' - 'echo "password: ${PYPI_PASSWORD}" >> ~/.pypirc' - pip install twine -- GitLab From 84cc6a15ac553df2b5e63ba46133e02e8bae7539 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 13:54:12 +0200 Subject: [PATCH 10/20] push to pypi --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8fdc576..f8fa89b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ stages: - lint - publish-pypi + include: - project: "gig-meneja/infrastructure" ref: master -- GitLab From 0fe9619ad3f4f6568d1f0c84832eff9e27c2d175 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 14:42:50 +0200 Subject: [PATCH 11/20] change app name to kmm4g --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index cabb733..0cf0081 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ import subprocess from setuptools import setup, find_packages -NAME = "kmm" +NAME = "kmm4g" VERSION = subprocess.run( "cat VERSION || git describe --tags 2>/dev/null || \ git branch | grep \\* | cut -d ' ' -f2", @@ -38,10 +38,10 @@ with open("requirements.txt") as f: setup( name=NAME, version=VERSION, - description="Kubernetes MySQL Manager", + description="Kubernetes MySQL Manager for GIG.tech based clouds.", author_email="abdalluh.mostafa@whitesky.cloud", url="https://gig.tech", - keywords=["kmm"], + keywords=["kmm4g"], install_requires=requirements, packages=find_packages(), python_requires=">=3.8", -- GitLab From 909364eeba727d02262c061b3f1ca45022fbe92b Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 15:22:52 +0200 Subject: [PATCH 12/20] add classifiers --- setup.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 0cf0081..ad0ee3b 100644 --- a/setup.py +++ b/setup.py @@ -39,10 +39,19 @@ setup( name=NAME, version=VERSION, description="Kubernetes MySQL Manager for GIG.tech based clouds.", + author="Abdalluh Mostafa", author_email="abdalluh.mostafa@whitesky.cloud", - url="https://gig.tech", - keywords=["kmm4g"], + url="https://git.gig.tech/a-team/solutions/rancher/kmm4g", + keywords=["kmm4g", "kmm", "Kubernetes", "MySQL", "Manager", "GIG"], install_requires=requirements, packages=find_packages(), python_requires=">=3.8", + classifiers=[ + "Programming Language :: Python :: 3.8", + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: DevOps', + 'Topic :: Software Development :: Build Tools', + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], ) -- GitLab From e5dd128b937c458bba4b5aac34c7d249c02738fb Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 15:23:21 +0200 Subject: [PATCH 13/20] rename to kmm4g --- {kmm => kmm4g}/mysql-cluster/.helmignore | 0 {kmm => kmm4g}/mysql-cluster/Chart.yaml | 0 {kmm => kmm4g}/mysql-cluster/templates/NodePort.yaml | 0 {kmm => kmm4g}/mysql-cluster/templates/_helpers.tpl | 0 {kmm => kmm4g}/mysql-cluster/templates/backup-secret.yaml | 0 {kmm => kmm4g}/mysql-cluster/templates/cluster.yaml | 0 {kmm => kmm4g}/mysql-cluster/templates/secret.yaml | 0 {kmm => kmm4g}/mysql-cluster/values.yaml | 0 {kmm => kmm4g}/mysql_as_service.py | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename {kmm => kmm4g}/mysql-cluster/.helmignore (100%) rename {kmm => kmm4g}/mysql-cluster/Chart.yaml (100%) rename {kmm => kmm4g}/mysql-cluster/templates/NodePort.yaml (100%) rename {kmm => kmm4g}/mysql-cluster/templates/_helpers.tpl (100%) rename {kmm => kmm4g}/mysql-cluster/templates/backup-secret.yaml (100%) rename {kmm => kmm4g}/mysql-cluster/templates/cluster.yaml (100%) rename {kmm => kmm4g}/mysql-cluster/templates/secret.yaml (100%) rename {kmm => kmm4g}/mysql-cluster/values.yaml (100%) rename {kmm => kmm4g}/mysql_as_service.py (100%) diff --git a/kmm/mysql-cluster/.helmignore b/kmm4g/mysql-cluster/.helmignore similarity index 100% rename from kmm/mysql-cluster/.helmignore rename to kmm4g/mysql-cluster/.helmignore diff --git a/kmm/mysql-cluster/Chart.yaml b/kmm4g/mysql-cluster/Chart.yaml similarity index 100% rename from kmm/mysql-cluster/Chart.yaml rename to kmm4g/mysql-cluster/Chart.yaml diff --git a/kmm/mysql-cluster/templates/NodePort.yaml b/kmm4g/mysql-cluster/templates/NodePort.yaml similarity index 100% rename from kmm/mysql-cluster/templates/NodePort.yaml rename to kmm4g/mysql-cluster/templates/NodePort.yaml diff --git a/kmm/mysql-cluster/templates/_helpers.tpl b/kmm4g/mysql-cluster/templates/_helpers.tpl similarity index 100% rename from kmm/mysql-cluster/templates/_helpers.tpl rename to kmm4g/mysql-cluster/templates/_helpers.tpl diff --git a/kmm/mysql-cluster/templates/backup-secret.yaml b/kmm4g/mysql-cluster/templates/backup-secret.yaml similarity index 100% rename from kmm/mysql-cluster/templates/backup-secret.yaml rename to kmm4g/mysql-cluster/templates/backup-secret.yaml diff --git a/kmm/mysql-cluster/templates/cluster.yaml b/kmm4g/mysql-cluster/templates/cluster.yaml similarity index 100% rename from kmm/mysql-cluster/templates/cluster.yaml rename to kmm4g/mysql-cluster/templates/cluster.yaml diff --git a/kmm/mysql-cluster/templates/secret.yaml b/kmm4g/mysql-cluster/templates/secret.yaml similarity index 100% rename from kmm/mysql-cluster/templates/secret.yaml rename to kmm4g/mysql-cluster/templates/secret.yaml diff --git a/kmm/mysql-cluster/values.yaml b/kmm4g/mysql-cluster/values.yaml similarity index 100% rename from kmm/mysql-cluster/values.yaml rename to kmm4g/mysql-cluster/values.yaml diff --git a/kmm/mysql_as_service.py b/kmm4g/mysql_as_service.py similarity index 100% rename from kmm/mysql_as_service.py rename to kmm4g/mysql_as_service.py -- GitLab From b163991323643fba1c0d8b7ef6e60d47d4e250ff Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Wed, 23 Mar 2022 15:30:47 +0200 Subject: [PATCH 14/20] change audience to Developers --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ad0ee3b..3c2a188 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ setup( classifiers=[ "Programming Language :: Python :: 3.8", 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: DevOps', + 'Intended Audience :: Developers', 'Topic :: Software Development :: Build Tools', "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", -- GitLab From 3d8bc2af555e46e420c7ab6faff8eec78411a3fb Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Thu, 24 Mar 2022 12:41:49 +0200 Subject: [PATCH 15/20] add readme for pypi --- setup.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.py b/setup.py index 3c2a188..690bb4f 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,11 @@ import subprocess from setuptools import setup, find_packages +# read the contents of your README file +from pathlib import Path +this_directory = Path(__file__).parent +long_description = (this_directory / "README.md").read_text() + NAME = "kmm4g" VERSION = subprocess.run( "cat VERSION || git describe --tags 2>/dev/null || \ -- GitLab From 434984a79716db4606e2687d8c6b3afb9f971dd0 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Thu, 24 Mar 2022 12:51:21 +0200 Subject: [PATCH 16/20] change to test pypi --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8fa89b..164e4f7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,7 +45,7 @@ publish-pypi: - echo " gig" >> ~/.pypirc - echo "" >> ~/.pypirc - echo "[gig]" >> ~/.pypirc - - 'echo "repository: https://upload.pypi.org/legacy/" >> ~/.pypirc' + - 'echo "repository: https://test.pypi.org/legacy/" >> ~/.pypirc' - 'echo "username: ${PYPI_USER}" >> ~/.pypirc' - 'echo "password: ${PYPI_PASSWORD}" >> ~/.pypirc' - pip install twine -- GitLab From 9de86a99d140153baf477dee8c053d7214970bd1 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Thu, 24 Mar 2022 12:58:07 +0200 Subject: [PATCH 17/20] test.pypi push --- setup.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 690bb4f..aea50e9 100644 --- a/setup.py +++ b/setup.py @@ -17,10 +17,8 @@ import subprocess from setuptools import setup, find_packages -# read the contents of your README file -from pathlib import Path -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() +with open('README.md') as f: + long_description = f.read() NAME = "kmm4g" VERSION = subprocess.run( -- GitLab From eeb109c692233023a50644818e131f721e1b2a06 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Thu, 24 Mar 2022 13:00:49 +0200 Subject: [PATCH 18/20] Add description --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index aea50e9..9f97119 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,8 @@ setup( author_email="abdalluh.mostafa@whitesky.cloud", url="https://git.gig.tech/a-team/solutions/rancher/kmm4g", keywords=["kmm4g", "kmm", "Kubernetes", "MySQL", "Manager", "GIG"], + long_description=long_description, + long_description_content_type='text/markdown', # This is important! install_requires=requirements, packages=find_packages(), python_requires=">=3.8", -- GitLab From 95fa37df71c091376ebd3c96d30b95e8cd8061ba Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Fri, 25 Mar 2022 17:40:09 +0200 Subject: [PATCH 19/20] rename to kmm4g --- kmm/mysql-cluster/.helmignore | 21 - kmm/mysql-cluster/Chart.yaml | 5 - kmm/mysql-cluster/templates/NodePort.yaml | 12 - kmm/mysql-cluster/templates/_helpers.tpl | 49 -- .../templates/backup-secret.yaml | 23 - kmm/mysql-cluster/templates/cluster.yaml | 78 --- kmm/mysql-cluster/templates/secret.yaml | 21 - kmm/mysql-cluster/values.yaml | 73 --- kmm/mysql_as_service.py | 468 ------------------ 9 files changed, 750 deletions(-) delete mode 100644 kmm/mysql-cluster/.helmignore delete mode 100644 kmm/mysql-cluster/Chart.yaml delete mode 100644 kmm/mysql-cluster/templates/NodePort.yaml delete mode 100644 kmm/mysql-cluster/templates/_helpers.tpl delete mode 100644 kmm/mysql-cluster/templates/backup-secret.yaml delete mode 100644 kmm/mysql-cluster/templates/cluster.yaml delete mode 100644 kmm/mysql-cluster/templates/secret.yaml delete mode 100644 kmm/mysql-cluster/values.yaml delete mode 100644 kmm/mysql_as_service.py diff --git a/kmm/mysql-cluster/.helmignore b/kmm/mysql-cluster/.helmignore deleted file mode 100644 index f0c1319..0000000 --- a/kmm/mysql-cluster/.helmignore +++ /dev/null @@ -1,21 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj diff --git a/kmm/mysql-cluster/Chart.yaml b/kmm/mysql-cluster/Chart.yaml deleted file mode 100644 index ff4837c..0000000 --- a/kmm/mysql-cluster/Chart.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: v1 -appVersion: "1.0" -description: A Helm chart for easy deployment of a MySQL cluster with MySQL operator. -name: cluster -version: 0.3.1 \ No newline at end of file diff --git a/kmm/mysql-cluster/templates/NodePort.yaml b/kmm/mysql-cluster/templates/NodePort.yaml deleted file mode 100644 index 8e2582d..0000000 --- a/kmm/mysql-cluster/templates/NodePort.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ .Release.Name }}-{{ template "mysql-cluster.name" . }}-service -spec: - type: NodePort - selector: - mysql.presslabs.org/cluster: {{ .Release.Name }}-{{ template "mysql-cluster.name" . }}-db - ports: - - nodePort: {{ .Values.mysqlnodeport }} - port: 3306 - targetPort: 3306 diff --git a/kmm/mysql-cluster/templates/_helpers.tpl b/kmm/mysql-cluster/templates/_helpers.tpl deleted file mode 100644 index 6f716b6..0000000 --- a/kmm/mysql-cluster/templates/_helpers.tpl +++ /dev/null @@ -1,49 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "mysql-cluster.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "mysql-cluster.fullname" -}} -{{- if .Values.fullnameOverride -}} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- if contains $name .Release.Name -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "mysql-cluster.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - - -{{- define "mysql-cluster.clusterName" -}} -{{- printf "%s-db" (include "mysql-cluster.fullname" .) | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{- define "mysql-cluster.secretName" -}} -{{- printf "%s-db" (include "mysql-cluster.fullname" .) | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{- define "mysql-cluster.backupSecretName" -}} -{{- printf "%s-db-backup" (include "mysql-cluster.fullname" .) | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{- define "mysql-cluster.initBucketSecretName" -}} -{{- printf "%s-db-backup" (include "mysql-cluster.fullname" .) | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/kmm/mysql-cluster/templates/backup-secret.yaml b/kmm/mysql-cluster/templates/backup-secret.yaml deleted file mode 100644 index b549232..0000000 --- a/kmm/mysql-cluster/templates/backup-secret.yaml +++ /dev/null @@ -1,23 +0,0 @@ -{{- if .Values.backupCredentials }} -apiVersion: v1 -kind: Secret -metadata: - name: {{ template "mysql-cluster.backupSecretName" . }} - labels: - app: {{ template "mysql-cluster.name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} - {{- if .Values.backupSecretLabels }} - {{- toYaml .Values.backupSecretLabels | nindent 4 }} - {{- end }} - {{- if .Values.backupSecretAnnotations }} - annotations: - {{ toYaml .Values.backupSecretAnnotations }} - {{- end }} -type: Opaque -data: - {{- range $key, $value := .Values.backupCredentials }} - {{ $key | upper }}: {{ $value | b64enc | quote }} - {{ end }} -{{- end -}} diff --git a/kmm/mysql-cluster/templates/cluster.yaml b/kmm/mysql-cluster/templates/cluster.yaml deleted file mode 100644 index 92e1d1e..0000000 --- a/kmm/mysql-cluster/templates/cluster.yaml +++ /dev/null @@ -1,78 +0,0 @@ -apiVersion: mysql.presslabs.org/v1alpha1 -kind: MysqlCluster -metadata: - name: {{ include "mysql-cluster.clusterName" . }} - labels: - app: {{ template "mysql-cluster.name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} -spec: - replicas: {{ .Values.replicas }} - - {{- if .Values.customSecretName }} - secretName: {{ .Values.customSecretName }} - {{- else }} - secretName: {{ include "mysql-cluster.secretName" . }} - {{- end }} - - {{- if .Values.image }} - image: {{ .Values.image }} - {{- end }} - - {{- if .Values.mysqlVersion }} - mysqlVersion: {{ .Values.mysqlVersion | quote }} - {{- end }} - - {{- if .Values.initBucketURL }} - initBucketURL: {{ .Values.initBucketURL }} - {{- end }} - {{- if .Values.initBucketSecretName }} - initBucketSecretName: {{ .Values.initBucketSecretName }} - {{- else if .Values.backupCredentials }} - initBucketSecretName: {{ include "mysql-cluster.initBucketSecretName" . }} - {{- else if .Values.backupSchedule }} - {{ required "One of .mysql.initBucketSecretName and .mysql.backupCredentials should be specified" "" }} - {{- end }} - - {{- if .Values.backupSecretName }} - backupSecretName: {{ .Values.backupSecretName }} - {{- else if .Values.backupCredentials }} - backupSecretName: {{ include "mysql-cluster.backupSecretName" . }} - {{- else if .Values.backupSchedule }} - {{ required "One of .mysql.backupSecretName and .mysql.backupCredentials should be specified" "" }} - {{- end }} - - {{- if .Values.serverIDOffset }} - serverIDOffset: {{ .Values.serverIDOffset }} - {{- end }} - - {{- if .Values.backupSchedule }} - backupSchedule: "{{ .Values.backupSchedule }}" - backupRemoteDeletePolicy: {{ .Values.backupRemoteDeletePolicy }} - backupURL: {{ required ".mysql.backupURL is missing" .Values.backupURL }} - {{- end }} - {{- if .Values.backupScheduleJobsHistoryLimit }} - backupScheduleJobsHistoryLimit: {{ .Values.backupScheduleJobsHistoryLimit }} - {{- end }} - - {{- if .Values.mysqlConf }} - mysqlConf: - {{- toYaml .Values.mysqlConf | nindent 4 }} - {{- end }} - - {{- if .Values.podSpec }} - podSpec: - {{- toYaml .Values.podSpec | nindent 4 }} - {{- end }} - - {{- if .Values.volumeSpec }} - volumeSpec: - {{- toYaml .Values.volumeSpec | nindent 4 }} - {{- end }} - - - {{- if .Values.initFileExtraSQL }} - initFileExtraSQL: - {{- toYaml .Values.initFileExtraSQL | nindent 6 }} - {{- end }} diff --git a/kmm/mysql-cluster/templates/secret.yaml b/kmm/mysql-cluster/templates/secret.yaml deleted file mode 100644 index bc48ab8..0000000 --- a/kmm/mysql-cluster/templates/secret.yaml +++ /dev/null @@ -1,21 +0,0 @@ -{{- if not .Values.customSecretName }} -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "mysql-cluster.secretName" . }} - labels: - app: {{ template "mysql-cluster.name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} - {{- if .Values.appSecretLabels }} - {{- toYaml .Values.appSecretLabels | nindent 4 }} - {{- end }} - {{- if .Values.appSecretAnnotations }} - annotations: - {{ toYaml .Values.appSecretAnnotations }} - {{- end }} -type: Opaque -data: - ROOT_PASSWORD: {{ required ".rootPassword is missing" .Values.rootPassword | b64enc | quote }} -{{- end }} diff --git a/kmm/mysql-cluster/values.yaml b/kmm/mysql-cluster/values.yaml deleted file mode 100644 index 1d1cb6b..0000000 --- a/kmm/mysql-cluster/values.yaml +++ /dev/null @@ -1,73 +0,0 @@ -# Default values for mysql-cluster. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -## The cluster number of nodes -replicas: 2 - -## For setting custom docker image or specifying mysql version -## the image field has priority over mysqlVersion. -# image: percona:5.7 -# mysqlVersion: "5.7" - -## MySQL connect credentials, those credentials will be provisioned in the cluster -rootPassword: -#appUser: "myuser" -#appPassword: "mypass" -#appDatabase: "mydb" -# appSecretLabels: {} -# appSecretAnnotations: {} - -## MySQL expose port using node port -mysqlnodeport: -#podSpec: -#mysqlConf: -volumeSpec: - persistentVolumeClaim: - accessModes: ["ReadWriteOnce"] - resources: - requests: - storage: 4Gi - -serverIDOffset: - -#initBucketURL: s3://my_bucket_name/mysql-cluster-db-auto-2022-02-22t12-29-00.xbackup.gz -initBucketURL: -initBucketSecretName: - -# Represents the time and frequency of making cluster backups, -# in a cron format with seconds -#backupSchedule: "0 0 0 * * *" */10 * * * * -backupSchedule: - -#The number of many backups to keep .. Ex: 10 -#backupScheduleJobsHistoryLimit: 10 -backupScheduleJobsHistoryLimit: - -# Your bucket name .. Ex: my_bucket_name -##backupURL: s3://my_bucket_name/ -backupURL: - -# The name of the secret that contains credentials for connecting to Object storage -# Or keep it epmty and it will create secret for you -#backupSecretName: os-backup-secret -backupSecretName: - -# specify the remote deletion policy. It can be on of ["retain", "delete"] -backupRemoteDeletePolicy: - -# backupSecretLabels: {} -# backupSecretAnnotations: {} - -backupCredentials: - - # Your Object storage Access key -# AWS_ACCESS_KEY_ID: - - # Your Object storage Secret key -# AWS_SECRET_ACCESS_KEY: -# S3_PROVIDER: Minio -# S3_PROVIDER: - - # Your Object storage URL after publish using receive proxy -# S3_ENDPOINT: \ No newline at end of file diff --git a/kmm/mysql_as_service.py b/kmm/mysql_as_service.py deleted file mode 100644 index f503483..0000000 --- a/kmm/mysql_as_service.py +++ /dev/null @@ -1,468 +0,0 @@ -#!/usr/bin/env/python -# from optparse import OptionError -from requests.structures import CaseInsensitiveDict -import requests -import os -from minio import Minio -menu_options = { - 1: 'Install MySQL-Operator', - 2: 'Create MySQL-Cluster', - 3: 'Create Cluster from existing backup', - 4: 'List Your Clusters', - 5: 'Edit Cluster', # change backup , change replica - 6: 'Remove Cluster', - 7: 'List Backups', - 8: 'Exit', -} - -# Menu for edit cluster options -menu_edit_cluster = { - 1: 'Change number of replica', - 2: 'Change backup schedule', -} - - -def print_menu(): - for key in menu_options.keys(): - print(key, '--', menu_options[key]) - - -def print_edit_cluster_menu(): - for key in menu_edit_cluster.keys(): - print(key, '--', menu_edit_cluster[key]) - - -def create_server_pool_lb(api_url, customer_id, cloudspace_id, - cluster_name, node_port, jwt): - # Create server pool and Loadbalancer using API - # make session - headers = CaseInsensitiveDict() - headers["Accept"] = "application/json" - headers["Authorization"] = "Bearer {}".format(jwt) - - ################################################## - print("Creating serverpool...") - # Create ServerPool - serverpool_api = f"https://{api_url}/alpha/customers/{customer_id}/cloudspaces/{cloudspace_id}\ -/ingress/server-pools?name={cluster_name}" - - # Make API request to create Serverpool - create_serverpool = requests.post(serverpool_api, headers=headers) - serverpool = create_serverpool.json() - - # save serverpool id to var "serverpool_id" - serverpool_id = serverpool['id'] - print(f"ServerPool Status {create_serverpool.status_code}") - - print("Add kubernetes hosts to serverpool...") - # get workers IPs - k8s_node_ip = "kubectl get node -o json | jq '.items[] |\ -.status.addresses[0].address'" - output = os.popen(k8s_node_ip).read() - # Save output to lines "split them line by line" - lines = output.splitlines() - # For loop to get workers IPs and add them to serverpool - for ip_count in range(len(lines)): - # remove "" from output - ip = lines[ip_count].replace('"', "") - # print (ip) - # API URL for post request to add host to server pool - add_host_to_serverpool_api = f"https://{api_url}/alpha/customers/\ -{customer_id}/cloudspaces/{cloudspace_id}/\ -ingress/server-pools/{serverpool_id}/\ -hosts?address={ip}" - # Create API request to add host to server pool - add_host = requests.post(add_host_to_serverpool_api, headers=headers) - - print(add_host.json()) - - print(f"Add hosts to ServerPool Status {add_host.status_code}") - ################################################## - - # Create LB - print("Creating LoadBalancer...") - lb_api = f"https://{api_url}/alpha/customers/{customer_id}/cloudspaces/\ -{cloudspace_id}/ingress/load-balancers" - # Create MySQL LB - create_mysql_lb = requests.post(lb_api, headers=headers, json={ - "name": f"{cluster_name}", - "description": "string", - "type": "TCP", - "front_end": { - "port": node_port, - "tls": { - "is_enabled": False, - "domain": "string", - "tls_termination": False - } - }, - "back_end": { - "serverpool_id": f"{serverpool_id}", - "target_port": node_port - } - }) - print(create_mysql_lb.json()) - - -def create_bucket(s3_url, s3_port, s3_access_key, s3_secret_key, mybucket): - endpoint_url = f"{s3_url}:{s3_port}" - s3_access = f"{s3_access_key}" - s3_secret = f"{s3_secret_key}" - client = Minio( - endpoint=endpoint_url, - secure=True, - access_key=s3_access, - secret_key=s3_secret - ) - found = client.bucket_exists(mybucket) - if not found: - client.make_bucket(mybucket) - print(f"Bucket {mybucket} has been created") - else: - print(f"Bucket {mybucket} already exists") - - -def test_s3_connection(s3_url, s3_port, s3_access_key, s3_secret_key): - endpoint_url = f"{s3_url}:{s3_port}" - s3_access = f"{s3_access_key}" - s3_secret = f"{s3_secret_key}" - client = Minio( - endpoint=endpoint_url, - secure=True, - access_key=s3_access, - secret_key=s3_secret - ) - try: - client.list_buckets() - print("Object storage connected") - - except Exception: - print("Object storage not reachable") - exit(0) - - -def install_mysql_operator(): - print('Installing MySQL-Operator...') - add_helm_repo = 'helm repo add bitpoke https://helm-charts.bitpoke.io' - os.popen(add_helm_repo).read() - update_helm_repo = 'helm repo update' - os.popen(update_helm_repo).read() - install_mysql_operator = "helm install mysql-operator\ -bitpoke/mysql-operator" - os.popen(install_mysql_operator).read() - # print (output) - print("MySQL-Operator is installed") - - -def create_cluster(): - print('Create MySQL-Cluster') - jwt = input("JWT: ") - # ex: cloud.gig.tech/api/1 - api_url = input("API URL: ") - customer_id = input("Customer ID: ") - cloudspace_id = input("CloudSpace ID: ") - cluster_name = input("Cluster Name: ") - replica = input("Number of replicas: ") - root_password = input("Root Password: ") - node_port = int(input("MySQL NodePort [30000-32767]: ")) - pvc_size = input("Cluster Size (Gi): ") - answer = None - while answer not in ("yes", "no", "y", "Y", "n", "N"): - answer = input("Enable Auto backup ? [yes/no]: ") - if answer == "yes" or answer == "y" or answer == "Y": - backup_schedule = None - while backup_schedule not in ("daily", "weekly", "monthly", - "yearly", "d", "D", "w", "W", "m", - "M", "y", "Y", "custom", "c", "C"): - backup_schedule = input("Backup Schedule [daily/weekly/\ -monthly/yearly/custom]: ") - if backup_schedule == "daily" or backup_schedule == "d" or\ - backup_schedule == "D": - my_backup_schedule = "0 0 * * * *" - backup_history_limit = input("Number of backups limit: ") - # print(f'"{my_backup_schedule}"') - s3_url = input("Object storage URL: ") - s3_port = input("Object storage port: ") - s3_access_key = input("Object storage access key: ") - s3_secret_key = input("Object storage secret key: ") - mybucket = input("Bucket Name: ") - # break - elif backup_schedule == "weekly" or backup_schedule == "w" or\ - backup_schedule == "W": - my_backup_schedule = "0 0 0 * * 0" - backup_history_limit = input("Number of backups limit: ") - s3_url = input("Object storage URL: ") - s3_port = input("Object storage port: ") - s3_access_key = input("Object storage access key: ") - s3_secret_key = input("Object storage secret key: ") - mybucket = input("Bucket Name: ") - # break - elif backup_schedule == "monthly" or backup_schedule == "m" or\ - backup_schedule == "M": - my_backup_schedule = "0 0 0 1 * *" - backup_history_limit = input("Number of backups limit: ") - s3_url = input("Object storage URL: ") - s3_port = input("Object storage port: ") - s3_access_key = input("Object storage access key: ") - s3_secret_key = input("Object storage secret key: ") - mybucket = input("Bucket Name: ") - # break - elif backup_schedule == "yearly" or backup_schedule == "y" or\ - backup_schedule == "Y": - my_backup_schedule = "15 0 0 1 1 *" - backup_history_limit = input("Number of backups limit: ") - s3_url = input("Object storage URL: ") - s3_port = input("Object storage port: ") - s3_access_key = input("Object storage access key: ") - s3_secret_key = input("Object storage secret key: ") - mybucket = input("Bucket Name: ") - # break - elif backup_schedule == "custom" or backup_schedule == "c" or\ - backup_schedule == "C": - my_backup_schedule = input("Custom backup cronjob: ") - backup_history_limit = input("Number of backups limit: ") - s3_url = input("Object storage URL: ") - s3_port = input("Object storage port: ") - s3_access_key = input("Object storage access key: ") - s3_secret_key = input("Object storage secret key: ") - mybucket = input("Bucket Name: ") - # break - else: - print("Error please enter correct value") - # Test S3 - test_s3_connection(s3_url, s3_port, s3_access_key, s3_secret_key) - create_bucket(s3_url, s3_port, s3_access_key, - s3_secret_key, mybucket) - # DEF CREATE SERVER POOL & LB - create_server_pool_lb(api_url, customer_id, cloudspace_id, - cluster_name, node_port, jwt) - # Deploy cluster with backup - print("Deploying your cluster with auto backup...") - command2 = f'helm install {cluster_name} ./mysql-cluster --set replicas={replica} \ ---set rootPassword={root_password} \ ---set mysqlnodeport={node_port} \ ---set backupSchedule="{my_backup_schedule}" \ ---set backupScheduleJobsHistoryLimit={backup_history_limit} \ ---set backupRemoteDeletePolicy=delete \ ---set backupURL="s3://{mybucket}/" \ ---set backupCredentials.AWS_ACCESS_KEY_ID="{s3_access_key}" \ ---set backupCredentials.AWS_SECRET_ACCESS_KEY="{s3_secret_key}" \ ---set backupCredentials.S3_PROVIDER=Minio \ ---set backupCredentials.S3_ENDPOINT=https://{s3_url} \ ---set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi' - output2 = os.popen(command2).read() - print(output2) - print("Please wait until the cluster becomes ready...") - print(f"Access your cluster with port {node_port} \n") - elif answer == "no" or answer == "n" or answer == "N": - # print(f"OUT") - # Deploy cluster without backup - # DEF CREATE SERVER POOL & LB - create_server_pool_lb(api_url, customer_id, cloudspace_id, - cluster_name, node_port, jwt) - # Deploy mysql cluster without backup - print("Deploying your cluster...") - command = f"helm install {cluster_name} ./mysql-cluster \ ---set replicas={replica} \ ---set rootPassword={root_password} \ ---set mysqlnodeport={node_port} \ ---set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi" - output = os.popen(command).read() - print(output) - print("Please wait until the cluster becomes ready...") - print(f"Access your cluster with port {node_port} \n") - else: - print("Please enter yes or no.") - - -def create_cluster_from_backup(): - print('Create Cluster from existing backup') - jwt = input("JWT: ") - # ex: cloud.gig.tech/api/1 - api_url = input("API URL: ") - customer_id = input("Customer ID: ") - cloudspace_id = input("CloudSpace ID: ") - cluster_name = input("Cluster Name: ") - replica = input("Number of replicas: ") - # use your root password from backup - root_password = input("Root Password: ") - node_port = int(input("MySQL NodePort [30000-32767]: ")) - pvc_size = input("Cluster Size (Gi): ") - list_backups() - # mybucket = input("Bucket Name: ") - # backup_file_name = input("Backup File Name: ") - backup_number = int(input("Enter your backup number: ")) - # print (mydict[backup_number]) - backup_file_name = mydict[backup_number] - print(f"You select {backup_file_name}") - backup_bucket_url = f's3://{mybucket}/{backup_file_name}' - # s3_access_key = input("Object storage access key: ") - # s3_secret_key = input("Object storage secret key: ") - # s3_url = input("Object storage URL: ") - s3_url = s3_endpoint - # DEF CREATE SERVER POOL & LB - create_server_pool_lb(api_url, customer_id, cloudspace_id, - cluster_name, node_port, jwt) - # Deploy your cluster .. - print("Deploying your cluster...") - command = f'helm install {cluster_name} ./mysql-cluster \ ---set replicas={replica} --set rootPassword={root_password} \ ---set mysqlnodeport={node_port} \ ---set initBucketURL={backup_bucket_url} \ ---set backupCredentials.AWS_ACCESS_KEY_ID="{s3_access_key}" \ ---set backupCredentials.AWS_SECRET_ACCESS_KEY="{s3_secret_key}" \ ---set backupCredentials.S3_PROVIDER=Minio \ ---set backupCredentials.S3_ENDPOINT=https://{s3_url} \ ---set volumeSpec.persistentVolumeClaim.resources.requests.storage={pvc_size}Gi' - output = os.popen(command).read() - print(output) - print("Please wait until the cluster becomes ready...") - print(f"Access your cluster with port {node_port}") - - -def edit_cluster(): - print('Edit your cluster') - cluster_name = input("Cluster Name: ") - while(True): - print_edit_cluster_menu() - option = '' - try: - option = int(input('Choice: ')) - except Exception: - print('Wrong input. Please enter a number ...') - # Check what choice was entered and act accordingly - if option == 1: - # print('1') - replica_num = input("Number of replicas:") - command = f'kubectl scale --replicas={replica_num}\ - mysqlcluster {cluster_name}' - output = os.popen(command).read() - print(output) - break - elif option == 2: - # print('2') - get_cluster_yaml = f'kubectl get mysqlcluster {cluster_name}\ - -o yaml > {cluster_name}.yaml ' - output = os.popen(get_cluster_yaml).read() - cronjob_input = input("Custom Cronjob:") - cronjob = f"'{cronjob_input}'" - # replace cronjob - replace_cronjob = f'sed -i "s/backupSchedule.*/backupSchedule: {cronjob}/g"\ - {cluster_name}.yaml' - output = os.popen(replace_cronjob).read() - apply_changes = f'kubectl apply -f {cluster_name}.yaml' - output = os.popen(apply_changes).read() - print(output) - break - else: - print('Invalid option. Please enter a number between 1 and 2.') - - -def list_clusters(): - print("List clusters....") - list_helm_deployment = 'helm list -A | grep cluster-0.3.1' - output = os.popen(list_helm_deployment).read() - firstline = True - # Print only first column "deployment name" - for line in output.splitlines(): - if firstline: # skip first line - firstline = False - # continue - fields = line.split() - deployment_name = fields[0] - print(f'helm deployment name: {deployment_name}') - list_deployment_resources = f'helm get all {deployment_name} | \ - grep -e mysql.presslabs.org/cluster -e nodePort | \ - sed "s/mysql.presslabs.org.*:/Cluster:/g" | sed "s/node//g"' - output = os.popen(list_deployment_resources).read() - print(output) - - -def remove_cluster(): - list_helm_deployment = 'helm list -A | grep cluster-0.3.1' - output = os.popen(list_helm_deployment).read() - # Print only first column "deployment name" - for line in output.splitlines(): - fields = line.split() - if len(fields) >= 1: - print(fields[0]) - deployment_name = input("Deployment Name to be remove: ") - if input("are you sure to delete? (y/n) ") != "y": - exit() - delete_deployment = f'helm delete {deployment_name}' - output = os.popen(delete_deployment).read() - print(output) - - -def list_backups(): - print('List Backups from Object Storage...') - global mybucket, s3_endpoint, s3_port, s3_access_key, s3_secret_key - s3_endpoint = input("Object storage endpoint: ") - s3_port = input("Object storage port: ") - s3_access_key = input("Object storage access key: ") - s3_secret_key = input("Object storage secret key: ") - mybucket = input("Bucket Name: ") - endpoint_url = f"{s3_endpoint}:{s3_port}" - s3_access = f"{s3_access_key}" - s3_secret = f"{s3_secret_key}" - test_s3_connection(s3_endpoint, s3_port, s3_access_key, s3_secret_key) - # print (endpoint_url,s3_access,s3_secret) - # list_buckets = f"'{mybucket}', prefix=None, recursive=True" - # print (list_buckets) - - client = Minio( - endpoint=endpoint_url, - secure=True, - access_key=s3_access, - secret_key=s3_secret - ) - index = 0 # start index with 0 - global mydict - mydict = {} # empty dic - # List Objects - objects = client.list_objects(mybucket, prefix=None, recursive=True) - for obj in objects: - # Save index and file backup name - backup_list = f"{index} - {obj.object_name} " - # save backup files to dics to list them by index in futuer xD - mydict[index] = obj.object_name - # Print index, file backup name - print(backup_list) - index += 1 - # backup_number = int(input("Enter your backup number: ")) - # return (mydict[backup_number]) - - -if __name__ == '__main__': - while(True): - print_menu() - option = '' - try: - option = int(input('Enter your choice: ')) - except Exception: - print('Wrong input. Please enter a number ...') - # Check what choice was entered and act accordingly - if option == 1: - install_mysql_operator() - # break; - elif option == 2: - create_cluster() - elif option == 3: - create_cluster_from_backup() - # elif option == 4: - # create_database() - elif option == 4: - list_clusters() - # elif option == 6: - # list_databases() - elif option == 5: - edit_cluster() - elif option == 6: - remove_cluster() - elif option == 7: - list_backups() - elif option == 8: - print('Thanks for using our service') - exit() - else: - print('Invalid option. Please enter a number between 1 and 8.') -- GitLab From 2f2ebb4d08b20e1bd290fe88616d53cd9ed3d681 Mon Sep 17 00:00:00 2001 From: abdalluhmostafa <abdalluh.mostafa@gmail.com> Date: Fri, 25 Mar 2022 17:43:43 +0200 Subject: [PATCH 20/20] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 96518ab..37f6348 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Access your cluster with port <MYSQL_NODE_PORT> | **Object Storage Secret Key** | The secret key for your object storage, you cand find it on **GIG Cloud Portal**. | | **Bucket Name** | Enter your bucket name (If you entered a name of **existing bucket** the script will use it. However, if you entered a new name that isn't used before the script will **create a bucket** with the new name for you then use it). | | **Enter Your Backup Number** | The script will show you the list of backups connected to you object storage endpoint you entered before, just enter the number of the desired backup to be used in this cluster. | -| + For every finished operation you will receive a couple of confirmation messages. At the end, you'll have your **MySQL Cluster** configured. -- GitLab