-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathfunc.py
36 lines (32 loc) · 1.22 KB
/
func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
# oci-list-instances-python version 1.0.
#
# Copyright (c) 2020 Oracle, Inc.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
import io
import json
from fdk import response
import oci
def handler(ctx, data: io.BytesIO=None):
signer = oci.auth.signers.get_resource_principals_signer()
resp = list_instances(signer)
return response.Response(
ctx,
response_data=json.dumps(resp),
headers={"Content-Type": "application/json"}
)
# List instances ---------------------------------------------------------------
def list_instances(signer):
client = oci.core.ComputeClient(config={}, signer=signer)
# OCI API to manage Compute resources such as compute instances, block storage volumes, etc.
try:
# Returns a list of all instances in the current compartment
inst = client.list_instances(signer.compartment_id)
# Create a list that holds a list of the instances id and name next to each other
inst = [[i.id, i.display_name] for i in inst.data]
except Exception as ex:
print("ERROR: accessing Compute instances failed", ex, flush=True)
raise
resp = { "instances": inst }
return resp