Skip to main content

Apache Libcloud driver for managing Kamatera compute resources

Project description

Apache Libcloud driver for Kamatera

Installation

  • Install Libcloud (Version 2.8.2 or higher)
  • Install the driver, using the same Python interpreter that Libcloud was installed in:
    • pip install libcloud-driver-kamatera

Usage

Enabling API access

To allow API access to your Kamatera account, you first need to add an API key by visiting Kamatera Console and adding a new key under API Keys. Use the created key Client ID and Secret as the arguments to the driver constructor.

Instantiating a driver

from libcloud_driver_kamatera import get_node_driver

cls = get_node_driver()
driver = cls('KAMATERA API CLIENT ID', 'KAMATERA API SECRET')

Getting server options

Select a location

locations = {location.id: location for location in driver.list_locations()}
for location in locations.values():
    print(location)

# <NodeLocation: id=AS, name=Hong Kong, country=China
# <NodeLocation: id=CA-TR, name=Toronto, country=Canada
# <NodeLocation: id=EU, name=Amsterdam, country=The Netherlands
# <NodeLocation: id=EU-FR, name=Frankfurt, country=Germany
# <NodeLocation: id=EU-LO, name=London, country=United Kingdom
# <NodeLocation: id=IL, name=Rosh Haayin, country=Israel
# <NodeLocation: id=IL-JR, name=Jerusalem, country=Israel
# <NodeLocation: id=IL-PT, name=Petach Tikva, country=Israel
# <NodeLocation: id=IL-RH, name=Rosh Haayin 2, country=Israel
# <NodeLocation: id=IL-TA, name=Tel Aviv, country=Israel
# <NodeLocation: id=US-NY2, name=New York, country=United States
# <NodeLocation: id=US-SC, name=Santa Clara, country=United States
# <NodeLocation: id=US-TX, name=Texas, country=United States

location = locations['US-NY2']

Create a node size object

# get the capabilities for this location

capabilities = driver.ex_list_capabilities(location)

# choose a cpu type

cpuTypes = {cpuType['id']: cpuType for cpuType in capabilities['cpuTypes']}
for cpuType in cpuTypes.values():
    print('%s: %s' % (cpuType['name'], cpuType['description']))

# Type B - General Purpose: Server CPUs are assigned to a dedicated physical
#          CPU Thread with reserved resources guaranteed.
# Type D - Dedicated: Server CPU are assigned to a dedicated physical CPU Core
#          (2 threads) with reserved resources guaranteed.
# Type T - Burstable: Server CPUs are assigned to a dedicated physical CPU
#          thread with reserved resources guaranteed.
# Type A - Availability: Server CPUs are assigned to a non-dedicated physical
#          CPU thread with no resources guaranteed.

cpuType = cpuTypes['B']

# choose number of cpu cores

print(cpuType['cpuCores'])

# [1, 2, 4, 6, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72]

cpuCores = 2

# choose amount of RAM

print(cpuType['ramMB'])

# [256, 512, 1024, 2048, 3072, 4096, 6144, 8192, 10240, 12288, 16384, 24576,
#  32768, 49152, 65536, 98304, 131072, 200704, 262144, 327680, 393216]

ramMB = 2048

# choose disk sizes

print(capabilities['diskSizeGB'])

# [5, 10, 15, 20, 30, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 450,
#  500, 600, 700, 800, 900, 1000, 1500, 2000, 3000, 4000]

# primary disk size

diskSizeGB = 20

# additional disks (up to 3 additional disks)

extraDiskSizesGB = [100, 200]

# choose a billing cycle

billingCycle = driver.EX_BILLINGCYCLE_MONTHLY
# billingCycle = driver.EX_BILLINGCYCLE_HOURLY

# in case of monthly billing cycle, choose traffic package

print(capabilities['monthlyTrafficPackage'])

# {'b50': '50Mbit/sec unmetered on 10Gbit/sec port',
#  't5000': '5000GB/month on 10Gbit/sec port'}

monthlyTrafficPackage = 't5000'

# create node size object

size = driver.ex_get_size(ramMB, diskSizeGB, cpuType['id'], cpuCores,
                          extraDiskSizesGB=extraDiskSizesGB,
                          monthlyTrafficPackage=monthlyTrafficPackage)

Choose an OS image

images = {image.id: image for image in driver.list_images(location)}

for image in images.values():
    print('%s: %s' % (image.id, image.name))

# list is shortened, actual list will vary and provide more OS image options

# US-NY2:6000C2987c9641fd2619a149ba2ca01a: CentOS 8.0 64-bit - Minimal
# US-NY2:6000C29b85c6367d215d403f44c28f48: CentOS 8.0 64-bit - Basic Server
# US-NY2:6000C29bb8fde673f515caf9bed695a1: Debian version 8.9 (jessie) 64-bit
# US-NY2:6000C29e4131d66b806c25c48ab0b810: FreeBSD 12.1 64-bit
# US-NY2:6000C2983bdd8b531ecfc6d892a35aa4: FreeBSD 11.1 32-bit
# US-NY2:6000C29a5a7220dcf84716e7bba74215: Ubuntu Server version 18.04 LTS
# US-NY2:6000C298bbb2d3b6e9721f4f4f3c5bf0: Ubuntu Server version 16.04 LTS

image = images['US-NY2:6000C29a5a7220dcf84716e7bba74215']

Set network configurations (up to 4 interfaces can be added)

networks = []

Add a wan to get a public IP

networks.append({'name': 'wan', 'ip': 'auto'})

add a vlan interface to get a private IP (vlan network name and ip should be configured in the Kamatera console)

networks.append({'name': '12345-my-vlan', 'ip': 'auto'})

Create a server

node = driver.create_node(
    name='test_libcloud_server',
    size=size,
    image=image,
    location=location,
    ex_networks=networks,
    ex_dailybackup=False,  # create daily backups for the node?
    ex_managed=False,  # provide managed support for the node?
    ex_billingcycle=billingCycle
)

Get the SSH connection details

print('root@%s  /  %s' % (node.public_ips[0],
                          node.extra['generated_password']))

Server operations

List all nodes (quick operation, provides only basic details for each node)

nodes = driver.list_nodes()

Get more details for a specific node

node = driver.list_nodes(ex_id=nodes[0].id)[0]
print(node)

List nodes with full details based on regex of node name

nodes = driver.list_nodes(ex_name_regex='test_libcloud.*')
print(nodes[0])

# <Node: uuid=9566552b254b42063e87ba644a982d330602b06c,
#        name=test_libcloud_server, state=RUNNING,
#        public_ips=['138.128.241.118'], private_ips=[], provider=Kamatera

print(nodes[0].extra)

# {'billingcycle': 'monthly', 'priceOn': '25', 'priceOff': '25',
#  'location': <NodeLocation: id=US-NY2>, 'dailybackup': False,
#  'managed': False}

list all nodes with full details (slower operation)

nodes = driver.list_nodes(ex_full_details=True)
node = nodes[0]

run operations

driver.start_node(node)
driver.stop_node(node)
driver.reboot_node(node)
driver.destroy_node(node)

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

libcloud_driver_kamatera-0.0.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

libcloud_driver_kamatera-0.0.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file libcloud_driver_kamatera-0.0.2.tar.gz.

File metadata

  • Download URL: libcloud_driver_kamatera-0.0.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for libcloud_driver_kamatera-0.0.2.tar.gz
Algorithm Hash digest
SHA256 22ccc1d50289c3689035c757f73d7ddbdb0ad50929dcc073e1ae4292b701176d
MD5 53035cc572e0cbe951c4a8c6512aae75
BLAKE2b-256 dc5f9bb0b4280671eab89c5c72a03b958d70d05702429e79b8bfe5513cd49714

See more details on using hashes here.

File details

Details for the file libcloud_driver_kamatera-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: libcloud_driver_kamatera-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.7 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.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for libcloud_driver_kamatera-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bae2f09312ee5c43bcfe5501b29ffaff43bc82b020ae171b4b26859943c9859d
MD5 ee5aae6f8c06091f7cc76cbf0f8de1f3
BLAKE2b-256 b18466db37b52a561bdfb234cfd07c3c5be992614d142dc47bd51f94e2b7f15d

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