def __init__(self, cluster_name_id, kube_config=None, key_file=None, metadata=None, aws_profile=None): """ Config file initialization :param cluster_name_id: Cluster name_id in format of name-uuid, lcj-cluster-515d9828-7515-11e6-9b3e-a0999b1b4e15 :param kube_config: kubernetes saved config file. :param key_file: cluster ssh key path :param metadata: path to cluster metadata :param aws_profile: AWS profile to access S3. """ assert AXEnv().is_in_pod( ) or cluster_name_id, "Must specify cluster name from outside cluster" self._aws_profile = aws_profile self._cluster_name_id = cluster_name_id self._config = AXClusterConfig(cluster_name_id=cluster_name_id, aws_profile=aws_profile) self._kube_config = kube_config if kube_config else self.default_config_path.format( cluster_name_id) tmp_kube_config = kube_config if kube_config else self.default_config_path.format( cluster_name_id) self._kube_config = os.getenv("ARGO_KUBE_CONFIG_PATH", tmp_kube_config) self._key_file = key_file if key_file else self.default_key_path.format( cluster_name_id) self._metadata_file = metadata if metadata else self.default_cluster_meta_path config_path = AXClusterConfigPath(name_id=cluster_name_id) self._bucket_name = config_path.bucket() self._bucket = Cloud().get_bucket(self._bucket_name, aws_profile=aws_profile) self._s3_kube_config_key = config_path.kube_config() self._s3_cluster_ssh_key = config_path.kube_ssh() self._s3_cluster_state_before_pause = config_path.state_before_pause() self._s3_cluster_meta = config_path.cluster_metadata() self._s3_cluster_software_info = config_path.versions() self._s3_platform_manifest_dir = config_path.platform_manifest_dir() self._s3_platform_config = config_path.platform_config() self._s3_cluster_current_state = config_path.current_state() self._s3_portal_support_flag = config_path.portal_support() self._s3_master_config_prefix = config_path.master_config_dir() self._s3_master_attributes_path = config_path.master_attributes_path() self._s3_master_user_data_path = config_path.master_user_data_path() # For cluster staging info, stage1 and stage2 can be uploaded, downloaded, deleted with AXClusterInfo # stage0 will can only be downloaded with AXClusterInfo. It will be uploaded during cluster information # initialization (i.e. upload cluster id an cluster config), and deleted during cluster information # clean up (i.e. during axinstaller uninstall) self._staging_info = { "stage0": config_path.cluster_install_stage0_key(), "stage1": config_path.cluster_install_stage1_key(), "stage2": config_path.cluster_install_stage2_key() }
def __init__(self, cluster_name_id, region=None, profile=None): self.cluster_name_id = cluster_name_id # Region and profile info can be passed in with upgrade code path, # when this is run from axclustermanager outside cluster. self.region = AWSMetaData().get_region() if region is None else region self.profile = profile if profile is None: session = boto3.Session(region_name=self.region) else: session = boto3.Session(region_name=self.region, profile_name=profile) self.ec2 = session.resource('ec2') self.client = session.client('ec2') self.cluster_info = AXClusterInfo(cluster_name_id=cluster_name_id, aws_profile=profile) self.cluster_config = AXClusterConfig(cluster_name_id=cluster_name_id, aws_profile=profile) cluster_config_path = AXClusterConfigPath(cluster_name_id) self.s3_bucket = cluster_config_path.bucket() self.s3_config_prefix = cluster_config_path.master_config_dir() self.s3_attributes_path = cluster_config_path.master_attributes_path() self.s3_user_data_path = cluster_config_path.master_user_data_path() logger.info( "Create MasterManager in region %s, attributes path: %s and user_data_path: %s", self.region, self.s3_attributes_path, self.s3_user_data_path) # The EC2 instance object for the current master self.master_instance = None # Properties/attributes to use when launching the new master self.attributes = {} # For upgrades. # The following values are set to None from master manager but to not None from upgrade code. self.aws_image = None self.instance_profile = None self.event_notification_client = EventNotificationClient( FACILITY_PLATFORM)