This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07bd878
commit 87f2812
Showing
75 changed files
with
3,339 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import sys | ||
import warnings | ||
import os | ||
|
||
from openstack import utils | ||
from openstack import connection | ||
|
||
username = "*************" | ||
password = '*************' | ||
userDomainId = "*************" | ||
auth_url = "https://iam.xxx.com/v3" # endpoint url | ||
|
||
conn = connection.Connection(auth_url=auth_url, | ||
user_domain_id=userDomainId, | ||
domain_id=userDomainId, | ||
username=username, | ||
password=password) | ||
|
||
def create_enterprise_project(_conn): | ||
data = { | ||
"name": "test56", | ||
"description": "test56" | ||
} | ||
res = _conn.eps.create_enterprise_project(**data) | ||
print res | ||
|
||
|
||
def list_enterprise_projects(_conn): | ||
query = { | ||
"name": "test" | ||
} | ||
enterprise_projects = _conn.eps.list_enterprise_projects(**query) | ||
print enterprise_projects | ||
|
||
|
||
def get_enterprise_project(_conn): | ||
enterpriseProjectId = "0e00f529-7d13-4d47-8c62-496a27ecb3c6" | ||
result = _conn.eps.get_enterprise_project( enterpriseProjectId) | ||
print result | ||
|
||
def enterprise_project_quotas(_conn): | ||
result = _conn.eps.enterprise_project_quotas() | ||
print result | ||
|
||
def update_enterprise_project(_conn): | ||
enterpriseProjectId = "0278f73a-c3dc-4089-99af-3cb2cf42f76b" | ||
data = { | ||
"name": "test008", | ||
"description": "test008" | ||
} | ||
result = _conn.eps.update_enterprise_project( enterpriseProjectId, **data) | ||
print result | ||
|
||
|
||
def filter_resource_enterprise_project(_conn): | ||
enterpriseProjectId = "0278f73a-c3dc-4089-99af-3cb2cf42f76b" | ||
data = { | ||
"projects": ["0605767f6f00d5762ff9c001c70e7359"], | ||
"limit": 10, | ||
"offset": 0, | ||
"resource_types": ["ecs", "scaling_group", "images", "disk", "vpcs"] | ||
} | ||
result = _conn.eps.filter_resource_enterprise_project( enterpriseProjectId, **data) | ||
print result | ||
|
||
|
||
def migrate_resource_enterprise_project(_conn): | ||
enterpriseProjectId = "0278f73a-c3dc-4089-99af-3cb2cf42f76b" | ||
data = { | ||
"project_id": "0605767f6f00d5762ff9c001c70e7359", | ||
"associated": False, | ||
"cloud_resource_type": "vpcs", | ||
"resource_id": "3dd93a56-2a1f-470e-91a4-3376ebde2fb6" | ||
} | ||
result = _conn.eps.migrate_resource_enterprise_project( enterpriseProjectId, **data) | ||
print result | ||
|
||
def enable_enterprise_project(_conn): | ||
enterpriseProjectId = "07b780ee-91ca-4861-a468-9f35ebd95586" | ||
data = { | ||
"action": "enable" | ||
} | ||
result = _conn.eps.operate_enterprise_project( enterpriseProjectId, **data) | ||
print result | ||
|
||
def disable_enterprise_project(_conn): | ||
enterpriseProjectId = "07b780ee-91ca-4861-a468-9f35ebd95586" | ||
data = { | ||
"action": "disable" | ||
} | ||
result = _conn.eps.operate_enterprise_project( enterpriseProjectId, **data) | ||
print result | ||
|
||
if __name__ == '__main__': | ||
create_enterprise_project(conn) | ||
list_enterprise_projects(conn) | ||
get_enterprise_project(conn) | ||
enterprise_project_quotas(conn) | ||
update_enterprise_project(conn) | ||
filter_resource_enterprise_project(conn) | ||
migrate_resource_enterprise_project(conn) | ||
enable_enterprise_project(conn) | ||
disable_enterprise_project(conn) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
#!/usr/bin/python | ||
# coding=utf-8 | ||
|
||
from openstack import connection | ||
|
||
username = "**********" | ||
password = "**********" | ||
userDomainId = "**********" | ||
auth_url = "**********" | ||
|
||
# create connection | ||
conn = connection.Connection( | ||
auth_url=auth_url, | ||
user_domain_id=userDomainId, | ||
domain_id=userDomainId, | ||
username=username, | ||
password=password | ||
) | ||
|
||
|
||
# Query an agency list | ||
# GET /v3.0/OS-AGENCY/agencies | ||
def get_agency_list(): | ||
agencies = conn.iam.agencies(domain_id=userDomainId) | ||
# agencies = conn.iam.agencies(domain_id=userDomainId, name="**********", trust_domain_id="**********") | ||
for agency in agencies: | ||
print(agency) | ||
|
||
|
||
# Query agency details | ||
# GET /v3.0/OS-AGENCY/agencies/{agency_id} | ||
def get_agency(): | ||
agency_id = "**********" | ||
agency = conn.iam.get_agency(agency_id) | ||
print(agency) | ||
|
||
|
||
# Create agency | ||
# POST /v3.0/OS-AGENCY/agencies | ||
def create_agency(): | ||
agency = { | ||
"name": "**********", | ||
"domain_id": "**********", | ||
"trust_domain_id": "**********", | ||
"trust_domain_name": "**********", | ||
"duration": "**********", | ||
"description": "**********" | ||
} | ||
agency = conn.iam.create_agency(**agency) | ||
print(agency) | ||
|
||
|
||
# Update agency | ||
# POST /v3.0/OS-AGENCY/agencies | ||
def update_agency(): | ||
agency_id = "**********" | ||
agency = { | ||
"agency": { | ||
"trust_domain_id": "**********", | ||
"trust_domain_name": "**********", | ||
"description": "**********", | ||
"duration": "**********" | ||
} | ||
} | ||
agency = conn.iam.update_agency(agency_id, **agency) | ||
print(agency) | ||
|
||
|
||
# Delete agency | ||
# DELETE /v3.0/OS-CREDENTIAL/credentials/{access_key} | ||
def delete_agency(): | ||
agency_id = "**********" | ||
conn.iam.delete_agency(agency_id) | ||
|
||
|
||
# Query domain permissions of an agency | ||
# GET /v3.0/OS-AGENCY/domains/{domain_id}/agencies/{agency_id}/roles | ||
def list_domain_agency_role(): | ||
domain_id = "**********" | ||
agency_id = "**********" | ||
roles = conn.iam.list_domain_agency_role(domain_id, agency_id) | ||
for role in roles: | ||
print(role) | ||
|
||
|
||
# Query project permissions of an agency | ||
# GET /v3.0/OS-AGENCY/projects/{project_id}/agencies/{agency_id}/roles | ||
def list_project_agency_role(): | ||
project_id = "**********" | ||
agency_id = "**********" | ||
roles = conn.iam.list_project_agency_role(project_id, agency_id) | ||
for role in roles: | ||
print(role) | ||
|
||
|
||
# Grant domain permission to an agency | ||
# PUT /v3.0/OS-AGENCY/domains/{domain_id}/agencies/{agency_id}/roles/{role_id} | ||
def grant_domain_agency_role(): | ||
domain_id = "**********" | ||
agency_id = "**********" | ||
role_id = "**********" | ||
result = conn.iam.grant_domain_agency_role(domain_id, agency_id, role_id) | ||
if result is True: | ||
print("Grant domain permission to an agency successfully") | ||
else: | ||
print("Grant domain permission to an agency failure") | ||
|
||
|
||
# Grant project permission to an agency | ||
# PUT /v3.0/OS-AGENCY/projects/{project_id}/agencies/{agency_id}/roles/{role_id} | ||
def grant_project_agency_role(): | ||
project_id = "**********" | ||
agency_id = "**********" | ||
role_id = "**********" | ||
result = conn.iam.grant_project_agency_role(project_id, agency_id, role_id) | ||
if result is True: | ||
print("Grant project permission to an agency successfully") | ||
else: | ||
print("Grant project permission to an agency failure") | ||
|
||
|
||
# Query whether an agency has specific domain permission | ||
# HEAD /v3.0/OS-AGENCY/domains/{domain_id}/agencies/{agency_id}/roles/{role_id} | ||
def check_domain_agency_role(): | ||
domain_id = "**********" | ||
agency_id = "**********" | ||
role_id = "**********" | ||
result = conn.iam.check_domain_agency_role(domain_id, agency_id, role_id) | ||
if result is True: | ||
print("The agency has this domain permission") | ||
else: | ||
print("The agency doesn't have this domain permission") | ||
|
||
|
||
# Query whether an agency has specific project permission | ||
# HEAD /v3.0/OS-AGENCY/projects/{project_id}/agencies/{agency_id}/roles/{role_id} | ||
def check_project_agency_role(): | ||
project_id = "**********" | ||
agency_id = "**********" | ||
role_id = "**********" | ||
result = conn.iam.check_project_agency_role(project_id, agency_id, role_id) | ||
if result is True: | ||
print("The agency has this project permission") | ||
else: | ||
print("The agency doesn't have this project permission") | ||
|
||
|
||
# Delete domain permission of an agency | ||
# DELETE /v3.0/OS-AGENCY/domains/{domain_id}/agencies/{agency_id}/roles/{role_id} | ||
def delete_domain_agency_role(): | ||
domain_id = "**********" | ||
agency_id = "**********" | ||
role_id = "**********" | ||
result = conn.iam.delete_domain_agency_role(domain_id, agency_id, role_id) | ||
if result is True: | ||
print("Delete domain permission of an agency successfully") | ||
else: | ||
print("Delete domain permission of an agency failure") | ||
|
||
|
||
# Delete project permission of an agency | ||
# DELETE /v3.0/OS-AGENCY/projects/{project_id}/agencies/{agency_id}/roles/{role_id} | ||
def delete_project_agency_role(): | ||
project_id = "**********" | ||
agency_id = "**********" | ||
role_id = "**********" | ||
result = conn.iam.delete_project_agency_role(project_id, agency_id, role_id) | ||
if result is True: | ||
print("Delete project permission of an agency successfully") | ||
else: | ||
print("Delete project permission of an agency failure") | ||
|
||
|
||
if __name__ == "__main__": | ||
get_agency_list() | ||
get_agency() | ||
create_agency() | ||
update_agency() | ||
delete_agency() | ||
list_domain_agency_role() | ||
list_project_agency_role() | ||
grant_domain_agency_role() | ||
grant_project_agency_role() | ||
check_domain_agency_role() | ||
check_project_agency_role() | ||
delete_domain_agency_role() | ||
delete_project_agency_role() |
Oops, something went wrong.