How to use delete_traffic_policy method in localstack

Best Python code snippet using localstack_python

FortiOSAPI.py

Source:FortiOSAPI.py Github

copy

Full Screen

1import json2import logging3import urllib4import jinja25import requests6from templates import *7try: # Python 2.7+8 from logging import NullHandler9except ImportError:10 class NullHandler(logging.Handler):11 def emit(self, record):12 pass13# requests.packages.urllib3.disable_warnings(InsecureRequestWarning)14# may need to move to specifying the ca or use Verify=false15# verify="/etc/ssl/certs/" on Debian to use the system CAs16logging.getLogger(__name__).addHandler(NullHandler())17# create logger18LOG = logging.getLogger('fortiosapi')19class FClient(object):20 def __init__(self):21 self.host = None22 self._https = False23 self._logged = False24 self._fortiversion = "Version is set when logged"25 # reference the fortinet version of the targeted product.26 self._session = requests.session() # use single session27 # persistant and same for all28 self._session.verify = False29 # (can be changed to) self._session.verify = '/etc/ssl/certs/' or True30 # Will be switch to true by default it uses the python CA list in this case31 self.timeout = 1032 self.cert = None33 self._apitoken = None34 self._license = None35 self.url_prefix = None36 def login(self, host, username, password, verify=False, cert=None, timeout=12, https=None,):37 self.host = host38 LOG.debug("self._https is %s", self._https)39 self._https = https40 if not self._https:41 self.url_prefix = 'http://' + self.host42 else:43 self.url_prefix = 'https://' + self.host44 url = self.url_prefix + '/logincheck'45 if not self._session:46 self._session = requests.session()47 # may happen if logout is called48 if verify is not False:49 self._session.verify = verify50 if cert is not None:51 self._session.cert = cert52 # set the default at 12 see request doc for details http://docs.python-requests.org/en/master/user/advanced/53 self.timeout = timeout54 res = self._session.post(55 url,56 data='username=' + urllib.request.pathname2url(username) + '&secretkey=' + urllib.request.pathname2url(57 password) + "&ajax=1",58 timeout=self.timeout)59 self.logging(res)60 # Ajax=1 documented in 5.6 API ref but available on 5.461 LOG.debug("logincheck res : %s", res.content)62 if res.content.decode('ascii')[0] == '1':63 # Update session's csrftoken64 self.update_cookie()65 self._logged = True66 return True67 else:68 self._logged = False69 raise Exception('login failed')70 def logout(self):71 try:72 url = self.url_prefix + '/logout'73 res = self._session.post(url, timeout=self.timeout)74 self._session.close()75 self._session.cookies.clear()76 self._logged = False77 # set license to Valid by default to ensure rechecked at login78 self.logging(res)79 return True80 except Exception as e:81 self.logging(e)82 return False83 @staticmethod84 def logging(response):85 try:86 LOG.debug("response content type : %s", response.headers['content-type'])87 LOG.debug("Request : %s on url : %s ", response.request.method,88 response.request.url)89 LOG.debug("Response : http code %s reason : %s ",90 response.status_code, response.reason)91 LOG.debug("raw response: %s ", response.content)92 except:93 LOG.warning("method errors in request when global")94 def update_cookie(self):95 # Retrieve server csrf and update session's headers96 LOG.debug("cookies are : %s ", self._session.cookies)97 for cookie in self._session.cookies:98 if cookie.name == 'ccsrftoken':99 csrftoken = cookie.value[1:-1] # token stored as a list100 LOG.debug("csrftoken before update : %s ", csrftoken)101 self._session.headers.update({'X-CSRFTOKEN': csrftoken})102 LOG.debug("csrftoken after update : %s ", csrftoken)103 LOG.debug("New session header is: %s", self._session.headers)104 def format_url(self, path):105 return self.url_prefix + path106 def get(self, path):107 url = self.format_url(path)108 return self._session.get(url)109 def post(self, path, para):110 url = self.format_url(path)111 return self._session.post(url, json.dumps(para))112 def delete(self, path):113 url = self.format_url(path)114 return self._session.delete(url)115 def put(self, path, para):116 url = self.format_url(path)117 return self._session.put(url, json.dumps(para))118 def _render(self, template, **message):119 '''Render API message from it's template120 :param template: defined API message with essential params.121 :param message: It is a dictionary, included values of the params122 for the template123 '''124 if not message:125 message = {}126 msg = jinja2.Template(template).render(**message)127 return json.loads(msg)128 def send_req(self, template, **message):129 template_data = self._render(template, **message)130 path = template_data["path"]131 method = template_data["method"]132 if method == "GET":133 return self.get(path)134 elif method == "POST":135 para = template_data["body"]["json"]136 return self.post(path, para)137 elif method == "PUT":138 para = template_data["body"]["json"]139 return self.put(path, para)140 elif method == "DELETE":141 return self.delete(path)142 else:143 raise Exception("method not support ")144 # QOS145 def add_traffic_shaper(self, **message):146 return self.send_req(ADD_TRAFFIC_SHAPERS,147 **message148 )149 def set_traffic_shaper(self, **message):150 return self.send_req(SET_TRAFFIC_SHAPERS,151 **message152 )153 def del_traffic_shaper(self, **message):154 return self.send_req(DELETE_TRAFFIC_SHAPERS,155 **message156 )157 def get_traffic_shaper(self, **message):158 return self.send_req(GET_TRAFFIC_SHAPERS,159 **message160 )161 def add_traffic_policy(self, **message):162 return self.send_req(ADD_TRAFFIC_POLICY,163 **message164 )165 def set_traffic_policy(self, **message):166 return self.send_req(SET_TRAFFIC_POLICY,167 **message168 )169 def del_traffic_policy(self, **message):170 return self.send_req(DELETE_TRAFFIC_POLICY,171 **message172 )173 def get_traffic_policy(self, **message):174 return self.send_req(GET_TRAFFIC_POLICY,175 **message176 )177 # VPN178 def add_vpn_p1(self, **message):179 return self.send_req(ADD_VPN_P1,180 **message181 )182 def set_vpn_p1(self, **message):183 return self.send_req(SET_VPN_P1,184 **message185 )186 def del_vpn_p1(self, **message):187 return self.send_req(DELETE_VPN_P1,188 **message189 )190 def get_vpn_p1(self, **message):191 return self.send_req(GET_VPN_P1,192 **message193 )194 def add_vpn_p2(self, **message):195 return self.send_req(ADD_VPN_P2,196 **message197 )198 def set_vpn_p2(self, **message):199 return self.send_req(SET_VPN_P2,200 **message201 )202 def del_vpn_p2(self, **message):203 return self.send_req(DELETE_VPN_P2,204 **message205 )206 def get_vpn_p2(self, **message):207 return self.send_req(GET_VPN_P2,208 **message209 )210 def add_route_static(self, **message):211 return self.send_req(ADD_ROUTER_STATIC,212 **message213 )214 def set_route_static(self, **message):215 return self.send_req(SET_ROUTER_STATIC,216 **message217 )218 def del_route_static(self, **message):219 return self.send_req(DELETE_ROUTER_STATIC,220 **message221 )222 def get_route_static(self, **message):223 return self.send_req(GET_ROUTER_STATIC,224 **message225 )226 # Address227 def get_address(self, **message):228 return self.send_req(GET_FIREWALL_ADDRESS,229 **message)230 def set_address(self, **message):231 return self.send_req(SET_FIREWALL_ADDRESS,232 **message)233 def add_address(self, **message):234 return self.send_req(ADD_FIREWALL_ADDRESS,235 **message)236 def del_address(self, **message):237 return self.send_req(DELETE_FIREWALL_ADDRESS,238 **message)239 def get_address_group(self, **message):240 return self.send_req(GET_FIREWALL_ADDRGRP,241 **message)242 # Address Group243 def add_address_group(self, **message):244 return self.send_req(ADD_FIREWALL_ADDRGRP,245 **message)246 def set_address_group(self, **message):247 return self.send_req(SET_FIREWALL_ADDRGRP,248 **message)249 def del_address_group(self, **message):250 return self.send_req(DELETE_FIREWALL_ADDRGRP,251 **message)252 # Service253 def get_service(self, **message):254 return self.send_req(GET_FIREWALL_SERVICE,255 **message)256 # Service_Group257 def get_service_group(self, **message):258 return self.send_req(GET_FIREWALL_SERVICE_GROUP,259 **message)260 # NAT261 def add_vip(self, **message):262 return self.send_req(ADD_FIREWALL_VIP,263 **message264 )265 def del_vip(self, **message):266 return self.send_req(DELETE_FIREWALL_VIP,267 **message268 )269 def get_vip(self, **message):270 return self.send_req(GET_FIREWALL_VIP,271 **message272 )273 def add_ippool(self, **message):274 return self.send_req(ADD_FIREWALL_IPPOOL275 **message276 )277 def del_ippool(self, **message):278 return self.send_req(DELETE_FIREWALL_IPPOOL,279 **message280 )281 def get_ippool(self, **message):282 return self.send_req(GET_FIREWALL_IPPOOL,283 **message284 )285 def add_cent_nat(self, **message):286 return self.send_req(add_central_snat_map,287 **message288 )289 def get_cent_nat(self, **message):290 return self.send_req(get_central_snat_map,291 **message292 )293 def del_cent_nat(self, **message):294 return self.send_req(del_central_snat_map,295 **message296 )297 def set_cent_nat(self, **message):298 return self.send_req(set_central_snat_map,299 **message300 )301 # Int302 def get_int(self, **message):303 return self.send_req(GET_INTERFACE,304 **message305 )306 def set_int(self, **message):307 return self.send_req(SET_INTERFACE,308 **message309 )310 def add_int(self, **message):311 return self.send_req(ADD_INTERFACE,312 **message313 )314 def del_int(self, **message):315 return self.send_req(DELETE_INTERFACE,316 **message317 )318 # Vdom319 def get_vdom(self, **message):320 return self.send_req(GET_VDOM,321 **message322 )323 def add_vdom(self, **message):324 return self.send_req(ADD_VDOM,325 **message326 )327 def del_vdom(self, **message):328 return self.send_req(DELETE_VDOM,329 **message330 )331 # Policy332 def add_firewall_policy(self, **message):333 return self.send_req(ADD_FIREWALL_POLICY,334 **message335 )336 def get_firewall_policy(self, **message):337 return self.send_req(GET_FIREWALL_POLICY,338 **message339 )340 def set_firewall_policy(self, **message):341 return self.send_req(SET_FIREWALL_POLICY,342 **message343 )344 def del_firewall_policy(self, **message):345 return self.send_req(DELETE_FIREWALL_POLICY,346 **message347 )348 def move_firewall_policy(self, **message):349 return self.send_req(MOVE_FIREWALL_POLICY,350 **message351 )352 # Monitor353 # Monitor354 def get_policy_statistics(self, **message):355 return self.send_req(GET_POLICY_STATISTICS,356 **message357 )358 def get_session(self, **message):359 return self.send_req(GET_SESSION,360 **message361 )362 363 def get_system_userange(self, **message):364 return self.send_req(GET_SYSTEM_UseRange,365 **message366 )367 def get_ha_status(self, **message):368 return self.send_req(GET_HA_STATIUS,369 **message370 )371 def get_inteface_status(self, **message):372 return self.send_req(GET_Interface_Status,373 **message374 )375 def get_inteface_select(self, **message):376 return self.send_req(GET_Interface_Select,377 **message378 ) 379 def get_ipsec_status(self, **message):380 return self.send_req(GET_IPSEC_STATIUS,381 **message382 )383 def get_routeing_table(self,**message):384 return self.send_req(GET_ROUTING_TABLE,385 **message386 )387 def get_bandwidtg_used(self,**message):388 return self.send_req(GET_Bandwidth_USED,389 **message390 )391 def get_ssl_settings(self, **message):392 return self.send_req(GET_VPN_SSL_Settings,393 **message394 )395 def put_ssl_settings(self, **message):396 return self.send_req(PUT_VPN_SSL_Settings,397 **message398 )399 def add_ssl_policy(self, **message):400 return self.send_req(ADD_VPN_SSL_Policy,401 **message402 )403 def get_ssl_policy(self, **message):404 return self.send_req(GET_VPN_SSL_Policy,405 **message406 )407 def put_ssl_policy(self, **message):408 return self.send_req(PUT_VPN_SSL_Policy,409 **message410 )411 def del_ssl_policy(self, **message):412 return self.send_req(DEL_VPN_SSL_Policy,413 **message414 )415 def add_user(self, **message):416 return self.send_req(ADD_LOCAl_USER,417 **message418 )419 def del_user(self, **message):420 return self.send_req(DEL_LOCAl_USER,421 **message422 )423 def put_user(self, **message):424 return self.send_req(PUT_LOCAl_USER,425 **message426 )427 def get_user(self, **message):428 return self.send_req(GET_LOCAl_USER,429 **message430 )431 def add_user_group(self,**message):432 return self.send_req(ADD_USER_GROUP,433 **message434 )435 def del_user_group(self,**message):436 return self.send_req(DEL_USER_GROUP,437 **message438 )439 def put_user_group(self,**message):440 return self.send_req(PUT_USER_GROUP,441 **message442 )443 def get_user_group(self,**message):444 return self.send_req(GET_USER_GROUP,445 **message...

Full Screen

Full Screen

client.py

Source:client.py Github

copy

Full Screen

...37 def delete_query_logging_config(self, Id: str) -> Dict:38 pass39 def delete_reusable_delegation_set(self, Id: str) -> Dict:40 pass41 def delete_traffic_policy(self, Id: str, Version: int) -> Dict:42 pass43 def delete_traffic_policy_instance(self, Id: str) -> Dict:44 pass45 def delete_vpc_association_authorization(self, HostedZoneId: str, VPC: Dict) -> Dict:46 pass47 def disassociate_vpc_from_hosted_zone(self, HostedZoneId: str, VPC: Dict, Comment: str = None) -> Dict:48 pass49 def generate_presigned_url(self, ClientMethod: str = None, Params: Dict = None, ExpiresIn: int = None, HttpMethod: str = None):50 pass51 def get_account_limit(self, Type: str) -> Dict:52 pass53 def get_change(self, Id: str) -> Dict:54 pass55 def get_checker_ip_ranges(self) -> Dict:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful