虛擬化平台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

同時添加了一些新的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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM