def _delete_cluster_bucket(self): logger.info("Deleting applatix-cluster bucket contents for cluster %s ...", self._name_id) cluster_bucket = Cloud().get_bucket(AXClusterConfigPath(name_id=self._name_id).bucket(), aws_profile=self._aws_profile, region=self._aws_region) idobj = AXClusterId(name=self._name_id) cluster_config_path = AXClusterConfigPath(name_id=self._name_id) cluster_name = idobj.get_cluster_name() prefix = cluster_name + "/" # TODO: Not idempotent here. # Consider the following case: if there is exception thrown when deleting S3 objects, install stage 1 # information has already been deleted but not everything are successfully deleted, the next time user # executes "delete", this program will assume install stage 1 has been cleaned up. exempt = [idobj.get_cluster_id_s3_key(), cluster_config_path.cluster_install_stage0_key()] logger.info("Deleting objects for cluster %s from bucket %s. This may take some while.", cluster_name, cluster_bucket.get_bucket_name()) cluster_bucket.delete_all(obj_prefix=prefix, exempt=exempt) logger.info("Deleting objects for cluster %s from bucket %s ... DONE", cluster_name, cluster_bucket.get_bucket_name()) logger.info("Deleting stage0 information ...") for item in exempt: cluster_bucket.delete_object(item) logger.info("Deleting stage0 information ... DONE")
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() }