Exemplo n.º 1
0
    def build_cluster_details(create_deployment: dict):
        # Standardize create deployment
        GrassOnPremisesExecutor._standardize_create_deployment(
            create_deployment=create_deployment)

        # Create user account
        logger.info(
            "Now is going to create an user account for maro cluster node.")
        if "super_user" in create_deployment["user"]:
            super_user = create_deployment["user"]["super_user"]
        else:
            super_user = ""
        GrassOnPremisesExecutor.create_user(
            admin_username=super_user,
            maro_user=create_deployment["user"]["admin_username"],
            ip_address=create_deployment["master"]["public_ip_address"],
            pubkey=create_deployment["user"]["admin_public_key"],
            ssh_port=create_deployment["connection"]["ssh"]["port"])

        # Get cluster name and save details
        cluster_name = create_deployment["name"]
        if os.path.isdir(
                os.path.expanduser(
                    f"{GlobalPaths.MARO_CLUSTERS}/{cluster_name}")):
            raise CliError(f"Cluster {cluster_name} already exist.")
        os.makedirs(
            os.path.expanduser(f"{GlobalPaths.MARO_CLUSTERS}/{cluster_name}"))
        save_cluster_details(cluster_name=cluster_name,
                             cluster_details=create_deployment)
Exemplo n.º 2
0
    def _init_master(self):
        logger.info("Initializing master node")

        # Load details
        cluster_details = self.cluster_details
        master_details = cluster_details["master"]
        admin_username = cluster_details["user"]["admin_username"]
        master_public_ip_address = cluster_details["master"][
            "public_ip_address"]
        ssh_port = cluster_details["connection"]["ssh"]["port"]

        # Make sure master is able to connect
        self.grass_executor.retry_connection_and_set_ssh_port(
            node_ip_address=master_public_ip_address)

        # Create folders
        path_list = {
            GlobalPaths.MARO_GRASS_LIB,
            f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}",
            f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/data",
            f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/images",
            f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/jobs",
            f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/schedules"
        }
        self._create_path_in_list(master_public_ip_address, path_list)

        # Copy required files
        copy_files_to_node(local_path=GlobalPaths.MARO_GRASS_LIB,
                           remote_dir=GlobalPaths.MARO_LIB,
                           admin_username=admin_username,
                           node_ip_address=master_public_ip_address,
                           ssh_port=ssh_port)
        copy_files_to_node(
            local_path=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}",
            remote_dir=GlobalPaths.MARO_CLUSTERS,
            admin_username=admin_username,
            node_ip_address=master_public_ip_address,
            ssh_port=ssh_port)

        # Get public key
        public_key = self.grass_executor.remote_get_public_key(
            node_ip_address=master_public_ip_address)

        # Remote init master
        self.grass_executor.remote_init_master()

        # Load master agent service
        self.grass_executor.remote_load_master_agent_service()

        # Save details
        master_details["public_key"] = public_key
        save_cluster_details(cluster_name=self.cluster_name,
                             cluster_details=cluster_details)
        self.grass_executor.remote_set_master_details(
            master_details=cluster_details["master"])

        logger.info_green("Master node is initialized")
Exemplo n.º 3
0
    def _init_master(self):
        logger.info("Initializing master node")

        # Load details
        cluster_details = self.cluster_details
        master_details = cluster_details['master']
        admin_username = cluster_details['user']['admin_username']
        master_public_ip_address = cluster_details['master']['public_ip_address']

        # Make sure master is able to connect
        self.grass_executor.retry_until_connected(node_ip_address=master_public_ip_address)

        # Create folders
        sync_mkdir(remote_path=GlobalPaths.MARO_GRASS_LIB,
                   admin_username=admin_username, node_ip_address=master_public_ip_address)
        sync_mkdir(remote_path=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}",
                   admin_username=admin_username, node_ip_address=master_public_ip_address)
        sync_mkdir(remote_path=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/data",
                   admin_username=admin_username, node_ip_address=master_public_ip_address)
        sync_mkdir(remote_path=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/images",
                   admin_username=admin_username, node_ip_address=master_public_ip_address)
        sync_mkdir(remote_path=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/jobs",
                   admin_username=admin_username, node_ip_address=master_public_ip_address)
        sync_mkdir(remote_path=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/schedules",
                   admin_username=admin_username, node_ip_address=master_public_ip_address)

        # Copy required files
        copy_files_to_node(
            local_path=f"{GlobalPaths.MARO_GRASS_LIB}/*",
            remote_dir=GlobalPaths.MARO_GRASS_LIB,
            admin_username=admin_username, node_ip_address=master_public_ip_address
        )
        copy_files_to_node(
            local_path=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/*",
            remote_dir=f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}",
            admin_username=admin_username, node_ip_address=master_public_ip_address
        )

        # Get public key
        public_key = self.grass_executor.remote_get_public_key(node_ip_address=master_public_ip_address)

        # Remote init master
        self.grass_executor.remote_init_master()

        # Load master agent service
        self.grass_executor.remote_load_master_agent_service()

        # Save details
        master_details['public_key'] = public_key
        master_details['image_files'] = {}
        save_cluster_details(
            cluster_name=self.cluster_name,
            cluster_details=cluster_details
        )
        self.grass_executor.remote_set_master_details(master_details=cluster_details['master'])

        logger.info_green("Master node is initialized")
Exemplo n.º 4
0
    def _set_cluster_id(self):
        # Load details
        cluster_details = self.cluster_details

        # Set cluster id
        cluster_details['id'] = generate_cluster_id()

        # Save details
        save_cluster_details(cluster_name=self.cluster_name,
                             cluster_details=cluster_details)
Exemplo n.º 5
0
    def build_cluster_details(create_deployment: dict):
        # Validate and fill optional value to deployment
        K8sAzureExecutor._validate_create_deployment(create_deployment=create_deployment)

        # Get cluster name and save details
        cluster_name = create_deployment['name']
        if os.path.isdir(os.path.expanduser(f"{GlobalPaths.MARO_CLUSTERS}/{cluster_name}")):
            raise CliException(f"cluster {cluster_name} is exist")
        os.makedirs(os.path.expanduser(f"{GlobalPaths.MARO_CLUSTERS}/{cluster_name}"))
        save_cluster_details(
            cluster_name=cluster_name,
            cluster_details=create_deployment
        )
Exemplo n.º 6
0
    def build_cluster_details(create_deployment: dict):
        # Standardize create deployment
        GrassAzureExecutor._standardize_create_deployment(create_deployment=create_deployment)

        # Get cluster name and save details
        cluster_name = create_deployment['name']
        if os.path.isdir(os.path.expanduser(f"{GlobalPaths.MARO_CLUSTERS}/{cluster_name}")):
            raise CliException(f"Cluster {cluster_name} is exist")
        os.makedirs(os.path.expanduser(f"{GlobalPaths.MARO_CLUSTERS}/{cluster_name}"))
        save_cluster_details(
            cluster_name=cluster_name,
            cluster_details=create_deployment
        )
Exemplo n.º 7
0
    def _create_master(self):
        logger.info("Creating master VM")

        # Load details
        cluster_details = self.cluster_details
        master_details = cluster_details['master']
        cluster_id = cluster_details['id']
        resource_group = cluster_details['cloud']['resource_group']
        admin_username = cluster_details['user']['admin_username']
        node_size = cluster_details['master']['node_size']

        # Create ARM parameters
        self._create_deployment_parameters(
            node_name='master',
            cluster_details=cluster_details,
            node_size=node_size,
            export_dir=os.path.expanduser(f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/parameters")
        )

        # Start deployment
        template_file_location = f"{GlobalPaths.MARO_GRASS_LIB}/azure/grass-create-default-node-template.json"
        parameters_file_location = f"{GlobalPaths.MARO_CLUSTERS}/{self.cluster_name}/parameters/master.json"
        AzureExecutor.start_deployment(
            resource_group=resource_group,
            deployment_name='master',
            template_file=template_file_location,
            parameters_file=parameters_file_location
        )

        # Get master IP addresses
        ip_addresses = AzureExecutor.list_ip_addresses(
            resource_group=resource_group,
            vm_name=f"{cluster_id}-master-vm"
        )
        public_ip_address = ip_addresses[0]["virtualMachine"]["network"]['publicIpAddresses'][0]['ipAddress']
        private_ip_address = ip_addresses[0]["virtualMachine"]["network"]['privateIpAddresses'][0]
        hostname = f"{cluster_id}-master-vm"
        master_details['public_ip_address'] = public_ip_address
        master_details['private_ip_address'] = private_ip_address
        master_details['hostname'] = hostname
        master_details['resource_name'] = f"{cluster_id}-master-vm"
        logger.info_green(f"You can login to your master node with: ssh {admin_username}@{public_ip_address}")

        # Save details
        save_cluster_details(
            cluster_name=self.cluster_name,
            cluster_details=cluster_details,
            sync=False
        )

        logger.info_green("Master VM is created")
Exemplo n.º 8
0
    def _check_and_get_account_sas(self):
        """
        Ref: https://msdn.microsoft.com/library/azure/mt584140.aspx
        """

        # Load details
        cluster_details = self.cluster_details
        cloud_details = cluster_details['cloud']
        cluster_id = cluster_details['id']

        # Regenerate sas if the key is None or expired TODO:
        if 'account_sas' not in cloud_details:
            account_sas = AzureExecutor.get_storage_account_sas(
                account_name=f'{cluster_id}st')
            cloud_details['account_sas'] = account_sas
            save_cluster_details(cluster_name=self.cluster_name,
                                 cluster_details=cluster_details)

        return cloud_details['account_sas']