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:
|
listNetworkOfferings
listNetworks
|
The following request parameters have been added:
|
createVlanIpRange
|
The following request parameters have been added:
|
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.
|
listVlanIpRanges
|
For nic responses, the following fields have been added.
|
listRouters
listZones
|
For DomainRouter and DataCenter response, the following fields have been added.
|
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:
|
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