public function __construct($url, $secret = array()) { $client = new Openstack($url, $secret); $computeService = $client->computerService(); $this->computeServer = $computeService->server(); $volumeService = $client->volumeService(); $this->volumeServer = $volumeService->server(); }
*/ /** * 用户使用说明: */ /** * 首先必须指定url */ $url = "172.16.4.31"; /** * 必须指定username, password, tenantName*(必须知道租户的名称) */ $secret = array("username" => "admin", "password" => "jcb410", "tenantName" => "admin"); /** * 接着创建Openstack实例 */ $client = new Openstack($url, $secret); /** * 然后由Openstack类创建 Service实例: 这里只实现了computeService, volumeService *当然必要时需要说明Service的$name, $region, $urlType(e.g. 'publicURL' or 'internalURL'.) */ $computeService = $client->computerService(); $volumeService = $client->volumeService(); /** *接下来以computerServer为例子: * 创建虚拟机: * 这里在server($computeId)方法中不需要指定computeId */ $computeServer = $compute_service->server(); /** * 得到所有虚拟机的信息 * 返回:json格式
/** * @param $url like: http://controller5:5000/v2.0/********* * @return as : http://172.16.4.31:5000/v2.0/************ */ private function getFormatUrl($url, Openstack $client) { $port_and_tail = strrchr($url, ":"); //like :5000/v2.0/******* $url = $client->getAuthUrl() . $port_and_tail; echo "<br/>Endpoint:: getFormatuUrl : {$url}<br/>"; return $url; }