Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

“Error 'ResourceSummaryCollection' object is not subscriptable” OCI PythonSDK

SNC-OracleMar 7 2021

I have python script that queries OCI Compute Instances with a defined tag and value of test and will take the results and stop any instance with those tags. I am expecting the query to return the result as a json object of according to this:
https://docs.oracle.com/en-us/iaas/Content/Search/Tasks/queryingresources.htm
However whenever I take the result and apply it to a variable I get the following error: "Error 'ResourceSummaryCollection' object is not subscriptable"
My function:
def do(signer):

print("Searching for untagged instance", flush=True)  

# results = ""  
# message = ""  
# resp    = ""  

try:  
    search\_client = oci.resource\_search.ResourceSearchClient(config={}, signer=signer)  
    print("Search client initialized",flush=True)  

    # PredefinedTag = "apps"  
    # key= "test"  
    # value= "test"  

    # structured\_search = oci.resource\_search.models.StructuredSearchDetails(  
    #         query="query instance resources where (definedTags.namespace = '{}' && definedTags.key = '{}' && definedTags.value = '{}')".format(PredefinedTag,key,value),  
    #         type='Structured',  
    #         matching\_context\_type=oci.resource\_search.models.SearchDetails.MATCHING\_CONTEXT\_TYPE\_NONE)  

    structured\_search = oci.resource\_search.models.StructuredSearchDetails(  
            query="query instance resources where (definedTags.namespace = 'apps' && definedTags.key = 'test' && definedTags.value = 'test')",  
            type='Structured',  
            matching\_context\_type=oci.resource\_search.models.SearchDetails.MATCHING\_CONTEXT\_TYPE\_NONE)  


    print("Step1",flush=True)  

    results = search\_client.search\_resources(structured\_search).data  

      
    print("Step1.5,flush=True")  
    # print(results\['items'\]\[0\]\['identifier'\])  
      
    print("Step2",flush=True)  
    # instanceId = results\['identifier'\]  
    instanceId = results\['items'\]\[0\]\['identifier'\]  
    print("Step3",flush=True)  
    resp = perform\_action(signer, instanceId , 'STOP')  
    print("Step4",flush=True)  


   
except oci.exceptions.ServiceError as e:  
        print('RQS Search failed with Service Error: {0}'.format(e),flush=True)  
        raise  
except oci.exceptions.RequestException as e:  
        print('RQS Search failed w/ a Request exception. {0}'.format(e),flush=True)  
        raise  

return resp

Comments

APEX.PROCESSING

Post Details

Added on Mar 7 2021
0 comments
227 views