def create_config_group(self, app_id, config_group_name, config_items, deploy_type, enable, service_ids, region_name, team_name): # create application config group group_req = { "app_id": app_id, "config_group_name": config_group_name, "deploy_type": deploy_type, "enable": enable, "region_name": region_name, "config_group_id": make_uuid(), } try: app_config_group_repo.get(region_name, app_id, config_group_name) except ApplicationConfigGroup.DoesNotExist: cgroup = app_config_group_repo.create(**group_req) create_items_and_services(cgroup, config_items, service_ids) region_app_id = region_app_repo.get_region_app_id( region_name, app_id) region_api.create_app_config_group( region_name, team_name, region_app_id, { "app_id": region_app_id, "config_group_name": config_group_name, "deploy_type": deploy_type, "service_ids": service_ids, "config_items": config_items, }) else: raise ErrAppConfigGroupExists return self.get_config_group(region_name, app_id, config_group_name)
def update_config_group(self, region_name, app_id, config_group_name, config_items, enable, service_ids, team_name): group_req = { "enable": enable, "update_time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), } try: cgroup = app_config_group_repo.get(region_name, app_id, config_group_name) except ApplicationConfigGroup.DoesNotExist: raise ErrAppConfigGroupNotFound else: app_config_group_repo.update(region_name, app_id, config_group_name, **group_req) app_config_group_item_repo.delete(cgroup.config_group_id) app_config_group_service_repo.delete(cgroup.config_group_id) create_items_and_services(cgroup, config_items, service_ids) region_app_id = region_app_repo.get_region_app_id( cgroup.region_name, app_id) region_api.update_app_config_group( cgroup.region_name, team_name, region_app_id, cgroup.config_group_name, { "service_ids": service_ids, "config_items": config_items, }) return self.get_config_group(region_name, app_id, config_group_name)
def get_config_group(self, region_name, app_id, config_group_name): try: cgroup = app_config_group_repo.get(region_name, app_id, config_group_name) except ApplicationConfigGroup.DoesNotExist: raise ErrAppConfigGroupNotFound config_group_info = build_response(cgroup) return config_group_info
def delete_config_group(self, region_name, team_name, app_id, config_group_name): cgroup = app_config_group_repo.get(region_name, app_id, config_group_name) region_app_id = region_app_repo.get_region_app_id( cgroup.region_name, app_id) try: region_api.delete_app_config_group(cgroup.region_name, team_name, region_app_id, cgroup.config_group_name) except region_api.CallApiError as e: if e.status != 404: raise e app_config_group_item_repo.delete(cgroup.config_group_id) app_config_group_service_repo.delete(cgroup.config_group_id) app_config_group_repo.delete(cgroup.region_name, app_id, config_group_name)