Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AutoScaleALL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,7 @@ def autoscale_region(region):
# Get Command Line Parser
parser = argparse.ArgumentParser()
parser.add_argument('-t', default="", dest='config_profile', help='Config file section to use (tenancy profile)')
parser.add_argument('-rp', action='store_true', default=False, dest='is_resource_principals', help='Use Resource Principals for Authentication')
parser.add_argument('-ip', action='store_true', default=False, dest='is_instance_principals', help='Use Instance Principals for Authentication')
parser.add_argument('-dt', action='store_true', default=False, dest='is_delegation_token', help='Use Delegation Token for Authentication')
parser.add_argument('-a', default="All", dest='action', help='Action All, Down, Up')
Expand Down Expand Up @@ -1685,7 +1686,7 @@ def autoscale_region(region):
print_header("Running Auto Scale")

# Identity extract compartments
config, signer = OCIFunctions.create_signer(cmd.config_profile, cmd.is_instance_principals, cmd.is_delegation_token)
config, signer = OCIFunctions.create_signer(cmd.config_profile, cmd.is_resource_principals, cmd.is_instance_principals, cmd.is_delegation_token)
compartments = []
tenancy = None
tenancy_home_region = ""
Expand Down
3 changes: 2 additions & 1 deletion CreateNameSpaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def MakeLog(msg):
# Get Command Line Parser
parser = argparse.ArgumentParser()
parser.add_argument('-t', default="", dest='config_profile', help='Config file section to use (tenancy profile)')
parser.add_argument('-rp', action='store_true', default=False, dest='is_resource_principals', help='Use Resource Principals for Authentication')
parser.add_argument('-ip', action='store_true', default=False, dest='is_instance_principals', help='Use Instance Principals for Authentication')
parser.add_argument('-dt', action='store_true', default=False, dest='is_delegation_token', help='Use Delegation Token for Authentication')

cmd = parser.parse_args()

config, signer = OCIFunctions.create_signer(cmd.config_profile, cmd.is_instance_principals, cmd.is_delegation_token)
config, signer = OCIFunctions.create_signer(cmd.config_profile, cmd.is_resource_principals, cmd.is_instance_principals, cmd.is_delegation_token)

MakeLog("Starts at " + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
MakeLog("\nConnecting to Identity Service...")
Expand Down
15 changes: 13 additions & 2 deletions OCIFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@
# Input - config_profile and is_instance_principals and is_delegation_token
# Output - config and signer objects
##########################################################################
def create_signer(config_profile, is_instance_principals, is_delegation_token):
def create_signer(config_profile, is_resource_principals, is_instance_principals, is_delegation_token):

# if resource principals authentications
if is_resource_principals:
try:
signer = oci.auth.signers.get_resource_principals_signer()
config = {'region': signer.region, 'tenancy': signer.tenancy_id}
return config, signer

except Exception:
print_header("Error obtaining resource principals certificate, aborting")
raise SystemExit

# if instance principals authentications
if is_instance_principals:
elif is_instance_principals:
try:
signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
config = {'region': signer.region, 'tenancy': signer.tenancy_id}
Expand Down
32 changes: 32 additions & 0 deletions func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import io
import json
import logging
import subprocess

from fdk import response


def handler(ctx, data: io.BytesIO = None):
result = None
try:
logging.getLogger().info("Scaling started")
result = subprocess.run(["/bin/python", "AutoScaleALL.py", "-rp"], capture_output=True)
logging.getLogger().info("Scaling completed ")
logging.getLogger().info("subprocess result out"+ str(result.stdout))
logging.getLogger().info("subprocess result err"+ str(result.stderr))
return response.Response(
ctx, response_data=json.dumps(
{"message": "Processing complete", "result_out": str(result.stdout), "result_err": str(result.stderr)}),
headers={"Content-Type": "application/json"}
)
except (Exception, ValueError) as ex:
logging.getLogger().info('error executing AutoScaleALL.py')
logging.getLogger().error("result.stdout:"+str(result.stdout))
logging.getLogger().error("result.stderr:"+str(result.stderr))
logging.getLogger().error(str(ex))

return response.Response(
ctx, response_data=json.dumps(
{"message": "Processing failed"}),
headers={"Content-Type": "application/json"}
)
9 changes: 9 additions & 0 deletions func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
schema_version: 20180708
name: oci-autoscaler
version: 1.0.0
runtime: python
build_image: fnproject/python:3.11-dev
run_image: fnproject/python:3.11
entrypoint: /python/bin/fdk /function/func.py handler
memory: 512
timeout: 300
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
oci==2.98.0
fdk>=0.1.83