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,
}
No comments:
Post a Comment