Apache Pulsar消息队列-Amazon Web Services 接口

作者: Apache Pulsar

Amazon Web Services 接口

Amazon Web Services 兼容接口
CloudStack可将AWS API调用转换为CloudStack本地调用,使得用户可以继续使用已有的AWS兼容工具。这个转换服务作为单独的web应用,就像在tomcat上的CloudStack管理服务一样,只是监听不同的端口。AWS兼容接口除了提供S3 REST API外,还提供EC2 SOAP和Query APIs。

注解

这项服务,之前是由CloudBridge独立软件实现的。现在已经完全集成到CloudStack管理服务中。

警告
EC2 Query API和S3 API兼容接口的支持工作正在进行中。S3的兼容API提供了一种在管理服务器的文件系统中存储数据的方法,它不是S3 后端实现的。

局限性
只支持使用基本网络的zone。
仅对全新安装的CloudStack可用。通过旧版本升级的不可用。
如弹性IP(EIP)和弹性负载均衡(ELB)这些特性,仅对有Citrix NetScaler设备的架构可用。用户接入有NetScaler设备的zone时,需要使用NetScaler-enabled网络方案(DefaultSharedNetscalerEIP和ELBNetworkOffering)。
支持的API版本

注解

支持更新版本的EC2 API的工作正在进行
使能EC2和S3兼容接口

提供AWS API兼容性的软件随CloudStack一起安装。在使用之前,你必须使能服务并操作一些安装步骤。

  1. 将全局配置参数中的每项服务设置为true。详看 [*Setting Global Configuration Parameters*].
  2. 创建一组匹配亚马逊服务方案的名称。这个可以按照管理员操作手册在CloudStack界面上进行操作。
    警告
    除了可能使用的EC2实例类型,确保已包含亚马逊默认服务方案,m1.small。
  3. 如果按照步骤1设置了配置参数后,没有重启,那么重启管理服务器。
       

  service cloudstack-management restart

以下内容提供了这些步骤的细节
开启服务

为了使能EC2和S3兼容服务,你需要将 enable.ec2.api \ 和 *enable.s3.api*的值设置为true。以使能你所需要的服务。这个可以在CloudStack的界面上的\*Global Settings*或者API来实现。

下面的截图展示如何通过GUI使能这些服务。

Use the GUI to set the configuration variable to true

使用CloudStack API最简单的方法是使用集成接口,这个接口可以使用无验证调用。在全局设置中将这个接口设置为8096,然后调用 updateConfiguration 。下面的URL展示如何使用。

  

 http://localhost:8096/client/api?command=updateConfiguration&name=enable.ec2.api&value=true

 http://localhost:8096/client/api?command=updateConfiguration&name=enable.ec2.api&value=true

一旦使能这些服务,重启服务器。
创建EC2兼容服务方案

可以定义兼容 Amazon EC2实例类型 http://aws.amazon.com/ec2/instance-types/ API名称的计算服务方案。(例如m1.small,m1.large),这个可以通过CloudStack界面进行操作。在 Service Offerings 中选择 Compute offering ,创建一个新的计算方案或者修改已存在的皆可。确保名称与EC2实例类型API名称匹配。下面的截图将展示如何操作。

Use the GUI to set the name of a compute service offering to an EC2 instance type API name.
修改AWS API端口

注解

(可选)AWS API在端口7080监听请求。如果你希望监听另外的端口,可通过如下步骤修改:

  1. 编辑文件 /etc/cloudstack/management/server.xml , /etc/cloudstack/management/server-nonssl.xml , [``].
  2. 在每个文件中找出
    的标签,在这个标签下,定位到<Connector executor=“tomcatThreadPool-internal” port= …<
  3. 将这个端口改为你想用的任何端口,并保存文件。
  4. 重启管理服务器。

如果你重装CloudStack,你需要重新使能服务并更新端口。
AWS API用户安装

总的来说,用户不需要察觉CloudStack所提供的翻译服务。只需将AWS API调用发送到CloudStack端,然后被转换为CloudStack API。Amazon EC2兼容接口用户可继续使用已有的EC2工具和脚本,并通过指定管理服务器的端及合适的用户证书,将它们用于CloudStack部署。为此,用户需要进行如下步骤的操作:
生成用户证书
向服务注册。
为了方便,设置关于EC2 SOAP命令行工具的环境变量。
AWS API命令行工具安装

为了使用EC2命令行工具,用户需要操作以下步骤:

  1. 确定你具有正确版本的EC2工具。所支持的版本可以在 [`]`_获取。
  2. 设置EC2环境变量。可在每次使用服务时设置或者写入合适的shell profile文件中。将端(如EC2_URL)替换为合适的CloudStack管理服务器地址和端口。可在bash文件中做如下操作。
  

 $ export EC2_CERT=/path/to/cert.pem

 $ export EC2_PRIVATE_KEY=/path/to/private_key.pem

 $ export EC2_URL=http://localhost:7080/awsapi

 $ export EC2_HOME=/path/to/EC2_tools_directory

使用超时设定确保AWS API命令完成
Amazon EC2命令行工具有默认的连接超时。在CloudStack中使用时,某些命令可能需要更长的超时。如果你发现命令在超时的时间内未完成,你可以指定用户定制超时。你可以将下面的可选命令行参数添加到任何支持CloudStack的EC2命令。

指定连接超时(秒)

  

 --connection-timeout TIMEOUT

指定请求超时(秒)

  

 --request-timeout TIMEOUT

例如:

  

 ec2-run-instances 2 --z us-test1 --n 1-3 --connection-timeout 120 --request-timeout 120

注解
CloudStack中的超时可选参数并非特定
支持AWS API调用
AWS API接口被使能后,CloudStack可支持下面的Amazon EC2命令。对于少数命令,CloudStack与Amazon EC2版本间有一些差异,差异已被标识。对于使用SOAP调用建立工具的用户,与之相关的命令也已给出。

表 1.弹性IP API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-allocate-address AllocateAddress associateIpAddress
ec2-associate-address AssociateAddress enableStaticNat
ec2-describe-addresses DescribeAddresses listPublicIpAddresses
ec2-diassociate-address DisassociateAddress disableStaticNat
ec2-release-address ReleaseAddress disassociateIpAddress

表 2.可用Zone API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-describe-availability-zones DescribeAvailabilityZones listZones

表 3.镜像API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-create-image CreateImage createTemplate
ec2-deregister DeregisterImage DeleteTemplate
ec2-describe-images DescribeImages listTemplates
ec2-register RegisterImage registerTemplate

表 4.镜像属性API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-describe-image-attribute DescribeImageAttribute listTemplatePermissions
ec2-modify-image-attribute ModifyImageAttribute updateTemplatePermissions
ec2-reset-image-attribute ResetImageAttribute updateTemplatePermissions

表 5.实例API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-describe-instances DescribeInstances listVirtualMachines
ec2-run-instances RunInstances deployVirtualMachine
ec2-reboot-instances RebootInstances rebootVirtualMachine
ec2-start-instances StartInstances startVirtualMachine
ec2-stop-instances StopInstances stopVirtualMachine
ec2-terminate-instances TerminateInstances destroyVirtualMachine

表 6 实例属性对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-describe-instance-attribute DescribeInstanceAttribute listVirtualMachines

表 7 密钥对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-add-keypair CreateKeyPair createSSHKeyPair
ec2-delete-keypair DeleteKeyPair deleteSSHKeyPair
ec2-describe-keypairs DescribeKeyPairs listSSHKeyPairs
ec2-import-keypair ImportKeyPair registerSSHKeyPair

表 8.密码API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-get-password GetPasswordData getVMPassword

表 9.安全组API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-authorize AuthorizeSecurityGroupIngress authorizeSecurityGroupIngress
ec2-add-group CreateSecurityGroup createSecurityGroup
ec2-delete-group DeleteSecurityGroup deleteSecurityGroup
ec2-describe-group DescribeSecurityGroups listSecurityGroups
ec2-revoke RevokeSecurityGroupIngress revokeSecurityGroupIngress

表 10.快照API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-create-snapshot CreateSnapshot createSnapshot
ec2-delete-snapshot DeleteSnapshot deleteSnapshot
ec2-describe-snapshots DescribeSnapshots listSnapshots

表 11.卷API对应表

EC2命令 SOAP调用 CloudStack API调用
ec2-attach-volume AttachVolume attachVolume
ec2-create-volume CreateVolume createVolume
ec2-delete-volume DeleteVolume deleteVolume
ec2-describe-volume DescribeVolume listVolumes
ec2-detach-volume DetachVolume detachVolume

示例

有很多工具可以提供接入AWS兼容API。本节中将提供CloudStack用户一些使用用例。
Boto示例
Boto是其中一个。Python包可以在 https://github.com/boto/boto 获取。本节中提供两个使用Boto并已被CloudStack AWS API接口测试过的Python脚本示例。

第一个是EC2示例,将访问和加密密钥改成你自己的,并更新端。

示例1.EC2 Boto示例

  

 !/usr/bin/env python



 import sys

 import os

 import boto

 import boto.ec2



 region = boto.ec2.regioninfo.RegionInfo(name="ROOT",endpoint="localhost")

 apikey='GwNnpUPrO6KgIdZu01z_ZhhZnKjtSdRwuYd4DvpzvFpyxGMvrzno2q05MB0ViBoFYtdqKd'

 secretkey='t4eXLEYWw7chBhDlaKf38adCMSHx_wlds6JfSx3z9fSpSOm0AbP9Moj0oGIzy2LSC8iw'



 def main():

  '''Establish connection to EC2 cloud'''

  conn =boto.connect_ec2(aws_access_key_id=apikey,

  aws_secret_access_key=secretkey,

  is_secure=False,

  region=region,

  port=7080,

  path="/awsapi",

  api_version="2010-11-15")



  '''Get list of images that I own'''

  images = conn.get_all_images()

  print images

*  myimage = images[0]

  '''Pick an instance type'''

  vm_type='m1.small'

*  reservation = myimage.run(instance_type=vm_type,security_groups=['default'])



 if __name__ == '__main__':

  main()

第二个是S3示例。S3接口在CloudStack中已被废弃。如果要使用,需要考察下RiakCS,Ceph或者GlusterFS系统。这个示例已完成并可用于其他S3端。

示例2.S3 Boto示例

  

 !/usr/bin/env python



 import sys

 import os

 from boto.s3.key import Key

 from boto.s3.connection import S3Connection

 from boto.s3.connection import OrdinaryCallingFormat



 apikey='ChOw-pwdcCFy6fpeyv6kUaR0NnhzmG3tE7HLN2z3OB_s-ogF5HjZtN4rnzKnq2UjtnHeg_yLA5gOw'

 secretkey='IMY8R7CJQiSGFk4cHwfXXN3DUFXz07cCiU80eM3MCmfLs7kusgyOfm0g9qzXRXhoAPCH-IRxXc3w'



 cf=OrdinaryCallingFormat()



 def main():

  '''Establish connection to S3 service'''

  conn =S3Connection(aws_access_key_id=apikey,aws_secret_access_key=secretkey, \

  is_secure=False, \

  host='localhost', \

  port=7080, \

  calling_format=cf, \

  path="/awsapi/rest/AmazonS3")



  try:

  bucket=conn.create_bucket('cloudstack')

  k = Key(bucket)

  k.key = 'test'

  try:

  k.set_contents_from_filename('/Users/runseb/Desktop/s3cs.py')

  except:

  print 'could not write file'

  pass

  except:

  bucket = conn.get_bucket('cloudstack')

  k = Key(bucket)

  k.key = 'test'

  try:

  k.get_contents_to_filename('/Users/runseb/Desktop/foobar')

  except:

  print 'Could not get file'

  pass



  try:

  bucket1=conn.create_bucket('teststring')

  k=Key(bucket1)

  k.key('foobar')

  k.set_contents_from_string('This is my silly test')

  except:

  bucket1=conn.get_bucket('teststring')

  k = Key(bucket1)

  k.key='foobar'

  k.get_contents_as_string()



 if __name__ == '__main__':

  main()

文章列表

更多推荐

更多
  • Pulsar消息队列-一套高可用实时消息系统实现 实时消息【即时通信】系统,有群聊和单聊两种方式,其形态异于消息队列:1 大量的 group 信息变动,群聊形式的即时通信系统在正常服务形态下,瞬时可能有大量用户登入登出。2 ...
  • Pulsar消息队列-Pulsar对比Kafka笔记 很多人查看 Pulsar 之前可能对 Kafka 很熟悉,参照上图可见二者内部结构的区别,Pulsar 和 Kafka 都是以 Topic 描述一个基本的数据集合,Topic 数据又分为若干 Partition,即对数据进行逻辑上的 ...
  • Pulsar消息队列-对 2017 年一套 IM 系统的反思 信系统的开发,前前后后参与或者主导了六七个 IM 系统的研发。上一次开发的 IM 系统的时间点还是 2018 年,关于该系统的详细描述见 [一套高可用实时消息系统实现][1] ...
  • Apache APISIX文档-快速入门指南-如何构建 Apache APISIX 如何构建 Apache APISIX,步骤1:安装 Apache APISIX,步骤2:安装 etcd,步骤3:管理 Apache APISIX 服务,步骤4:运行测试案例,步骤5:修改 Admin API key,步骤6:为 Apac
  • Apache APISIX文档-快速入门指南-快速入门指南 快速入门指南,概述,前提条件,第一步:安装 Apache APISIX,第二步:创建路由,第三步:验证,进阶操作,工作原理,创建上游服务Upstream,绑定路由与上游服务,添加身份验证,为路由添加前缀,APISIX Dashboard
  • Apache APISIX文档-架构设计-APISIX APISIX,软件架构,插件加载流程,插件内部结构,配置 APISIX,插件加载流程,比如指定 APISIX 默认监听端口为 8000,并且设置 etcd 地址为 http://foo:2379, 其他配置保持默认。在 ...
  • Apache APISIX文档-架构设计-Service Service 是某类 API 的抽象(也可以理解为一组 Route 的抽象)。它通常与上游服务抽象是一一对应的,Route 与 Service 之间,通常是 N:1 的关系,参看下图。不同 Route 规则同时绑定到一个 Service ...
  • Apache APISIX文档-架构设计-Plugin Config 如果你想要复用一组通用的插件配置,你可以把它们提取成一个 Plugin config,并绑定到对应的路由上。举个例子,你可以这么做:创建 Plugin config,如果这个路由已经配置了 plugins,那么 Plugin config ...
  • Apache APISIX文档-架构设计-Debug Mode 注意:在 APISIX 2.10 之前,开启基本调试模式曾经是设置 conf/config.yaml 中的 apisix.enable_debug 为 true。设置 conf/debug.yaml 中的选项,开启高级调试模式。由于 ...
  • Apache APISIX文档-架构设计-Consumer 如上图所示,作为 API 网关,需要知道 API Consumer(消费方)具体是谁,这样就可以对不同 API Consumer 配置不同规则。授权认证:比如有 [key-auth] 等。获取 consumer_...
  • 近期文章

    更多
    文章目录

      推荐作者

      更多