虚拟化平台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提供的三种角色

  1. 管​理​员​。​获​得​云​的​所​有​功​能​,包​括​虚​拟​和​物​理​资​源​管​理​。​
  2. 域​管​理​员​。​进​入​到​虚​拟​资​源​的​云​属​于​管​理​员​的​域​。
  3. 用​户​。​只​访​问​允​许​用​户​管​理​的​功​能​,虚​拟​实​例​,存​储​,和​网​络​。​

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(或​使​用​其​它​端​口​号​):

  1. 确​保​第​一​个​管​理​服​务​器​安​装​并​运​行​.
  2. 设​置​你​期​望​的​端​口​号​到​全​局​配​置​参​数​ integration.api.port.
  3. 重​启​管​理​服​务​器​.
  4. 在​管​理​服​务​器​的​节​点​上​, 创​建​一​个​防​火​墙​规​则​以​便​允​许​访​问​这​个​端​口​.

使用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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏一个会写诗的程序员的博客

《Spring Boot极简教程》第8章 Spring Boot集成Groovy,Grails开发第8章 Spring Boot集成Groovy,Grails开发小结参考资料

本章介绍Spring Boot集成Groovy,Grails开发。我们将开发一个极简版的pms(项目管理系统)。

1532
来自专栏Ryan Miao

SpringCloud学习2-Springboot监控模块(actuator)

前言 学习一项新技术最大的困难是什么? 是资料。让人高兴的是找到了一本系统学习Spring Cloud的教程,《Spring Cloud微服务实战》, 接下来的...

2.7K11
来自专栏大数据互联网思维

SpringCloud学习2-Springboot监控模块+

学习一项新技术最大的困难是什么? 是资料。让人高兴的是找到了一本系统学习Spring Cloud的教程,《Spring Cloud微服务实战》, 接下来的学习目...

1200
来自专栏史上最简单的Spring Cloud教程

一篇SSM框架整合友好的文章(三)

一.SpringMVC理论 它始终是围绕 handler、 数据模型 model、 页面view进行开发的。 运行流程图: ? 通过mvc配置...

2246
来自专栏pangguoming

简单的Hibernate入门简介

其实Hibernate本身是个独立的框架,它不需要任何web server或application server的支持。然而,大多数的Hibernate入门介绍...

3649
来自专栏Java3y

Druid数据库连接池就是这么简单

前言 本章节主要讲解Druid数据库连接池,为什么要学Druid数据库连接池呢?? 我的知识储备数据库连接池有两种->C3P0,DBCP,可是现在看起来并不够用...

48411
来自专栏杨建荣的学习笔记

使用shell脚本快速得到主备关系(r9笔记第93天)

对于备库的使用,尤其是一主多备的环境,一直以来有一点感觉不大给力,那就是主备库的关系,总是感觉会少一点什么。 尤其是在做月度404审计的时候,总是要反复确认备库...

3626
来自专栏Ryan Miao

gradle中使用嵌入式(embedded) tomcat, debug 启动

在gradle项目中使用embedded tomcat。 最开始部署项目需要手动将web项目打成war包,然后手动上传到tomcat的webapp下,然后启动t...

4809
来自专栏数据库新发现

Use Orastress! to test your database

http://www.eygle.com/special/Use.Orastress.2.Test.Oracle.db.htm

962
来自专栏编程

Spring in Action 要点总结

一、Spring基础 1. Environment 环境抽象:profiles 和 properties. 2. SpEL Spring EL 表达式 3. 设...

1895

扫码关注云+社区

领取腾讯云代金券