murano package 中包含Classes、Resources、UI三个文件夹和manifest.yaml、logo.png两个文件,其中manifest.yaml是必须包含的文件。
package解析的入口是manifest.yaml,概括的定义了这个package是什么和有什么样的用途;Classes中定义了这个package中各种运行的方法或者是应用初始化部署等的定义;Resources中主要是各种执行脚步和配置;UI定义了显示样式以及提交应用申请的参数;logo.png即为该应用的logo文件。
使用时,需要将这几个文件打包成**.zip文件,然后通过murano的接口上传上去即可。
manifest.yaml 包含的如下几个部分
如下,为默认基础库io.murano的manifest.yaml
Format: 1.0
Type: Library
FullName: io.murano
Name: Core library
Description: |
Core MuranoPL library
Classes:
io.murano.Object: Object.yaml
io.murano.Environment: Environment.yaml
io.murano.StackTrace: StackTrace.yaml
io.murano.SharedIp: SharedIp.yaml
io.murano.File: File.yaml
注: Classes仅截出一部分作为示例。根据上面的描述,我们可以这么立即,这个库版本是1.0,记作io.murano
,包含有io.murano.Object
等Classes,io.murano.Object
在Classes/Object.yaml
中定义的。
Class 包含如下几个部分,这个和java中定义一个类的形式是一样的,只不过没有没有接口等概念而已。
注:
- Contract 详见http://muranotest.readthedocs.org/en/latest/articles/murano_pl.html#contract
- Usage 详见 http://muranotest.readthedocs.org/en/latest/articles/murano_pl.html#usage
- Expression 详见 http://muranotest.readthedocs.org/en/latest/articles/murano_pl.html#expressions
- Assignment详见 http://muranotest.readthedocs.org/en/latest/articles/murano_pl.html#assignment
如下,为guacamole应用的Class定义
Namespaces:
=: io.murano.apps
std: io.murano
sys: io.murano.system
srv: io.murano.apps.apache
Name: Guacamole
Extends: std:Application
Properties:
name:
Contract: $.string().notNull()
username:
Contract: $.string().notNull()
password:
Contract: $.string().notNull()
server:
Contract: $.class(srv:Tomcat).notNull()
Methods:
initialize:
Body:
- $._environment: $.find(std:Environment).require()
deploy:
Body:
- If: not $.getAttr(deployed, false)
Then:
# Deploy Tomcat
- $._environment.reporter.report($this, 'Ensuring Tomcat is deployed')
- $.server.deploy()
# Deploy Guacamole
- $._environment.reporter.report($this, 'Deploying Guacamole')
- $resources: new(sys:Resources)
- $template: $resources.yaml('DeployGuacamole.template').bind(dict(
username => $.username,
password => $.password
))
- $.server.instance.agent.call($template, $resources)
- If: $.server.instance.assignFloatingIp
Then:
- $address: $.server.instance.floatingIpAddress
Else:
- $address: $.server.instance.ipAddresses[0]
- $._environment.reporter.report($this, 'Guacamole {0} is available at http://{1}:{2}/guacamole'.format($.name, $address, 8080))
- $.setAttr(deployed, true)
定义名称为Guacamole
,命名空间是io.murano.apps
,所以该Class的标示为io.murano.apps.Guacamole
,该Class继承于io.murano.Application
,包含参数name、username、password、server,其中server为一个Class实例,为io.murano.apps.apache.Tomet
实例,且不能为空。提供了构造初始化方法和deploy方法。deploy方法定义如下:
如果Class实例未部署(deployed为false),则第一步,输出部署过程Ensuring Tomcat is deployed
,接着调用server实例的deploy方法部署tomcat;第二步,输出部署过程Deploy Guacamole
,接着新建实例传递部署模版DeployGuacamole.template到server的agent中,交给agent实现部署,完成之后,如果需要绑定floatingIP,绑定设置地址为floatingIp否则设置为server的第一个地址,最后输出结果Guacamole {0} is available at http://address:8080/guacamole
。
Resource主要是一些执行的脚本和部署模版,提供给Class执行方法中调用,部署模版格式如下:
如下,为guacamole部署模版:
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy Guacamole
Parameters:
username: $username
password: $password
Body: |
return deploy('{0} {1}'.format(args.username, args.password)).stdout
Scripts:
deploy:
Type: Application
Version: 1.0.0
EntryPoint: deployGuacamole.sh
Files: []
Options:
captureStdout: true
captureStderr: true
定义部署的版本和Class调用传递的参数以及部署返回的输出
UI定义结构如下:
以guacamole显示的UI为例分析:
Version: 2
Application:
?:
type: io.murano.apps.Guacamole
name: $.appConfiguration.name
username: $.appConfiguration.username
password: $.appConfiguration.password
server: $.appConfiguration.server
Forms:
- appConfiguration:
fields:
- name: license
type: string
description: Apache License, Version 2.0
hidden: true
required: false
- name: name
type: string
label: Application Name
initial: Guacamole
description: >-
Enter a desired name for the application. Just A-Z, a-z, 0-9, dash and
underline are allowed
- name: username
type: string
label: Username
initial: guac
description: >-
Please, provide a username that is going to be used to access Guacamole and ssh into the server instance to
modify the Guacamole configuration
- name: password
type: password
label: Password
descriptionTitle: Password
description: >-
Please, provide a strong password that is going to be used to access Guacamole and ssh into the server instance to
modify the Guacamole configuration
- name: server
type: io.murano.apps.apache.Tomcat
label: Application Server
description: >-
Select an instance of Application Server to run the app
定义了UI显示的字段licese、name、username、password、server,其中server定义的是一个应用tomcat,也就是说依赖一个新的应用。
最终供部署使用的参数为name、username、password、server。
虽然说murano的package具很多好的特性,但是依然存在着一些缺陷如:
模板测试,如果想要写好murano模版不是一件容易的事情,如果说去理解、弄明白murano的模板结构不算难的话,那么测试模板的正确性,可用性就是一个很大的痛点,目前在官方也没有找到模板测试相关的资料。