IBM Cloud Virtual Private Cloud (VPC) Python SDK Version 0.4.0
Python client library to interact with various IBM Cloud Virtual Private Cloud (VPC) Service APIs.
Note As IBM continues to invest and innovate on the IBM Cloud Virtual Private Cloud (gen 2 compute) infrastructure, we're focusing on delivering maximum value in a single VPC Infrastructure platform. To support this effort, generation 1 compute infrastructure is being deprecated. The end of service date is 26 February 2021. For more information, see the Start your migration blog.
Table of Contents
- Overview
- Prerequisites
- Installation
- Using the SDK
- Setting up VPC service
- Setting up VPC on Classic service
- Questions
- Issues
- Open source @ IBM
- Contributing
- License
Overview
The IBM Cloud Virtual Private Cloud (VPC) Python SDK allows developers to programmatically interact with the following IBM Cloud services:
| Service Name | Imported Class Name |
|---|---|
| VPC | VpcV1 |
| VPC Gen 1 | VpcClassicV1 |
Prerequisites
- An IBM Cloud account.
- An IAM API key to allow the SDK to access your account. Create one here.
- Python 3.5.3 or above.
Installation
To install, use pip or easy_install:
pip install --upgrade "ibm-vpc>=0.4.0"
or
easy_install --upgrade "ibm-vpc>=0.4.0"
Using the SDK
For general SDK usage information, please see this link
Setting up VPC service
from ibm_vpc import VpcV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_cloud_sdk_core import ApiException
authenticator = IAMAuthenticator("YOUR_IBMCLOUD_API_KEY")
service = VpcV1('2020-06-02', authenticator=authenticator)
# Listing VPCs
print("List VPCs")
try:
vpcs = service.list_vpcs().get_result()['vpcs']
except ApiException as e:
print("List VPC failed with status code " + str(e.code) + ": " + e.message)
for vpc in vpcs:
print(vpc['id'], "\t", vpc['name'])
# Listing Subnets
print("List Subnets")
try:
subnets = service.list_subnets().get_result()['subnets']
except ApiException as e:
print("List subnets failed with status code " + str(e.code) + ": " + e.message)
for subnet in subnets:
print(subnet['id'], "\t", subnet['name'])
# Listing Instances
print("List Instances")
try:
instances = service.list_instances().get_result()['instances']
except ApiException as e:
print("List instances failed with status code " + str(e.code) + ": " + e.message)
for instance in instances:
print(instance['id'], "\t", instance['name'])
instanceId = instances[0]['id']
instanceName = instances[0]['name']
# Updating Instance
print("Updated Instance")
try:
newInstanceName = instanceName + "-1"
instance = service.update_instance(
id=instanceId,
name=newInstanceName,
).get_result()
except ApiException as e:
print("Update instance failed with status code " + str(e.code) + ": " + e.message)
print(instance['id'], "\t", instance['name'])
Setting up VPC on Classic service
from ibm_vpc import VpcClassicV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_cloud_sdk_core import ApiException
authenticator = IAMAuthenticator("YOUR_IBMCLOUD_API_KEY")
service = VpcClassicV1('2020-06-02', authenticator=authenticator)
# Listing VPCs
print("List VPCs")
try:
vpcs = service.list_vpcs().get_result()['vpcs']
except ApiException as e:
print("List VPC failed with status code " + str(e.code) + ": " + e.message)
for vpc in vpcs:
print(vpc['id'], "\t", vpc['name'])
print("\n")
# Listing Subnets
print("List Subnets")
try:
subnets = service.list_subnets().get_result()['subnets']
except ApiException as e:
print("List subnets failed with status code " + str(e.code) + ": " + e.message)
for subnet in subnets:
print(subnet['id'], "\t", subnet['name'])
# Listing Instances
print("List Instances")
try:
instances = service.list_instances().get_result()['instances']
except ApiException as e:
print("List instances failed with status code " + str(e.code) + ": " + e.message)
for instance in instances:
print(instance['id'], "\t", instance['name'])
instanceId = instances[0]['id']
instanceName = instances[0]['name']
# Updating Instance
print("Updated Instance")
try:
newInstanceName = instanceName + "-1"
instance = service.update_instance(
id=instanceId,
name=newInstanceName,
).get_result()
except ApiException as e:
print("Update instance failed with status code " + str(e.code) + ": " + e.message)
print(instance['id'], "\t", instance['name'])
Questions
If you are having difficulties using this SDK or have a question about the IBM Cloud services, please ask a question Stack Overflow.
Issues
If you encounter an issue with the project, you are welcome to submit a bug report. Before that, please search for similar issues. It's possible that someone has already reported the problem.
Open source @ IBM
Find more open source projects on the IBM Github Page
Contributing
See CONTRIBUTING.
License
This SDK is released under the Apache 2.0 license. The license's full text can be found in LICENSE.
Metadata
Release files for ibm-vpc 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ibm-vpc-0.4.0.tar.gz | 288.7 kB | Details |
Release files / ibm-vpc-0.4.0.tar.gz
| Download URL | ibm-vpc-0.4.0.tar.gz |
|---|---|
| Size | 288.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e523ec565f387acb86443db7899117e6f117d47718617f42fdbce984fc699fb
|
|
BLAKE2b-256 checksum How to use checksums |
e6692a80f1bac7998f0b55a316ab3f48e1a935e61ac99a77bd29c4cec663024d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.5.6
|