目前还在进行中,开源在 https://github.com/yeasy/openstack_code_Heat,欢迎大家参与完善。
Showing posts with label Heat. Show all posts
Showing posts with label Heat. Show all posts
Thursday, October 30, 2014
Tuesday, September 23, 2014
OpenStack Heat template中类型定义的一个坑
最新的Heat template目前支持string | number | json | comma_delimited_list | boolean等类型。
采用默认的hot格式,yaml文件格式。
定义一个string类型的属性,内容为true或false的时候,会报错。
查看heat engine的log会发现这个属性值默认被转为了boolean类型。
这是为何呢?
查看heat的代码,heat是调用的yaml库来直接load文件的,而对于yaml语言来说,如下的字符串都会被解析为bool类型。
y, Y, yes, Yes, YES
n, N, no, No, NO
true, True, TRUE
false, False, FALSE
on, On, ON
off, Off, OFF
采用默认的hot格式,yaml文件格式。
定义一个string类型的属性,内容为true或false的时候,会报错。
查看heat engine的log会发现这个属性值默认被转为了boolean类型。
这是为何呢?
查看heat的代码,heat是调用的yaml库来直接load文件的,而对于yaml语言来说,如下的字符串都会被解析为bool类型。
y, Y, yes, Yes, YES
n, N, no, No, NO
true, True, TRUE
false, False, FALSE
on, On, ON
off, Off, OFF
OpenStack Heat中添加新资源示例
在OpenStack Heat中,资源都是通过继承resource类来实现的。
heat-engine在启动的时候会扫描预设目录来加载各种资源插件。
这种模式提供了极大的灵活性,用户可以很容易的添加自己的资源类型和指定响应行动。
下面给出了定义新资源的一个简单示例,资源被创建后在log中给出属性信息。
heat-engine在启动的时候会扫描预设目录来加载各种资源插件。
这种模式提供了极大的灵活性,用户可以很容易的添加自己的资源类型和指定响应行动。
下面给出了定义新资源的一个简单示例,资源被创建后在log中给出属性信息。
#This file should be put into the plugin_dirs of OpenStack HEAT.
#plugin_dirs=/usr/lib64/heat,/usr/lib/heat
#After that, restart the heat engine to enable it.
# service openstack-heat-engine restart
#Provide the OS::Neutron::ServicePolicy resource.
from heat.engine import attributes
from heat.engine import properties
from heat.engine import resource
from heat.openstack.common import log as logging
LOG = logging.getLogger(__name__)
classServicePolicy(resource.Resource):
PROPERTIES = (
NAME, SRC, DST,
) = (
'name', 'src', 'dst',
)
ATTRIBUTES = (
NAME,
)
properties_schema = {
NAME: properties.Schema(
properties.Schema.STRING,
_('Name of the service policy.')
),
SRC: properties.Schema(
properties.Schema.STRING,
_('Source of the service policy.')
),
DST: properties.Schema(
properties.Schema.STRING,
_('Destination of the service policy.')
),
}
attributes_schema = {
NAME: attributes.Schema(
_('Name of the service policy.')
),
}
def handle_create(self):
LOG.info(self.properties.get(self.NAME))
LOG.info(self.properties.get(self.SRC))
LOG.info(self.properties.get(self.DST))
def handle_delete(self):
pass
def _resolve_attribute(self, name):
if name == self.NAME:
return self.properties.get(self.NAME)
def resource_mapping():
return {
'OS::Neutron::ServicePolicy':ServicePolicy,
}
#plugin_dirs=/usr/lib64/heat,/usr/lib/heat
#After that, restart the heat engine to enable it.
# service openstack-heat-engine restart
#Provide the OS::Neutron::ServicePolicy resource.
from heat.engine import attributes
from heat.engine import properties
from heat.engine import resource
from heat.openstack.common import log as logging
LOG = logging.getLogger(__name__)
classServicePolicy(resource.Resource):
PROPERTIES = (
NAME, SRC, DST,
) = (
'name', 'src', 'dst',
)
ATTRIBUTES = (
NAME,
)
properties_schema = {
NAME: properties.Schema(
properties.Schema.STRING,
_('Name of the service policy.')
),
SRC: properties.Schema(
properties.Schema.STRING,
_('Source of the service policy.')
),
DST: properties.Schema(
properties.Schema.STRING,
_('Destination of the service policy.')
),
}
attributes_schema = {
NAME: attributes.Schema(
_('Name of the service policy.')
),
}
def handle_create(self):
LOG.info(self.properties.get(self.NAME))
LOG.info(self.properties.get(self.SRC))
LOG.info(self.properties.get(self.DST))
def handle_delete(self):
pass
def _resolve_attribute(self, name):
if name == self.NAME:
return self.properties.get(self.NAME)
def resource_mapping():
return {
'OS::Neutron::ServicePolicy':ServicePolicy,
}
Subscribe to:
Posts (Atom)