虚拟化平台cloudstack(8)——从UI开始
UI
ucloudstack采用的是前后端分离的架构,就是说前端可以选择使用web、swing甚至其它的界面,都可以。
我们来看cloudstack的UI信息吧,所有的cloudstack的UI都在{cloudstack_home}/cloudstack/ui目录下。
用firefox打开工程,打开firebug,找到login.js,在100行加上断点。
执行登录,这时就会触发断点,让我们看看发生了什么:
最终是使用jquery的ajax来提交post请求给服务器端,也就是说,manager server提供给我们的是一组API,我们可以通过http的请求方式提交请求。
处理http请求
看完了前端,我们继续看一下后端处理。
在web.xml中,我们看到所有的api/请求都会到ApiServlet中处理。
<servlet>
<servlet-name>apiServlet</servlet-name>
<servlet-class>com.cloud.api.ApiServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>apiServlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
在ApiServlet中,重点看下
@Override
public void init(ServletConfig config) throws ServletException {
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
}
这样在web容器中就可以查看spring中使用注解的接口了。
说实话这块感觉设计的挺一般的,一个servlet里边承担了太多的任务,我打了个断点在
processRequest(req, resp);
这个方法中,但是一个登录的操作就走了四次断点,一个退出操作又走了两次,不清楚这块为什么这样设计。
而且很多业务代码都在这个类中操作,感觉很冗余。但这个不是我们重点关心的问题。
CloudStack API提供的三种角色
- 管理员。获得云的所有功能,包括虚拟和物理资源管理。
- 域管理员。进入到虚拟资源的云属于管理员的域。
- 用户。只访问允许用户管理的功能,虚拟实例,存储,和网络。
API文档的地址
http://cloudstack.apache.org/docs/api/
可以看到不同角色的API的地址,进去之后,可以看到每个API的详细描述。
处理简单列举一下4.1中API的新特性
在VM中重新配置物理网络
支持IPV6
扩展VMX设置
重新设置SSH密钥来访问虚拟机
在4.1中改变的API命令:
API Commands |
Description |
---|---|
createNetworkOffering |
The following request parameters have been added: isPersistent startipv6 endipv6 ip6gateway ip6cidr |
listNetworkOfferings listNetworks |
The following request parameters have been added: isPersistent This parameter determines if the network or network offering listed are persistent or not. ip6gateway ip6cidr |
createVlanIpRange |
The following request parameters have been added: startipv6 endipv6 ip6gateway ip6cidr |
deployVirtualMachine |
The following parameter has been added: ip6Address. The following parameter is updated to accept the IPv6 address: iptonetworklist. |
CreateZoneCmd |
The following parameter have been added: ip6dns1, ip6dns2. |
listRouters listVirtualMachines |
For nic responses, the following fields have been added. ip6address ip6gateway ip6cidr |
listVlanIpRanges |
For nic responses, the following fields have been added. startipv6 endipv6 ip6gateway ip6cidr |
listRouters listZones |
For DomainRouter and DataCenter response, the following fields have been added. ip6dns1 ip6dns2 |
addF5LoadBalancer configureNetscalerLoadBalancer addNetscalerLoadBalancer listF5LoadBalancers configureF5LoadBalancer listNetscalerLoadBalancers |
The following response parameter is removed: inline. |
listFirewallRules createFirewallRule |
The following request parameter is added: traffictype (optional). |
listUsageRecords |
The following response parameter is added: virtualsize. |
deleteIso |
The following request parameter is added: forced (optional). |
createStoragePool |
The following request parameters are made mandatory: podid clusterid |
createAccount |
The following new request parameters are added: accountid, userid |
createUser |
The following new request parameter is added: userid |
createDomain |
The following new request parameter is added: domainid |
listZones |
The following request parameters is added: securitygroupenabled |
- isPersistent
- startipv6
- endipv6
- ip6gateway
- ip6cidr
listNetworkOfferings listNetworks The following request parameters have been added:
- isPersistent This parameter determines if the network or network offering listed are persistent or not.
- ip6gateway
- ip6cidr
createVlanIpRange The following request parameters have been added:
- startipv6
- endipv6
- ip6gateway
- ip6cidr
deployVirtualMachine The following parameter has been added: ip6Address. The following parameter is updated to accept the IPv6 address: iptonetworklist. CreateZoneCmd The following parameter have been added: ip6dns1, ip6dns2. listRouters listVirtualMachines For nic responses, the following fields have been added.
- ip6address
- ip6gateway
- ip6cidr
listVlanIpRanges For nic responses, the following fields have been added.
- startipv6
- endipv6
- ip6gateway
- ip6cidr
listRouters listZones For DomainRouter and DataCenter response, the following fields have been added.
- ip6dns1
- ip6dns2
addF5LoadBalancer configureNetscalerLoadBalancer addNetscalerLoadBalancer listF5LoadBalancers configureF5LoadBalancer listNetscalerLoadBalancers The following response parameter is removed: inline. listFirewallRules createFirewallRule The following request parameter is added: traffictype (optional). listUsageRecords The following response parameter is added: virtualsize. deleteIso The following request parameter is added: forced (optional). createStoragePool The following request parameters are made mandatory:
- podid
- clusterid
createAccount The following new request parameters are added: accountid, userid createUser The following new request parameter is added: userid createDomain The following new request parameter is added: domainid listZones The following request parameters is added: securitygroupenabled
同时添加了一些新的API
- createEgressFirewallRules (creates an egress firewall rule on the guest network.)
- deleteEgressFirewallRules (deletes a egress firewall rule on the guest network.)
- listEgressFirewallRules (lists the egress firewall rules configured for a guest network.)
- resetSSHKeyForVirtualMachine (Resets the SSHkey for virtual machine.)
- addBaremetalHost (Adds a new host.)
- addNicToVirtualMachine (Adds a new NIC to the specified VM on a selected network.)
- removeNicFromVirtualMachine (Removes the specified NIC from a selected VM.)
- updateDefaultNicForVirtualMachine (Updates the specified NIC to be the default one for a selected VM.)
- addRegion (Registers a Region into another Region.)
- updateRegion (Updates Region details: ID, Name, Endpoint, User API Key, and User Secret Key.)
- removeRegion (Removes a Region from current Region.)
- listRegions (List all the Regions. Filter them by using the ID or Name.)
- getUser (This API can only be used by the Admin. Get user details by using the API Key.)
配置8096端口
8096端口, 不需要验证即可进行API调用. 在所有的3.0.1版本全新安装时, 这个端口都是默认被禁用的. 你可以通过下面的设置启用8096(或使用其它端口号):
- 确保第一个管理服务器安装并运行.
- 设置你期望的端口号到全局配置参数 integration.api.port.
- 重启管理服务器.
- 在管理服务器的节点上, 创建一个防火墙规则以便允许访问这个端口.
使用API请求
所有CloudStack API请求都是以HTTP GET/POST形式提交, 同时附上相关的命令和参数. 无论是HTTP或HTTPS, 一个请求都有以下内容组成:
- CloudStack API URL: 这是Web服务API入口(例如, http://www.cloud.com:8080/client/api)
- 命令: 你想要执行的Web服务命令, 比如开启一个虚拟机或创建一个磁盘卷
- 参数: 命令所需的任何必要或可选的参数
一个API GET请求的样例看起来像这样:
http://localhost:8080/client/api?command=deployVirtualMachine&serviceOfferingId=1&diskOfferingId=1&templateId=2&zoneId=4&apiKey=miVr6X7u6bN_sdahOBpjNejPgEsT35eXq-jB8CG20YI3yaxXcgpyuaIRmFI_EJTVwZ0nUkkJbPmY3y2bciKwFQ&signature=Lxx1DM40AjcXU%2FcaiK8RAP0O1hU%3D
更容易读的方式:
http://localhost:8080/client/api
?command=deployVirtualMachine
&serviceOfferingId=1
&diskOfferingId=1
&templateId=2
&zoneId=4 &apiKey=miVr6X7u6bN_sdahOBpjNejPgEsT35eXqjB8CG20YI3yaxXcgpyuaIRmFI_EJTVwZ0nUkkJbPmY3y2bciKwFQ
&signature=Lxx1DM40AjcXU%2FcaiK8RAP0O1hU%3D
- [原创翻译]Protocol Buffer Basics: C#
- 详解 Android Activity 生命周期
- 设计模式:装饰者模式
- 详解 常量指针和指针常量
- python 列表 总结
- 详解c++指针的指针和指针的引用
- QTableView 一列添加两个按钮
- [个人翻译]Redis 集群教程(上)
- Docker实践--部署Nodejs应用
- 【权限的思考】(一)使用反射实现动态权限
- 【swift学习笔记】一.页面转跳的条件判断和传值
- 【swift学习笔记】二.页面转跳数据回传
- 【swift学习笔记】三.使用xib自定义UITableViewCell
- 【swift学习笔记】四.swift使用Alamofire和swiftyJson
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 嵌入式Linux重启QT应用程序的简单办法(基于QT4.8 qws)
- CentOS下MySQL的彻底卸载的几种方法
- centos7中安装Android SDK的方法步骤
- centos配置ssh免密码登录后仍要输入密码的解决方法
- CentOS7.2安装Nginx的方法步骤
- CentOS安装Python2.7与Python2.6并存的方法
- 详解Centos下YUM安装PHP的两种方式
- linux下make命令实现输出高亮的方法
- Ubuntu彻底卸载MySQL、Apache2和Php的方法教程
- linux下如何创建守护进程的步骤
- ubuntu系统中/etc/rc.local和/etc/init.d/rc.local的区别详解
- centos6.8下hadoop3.1.1完全分布式安装指南(推荐)
- 批处理模式下运行 top 命令的方法
- 关于CentOs系统自带python和yum卸载后的解决办法
- Linux sftp命令用法总结