Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moving to pycryptodome since pycrypto is depricated #26

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8b32150
ucs device type for newer imcs supporting xml sessions
Mar 5, 2018
9ecac59
moving to pycryptodome since pycrypto is depricated
kmccabe2 May 7, 2018
55704b6
removing requests version requirement
kmccabe2 May 7, 2018
97c1f0f
add user changed to function
May 24, 2018
4d0c2a2
Merge pull request #23 from dsoper2/ucs_bulk_claim
dsoper2 May 24, 2018
9aa1fc8
Update to API version: 1.0.5-612 supporting HX deployment and other r…
Jun 4, 2018
1ae2161
Merge remote-tracking branch 'upstream/master' into api-1-0-5-612
Jun 5, 2018
d630faf
Merge pull request #27 from dsoper2/api-1-0-5-612
dsoper2 Jun 5, 2018
800683a
Version updated to 1.0.1 and changed urllib3 dependency <= 1.22 to av…
Jun 8, 2018
637a748
Merge pull request #29 from dsoper2/requests
dsoper2 Jun 8, 2018
3a1c711
SDK version 1.0.2 following API version: 1.0.7-681
Aug 2, 2018
2a44a4b
Merge pull request #30 from dsoper2/master
dsoper2 Aug 2, 2018
9f4a217
pycryptodome support for Python 2 or 3 byte strings
Aug 31, 2018
5f32010
Merge pull request #31 from dsoper2/master
dsoper2 Aug 31, 2018
67afad5
1.0.9-228
ategaw-cisco Oct 18, 2018
1847fee
1.0.9-228 version and requirements for examples scripts.
Oct 23, 2018
339a2a2
Merge pull request #32 from CiscoUcs/update_1.0.9-228
dsoper2 Oct 23, 2018
2744fca
fix for duplicate parameters
Nov 2, 2018
729f818
Merge pull request #33 from dipeshah/update_1.0.9-255
dsoper2 Nov 6, 2018
c07ef72
retry on 5XX status error from device connector API
Dec 6, 2018
d9fc35c
Merge pull request #34 from dsoper2/master
dsoper2 Dec 6, 2018
616d780
CSCvn28766: Red Hat, Ubuntu and CentOS support for the Intersight OS …
sopatnai Mar 12, 2019
ad7edf3
CSCvn28766: Updated Readme to add supported flavors
sopatnai Mar 14, 2019
5e1be50
CSCvn28766: Updated Readme to add supported flavors
sopatnai Mar 14, 2019
4602455
urllib3 version 1.23 and later to address security vulnerabilities
Apr 11, 2019
6eaa6a3
Merge pull request #37 from dsoper2/requests
dsoper2 Apr 11, 2019
8846507
Added SUSE support for OS Discovery Tool
malu-cisco May 31, 2019
a0bce21
Added SUSE support for OS Discovery Tool
malu-cisco May 31, 2019
780e670
:wq
kmccabe2 Aug 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2,132 changes: 1,493 additions & 639 deletions README.md

Large diffs are not rendered by default.

116 changes: 54 additions & 62 deletions examples/add_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,60 @@
import json
import argparse
from intersight.intersight_api_client import IntersightApiClient
from intersight.apis import iam_account_api
from intersight.apis import iam_user_api
from intersight.apis import iam_role_api
from intersight.apis import iam_end_point_role_api
from intersight.apis import iam_permission_api
from intersight.apis import iam_idp_reference_api
from intersight.apis import iam_user_api


def add_user(intersight_api_params, username, user_role='Account Administrator'):
# Create Intersight API instance
# ----------------------
api_instance = IntersightApiClient(
host=intersight_api_params['api_base_uri'],
private_key=intersight_api_params['api_private_key_file'],
api_key_id=intersight_api_params['api_key_id'],
)

# GET Permissions
permissions_handle = iam_permission_api.IamPermissionApi(api_instance)
kwargs = dict(filter="Name eq '%s'" % user_role)
permissions_result = permissions_handle.iam_permissions_get(**kwargs)

if permissions_result.results:
# GET IdpReference
idp_reference_handle = iam_idp_reference_api.IamIdpReferenceApi(api_instance)
idp_reference_name = 'Cisco'
kwargs = dict(filter="Name eq '%s'" % idp_reference_name)
idp_reference_result = idp_reference_handle.iam_idp_references_get(**kwargs)
if idp_reference_result.results:
user_matches = False
# GET Users
users_handle = iam_user_api.IamUserApi(api_instance)
kwargs = dict(filter="Email eq '%s'" % username)
users_result = users_handle.iam_users_get(**kwargs)
if (
users_result.results and
users_result.results[0].permissions[0].moid == permissions_result.results[0].moid and
users_result.results[0].idpreference.moid == idp_reference_result.results[0].moid
):
user_matches = True

if not user_matches:
# POST Users with Permissions and IdpReference
users_body = {
'Email': username,
'Idpreference': idp_reference_result.results[0].moid,
'Permissions': [permissions_result.results[0].moid],
}
users_result = users_handle.iam_users_post(users_body)
result['changed'] = True
else: # user exists and IdP/Permissions match
print('User exists with requested role:', username)
else:
print('Could not find IdP', idp_reference_name)
else:
print('Invalid user role', user_role)


if __name__ == "__main__":
result = dict(changed=False)
Expand All @@ -25,64 +74,7 @@
with open(args.api_params, 'r') as api_file:
intersight_api_params = json.load(api_file)

# Create Intersight API instance
# ----------------------
api_instance = IntersightApiClient(
host=intersight_api_params['api_base_uri'],
private_key=intersight_api_params['api_private_key_file'],
api_key_id=intersight_api_params['api_key_id'],
)

# GET Users
users_handle = iam_user_api.IamUserApi(api_instance)
kwargs = dict(filter="Name eq '%s'" % args.id)
users_result = users_handle.iam_users_get(**kwargs)
if users_result.results:
print("User already exists:", args.id)
else:
# GET Accounts
accounts_handle = iam_account_api.IamAccountApi(api_instance)
accounts_result = accounts_handle.iam_accounts_get()

# POST Users with Idpreference
users_body = {
'Name': args.id,
'Idpreference': accounts_result.results[0].idpreferences[0],
}
users_result = users_handle.iam_users_post(users_body)
result['changed'] = True

# GET Users
kwargs = dict(filter="Name eq '%s'" % args.id)
users_result = users_handle.iam_users_get(**kwargs)

# GET Roles
roles_handle = iam_role_api.IamRoleApi(api_instance)
roles_result = roles_handle.iam_roles_get()
for role in roles_result.results:
if role.name == args.role:
# GET EndPointRoles
end_point_roles_handle = iam_end_point_role_api.IamEndPointRoleApi(api_instance)
endpoint_roles = {}
endpoint_roles['Read-Only'] = 'endpoint-readonly'
endpoint_roles['Account Administrator'] = 'endpoint-admin'
kwargs = dict(filter="RoleType eq '%s'" % endpoint_roles[args.role])
end_point_roles_result = end_point_roles_handle.iam_end_point_roles_get(**kwargs)

# POST Permissions with EndPointRoles
permissions_handle = iam_permission_api.IamPermissionApi(api_instance)
permissions_body = {
'Subject': users_result.results[0].moid,
'Type': 'User',
'Account': accounts_result.results[0].account_moid,
'EndPointRoles': end_point_roles_result.results,
'Roles': [role],
}
permissions_result = permissions_handle.iam_permissions_post(permissions_body)
break
else:
# for loop completed without finding a role
print("Role not found:", args.role)
add_user(intersight_api_params, args.id, args.role)

except Exception as err:
print("Exception:", str(err))
Expand Down
51 changes: 33 additions & 18 deletions examples/claim_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import argparse
import os.path
import json
from time import sleep
from intersight.intersight_api_client import IntersightApiClient
from intersight.apis import asset_device_claim_api
import device_connector
Expand Down Expand Up @@ -33,20 +34,23 @@
result = dict(changed=False)
result['msg'] = " Host: %s" % device['hostname']
# default access mode to allow control (Read-only False) and set to a boolean value if a string
if device.get('read_only') == None:
if not device.get('read_only'):
device['read_only'] = False
else:
if device['read_only'] == 'True' or device['read_only'] == 'true':
device['read_only'] = True
elif device['read_only'] == 'False' or device['read_only'] == 'false':
device['read_only'] = False
# create device connector object based on device type
if device['device_type'] == 'ucsm' or device['device_type'] == 'ucspe':
if device['device_type'] == 'ucs' or device['device_type'] == 'ucsm' or device['device_type'] == 'ucspe':
dc_obj = device_connector.UcsDeviceConnector(device)
elif device['device_type'] == 'hx':
dc_obj = device_connector.HxDeviceConnector(device)
elif device['device_type'] == 'imc':
dc_obj = device_connector.ImcDeviceConnector(device)
# attempt ucs connection and if that doesn't login revert to older imc login
dc_obj = device_connector.UcsDeviceConnector(device)
if not dc_obj.logged_in:
dc_obj = device_connector.ImcDeviceConnector(device)
else:
result['msg'] += " Unknown device_type %s" % device['device_type']
return_code = 1
Expand All @@ -59,16 +63,16 @@
print(json.dumps(result))
continue

ro_json = dc_obj.enable_connector()
if ro_json['AdminState'] is False:
ro_json = dc_obj.configure_connector()
if not ro_json['AdminState']:
return_code = 1
if ro_json.get('ApiError'):
result['msg'] += ro_json['ApiError']
print(json.dumps(result))
continue

# set access mode (ReadOnlyMode True/False) to desired state
if (ro_json.get('ReadOnlyMode') != None) and (ro_json['ReadOnlyMode'] != device['read_only']):
if (ro_json.get('ReadOnlyMode') is not None) and (ro_json['ReadOnlyMode'] != device['read_only']):
ro_json = dc_obj.configure_access_mode(ro_json)
if ro_json.get('ApiError'):
result['msg'] += ro_json['ApiError']
Expand All @@ -77,23 +81,34 @@
continue
result['changed'] = True

# if not connected, configure proxy settings if proxy settings were provided
if ro_json['ConnectionState'] != 'Connected' and device.get('proxy_host') and device.get('proxy_port'):
ro_json = dc_obj.configure_proxy(ro_json)
if ro_json.get('ApiError'):
result['msg'] += ro_json['ApiError']
return_code = 1
print(json.dumps(result))
continue
result['changed'] = True
# configure proxy settings (changes reported in called function)
ro_json = dc_obj.configure_proxy(ro_json, result)
if ro_json.get('ApiError'):
result['msg'] += ro_json['ApiError']
return_code = 1
print(json.dumps(result))
continue

# wait for a connection to establish before checking claim state
for _ in range(10):
if ro_json['ConnectionState'] != 'Connected':
sleep(1)
ro_json = dc_obj.get_status()
else:
break

result['msg'] += " AdminState: %s" % ro_json['AdminState']
result['msg'] += " ConnectionState: %s" % ro_json['ConnectionState']
result['msg'] += " Claimed state: %s" % ro_json['AccountOwnershipState']

# if connected and unclaimed, get device id and claim code
if ro_json['ConnectionState'] == 'Connected' and ro_json['AccountOwnershipState'] != 'Claimed':
(claim_resp, device_id, claim_code) = dc_obj.get_claim_info()
if ro_json['ConnectionState'] != 'Connected':
return_code = 1
print(json.dumps(result))
continue

if ro_json['AccountOwnershipState'] != 'Claimed':
# attempt to claim
(claim_resp, device_id, claim_code) = dc_obj.get_claim_info(ro_json)
if claim_resp.get('ApiError'):
result['msg'] += claim_resp['ApiError']
return_code = 1
Expand Down
13 changes: 2 additions & 11 deletions examples/delete_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse
from intersight.intersight_api_client import IntersightApiClient
from intersight.apis import iam_user_api
from intersight.apis import iam_permission_api

if __name__ == "__main__":
result = dict(changed=False)
Expand All @@ -30,20 +29,12 @@

# GET Users
users_handle = iam_user_api.IamUserApi(api_instance)
kwargs = dict(filter="Name eq '%s'" % args.id)
kwargs = dict(filter="Email eq '%s'" % args.id)
users_result = users_handle.iam_users_get(**kwargs)
if users_result.results:
# GET Permissions
permissions_handle = iam_permission_api.IamPermissionApi(api_instance)
kwargs = dict(filter="Subject eq '%s'" % users_result.results[0].moid)
permissions_result = permissions_handle.iam_permissions_get(**kwargs)

# DELETE Permissions
permissions_delete_result = permissions_handle.iam_permissions_moid_delete(moid=permissions_result.results[0].moid)
result['changed'] = True

# DELETE Users
users_delete_result = users_handle.iam_users_moid_delete(moid=users_result.results[0].moid)
result['changed'] = True
else:
print("User not found:", args.id)

Expand Down
Loading