def deactivate_cluster(self, cluster): """ deactivates a cluster and allocates environments on it to other clusters :param cluster: name of deactivated cluster :return: """ # 1. get a list of environments allocated to the deactivated cluster self.logger.info("Deactivating cluster " + cluster) mongo_persistence_manager = MongoPersistenceManager(url=MONGOURL, db=MONGODB, uid=MONGOUID, pwd=MONGOPWD) mongo_persistence_manager.connect() results = mongo_persistence_manager.find(ENVIRONMENTS_COLLECTION, {CLUSTER_IDENTIFIER: cluster}) self.logger.info( "Cluster has " + str(len(results)) + " environments currently allocated - re-allocating these") # 2. remove currennt allocations mongo_persistence_manager.delete(ENVIRONMENTS_COLLECTION, {CLUSTER_IDENTIFIER: cluster}) # 3. re-allocate for record in results: self.logger.info("Reallocating env " + record["env"] + " for project " + record["project"]) envs = [] envs.append(record["env"]) self.allocate_env(record["project"], envs) self.logger.info("Re-allocation complete")
def remove_env(self, project, env=None): """ Removes an environment from a project ("DEV" environment CANNOT be removed) :param project: name of project :param env: name of environment :return: None """ self.logger.info( "Entering remove_env with parameters project %s, env %s" % (project, env)) # remove record from the database mongo_persistence_manager = MongoPersistenceManager(url=MONGOURL, db=MONGODB, uid=MONGOUID, pwd=MONGOPWD) mongo_persistence_manager.connect() removal_json = {PROJECT_IDENTIFIER: project} if env is not None: removal_json[ENVIRONMENT_IDENTIFIER] = env mongo_persistence_manager.delete(ENVIRONMENTS_COLLECTION, removal_json) self.logger.info( "Removed record for project environment from environments collection" ) return