Code Monkey home page Code Monkey logo

ibmcloud-python-sdk's Introduction

PyPi Downloads License codecov

IBM Cloud Python SDK

ibmcloud-python-sdk aims to talk to IBM Cloud. To do this, it requires a configuration file. ibmcloud-python-sdk favours clouds.yaml file, but can also use environment variables (see below). An example:

---
clouds:
  default: demo-acc
  demo-acc:
    profile: demo
    description: Credentials from my IBM Cloud demo account
    key: XxX1234567890XxX
    region: us-south
    version: 2021-06-15
    generation: 2
    cis_username: [email protected]
    cis_apikey: abc123def456ghi789klm0n
  prod-acc:
    profile: prod
    description: Credentials from my IBM Cloud production account
    key: zZz1234567890zZz
    region: us-south
    version: 2021-06-15
    generation: 2
    cis_username: [email protected]
    cis_apikey: @@abc123def456ghi789klm0n@@

The clouds.yaml file will be searched at first into ~/.ibmcloud directory but this behavior could be overrided by an environment variable.

Environment variables

Variable Description Example Mandatory
IC_CONFIG_FILE Absolute path to the clouds.yaml file ~/vault/ibm.yaml [ ]
IC_CONFIG_NAME Name of the default cloud configuration demo [ ]
IC_REGION Region were to connect us-south [x]
IC_VERSION Requests the version of the API 2021-06-15 [x]
IC_GENERATION The infrastructure generation for the request 2 [x]
IC_SDK_CONFIG_FILE Absolute path to the sdk.yaml file ~/.config/ibmcloud/sdk.yaml [ ]
IC_API_KEY API key created via the IBM Cloud IAM system XxX1234567890XxX [x]
SL_USERNAME SoftLayer user goldyfruit [ ]
SL_API_KEY SoftLayer API key abc123def456ghi789klm0n [ ]

Documentation

Documentation for the IBM Cloud Python SDK is available here.

IBM Cloud Python SDK leverages existing Python SDKs such as:

Supported features

Only VPC Gen 2 is supported by this SDK.

Service Feature
CIS Baremetal, Object Storage
DNS Public Zone, Private Zone
EM Get Account, Get Enterprise
IAM Policies, Roles
POWER Power System
RESOURCE Binding, Group, Instance, Key
VPC ACL, FIP, Gateway, Geo, Image, Instance, Key, Load Balancer, Security, Subnet, Volume, VPC, VPN

Installation

Install from PyPi via pip:

python -m venv ~/virtualenvs/ibmcloud-python-sdk
source ~/virtualenvs/ibmcloud-python-sdk/bin/activate
pip install ibmcloud-python-sdk

Or you can install from source:

cd ~/Git
git clone https://github.com/goldyfruit/ibmcloud-python-sdk.git
python -m venv ~/virtualenvs/ibmcloud-python-sdk
source ~/virtualenvs/ibmcloud-python-sdk/bin/activate
cd ~/Git/ibmcloud-python-sdk
pip install .

We recommend to use Python virtual environment to install the SDK.

Caching

The SDK has caching capability (memcached only for now) to improve the HTTP requests speed. To enable this mechanisim please configure the SDK properly using ~/.ibmcloud/sdk.yaml file.

---
sdk:
  cache_ttl: 60
  memcached:
    - 127.0.0.1:11211

Muttiple cache servers could be configured as well.

---
sdk:
  cache_ttl: 60
  memcached:
    - 127.0.0.1:11211
    - 127.0.0.1:11212
    - 127.0.0.1:11213

An easy way to deploy memcached server is to use container.

Podman

podman run -dt -p 11211:11211 --name memcached -d memcached

Docker

sudo docker run -dt -p 11211:11211 --name memcached -d memcached

Examples

A list of examples on how to use this SDK can be found at here.

List VPCs

from ibmcloud_python_sdk.vpc import vpc as ic


vpc = ic.Vpc()
vpc.get_vpc("ibmcloud-vpc-baby")

Create a VPC instance

from ibmcloud_python_sdk.vpc import vpc as icv
from ibmcloud_python_sdk.resource import resource_group as icr
import sys


# Variables
vpc_name = 'ibmcloud-vpc-baby'
resource_group_name = 'ibmcloud-resource-group-baby'

# Intentiate classes
vpc = icv.Vpc()
rg = icr.ResourceGroup()

# Retrieve resource group ID and check for error
resource_group_info = rg.get_resource_group(resource_group_name)
if 'errors' in resource_group_info:
    print(resource_group_info['errors'])
    sys.exit()

# Create the VPC based on variable and resource group ID
response = vpc.create_vpc(
            name=vpc_name,
            resource_group=resource_group_info['id'],
            address_prefix_management='auto',
            classic_access=True
        )

# Check for error during the VPC creation process
if 'errors' in response:
    print(response['errors'])
else:
    print(response)

FAQ

  • CRN or HREF could not be used as ID to retrieve resources
  • PATCH method (update) is not yet supported which means a resource cannot be updated

Copyright

See the bundled LICENSE file for more information.

ibmcloud-python-sdk's People

Contributors

dependabot[bot] avatar dollierp avatar goldyfruit avatar jamesregis avatar maxbab avatar rabin-io avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

ibmcloud-python-sdk's Issues

Contributing?

I just recently noticed your project here and there are quite a few APIs you have that are orthogonal to the work I have been doing at https://github.com/IBM/redstone

I didn't find a contributing section in your docs or the project here, and was wondering where you are collaborating, either within or without IBM.

Some functions can't see more than 50 resources

Hi,
many functions can list only the first 50 resources.
We should include the limit parameter in the URL and manage very long list.

path = ("/v1/volumes?version={}&generation={}&limit=100".format(self.cfg["version"], self.cfg["generation"]))

Find resource by name

We should improve the get_*_by_name by using the builtin API function and introduce the name parameter.
.
For get_volume_by_id, a solution could be :

path = ("/v1/volumes?version={}&generation={}&name={}".format(
 self.cfg["version"], self.cfg["generation"], name))

 query = qw("iaas", "GET", path, headers())["data"]

 if query.volumes:
     return query.volumes[0]
 else:
     return query

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.