Skip to main content

VPC

Project description

HuaweiCloud Python Software Development Kit (Python SDK)

The HuaweiCloud Python SDK allows you to easily work with Huawei Cloud services such as Elastic Compute Service (ECS) and Virtual Private Cloud(VPC) without the need to handle API related tasks.

This document introduces how to obtain and use HuaweiCloud Python SDK.

Getting Started

  • To use HuaweiCloud Python SDK, you must have Huawei Cloud account as well as the Access Key and Secret key of the HuaweiCloud account.

    The accessKey is required when initializing {Service}Client. You can create an AccessKey in the Huawei Cloud console. For more information, see My Credentials.

  • HuaweiCloud Python SDK requires python 3 or later.

Install Python SDK

HuaweiCloud Python SDK supports Python 3 or later. Run python --version to check the version of Python.

  • Use python pip

    Run the following command to install the individual libraries of HuaweiCloud services:

     # Install the core library
     pip install huaweicloudsdkcore
    
     # Install the VPC management library
     pip install huaweicloudsdkvpc
    
  • Install from source

    Run the following command to install the individual libraries of HuaweiCloud services:

     # Install the core library
     cd huaweicloudsdkcore-${version}
     python setup.py install
    
     # Install the VPC management library
     cd huaweicloudsdkvpc-${version}
     python setup.py install
    

Use Python SDK

  1. Import the required modules as follows:

    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkcore.http.http_config import HttpConfig
    from huaweicloudsdkvpc.v2 import VpcClient
    
  2. Config {Service}Client Configurations

    # Using the default configuration
    config = HttpConfig.get_default_config()
    
    # Set Proxy if needed
    config.proxy_protocol = 'http'
    config.proxy_host = 'proxy.huaweicloud.com'
    config.proxy_port = 80
    config.proxy_user = 'test'
    config.proxy_password = 'test'
    
    # Skip ssl certifaction checking while using https protocal if needed
    config.ignore_ssl_verification = True
    
  3. Initialize the {Service}Client instance:

    credentials = BasicCredentials(ak, sk, project_id)
    
    vpc_client = VpcClient.new_builder(VpcClient) \
        .with_config(config) \
        .with_credentials(credentials) \
        .with_endpoint(endpoint) \
        .build()
    

    where:

    • ak is the access key id for your account.
    • sk is the secret access key for your account.
    • project_id is the id of the project.
    • endpoint is the service specific endpoints, see Regions and Endpoints
  4. Send a request and print response.

    # Initialize a request and set parameters
    response = client.list_vpcs()
    print(respones)
    

Code example

The following example shows how to query a list of VPC in a specific region. Substitute the values for {your ak string}, {your sk string}, {your endpoint} and {your project id}.

# coding: utf-8


from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcore.http.http_config import HttpConfig
from huaweicloudsdkvpc.v2 import VpcClient


def list_vpc(client):
    try:
        response = client.list_vpcs()
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)


if __name__ == "__main__":
    ak = "{your ak string}"
    sk = "{your sk string}"
    endpoint = "{your endpoint}"
    project_id = "{your project id}"

    config = HttpConfig.get_default_config()
    config.ignore_ssl_verification = True
    credentials = BasicCredentials(ak, sk, project_id)

    vpc_client = VpcClient.new_builder(VpcClient) \
        .with_config(config) \
        .with_credentials(credentials) \
        .with_endpoint(endpoint) \
        .build()

    list_vpc(vpc_client)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

huaweicloudsdkvpc-3.0.2b0-py3-none-any.whl (120.8 kB view details)

Uploaded Python 3

File details

Details for the file huaweicloudsdkvpc-3.0.2b0-py3-none-any.whl.

File metadata

  • Download URL: huaweicloudsdkvpc-3.0.2b0-py3-none-any.whl
  • Upload date:
  • Size: 120.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for huaweicloudsdkvpc-3.0.2b0-py3-none-any.whl
Algorithm Hash digest
SHA256 1aa0f8c0b71f24bedfb7142cc18c85b3d49398373ae69008cb96ff2031e1dd66
MD5 f3ccc72e52dc44ae42d8a675e582a3bb
BLAKE2b-256 a879f0965d47490801cadc5c6fd32b2ec922270e47cc0cd5e69e5efa0de0ff0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page