歡迎轉載,轉載請註明出處:http://my.oschina.net/fmnismehtml
##簡介 murano是OpenStack的Application Catalog服務,推崇AaaS(Anything-as-a-Service)的概念,經過統一的框架和API實現應用程序快速部署和應用程序生命週期管理的功能,下降應用程序對底層平臺(OpenStack層和虛擬化層)的依賴。git
能夠閱讀這邊博客瞭解下murano:Murano環境搭建、使用介紹和思考,具體安裝過程則參考官方文檔.github
##需求 如今murano還不支持在實例中添加volume,不過murano是經過heat建立資源的,而heat是能夠建立並附加volume的,heat能夠作到的事,murano就能夠作到(固然還能夠作的更多),下面咱們就來一步一步的實現這個功能。apache
##修改io.murano ###建立Cinder.yamlapp
murano的核心庫放在murano/meta/io.murano
中,首先在murano/meta/io.murano/manifest.yaml
中註冊Cinder類,將下面的內容複製到manifest.yaml中並保存:框架
io.murano.resources.Cinder: resources/Cinder.yaml
建立murano/meta/io.murano/Class/resources/Cinder.yaml
文件:測試
Namespaces: =: io.murano.resources # 當前命名空間 std: io.murano Name: Cinder Properties: # 要建立的Volume大小,單位GB size: Contract: $.int().notNull() Methods: initialize: Body: - $._environment: $.find(std:Environment).require() genTemplate: Arguments: # volume要附加到的實例 - instance: Contract: $.class(Instance).notNull() Body: # $volumeName表示將要建立的volume名字,$instance.name是實例的名字,同時也是heat模板中instance的名字。 - $volumeName: format('volume-{0}-{1}', $.id(), $instance.name) - $volumeAttachment: format('volumeAttachment-{0}-{1}', $.id(), $instance.name) # $template裏保存的是標準的heta模板 # 模板首先建立了一個Volume,而後用VolumeAttachment附加到指定的實例上 - $template: resources: $volumeName: type: OS::Cinder::Volume properties: size: $.size $volumeAttachment: type: OS::Cinder::VolumeAttachment properties: volume_id: { get_resource: $volumeName } instance_uuid: { get_resource: $instance.name } # 返回建立的模板,改模版會在後面的步驟中合併到一個完整的heat模板中去。 - Return: $template
###修改Instance.yamlui
修改murano/meta/io.murano/Class/resources/Instance.yaml
this
(1) 在Properties:
塊裏追加下面的內容:spa
volumeSize: Contract: $.int() Default: null
這個是給app傳參數進來用的。
(2) 在第99行(也就是- $.networks.customNetworks.select($this.joinNet($, $securityGroupName))
)後面添加以下內容:
- If: $.volumeSize != null Then: - $cinder: new(Cinder, size => $.volumeSize) - $volumeTemplate: $cinder.genTemplate($this) - $.instanceTemplate: $.instanceTemplate.mergeWith($volumeTemplate)
這幾行代碼很好理解:若是$.volumeSize
不爲空,則實例化一個Cinder對象,而後將生成的volume模板合併的到$.instanceTemplate
模板中去。
###更新io.murano
``` murano-manage --config-file ./etc/murano/murano.conf import-package meta/io.murano/ --update ```
##修改murano-app murano如今能夠添加volume了,如今還要修改一個app來讓它使用該功能,須要注意的是,Instance.yaml中的volumeSize
參數是可選參數,因此現有的app不修改也不會有問題的。
這裏咱們用Tomcat
app來測試,Tomcat
能夠在https://github.com/openstack/murano-apps.git
下載,下載完後記得git checkout -t origin/stable/kilo
切換到的正確的分支。
編輯murano-apps/Tomcat/package/UI/ui.yaml
:
Version: 2 Application: ?: type: io.murano.apps.apache.Tomcat name: $.appConfiguration.name instance: ?: type: io.murano.resources.LinuxMuranoInstance name: generateHostname($.instanceConfiguration.unitNamingPattern, 1) flavor: $.instanceConfiguration.flavor image: $.instanceConfiguration.osImage keyname: $.instanceConfiguration.keyPair availabilityZone: $.instanceConfiguration.availabilityZone assignFloatingIp: $.appConfiguration.assignFloatingIP volumeSize: $.instanceConfiguration.volumeSize #添加這一行 [...] - name: unitNamingPattern type: string label: Instance Naming Pattern required: false maxLength: 64 regexpValidator: '^[a-zA-z][-_\w]*$' errorMessages: invalid: Just letters, numbers, underscores and hyphens are allowed. helpText: Just letters, numbers, underscores and hyphens are allowed. description: >- Specify a string, that will be used in instance hostname. Just A-Z, a-z, 0-9, dash and underline are allowed. # 添加下面幾行 - name: volumeSize type: integer label: Volume Size(GB) required: false description: Instance Volume Size.
上文中的[...]
表示省略掉的內容,須要修改的地方有註釋。修改完後,建立Tomcat時會多一個可選的參數VolumeSize
,若是該參數不爲空就會建立volume了。
更新Tomcat代碼:
murano-manage --config-file ./etc/murano/murano.conf import-package ../murano-apps/Tomcat/package --update
修改到這裏就結束了,enjoy it!