- print_log monitor.log
-}
-
-congress_add_rule() {
- name=$1
- policy=$2
- rule=$3
-
- if ! openstack congress policy rule list $policy | grep -q -e "// Name: $name$" ; then
- openstack congress policy rule create --name $name $policy "$rule"
- fi
-}
-
-congress_del_rule() {
- name=$1
- policy=$2
-
- if openstack congress policy rule list $policy | grep -q -e "^// Name: $name$" ; then
- openstack congress policy rule delete $policy $name
- fi
-}
-
-congress_setup_rules() {
- congress_add_rule host_down classification \
- 'host_down(host) :-
- doctor:events(hostname=host, type="compute.host.down", status="down")'
-
- congress_add_rule active_instance_in_host classification \
- 'active_instance_in_host(vmid, host) :-
- nova:servers(id=vmid, host_name=host, status="ACTIVE")'
-
- congress_add_rule host_force_down classification \
- 'execute[nova:services.force_down(host, "nova-compute", "True")] :-
- host_down(host)'
-
- congress_add_rule error_vm_states classification \
- 'execute[nova:servers.reset_state(vmid, "error")] :-
- host_down(host),
- active_instance_in_host(vmid, host)'
-}
-
-start_inspector() {
- if [[ "$INSPECTOR_TYPE" == "sample" ]] ; then
- pgrep -f "python inspector.py" && return 0
- python inspector.py "$INSPECTOR_PORT" > inspector.log 2>&1 &
- elif [[ "$INSPECTOR_TYPE" == "congress" ]] ; then
- nova_api_min_version="2.11"
- nova_api_version=$(openstack congress datasource list | \
- grep nova | grep -Po "(?<='api_version': ')[^']*")
- [[ -z $nova_api_version ]] && nova_api_version="2.0"
- if [[ "$nova_api_version" < "$nova_api_min_version" ]]; then
- echo "ERROR: Congress Nova datasource API version < $nova_api_min_version ($nova_api_version)"
- exit 1
- fi
- openstack congress driver list | grep -q " doctor "
- openstack congress datasource list | grep -q " doctor " || {
- openstack congress datasource create doctor doctor
- }
- congress_setup_rules
- fi
-}
-
-stop_inspector() {
- if [[ "$INSPECTOR_TYPE" == "sample" ]] ; then
- pgrep -f "python inspector.py" || return 0
- kill $(pgrep -f "python inspector.py")
- print_log inspector.log
- elif [[ "$INSPECTOR_TYPE" == "congress" ]] ; then
- congress_del_rule host_force_down classification
- congress_del_rule error_vm_states classification
- congress_del_rule active_instance_in_host classification
- congress_del_rule host_down classification
- fi