A
This commit is contained in:
		
					parent
					
						
							
								23b61a7442
							
						
					
				
			
			
				commit
				
					
						d8bbf22c79
					
				
			
		
					 7 changed files with 162 additions and 225 deletions
				
			
		
							
								
								
									
										87
									
								
								app/api.py
									
										
									
									
									
								
							
							
						
						
									
										87
									
								
								app/api.py
									
										
									
									
									
								
							| 
						 | 
					@ -1,19 +1,9 @@
 | 
				
			||||||
import click
 | 
					import click
 | 
				
			||||||
import subprocess
 | 
					import subprocess as sp
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from app.helper import (
 | 
					from app.helper import clone_common, clone_etcd_wrapper
 | 
				
			||||||
    clone,
 | 
					 | 
				
			||||||
    clone_common,
 | 
					 | 
				
			||||||
    clone_etcd_wrapper,
 | 
					 | 
				
			||||||
    GitOperation,
 | 
					 | 
				
			||||||
    PipenvOperation,
 | 
					 | 
				
			||||||
    FileOperation,
 | 
					 | 
				
			||||||
    PackageManagementOperation,
 | 
					 | 
				
			||||||
    VirtualenvOperation
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
@click.group()
 | 
					@click.group()
 | 
				
			||||||
def api():
 | 
					def api():
 | 
				
			||||||
| 
						 | 
					@ -27,58 +17,43 @@ def api():
 | 
				
			||||||
@click.option("--auth_realm", required=True)
 | 
					@click.option("--auth_realm", required=True)
 | 
				
			||||||
@click.option("--realm_allowed", multiple=True, required=True)
 | 
					@click.option("--realm_allowed", multiple=True, required=True)
 | 
				
			||||||
@click.option("--etcd_url", required=True)
 | 
					@click.option("--etcd_url", required=True)
 | 
				
			||||||
@click.option("--etcd_password", required=True)
 | 
					@click.option("--otp_server", default="https://otp.ungleich.ch/ungleichotp/", 
 | 
				
			||||||
@click.option(
 | 
					              help="URL of ungleich OTP server")
 | 
				
			||||||
    "--otp_server",
 | 
					def setup(path, auth_name, auth_seed, auth_realm,
 | 
				
			||||||
    default="https://otp.ungleich.ch/ungleichotp/",
 | 
					          realm_allowed, otp_server, etcd_url):
 | 
				
			||||||
    help="URL of ungleich OTP server")
 | 
					    
 | 
				
			||||||
def setup(
 | 
					 | 
				
			||||||
    path,
 | 
					 | 
				
			||||||
    auth_name,
 | 
					 | 
				
			||||||
    auth_seed,
 | 
					 | 
				
			||||||
    auth_realm,
 | 
					 | 
				
			||||||
    realm_allowed,
 | 
					 | 
				
			||||||
    otp_server,
 | 
					 | 
				
			||||||
    etcd_url,
 | 
					 | 
				
			||||||
    etcd_password,
 | 
					 | 
				
			||||||
):
 | 
					 | 
				
			||||||
    os.chdir(path)
 | 
					    os.chdir(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    repo_name = "ucloud-api"
 | 
					    repo_name = "ucloud-api"
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Git Operation Depends on success of previous operation i.e PackageManagementOperation
 | 
					    # Clone main repo
 | 
				
			||||||
    op = GitOperation.clone(
 | 
					    sp.check_output(['git', 'clone',
 | 
				
			||||||
        url=f"https://code.ungleich.ch/ungleich-public/{repo_name}.git",
 | 
					                    f'https://code.ungleich.ch/ungleich-public/{repo_name}.git'
 | 
				
			||||||
        arguments="-b wip"
 | 
					                    '-b', 'wip'])
 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    content = (
 | 
					    # Create .env file
 | 
				
			||||||
        f"AUTH_NAME={auth_name}\n"
 | 
					    with open(os.path.join(repo_name, ".env"), "w") as f:
 | 
				
			||||||
        f"AUTH_SEED={auth_seed}\n"
 | 
					        content = (
 | 
				
			||||||
        f"AUTH_REALM={auth_realm}\n"
 | 
					            f"AUTH_NAME={auth_name}\n"
 | 
				
			||||||
        f"REALM_ALLOWED={list(realm_allowed)}\n"
 | 
					            f"AUTH_SEED={auth_seed}\n"
 | 
				
			||||||
        f"OTP_SERVER={otp_server}\n"
 | 
					            f"AUTH_REALM={auth_realm}\n"
 | 
				
			||||||
        f"ETCD_URL={etcd_url}\n"
 | 
					            f"REALM_ALLOWED={list(realm_allowed)}\n"
 | 
				
			||||||
        f"ETCD_PASSWORD={etcd_password}\n"
 | 
					            f"OTP_SERVER={otp_server}\n"
 | 
				
			||||||
    )
 | 
					            f"ETCD_URL={etcd_url}\n"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        f.writelines(content)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # FileOperation depends on success of previos operation i.e GitOperation.clone
 | 
					    # Clone Common and Etcd Wrapper
 | 
				
			||||||
    op.add(FileOperation.write, path=os.path.join(repo_name, ".env"), content=content)
 | 
					    clone_common()
 | 
				
			||||||
 | 
					    clone_etcd_wrapper()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op.add(
 | 
					    # Copy Etcd Wrapper inside ucloud_common as ucloud_common
 | 
				
			||||||
        GitOperation.clone,
 | 
					    # also needs etcd wrapper
 | 
				
			||||||
        path=repo_name,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ungleich-public/ucloud_common",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    op.add(
 | 
					 | 
				
			||||||
        GitOperation.clone,
 | 
					 | 
				
			||||||
        path=repo_name,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    shutil.copytree(
 | 
					    shutil.copytree(
 | 
				
			||||||
        src=os.path.join(repo_name, "etcd3_wrapper"),
 | 
					        src=os.path.join(repo_name, "etcd3_wrapper"),
 | 
				
			||||||
        dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"),
 | 
					        dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    op.add(PipenvOperation.create, path=repo_name, site_packages=True)
 | 
					    
 | 
				
			||||||
    op.add(PipenvOperation.install, path=repo_name)
 | 
					    # Create virtualenv with site-packages enabled and install all dependencies
 | 
				
			||||||
 | 
					    sp.check_output(['pipenv','--site-packages', '--python', '3'], path=repo_name)
 | 
				
			||||||
 | 
					    sp.check_output(['pipenv', 'install'], path=repo_name)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										53
									
								
								app/file.py
									
										
									
									
									
								
							
							
						
						
									
										53
									
								
								app/file.py
									
										
									
									
									
								
							| 
						 | 
					@ -1,16 +1,8 @@
 | 
				
			||||||
import click
 | 
					import click
 | 
				
			||||||
import subprocess
 | 
					import subprocess as sp
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from app.helper import (
 | 
					from app.helper import clone_etcd_wrapper
 | 
				
			||||||
    clone,
 | 
					 | 
				
			||||||
    clone_common,
 | 
					 | 
				
			||||||
    clone_etcd_wrapper,
 | 
					 | 
				
			||||||
    GitOperation,
 | 
					 | 
				
			||||||
    PipenvOperation,
 | 
					 | 
				
			||||||
    FileOperation,
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
@click.group()
 | 
					@click.group()
 | 
				
			||||||
def file_scan():
 | 
					def file_scan():
 | 
				
			||||||
| 
						 | 
					@ -22,36 +14,31 @@ def file_scan():
 | 
				
			||||||
@click.option("--base_dir", required=True)
 | 
					@click.option("--base_dir", required=True)
 | 
				
			||||||
@click.option("--file_prefix", required=True)
 | 
					@click.option("--file_prefix", required=True)
 | 
				
			||||||
@click.option("--etcd_url", required=True)
 | 
					@click.option("--etcd_url", required=True)
 | 
				
			||||||
@click.option("--etcd_password", required=True)
 | 
					def setup(path, base_dir, file_prefix, etcd_url):
 | 
				
			||||||
def setup(path, base_dir, file_prefix, etcd_url, etcd_password):
 | 
					 | 
				
			||||||
    os.chdir(path)
 | 
					    os.chdir(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    repo_name = "ucloud-file-scan"
 | 
					    repo_name = "ucloud-file-scan"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op_result = GitOperation.clone(
 | 
					    # Clone main repository
 | 
				
			||||||
        f"https://code.ungleich.ch/ungleich-public/{repo_name}.git",
 | 
					    sp.check_output(['git', 'clone',
 | 
				
			||||||
        arguments="-b wip"
 | 
					                    f'https://code.ungleich.ch/ungleich-public/{repo_name}.git'
 | 
				
			||||||
    )
 | 
					                    '-b', 'wip'])
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    content = (
 | 
					    # Create .env file
 | 
				
			||||||
        f"BASE_DIR={base_dir}\n"
 | 
					    with open(os.path.join(repo_name, ".env"), "w") as f:
 | 
				
			||||||
        f"FILE_PREFIX={file_prefix}\n"
 | 
					        content = (
 | 
				
			||||||
        f"ETCD_URL={etcd_url}\n"
 | 
					            f"BASE_DIR={base_dir}\n"
 | 
				
			||||||
        f"ETCD_PASSWORD={etcd_password}\n"
 | 
					            f"FILE_PREFIX={file_prefix}\n"
 | 
				
			||||||
    )
 | 
					            f"ETCD_URL={etcd_url}\n"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        f.writelines(content)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    op_result.add(
 | 
					    # Clone etcd wrapper
 | 
				
			||||||
        FileOperation.write, path=os.path.join(repo_name, ".env"), content=content
 | 
					    clone_etcd_wrapper()
 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    op_result.add(
 | 
					    # Create virtualenv with site-packages enabled and install all dependencies
 | 
				
			||||||
        GitOperation.clone,
 | 
					    sp.check_output(['pipenv','--site-packages', '--python', '3'], path=repo_name)
 | 
				
			||||||
        path=repo_name,
 | 
					    sp.check_output(['pipenv', 'install'], path=repo_name)
 | 
				
			||||||
        url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    op_result.add(PipenvOperation.create, path=repo_name, site_packages=True)
 | 
					 | 
				
			||||||
    op_result.add(PipenvOperation.install, path=repo_name)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Write Crontab entry
 | 
					    # Write Crontab entry
 | 
				
			||||||
    with open("/etc/crontabs/root", "a") as crontab:
 | 
					    with open("/etc/crontabs/root", "a") as crontab:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
 | 
					import subprocess as sp
 | 
				
			||||||
import inspect
 | 
					import inspect
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,12 +24,14 @@ def clone(repo):
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def clone_common():
 | 
					def clone_common(path='.'):
 | 
				
			||||||
    return clone("https://code.ungleich.ch/ungleich-public/ucloud_common")
 | 
					    sp.check_output(['git', 'clone',
 | 
				
			||||||
 | 
					                    f'https://code.ungleich.ch/ungleich-public/ucloud_common'], path=path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def clone_etcd_wrapper():
 | 
					def clone_etcd_wrapper(path='.'):
 | 
				
			||||||
    return clone("https://code.ungleich.ch/ahmedbilal/etcd3_wrapper")
 | 
					    sp.check_output(['git', 'clone',
 | 
				
			||||||
 | 
					                    f'https://code.ungleich.ch/ahmedbilal/etcd3_wrapper'], path=path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Result(object):
 | 
					class Result(object):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										63
									
								
								app/host.py
									
										
									
									
									
								
							
							
						
						
									
										63
									
								
								app/host.py
									
										
									
									
									
								
							| 
						 | 
					@ -1,16 +1,9 @@
 | 
				
			||||||
import click
 | 
					import click
 | 
				
			||||||
import subprocess
 | 
					import subprocess as sp
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from app.helper import (
 | 
					from app.helper import clone_common, clone_etcd_wrapper
 | 
				
			||||||
    clone,
 | 
					 | 
				
			||||||
    clone_common,
 | 
					 | 
				
			||||||
    clone_etcd_wrapper,
 | 
					 | 
				
			||||||
    GitOperation,
 | 
					 | 
				
			||||||
    PipenvOperation,
 | 
					 | 
				
			||||||
    FileOperation,
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@click.group()
 | 
					@click.group()
 | 
				
			||||||
| 
						 | 
					@ -24,45 +17,37 @@ def host():
 | 
				
			||||||
@click.option("--ssh_key_path", required=True, help="For Example, ~/.ssh/id_rsa")
 | 
					@click.option("--ssh_key_path", required=True, help="For Example, ~/.ssh/id_rsa")
 | 
				
			||||||
@click.option("--ssh_key_pass", required=True)
 | 
					@click.option("--ssh_key_pass", required=True)
 | 
				
			||||||
@click.option("--etcd_url", required=True)
 | 
					@click.option("--etcd_url", required=True)
 | 
				
			||||||
@click.option("--etcd_password", required=True)
 | 
					def setup(path, ssh_username, ssh_key_path, ssh_key_pass, etcd_url):
 | 
				
			||||||
def setup(path, ssh_username, ssh_key_path, ssh_key_pass, etcd_url, etcd_password):
 | 
					 | 
				
			||||||
    os.chdir(path)
 | 
					    os.chdir(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    repo_name = "ucloud-vm"
 | 
					    repo_name = "ucloud-vm"
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    op_result = GitOperation.clone(
 | 
					    # Clone main repo
 | 
				
			||||||
        f"https://code.ungleich.ch/ungleich-public/{repo_name}.git",
 | 
					    sp.check_output(['git', 'clone',
 | 
				
			||||||
        arguments="-b wip"
 | 
					                    f'https://code.ungleich.ch/ungleich-public/{repo_name}.git'
 | 
				
			||||||
    )
 | 
					                    '-b', 'wip'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    content = (
 | 
					    # Create .env file
 | 
				
			||||||
        f"ssh_username={ssh_username}\n"
 | 
					    with open(os.path.join(repo_name, ".env"), "w") as f:
 | 
				
			||||||
        f"ssh_pkey={ssh_key_path}\n"
 | 
					        content = (
 | 
				
			||||||
        f"ssh_private_key_password={ssh_key_pass}\n"
 | 
					            f"ssh_username={ssh_username}\n"
 | 
				
			||||||
        f"ETCD_URL={etcd_url}\n"
 | 
					            f"ssh_pkey={ssh_key_path}\n"
 | 
				
			||||||
        f"ETCD_PASSWORD={etcd_password}\n"
 | 
					            f"ssh_private_key_password={ssh_key_pass}\n"
 | 
				
			||||||
    )
 | 
					            f"ETCD_URL={etcd_url}\n"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        f.writelines(content)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op_result.add(
 | 
					    # Clone Common and Etcd Wrapper
 | 
				
			||||||
        FileOperation.write, path=os.path.join(repo_name, ".env"), content=content
 | 
					    clone_common()
 | 
				
			||||||
    )
 | 
					    clone_etcd_wrapper()
 | 
				
			||||||
 | 
					 | 
				
			||||||
    op_result.add(
 | 
					 | 
				
			||||||
        GitOperation.clone,
 | 
					 | 
				
			||||||
        path=repo_name,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ungleich-public/ucloud_common",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    op_result.add(
 | 
					 | 
				
			||||||
        GitOperation.clone,
 | 
					 | 
				
			||||||
        path=repo_name,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Copy Etcd Wrapper inside ucloud_common as ucloud_common
 | 
				
			||||||
 | 
					    # also needs etcd wrapper
 | 
				
			||||||
    shutil.copytree(
 | 
					    shutil.copytree(
 | 
				
			||||||
        src=os.path.join(repo_name, "etcd3_wrapper"),
 | 
					        src=os.path.join(repo_name, "etcd3_wrapper"),
 | 
				
			||||||
        dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"),
 | 
					        dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op_result.add(PipenvOperation.create, path=repo_name, site_packages=True)
 | 
					    # Create virtualenv with site-packages enabled and install all dependencies
 | 
				
			||||||
    op_result.add(PipenvOperation.install, path=repo_name)
 | 
					    sp.check_output(['pipenv','--site-packages', '--python', '3'], path=repo_name)
 | 
				
			||||||
 | 
					    sp.check_output(['pipenv', 'install'], path=repo_name)
 | 
				
			||||||
							
								
								
									
										49
									
								
								app/image.py
									
										
									
									
									
								
							
							
						
						
									
										49
									
								
								app/image.py
									
										
									
									
									
								
							| 
						 | 
					@ -1,16 +1,8 @@
 | 
				
			||||||
import click
 | 
					import click
 | 
				
			||||||
import subprocess
 | 
					import subprocess as sp
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from app.helper import (
 | 
					from app.helper import clone_etcd_wrapper
 | 
				
			||||||
    clone,
 | 
					 | 
				
			||||||
    clone_common,
 | 
					 | 
				
			||||||
    clone_etcd_wrapper,
 | 
					 | 
				
			||||||
    GitOperation,
 | 
					 | 
				
			||||||
    PipenvOperation,
 | 
					 | 
				
			||||||
    FileOperation,
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
@click.group()
 | 
					@click.group()
 | 
				
			||||||
def image():
 | 
					def image():
 | 
				
			||||||
| 
						 | 
					@ -21,35 +13,30 @@ def image():
 | 
				
			||||||
@click.option("--path", required=True)
 | 
					@click.option("--path", required=True)
 | 
				
			||||||
@click.option("--base_dir", required=True)
 | 
					@click.option("--base_dir", required=True)
 | 
				
			||||||
@click.option("--etcd_url", required=True)
 | 
					@click.option("--etcd_url", required=True)
 | 
				
			||||||
@click.option("--etcd_password", required=True)
 | 
					def setup(path, base_dir, etcd_url):
 | 
				
			||||||
def setup(path, base_dir, etcd_url, etcd_password):
 | 
					 | 
				
			||||||
    os.chdir(path)
 | 
					    os.chdir(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    repo_name = "ucloud-image-scanner"
 | 
					    repo_name = "ucloud-image-scanner"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op_result = GitOperation.clone(
 | 
					    # Clone main repo
 | 
				
			||||||
        f"https://code.ungleich.ch/ungleich-public/{repo_name}.git",
 | 
					    sp.check_output(['git', 'clone',
 | 
				
			||||||
        arguments="-b wip"
 | 
					                    f'https://code.ungleich.ch/ungleich-public/{repo_name}.git'
 | 
				
			||||||
    )
 | 
					                    '-b', 'wip'])
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    content = (
 | 
					    # Create .env file
 | 
				
			||||||
        f"BASE_DIR={base_dir}\n"
 | 
					    with open(os.path.join(repo_name, ".env"), "w") as f:
 | 
				
			||||||
        f"ETCD_URL={etcd_url}\n"
 | 
					        content = (
 | 
				
			||||||
        f"ETCD_PASSWORD={etcd_password}\n"
 | 
					            f"BASE_DIR={base_dir}\n"
 | 
				
			||||||
    )
 | 
					            f"ETCD_URL={etcd_url}\n"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        f.writelines(content)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    op_result.add(
 | 
					 | 
				
			||||||
        FileOperation.write, path=os.path.join(repo_name, ".env"), content=content
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op_result.add(
 | 
					    clone_etcd_wrapper()
 | 
				
			||||||
        GitOperation.clone,
 | 
					 | 
				
			||||||
        path=repo_name,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    op_result.add(PipenvOperation.create, path=repo_name, site_packages=True)
 | 
					    # Create virtualenv with site-packages enabled and install all dependencies
 | 
				
			||||||
    op_result.add(PipenvOperation.install, path=repo_name)
 | 
					    sp.check_output(['pipenv','--site-packages', '--python', '3'], path=repo_name)
 | 
				
			||||||
 | 
					    sp.check_output(['pipenv', 'install'], path=repo_name)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Write Crontab entry
 | 
					    # Write Crontab entry
 | 
				
			||||||
    with open("/etc/crontabs/root", "a") as crontab:
 | 
					    with open("/etc/crontabs/root", "a") as crontab:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,16 +1,9 @@
 | 
				
			||||||
import click
 | 
					import click
 | 
				
			||||||
import subprocess
 | 
					import subprocess as sp
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from app.helper import (
 | 
					from app.helper import clone_common, clone_etcd_wrapper
 | 
				
			||||||
    clone,
 | 
					 | 
				
			||||||
    clone_common,
 | 
					 | 
				
			||||||
    clone_etcd_wrapper,
 | 
					 | 
				
			||||||
    GitOperation,
 | 
					 | 
				
			||||||
    PipenvOperation,
 | 
					 | 
				
			||||||
    FileOperation,
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@click.group()
 | 
					@click.group()
 | 
				
			||||||
| 
						 | 
					@ -24,45 +17,37 @@ def scheduler():
 | 
				
			||||||
@click.option("--host_prefix", required=True)
 | 
					@click.option("--host_prefix", required=True)
 | 
				
			||||||
@click.option("--request_prefix", required=True)
 | 
					@click.option("--request_prefix", required=True)
 | 
				
			||||||
@click.option("--etcd_url", required=True)
 | 
					@click.option("--etcd_url", required=True)
 | 
				
			||||||
@click.option("--etcd_password", required=True)
 | 
					def setup(path, vm_prefix, host_prefix, request_prefix, etcd_url):
 | 
				
			||||||
def setup(path, vm_prefix, host_prefix, request_prefix, etcd_url, etcd_password):
 | 
					 | 
				
			||||||
    os.chdir(path)
 | 
					    os.chdir(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    repo_name = "ucloud-scheduler"
 | 
					    repo_name = "ucloud-scheduler"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op_result = GitOperation.clone(
 | 
					    # Clone main repo
 | 
				
			||||||
        f"https://code.ungleich.ch/ungleich-public/{repo_name}.git",
 | 
					    sp.check_output(['git', 'clone',
 | 
				
			||||||
        arguments="-b wip"
 | 
					                    f'https://code.ungleich.ch/ungleich-public/{repo_name}.git'
 | 
				
			||||||
    )
 | 
					                    '-b', 'wip'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    content = (
 | 
					    # Create .env file
 | 
				
			||||||
        f"VM_PREFIX={vm_prefix}\n"
 | 
					    with open(os.path.join(repo_name, ".env"), "w") as f:
 | 
				
			||||||
        f"HOST_PREFIX={host_prefix}\n"
 | 
					        content = (
 | 
				
			||||||
        f"REQUEST_PREFIX={request_prefix}\n"
 | 
					            f"VM_PREFIX={vm_prefix}\n"
 | 
				
			||||||
        f"ETCD_URL={etcd_url}\n"
 | 
					            f"HOST_PREFIX={host_prefix}\n"
 | 
				
			||||||
        f"ETCD_PASSWORD={etcd_password}\n"
 | 
					            f"REQUEST_PREFIX={request_prefix}\n"
 | 
				
			||||||
    )
 | 
					            f"ETCD_URL={etcd_url}\n"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        f.writelines(content)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    op_result.add(
 | 
					    # Clone Common and Etcd Wrapper
 | 
				
			||||||
        FileOperation.write, path=os.path.join(repo_name, ".env"), content=content
 | 
					    clone_common()
 | 
				
			||||||
    )
 | 
					    clone_etcd_wrapper()
 | 
				
			||||||
 | 
					 | 
				
			||||||
    op_result.add(
 | 
					 | 
				
			||||||
        GitOperation.clone,
 | 
					 | 
				
			||||||
        path=repo_name,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ungleich-public/ucloud_common",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    op_result.add(
 | 
					 | 
				
			||||||
        GitOperation.clone,
 | 
					 | 
				
			||||||
        path=repo_name,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Copy Etcd Wrapper inside ucloud_common as ucloud_common
 | 
				
			||||||
 | 
					    # also needs etcd wrapper
 | 
				
			||||||
    shutil.copytree(
 | 
					    shutil.copytree(
 | 
				
			||||||
        src=os.path.join(repo_name, "etcd3_wrapper"),
 | 
					        src=os.path.join(repo_name, "etcd3_wrapper"),
 | 
				
			||||||
        dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"),
 | 
					        dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    op_result.add(PipenvOperation.create, path=repo_name, site_packages=True)
 | 
					    # Create virtualenv with site-packages enabled and install all dependencies
 | 
				
			||||||
    op_result.add(PipenvOperation.install, path=repo_name)
 | 
					    sp.check_output(['pipenv','--site-packages', '--python', '3'], path=repo_name)
 | 
				
			||||||
 | 
					    sp.check_output(['pipenv', 'install'], path=repo_name)
 | 
				
			||||||
							
								
								
									
										41
									
								
								init.sh
									
										
									
									
									
								
							
							
						
						
									
										41
									
								
								init.sh
									
										
									
									
									
								
							| 
						 | 
					@ -1,10 +1,17 @@
 | 
				
			||||||
# Install QEMU
 | 
					get_distro() {
 | 
				
			||||||
(git clone https://github.com/ahmedbilal/qemu-with-rbd-alpine.git \
 | 
						OS=$(cat /etc/*release | grep ID | head -1 | cut -c 4-)
 | 
				
			||||||
 && cd qemu-with-rbd-alpine && apk add *.apk --allow-untrusted)
 | 
						echo $OS
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					case $(get_distro) in
 | 
				
			||||||
 | 
					    "alpine")
 | 
				
			||||||
 | 
					    # Install QEMU
 | 
				
			||||||
 | 
					    (git clone https://github.com/ahmedbilal/qemu-with-rbd-alpine.git \
 | 
				
			||||||
 | 
					    && cd qemu-with-rbd-alpine && apk add *.apk --allow-untrusted)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Enable Alpine (3.10 + Edge) Repos
 | 
					    # Enable Alpine (3.10 + Edge) Repos
 | 
				
			||||||
cat > /etc/apk/repositories << EOF
 | 
					    cat > /etc/apk/repositories << EOF
 | 
				
			||||||
http://dl-cdn.alpinelinux.org/alpine/v3.10/main
 | 
					http://dl-cdn.alpinelinux.org/alpine/v3.10/main
 | 
				
			||||||
http://dl-cdn.alpinelinux.org/alpine/v3.10/community
 | 
					http://dl-cdn.alpinelinux.org/alpine/v3.10/community
 | 
				
			||||||
http://dl-cdn.alpinelinux.org/alpine/edge/main
 | 
					http://dl-cdn.alpinelinux.org/alpine/edge/main
 | 
				
			||||||
| 
						 | 
					@ -13,17 +20,25 @@ http://dl-cdn.alpinelinux.org/alpine/edge/testing
 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Update Package List and Upgrade System
 | 
					    # Update Package List and Upgrade System
 | 
				
			||||||
apk update
 | 
					    apk update
 | 
				
			||||||
apk upgrade
 | 
					    apk upgrade
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Install system packages
 | 
					    # Install system packages
 | 
				
			||||||
apk add python3 ceph py2-pip py3-pip etcd-ctl
 | 
					    apk add python3 ceph py2-pip py3-pip etcd-ctl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Some python package dependencies
 | 
					    # Some python package dependencies
 | 
				
			||||||
apk add libffi-dev openssl-dev make alpine-sdk gcc g++ python3-dev
 | 
					    apk add libffi-dev openssl-dev make alpine-sdk gcc g++ python3-dev
 | 
				
			||||||
 | 
					
 | 
				
			||||||
apk add py3-grpcio py3-protobuf py3-tempita
 | 
					    apk add py3-grpcio py3-protobuf py3-tempita
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					"devuan")
 | 
				
			||||||
 | 
					    apt update
 | 
				
			||||||
 | 
					    apt upgrade
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    apt install python3 qemu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pip3 install --upgrade pip
 | 
					pip3 install --upgrade pip
 | 
				
			||||||
pip2 install --upgrade pip
 | 
					pip2 install --upgrade pip
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue