Kamatera计算资源管理的Apache Libcloud驱动程序
项目描述
Apache Libcloud为Kamatera提供驱动程序
安装
- 安装Libcloud(版本2.8.2或更高版本)
- 使用与Libcloud安装相同的Python解释器安装驱动程序
pip安装libcloud-driver-kamatera
使用方法
启用API访问
为了允许API访问您的Kamatera账户,您需要首先通过访问Kamatera控制台并在API密钥下添加新密钥来添加API密钥。使用创建的密钥Client ID和Secret作为驱动程序构造函数的参数。
实例化一个驱动程序
from libcloud_driver_kamatera import get_node_driver
cls = get_node_driver()
driver = cls('KAMATERA API CLIENT ID', 'KAMATERA API SECRET')
获取服务器选项
选择位置
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']
创建节点大小对象
# 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)
选择操作系统映像
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']
设置网络配置(最多可以添加4个接口)
networks = []
添加wan以获取公共IP
networks.append({'name': 'wan', 'ip': 'auto'})
添加vlan接口以获取私有IP(vlan网络名称和IP应在Kamatera控制台中配置)
networks.append({'name': '12345-my-vlan', 'ip': 'auto'})
创建服务器
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
)
获取SSH连接详情
print('root@%s / %s' % (node.public_ips[0],
node.extra['generated_password']))
服务器操作
列出所有节点(快速操作,为每个节点提供基本详情)
nodes = driver.list_nodes()
获取特定节点的更多详情
node = driver.list_nodes(ex_id=nodes[0].id)[0]
print(node)
根据节点名称的正则表达式列出带有完整详情的节点
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}
列出带有完整详情的所有节点(较慢的操作)
nodes = driver.list_nodes(ex_full_details=True)
node = nodes[0]
运行操作
driver.start_node(node)
driver.stop_node(node)
driver.reboot_node(node)
driver.destroy_node(node)
项目详情
下载文件
下载适用于您平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
libcloud_driver_kamatera-0.0.2.tar.gz (11.9 kB 查看哈希值)
构建分布
关闭
libcloud_driver_kamatera-0.0.2.tar.gz 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 22ccc1d50289c3689035c757f73d7ddbdb0ad50929dcc073e1ae4292b701176d |
|
MD5 | 53035cc572e0cbe951c4a8c6512aae75 |
|
BLAKE2b-256 | dc5f9bb0b4280671eab89c5c72a03b958d70d05702429e79b8bfe5513cd49714 |
关闭
libcloud_driver_kamatera-0.0.2-py3-none-any.whl 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | bae2f09312ee5c43bcfe5501b29ffaff43bc82b020ae171b4b26859943c9859d |
|
MD5 | ee5aae6f8c06091f7cc76cbf0f8de1f3 |
|
BLAKE2b-256 | b18466db37b52a561bdfb234cfd07c3c5be992614d142dc47bd51f94e2b7f15d |