def template(export_path: str, **kwargs): # Late import. from maro.cli.k8s.executors.k8s_aks_executor import K8sAksExecutor K8sAksExecutor.template( export_path=export_path )
def create(deployment_path: str, **kwargs): try: with open(deployment_path, 'r') as fr: create_deployment = yaml.safe_load(fr) if create_deployment["mode"] == "k8s/aks": K8sAksExecutor.build_cluster_details( create_deployment=create_deployment) executor = K8sAksExecutor(cluster_name=create_deployment["name"]) executor.create() else: raise BadRequestError( f"Unsupported command in mode '{create_deployment['mode']}'.") except KeyError as e: raise InvalidDeploymentTemplateError(f"Missing key '{e.args[0]}'.") except FileNotFoundError: raise FileOperationError("Invalid template file path.")
def setUpClass(cls, file_path: str = os.path.abspath(__file__)) -> None: # Get and set params GlobalParams.LOG_LEVEL = logging.DEBUG cls.test_id = uuid.uuid4().hex[:8] os.makedirs( os.path.expanduser(f"{GlobalPaths.MARO_TEST}/{cls.test_id}"), exist_ok=True) os.makedirs( os.path.expanduser(f"{GlobalPaths.MARO_TEST}/{cls.test_id}/tar"), exist_ok=True) cls.file_path = os.path.abspath(__file__) cls.dir_path = os.path.dirname(cls.file_path) cls.deployment_template_path = os.path.normpath( os.path.join(cls.dir_path, "../templates/test_k8s_azure_create.yml")) cls.deployment_path = os.path.expanduser( f"{GlobalPaths.MARO_TEST}/{cls.test_id}/test_k8s_azure_create.yml") cls.config_path = os.path.normpath( os.path.join(cls.dir_path, "../config.yml")) # Load config and save deployment with open(cls.deployment_template_path) as fr: deployment_details = yaml.safe_load(fr) with open(cls.config_path) as fr: config_details = yaml.safe_load(fr) if config_details["cloud/subscription"] and config_details[ "user/admin_public_key"]: deployment_details["cloud"]["subscription"] = config_details[ "cloud/subscription"] deployment_details["user"][ "admin_public_key"] = config_details[ "user/admin_public_key"] else: raise Exception("Invalid config") with open(cls.deployment_path, "w") as fw: yaml.safe_dump(deployment_details, fw) # Get params from deployments cls.cluster_name = deployment_details["name"] # Init test files cls.local_big_file_path = os.path.expanduser( f"{GlobalPaths.MARO_TEST}/{cls.test_id}/big_file") cls.local_small_files_path = os.path.expanduser( f"{GlobalPaths.MARO_TEST}/{cls.test_id}/small_files") command = f"dd if=/dev/zero of={cls.local_big_file_path} bs=1 count=0 seek=1G" SubProcess.run(command) command = f"git clone [email protected]:microsoft/maro.git {cls.local_small_files_path}" SubProcess.run(command) # Create cluster command = f"maro k8s create --debug {cls.deployment_path}" SubProcess.interactive_run(command) cls.cluster_details = load_cluster_details( cluster_name=cls.cluster_name) cls.cluster_id = cls.cluster_details["id"] cls.executor = K8sAksExecutor(cluster_name=cls.cluster_name) time.sleep(15) cls.pod_name = cls._get_redis_pod_name()
def delete(cluster_name: str, **kwargs): cluster_details = load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.delete() else: raise BadRequestError(f"Unsupported command in mode '{cluster_details['mode']}'.")
def remove_data(cluster_name: str, remote_path: str, **kwargs): cluster_details = load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.remove_data(remote_path=remote_path) else: raise BadRequestError( f"Unsupported command in mode '{cluster_details['mode']}'.")
def stop_schedule(cluster_name: str, schedule_name: str, **kwargs): # Load details cluster_details = load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.stop_schedule(schedule_name=schedule_name) else: raise BadRequestError( f"Unsupported command in mode '{cluster_details['mode']}'.")
def get_job_logs(cluster_name: str, job_name: str, **kwargs): # Load details cluster_details = load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.get_job_logs(job_name=job_name) else: raise BadRequestError( f"Unsupported command in mode '{cluster_details['mode']}'.")
def start_job(cluster_name: str, deployment_path: str, **kwargs): # Load details cluster_details = load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.start_job(deployment_path=deployment_path) else: raise BadRequestError( f"Unsupported command in mode '{cluster_details['mode']}'.")
def create(deployment_path: str, **kwargs): # Late import. import yaml from maro.cli.k8s.executors.k8s_aks_executor import K8sAksExecutor from maro.utils.exception.cli_exception import BadRequestError, FileOperationError, InvalidDeploymentTemplateError try: with open(deployment_path, "r") as fr: create_deployment = yaml.safe_load(fr) if create_deployment["mode"] == "k8s/aks": K8sAksExecutor.create(create_deployment=create_deployment) else: raise BadRequestError( f"Unsupported operation in mode '{create_deployment['mode']}'." ) except KeyError as e: raise InvalidDeploymentTemplateError(f"Missing key '{e.args[0]}'.") except FileNotFoundError: raise FileOperationError("Invalid template file path.")
def scale_node(cluster_name: str, replicas: int, node_size: str, **kwargs): cluster_details = load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.scale_node( replicas=replicas, node_size=node_size ) else: raise BadRequestError(f"Unsupported command in mode '{cluster_details['mode']}'.")
def delete(cluster_name: str, **kwargs): # Late import. from maro.cli.k8s.executors.k8s_aks_executor import K8sAksExecutor from maro.cli.utils.details_reader import DetailsReader from maro.utils.exception.cli_exception import BadRequestError cluster_details = DetailsReader.load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.delete() else: raise BadRequestError(f"Unsupported operation in mode '{cluster_details['mode']}'.")
def start_schedule(cluster_name: str, deployment_path: str, **kwargs): # Late import. from maro.cli.k8s.executors.k8s_aks_executor import K8sAksExecutor from maro.cli.utils.details_reader import DetailsReader from maro.utils.exception.cli_exception import BadRequestError # Load details cluster_details = DetailsReader.load_cluster_details( cluster_name=cluster_name) if cluster_details["mode"] == "k8s/aks": executor = K8sAksExecutor(cluster_name=cluster_name) executor.start_schedule(deployment_path=deployment_path) else: raise BadRequestError( f"Unsupported operation in mode '{cluster_details['mode']}'.")
def template(export_path: str, **kwargs): K8sAksExecutor.template( export_path=export_path )