Giter Club home page Giter Club logo

zenlayercloud-sdk-python's Introduction

Quick Start(δΈ­ζ–‡)


Introduction

Welcome to Zenlayer Cloud API Software Developer Kit (SDK). SDK is a supporting tool for Zenlayer Cloud API. It currently supports Bare Metal Instance, Elastic IP, DDoS Protected IP and other products. More cloud services will be supported for SDK.

Requirements

  1. The python environment is installed. version 3.6 or later is used.
  2. A Zenlayer Cloud account is created and an Access Key ID and an Access Key Password are created. See Generate an API Access Key for more details.

Installation

Installation with Pip (Recommended)

You can install the ZenlayerCloud API Python SDK into your project using the pip installation method. If your project environment does not have pip installed, please refer to the pip official website for detailed installation instructions.

To install or upgrade using pip, execute the following command in the command line:

pip install --upgrade zenlayercloud-sdk-python

Please note that if you have both Python 2 and Python 3 environments, the Python 3 environment should use the pip3 command for installation.

Installation from source

Go to the Github repository to download the latest code.

$ cd zenlayercloud-sdk-python
$ python setup.py install

# Examples

Take CreateInstances as an example.

```python
from zenlayercloud.bmc.v20221120 import bmc_client, models
from zenlayercloud.bmc.v20221120.models import InstanceChargePrepaid
from zenlayercloud.common.config import Config
from zenlayercloud.common.credential import Credential
from zenlayercloud.common.excpetion.zenlayer_cloud_sdk_exception import ZenlayerCloudSdkException

if __name__ == '__main__':
   logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', level=logging.DEBUG)
   
   try:
     credential = Credential("< Your AccessKeyId >", "< Your AccessKeyPassword >")
     config = Config(debug=True)
   
     client = bmc_client.BmcClient(credential=credential, config=config)
   
     print(InstanceChargePrepaid({"period": 1}).serialize())
     request = models.CreateInstancesRequest()
     request.zoneId = "SEL-A"
     request.instanceChargeType = "PREPAID"
     request.instanceTypeId = "S8A"
     request.internetChargeType = "ByBandwidth"
     request.instanceChargePrepaid = InstanceChargePrepaid({"period": 1})
   
     response = client.CreateInstances(request)
     print(response)
   except ZenlayerCloudSdkException as err:
     print(err)

More Configuration

Before creating a client, you can configure the values of fields in the Config if needed.

from zenlayercloud.common.config import Config

conf = Config()

The specific configuration options are explained below:

Timeout

The SDK has a default timeout of 60 seconds. If needed, please refer to the code to get the latest default value. Unit: seconds

from zenlayercloud.common.config import Config

conf = Config(debug=True)
conf.request_timeout = 120

Debugging

You can enable debug mode, which will print more detailed logs (including request and response data). This can be useful for detailed error troubleshooting. Debug mode is disabled by default.

Default: False

from zenlayercloud.common.config import Config

conf = Config(debug=True)

Proxy

If you are in an environment with a proxy, you can set the proxy using the following method.

from zenlayercloud.common.config import Config

conf = Config(proxy="http://host:port")

Certificate Issue

When installing Python 3.6 or above on the Mac operating system, you may encounter a certificate error: Error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056). This is because on Mac OS, Python no longer uses the system's default certificates and does not provide its own certificates. When making HTTPS requests, it requires the use of certificates provided by the certifi library. However, the SDK does not support specifying certificates, so the only solution is to install the certificates by running the command sudo "/Applications/Python 3.6/Install Certificates.command".

The Python SDK uses the certificates provided by the certifi library by default. If you need to specify a certificate, you can do so with the following settings. If you want to skip certificate verification, pass False as the value.

# Specify the certificate
conf = Config(certification="/path/to/certification")

# Skip certificate verification
conf = Config(certification=False)

Quick Start(Chinese)

zenlayercloud-sdk-python's People

Contributors

wolfgangzhu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.