Skip to main content

Pureport client command line interface

Project description

Pureport Python Client

A thin Python 3 client for the Pureport ReST API, backed by requests.

Install

pip install pureport-client

For Python2, you can use any version prior to 1.0.0.

pip install pureport-client<1

Usage

from pureport.api.client import Client
from pureport.exception.api import ClientHttpException, NotFoundException

### Create the Client and login with your API Key
client = Client()
client.login("MY_API_KEY", "MY_API_SECRET")

### List Accounts
accounts = client.accounts.list()
first_account = accounts[0]

### List all Networks for the first Account
networks = client.accounts.networks(first_account['id']).list()

### Create a Network for the Account
new_network = client.accounts.networks(first_account['id']).create({
    'name': 'My First Network'
})

### Obtain a Pureport location link for a new Connection
location = client.locations.list()[0]
location_link = Client.to_link(location, location['name'])

### Create an AWS Connection
new_connection_data = {
    'name': 'My First AWS Connection',
    'type': 'AWS_DIRECT_CONNECT',
    'speed': 50,
    'highAvailability': True,
    'peering': {
        'type': 'PRIVATE'
    },
    'location': location_link,
    'billingTerm': 'HOURLY',
    'awsAccountId': 'YOUR_AWS_ACCOUNT_ID',
    'awsRegion': 'YOUR_AWS_REGION' # e.g. 'us-west-2'
}

new_connection = None
try:
    new_connection = client.networks.connections(new_network['id']).create(new_connection_data)
except ClientHttpException as e:
    print(e.response.text)

### Retrieve the new AWS Connection by the returned object
client.connections.get(new_connection['id'])

### Delete the new AWS Connection
client.connections.delete(new_connection['id'])

### Expect a 404 error for the deleted connection
try:
    client.connections.get(new_connection['id'])
except NotFoundException as e:
    print(e.response.text)

### Delete the Network
client.networks.delete(new_network['id'])

CLI Usage

This uses jq to help parse the JSON output from the Pureport client.

export PUREPORT_API_KEY="MY_API_KEY"
export PUREPORT_API_SECRET="MY_API_SECRET"

### List accounts
pureport accounts list | jq

### List all networks for the first account
first_account_id=$(pureport accounts list --name traynham | jq -r '.[0].id')
pureport accounts networks -a $first_account_id list

### Create a Network for the Account and persist it's id
new_network_id=$(pureport accounts networks -a $first_account_id create '{"name": "My First Network"}' | jq -r '.id')

### List all pureport locations
pureport locations list | jq

### Create a link object with the first location
location_link=$(pureport locations list | jq -r '.[0] | {id: .id, href: .href, title: .name}')

### Create an AWS Connection
new_connection_id=$(pureport networks connections -n $new_network_id create --wait_until_active '{
    "name": "My First AWS Connection",
    "type": "AWS_DIRECT_CONNECT",
    "speed": 50,
    "highAvailability": true,
    "peering": {
        "type": "PRIVATE"
    },
    "location": '$location_link',
    "billingTerm": "HOURLY",
    "awsAccountId": "YOUR_AWS_ACCOUNT_ID",
    "awsRegion": "YOUR_AWS_REGION"
}' | jq -r '.id')

### Retrieve the new AWS Connection with the returned id
pureport connections get $new_connection_id | jq

### Delete the new AWS Connection
pureport connections delete --wait_until_deleted $new_connection_id

### Delete the Network
pureport networks delete $new_network_id

Project details


Download files

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

Source Distribution

pureport-client-1.0.12.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

pureport_client-1.0.12-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

Details for the file pureport-client-1.0.12.tar.gz.

File metadata

  • Download URL: pureport-client-1.0.12.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pureport-client-1.0.12.tar.gz
Algorithm Hash digest
SHA256 3ab1b769e2bae8c6892af03c45af5ccac5d0de64bd0685281d1cdecd61dadf83
MD5 40323d465fcf9f2821b65710d96e6ef1
BLAKE2b-256 74afd40d75b10cb3d46ebc6aad0d7a17a80841eba30bb67cf0fb0d7b6fb65048

See more details on using hashes here.

File details

Details for the file pureport_client-1.0.12-py3-none-any.whl.

File metadata

  • Download URL: pureport_client-1.0.12-py3-none-any.whl
  • Upload date:
  • Size: 51.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pureport_client-1.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 ceff3f651c3b5d2f314247e6ca5ce08c1e33e7101ab406d444edb09608d3e1c5
MD5 b4805a7d144e75a1da45e5ae461b965d
BLAKE2b-256 7c32873af2a723c37dab1c89ef19007ca243773d2375983eddaf8bf2a4d94272

See more details on using hashes here.

Supported by

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