Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
release python sdk 1.0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
karonganyong committed Apr 20, 2020
1 parent 07bd878 commit 87f2812
Show file tree
Hide file tree
Showing 75 changed files with 3,339 additions and 529 deletions.
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: huaweicloud-sdk-python
Version: 1.0.22
Version: 1.0.23
Summary: An SDK for building applications to work with OpenStack
Home-page: https://github.com/huaweicloud/huaweicloud-sdk-python
Author: huawei
Expand Down
3 changes: 1 addition & 2 deletions examples/bss/v1/customer_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
user_domain_id=userDomainId,
domain_id=userDomainId,
username=username,
password=password,
verify=False)
password=password)

data = {
"searchType": "email",
Expand Down
2 changes: 1 addition & 1 deletion examples/compute/v2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_server():
"flavor_id": "s1.medium",
"security_groups":[
{
"name": "Sys-default"
"name": "default"
}
],
"networks":[
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_server():
"flavor_id": "s1.medium",
"security_groups":[
{
"name": "Sys-default"
"name": "default"
}
],
"networks":[
Expand Down
Empty file added examples/eps/v1/__init__.py
Empty file.
104 changes: 104 additions & 0 deletions examples/eps/v1/enterprise_project.py
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
187 changes: 187 additions & 0 deletions examples/iam/v3/agency.py
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()
Loading

0 comments on commit 87f2812

Please sign in to comment.