#!/bin/sh # # Copyright 2016 Canonical Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # OCF instance parameters # OCF_RESKEY_logfile # OCF_RESKEY_errlogfile # # This RA starts $binfile with $cmdline_options as $user in $workdir and writes a $pidfile from that. # If you want it to, it logs: # - stdout to $logfile, stderr to $errlogfile or # - stdout and stderr to $logfile # - or to will be captured by lrmd if these options are omitted. # Monitoring is done through $pidfile or your custom $monitor_hook script. # The RA expects the program to keep running "daemon-like" and # not just quit and exit. So this is NOT (yet - feel free to # enhance) a way to just run a single one-shot command which just # does something and then exits. # XXX Update all comments # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs # OCF parameters are as below # OCF_RESKEY_fqdn # OCF_RESKEY_ip_address # OCF_RESKEY_ttl # OCF_RESKEY_maas_url # OCF_RESKEY_maas_credentials # OCF_RESKEY_cfg_dir # Defaults OCF_RESKEY_cfg_dir_default="/etc/maas_dns" OCF_RESKEY_logfile_default="/var/log/maas_dns_${OCF_RESOURCE_INSTANCE}.log" OCF_RESKEY_errlogfile_default="/var/log/maas_dns_${OCF_RESOURCE_INSTANCE}_error.log" : ${OCF_RESKEY_cfg_dir=${OCF_RESKEY_cfg_dir_default}} : ${OCF_RESKEY_logfile=${OCF_RESKEY_logfile_default}} : ${OCF_RESKEY_errlogfile=${OCF_RESKEY_errlogfile_default}} maas_dns_usage() { cat </dev/null 2>&1 then ocf_log err "user $user does not exist." exit $OCF_ERR_INSTALLED fi for logfilename in "$logfile" "$errlogfile" do if [ -n "$logfilename" ]; then mkdir -p `dirname $logfilename` || { ocf_log err "cannot create $(dirname $logfilename)" exit $OCF_ERR_INSTALLED } fi done if [ ! -r $ipaddrfile ] then ocf_log err "$ipaddrfile does not exist or cannot be read" exit $OCF_ERR_INSTALLED fi if [ `my_ip` = "no" ] then ocf_log err "IP address is not found in $ipaddrfile" exit $OCF_ERR_INSTALLED fi return $OCF_SUCCESS } maas_dns_meta() { cat < 1.0 OCF RA to manage MAAS DNS entries. This will call out to maas_dns.py with the command name, fqdn, ip_address, maas_url and maas_credentials OCF RA to manage MAAS DNS entries The fully qualified domain name for the DNS entry. Fully qualified domain name The IP address for the DNS entry. Deprecated option, do not use. IP Address The URL to the MAAS host where the DNS entry will be updated. MAAS URL MAAS Oauth credentials for the MAAS API MAAS Credentials File to write STDOUT to File to write STDOUT to File to write STDERR to File to write STDERR to Directory containing resource config files containing IP address information for the resource running on the local server. IP address config file directory END exit 0 } case "$1" in meta-data|metadata|meta_data) maas_dns_meta ;; start) maas_dns_start ;; stop) maas_dns_stop ;; monitor) maas_dns_monitor ;; status) maas_dns_status ;; validate-all) maas_dns_validate ;; *) maas_dns_usage ocf_log err "$0 was called with unsupported arguments: $*" exit $OCF_ERR_UNIMPLEMENTED ;; esac