def aliyun_nas_api(): all_keys_obj_list = __get_all_aliyun_keys() ret_nas_list = [] ret_nas_pkg_list = [] for keys_obj in all_keys_obj_list: nas_list = get_aliyun_resource( access_key=keys_obj.access_key, access_secret=keys_obj.access_secret, region_id=keys_obj.region_id, resource='nas', kwargs={ 'region_id': keys_obj.region_id } ) nas_package_list = get_aliyun_resource( access_key=keys_obj.access_key, access_secret=keys_obj.access_secret, region_id=keys_obj.region_id, resource='nas_package', kwargs={ 'region_id': keys_obj.region_id } ) ret_nas_list.extend(nas_list) ret_nas_pkg_list.extend(nas_package_list) return ret_nas_list, ret_nas_pkg_list
def create(self, request, *args, **kwargs): serializer = self.serializer_class(data=request.data) serializer.is_valid(raise_exception=True) app_obj = AppDetail.objects.get( app_name=serializer.validated_data['app_name']) ecs_obj_list = get_app_rel_host(app_id=app_obj.id)['aliyun'] ecs_obj = ecs_obj_list.get( private_ip__contains=serializer.validated_data['ip'], environment=serializer.validated_data['env']) aliyun_key_obj = AliyunKeys.objects.get(id=ecs_obj.ac_key_id) try: res = get_aliyun_resource( access_key=aliyun_key_obj.access_key, access_secret=aliyun_key_obj.access_secret, region_id=aliyun_key_obj.region_id, resource='adjust_slb', kwargs={ 'app_name': app_obj.app_name, 'weight': serializer.validated_data['weight'], 'server_id': ecs_obj.instance_id }) except Exception as e: logger.error('调整slb 失败') logger.exception(e) res = {} return Response(res, status=status.HTTP_200_OK)
def aliyun_rds_api(): all_keys_obj_list = __get_all_aliyun_keys() ret_list = [] for keys_obj in all_keys_obj_list: data_list = get_aliyun_resource( access_key=keys_obj.access_key, access_secret=keys_obj.access_secret, region_id=keys_obj.region_id, resource='rds', kwargs={ 'region_id': keys_obj.region_id } ) ret_list.extend(data_list) return ret_list