QuestionQ88

VerifiedUnderstanding and Using APIs

Question Image

Refer to the exhibit. Drag the code from the bottom into the missing boxes to build a Python script using the Cisco SDK. Not every option is used.

Drag & Drop
import sys, json, argparse
from intersight.intersight_api_client import IntersightApiClient
from intersight.apis import asset_device_registration_api, asset_device_claim_api

result = dict(changed=False)

parser = argparse.ArgumentParser()
parser.add_argument('-a', '--api_params', default='intersight_api_params.json')
parser.add_argument('-t', '--target_host', dest='hostname', required=True)
args = parser.parse_args()
with open(args.api_params, 'r') as api_file:
    intersight_api_params = json.load(  )

api_instance = IntersightApiClient(
    host=intersight_api_params[''],
    private_key=intersight_api_params['api_private_key_file'],
    api_key_id=intersight_api_params['api_key_id'],
)
api_handle = asset_device_registration_api.AssetDeviceRegistrationApi(api_instance)

kwargs = dict(filter="ConnectionStatus eq 'Connected'")
api_result = api_handle.asset_device_registrations_get(**  )
for device in api_result.results:
    if device.device_ip_address[0] == args.hostname:
        api_handle = asset_device_claim_api.AssetDeviceClaimApi(api_instance)
        api_handle.asset_device_claims_moid_delete(moid=device.device_claim.moid)
        result['changed'] = True
        break
Explanation

api_file is the file object opened from the command-line API-parameters path and is therefore the input to json.load. The parsed configuration uses api_base_uri for the SDK client's host. kwargs contains the filter and is unpacked as keyword arguments when retrieving asset device registrations.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!