Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapi_keys_example.py
More file actions
Latest commit
61 lines (49 loc) · 2.26 KB
/
Copy pathapi_keys_example.py
File metadata and controls
61 lines (49 loc) · 2.26 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
importlogging
importtraceback
fromtimeimportsleep
# Place script specific intersight api imports here
fromintersight.apiimportiam_api
fromintersight.model.iam_api_keyimportIamApiKey
importintersight
importcredentials
FORMAT='%(asctime)-15s [%(levelname)s] [%(filename)s:%(lineno)s] %(message)s'
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
logger=logging.getLogger('openapi')
defmain():
client=credentials.config_credentials()
try:
# Create version 2 API key ID and Secret key
api_key=IamApiKey()
api_key.purpose='python_key_v2'
iam_keys_instance=iam_api.IamApi(client)
api_response=iam_keys_instance.create_iam_api_key(api_key)
print('Private v2 Key:', api_response.private_key)
withopen('SecretKey_Python_v2.txt', 'w') asfile:
file.write(api_response.private_key)
api_key_id=api_response.account_moid+'/'+api_response.user.moid+'/'+api_response.moid
print('Api v2 Key Id:', api_key_id)
withopen('ApiKeyIdFile_Python_v2', 'w') asfile:
file.write(api_key_id)
# Delete v2 key
api_response=iam_keys_instance.delete_iam_api_key(moid=api_response.moid)
sleep(5)
# Create version 3 API key ID and Secret key
api_key.purpose='python_key_v3'
api_key.hash_algorithm='SHA256'
api_key.key_spec=dict(curve='P256', object_type='pkix.EcdsaKeySpec', class_id='pkix.EcdsaKeySpec')
api_key.signing_algorithm='Ecdsa'
api_response=iam_keys_instance.create_iam_api_key(api_key)
print('Private v3 Key:', api_response.private_key)
withopen('SecretKey_Python_v3.txt', 'w') asfile:
file.write(api_response.private_key)
api_key_id=api_response.account_moid+'/'+api_response.user.moid+'/'+api_response.moid
print('Api v3 Key Id:', api_key_id)
withopen('ApiKeyIdFile_Python_v3', 'w') asfile:
file.write(api_key_id)
# Delete v3 key
api_response=iam_keys_instance.delete_iam_api_key(moid=api_response.moid)
exceptintersight.OpenApiExceptionasexp:
logger.error("Exception when calling API: %s\n", exp)
traceback.print_exc()
if__name__=="__main__":
main()