Skip to content

Commit

Permalink
Cloudlet
Browse files Browse the repository at this point in the history
  • Loading branch information
achuthakamai committed Dec 29, 2023
1 parent e46433f commit bc9ace8
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyakamai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
from .akamaiehn import AkamaiEdgeHostName
from .akamaicasemanagement import AkamaiCaseManagement
from .akamaichinacdn import AkamaiChinaCDN
from .akamaicloudlets import AkamaiCloudlets

Binary file modified pyakamai/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified pyakamai/__pycache__/akamaiehn.cpython-311.pyc
Binary file not shown.
Binary file modified pyakamai/__pycache__/akamailds.cpython-311.pyc
Binary file not shown.
Binary file added pyakamai/__pycache__/akamains.cpython-311.pyc
Binary file not shown.
Binary file modified pyakamai/__pycache__/akamaiproperty.cpython-311.pyc
Binary file not shown.
Binary file added pyakamai/__pycache__/akamaiss.cpython-311.pyc
Binary file not shown.
Binary file modified pyakamai/__pycache__/pyakamai.cpython-311.pyc
Binary file not shown.
129 changes: 129 additions & 0 deletions pyakamai/akamaicloudlets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
""" Copyright 2015 Akamai Technologies, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import sys
import os
import requests
import logging
import json
from akamai.edgegrid import EdgeGridAuth, EdgeRc
from .http_calls import EdgeGridHttpCaller

class AkamaiCloudlets():
def __init__(self,prdHttpCaller,accountSwitchKey=None):
self._prdHttpCaller = prdHttpCaller
self.accountSwitchKey = accountSwitchKey
return None

def listPolicies(self):
ep = '/cloudlets/api/v2/policies'
params = {}
if self.accountSwitchKey:
params['accountSwitchKey']= self.accountSwitchKey
status,policyList = self._prdHttpCaller.getResult(ep,params=params)
else:
status,policyList = self._prdHttpCaller.getResult(ep)
return status,policyList

def getPolicyVersion(self,policyId,version):
ep = '/cloudlets/api/v2/policies/{}/versions/{}'.format(policyId,version)
params = {}
if self.accountSwitchKey:
params['accountSwitchKey']= self.accountSwitchKey
status,policyDetail = self._prdHttpCaller.getResult(ep,params=params)
else:
status,policyDetail = self._prdHttpCaller.getResult(ep)
return status,policyDetail

def updatePolicyVersion(self,policyId,version,description,matchRulesDict):
ep = '/cloudlets/api/v2/policies/{}/versions/{}'.format(policyId,version)
headers = {'Content-Type': 'application/json'}

record ={}
record['description'] = description
record['matchRules'] = matchRulesDict

recordjson = json.dumps(record)
#print(recordjson)


if self.accountSwitchKey:
params = {'accountSwitchKey':self.accountSwitchKey}
status,result = self._prdHttpCaller.putResult(ep,recordjson,headers=headers,params=params)
else:
status,result = self._prdHttpCaller.putResult(ep,recordjson,headers=headers)

if status in [201,200]:
print("Successfully update the Policy with new ruleset")
return True
else:
print("Failed to update the Policy with new ruleset")
print(json.dumps(result,indent=2))
return False

def createPolicyVersion(self,policyId,description,matchRulesDict):
ep = '/cloudlets/api/v2/policies/{}/versions'.format(policyId)
headers = {'Content-Type': 'application/json'}

record ={}
record['description'] = description
record['matchRules'] = matchRulesDict

recordjson = json.dumps(record)
#print(recordjson)


if self.accountSwitchKey:
params = {'accountSwitchKey':self.accountSwitchKey}
status,result = self._prdHttpCaller.postResult(ep,recordjson,headers=headers,params=params)
else:
status,result = self._prdHttpCaller.postResult(ep,recordjson,headers=headers)

if status in [201,200]:
print("Successfully created new Policy with new ruleset")
return True,result['version']
else:
print("Failed to create new Policy with new ruleset")
print(json.dumps(result,indent=2))
return False,0

def activatePolicyVersion(self,policyId,version,network):
ep = '/cloudlets/api/v2/policies/{}/versions/{}/activations'.format(policyId,version)
headers = {
"accept": "application/json",
"content-type": "application/json"
}
record ={}
record['network'] = network

recordjson = json.dumps(record)
if self.accountSwitchKey:
params = {'accountSwitchKey':self.accountSwitchKey}
status,result = self._prdHttpCaller.postResult(ep,recordjson,headers=headers,params=params)
else:
status,result = self._prdHttpCaller.postResult(ep,recordjson,headers=headers)

if status in [201,200]:
print("Successfully activated the policy")
return True
else:
print("Failed to activate the policy")
print(json.dumps(result,indent=2))
return False





4 changes: 4 additions & 0 deletions pyakamai/pyakamai.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .akamaidiagnostictools import AkamaiDiagnosticTools
from .akamains import AkamaiNetstorage
from .akamaiss import AkamaiSiteShield
from .akamaicloudlets import AkamaiCloudlets
import sys
import os
import requests
Expand Down Expand Up @@ -81,6 +82,9 @@ def client(self, product, *args):
elif product == 'chinacdn':
class_obj = AkamaiChinaCDN(self._prdHttpCaller,self.accountSwitchKey,*args)

elif product == 'cloudlets':
class_obj = AkamaiCloudlets(self._prdHttpCaller,self.accountSwitchKey,*args)

elif product == 'diagnostictools':
class_obj = AkamaiDiagnosticTools(self._prdHttpCaller,self.accountSwitchKey,*args)

Expand Down

0 comments on commit bc9ace8

Please sign in to comment.