- 如果想对一个文件进行open操作,最好先对这个文件付予权限,’777 最大权限’
- 如果对一个文件既要读又要写, 使用”w+“,并且是必须的
- utils中不能使用“*”等匹配符,什么都不可以 无论是mv、 cp 还是yum_install
ctx_properties.get
不能用ctx_properties[]
python setup.py install
执行时必须在setup.py
存在的目录下- 注意文件的格式 用
set ff
查看, 如果时dos ,那么用set ff=unix
改成unix - 如果从Windows中传到虚拟机中,那么文件很可能都是dos格式, 那么如果一个个修改会比较困难,那么使用
find . -type f -exec dos2unix {} \;
, 一次性修改 - 当用
touch
创建一个文件之后需要给文件付予权限
ctx_properties = utils.ctx_factory.create(SERVICE_NAME)
是必须的
runtime_props = ctx.instance.runtime_properties
如果想要得到属性,必须先定义
- 在代码中需要使用的一些属性必须都要在input文件中的manager-input.yaml中有的,比如
#############################
#vmware-exporter inputs
############################
vmware_exporter_source_url:
type: string
default: vmware-exporter-data.tar.gz
vmware_exporter_url:
type: string
default: 'http://127.0.0.1:9272'
- type文件夹中的manager-type.yaml中,存储的是组件的节点,
properties: 里面的是代码中需要用 例如consul = ctx_properties.get('consul_url')
方法获取的属性。
其中的属性必须在input文件中的manager-input.yaml
中也存在
manager.nodes.Vmware_exporter:
derived_from: cloudify.nodes.SoftwareComponent
properties:
vmware_exporter_source_url:
description: Vmware_exporter Source URL
type: string
default: { get_input: vmware_exporter_source_url }
consul_url:
description: Consul URL
type: string
default: { get_input: consul_url }
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: fabric.fabric_plugin.tasks.run_script
inputs:
script_path:
default: components/vmware-exporter/scripts/create.py
hide_output: *hide_output
fabric_env: *simple_fabric_env
configure:
implementation: fabric.fabric_plugin.tasks.run_script
inputs:
script_path:
default: components/vmware-exporter/scripts/configure.py
hide_output: *hide_output
fabric_env: *simple_fabric_env
start:
implementation: fabric.fabric_plugin.tasks.run_script
inputs:
script_path:
default: components/vmware-exporter/scripts/start.py
hide_output: *hide_output
fabric_env: *simple_fabric_env
stop:
implementation: fabric.fabric_plugin.tasks.run_script
inputs:
script_path:
default: components/vmware-exporter/scripts/stop.py
hide_output: *hide_output
fabric_env: *simple_fabric_env
delete:
implementation: fabric.fabric_plugin.tasks.run_script
inputs:
script_path:
default: components/vmware-exporter/scripts/delete.py
hide_output: *hide_output
fabric_env: *simple_fabric_env
6. service文件中如果有变量
例如:
[Unit]
Description=Vmware Exporter
After=network.target
[Service]
EnvironmentFile=-/etc/sysconfig/cloudchef-vmware-exporter
ExecStart=$HOME_PATH/vmware_exporter/vmware_exporter/vmware_exporter.py -c $CONSUL_IP
ExecStop=/bin/kill -15 $MAINPID
LimitNOFILE=102400
[Install]
WantedBy=default.target
- 首先在service的同一个目录中创建一个文件,例如
cloudchef-vmware-exporter
cloudchef-vmware-exporter
里面的内容
CONSUL_IP='{{ ctx.instance.runtime_properties.consul_ip }}'
HOME_PATH='{{ ctx.instance.runtime_properties.home_path }}'
注意 里面的consul_ip
,和home_path
, 都已经在type文件中的manager-type.yaml和input文件中的manager-input.yaml
里面存在,或者已经用 例如 runtime_props['consul_ip'] = consul_ip
的方法写到runtime_props
里面才可以使用
- service中的
EnvironmentFile=-/etc/sysconfig/cloudchef-vmware-exporter
是必须存在