Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    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')
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def test_remove_empty_from_dict(self):
     d = dict(k1=None, k2='', k3='abc')
     self.assertEqual({'k3': 'abc'}, utils.remove_empty_from_dict(d))