def get_antiddos_weekly_report(self, period_start_date=None): """get weekly anti-ddos report for all EIP :param period_start_date: period start date (datetime) :return: """ if period_start_date: epoch = time.mktime(period_start_date.timetuple()) params = utils.remove_empty_from_dict( {"period_start_date": int(epoch * 1000)}) else: params = {} url = "/antiddos/weekly" return self._get(url, params=params, resource_class=resource.AntiDDosWeeklyReport)
def get_antiddos_daily_logs(self, floating_ip_id, sort_dir=None, limit=None, offset=None): """get past 24 hours anti-ddos logs, delay is less than 5 minutes""" params = utils.remove_empty_from_dict({ "sort_dir": sort_dir, "limit": limit, "offset": offset, }) url = "/antiddos/%s/logs" % floating_ip_id return self._list(url, key="logs", params=params, resource_class=resource.AntiDDosLog)
def list(self, status=None, ip=None, limit=None, offset=None): """list antiddos status of all EIP :param status: normal|configging|notConfig|packetcleaning|packetdropping :param ip: query for ip matches ".*ip.*" :param limit: max returned length :param offset: query offset :return: """ params = utils.remove_empty_from_dict({ "status": status, "ip": ip, "limit": limit, "offset": offset, }) return self._list("/antiddos", params=params, key='ddosStatus')
def update_antiddos(self, floating_ip_id, enable_l7, traffic_pos_id, http_request_pos_id, cleaning_access_pos_id, app_type_id): """update anti DDos""" data = utils.remove_empty_from_dict({ "enable_L7": enable_l7, "traffic_pos_id": traffic_pos_id, "http_request_pos_id": http_request_pos_id if enable_l7 else 15, "cleaning_access_pos_id": cleaning_access_pos_id, "app_type_id": app_type_id }) resource_url = "/antiddos/%s" % floating_ip_id return self._update_all(resource_url, data, raw=True)
def open_antiddos(self, floating_ip_id, enable_l7, traffic_pos_id, http_request_pos_id, cleaning_access_pos_id, app_type_id): """Open AntiDDos""" data = utils.remove_empty_from_dict({ "enable_L7": enable_l7, "traffic_pos_id": traffic_pos_id, "http_request_pos_id": http_request_pos_id if enable_l7 else 15, "cleaning_access_pos_id": cleaning_access_pos_id, "app_type_id": app_type_id }) return self._create("/antiddos/%s" % floating_ip_id, data=data, raw=True)
def test_remove_empty_from_dict(self): d = dict(k1=None, k2='', k3='abc') self.assertEqual({'k3': 'abc'}, utils.remove_empty_from_dict(d))