Revision db147305 daemons/ganeti-watcher
b/daemons/ganeti-watcher | ||
---|---|---|
47 | 47 |
from ganeti import ssconf |
48 | 48 |
from ganeti import bdev |
49 | 49 |
from ganeti import hypervisor |
50 |
from ganeti import rapi |
|
50 | 51 |
from ganeti.confd import client as confd_client |
51 | 52 |
|
53 |
import ganeti.rapi.client # pylint: disable-msg=W0611 |
|
54 |
|
|
52 | 55 |
|
53 | 56 |
MAXTRIES = 5 |
54 | 57 |
BAD_STATES = ['ERROR_down'] |
... | ... | |
595 | 598 |
return os.fdopen(statefile_fd, "w+") |
596 | 599 |
|
597 | 600 |
|
601 |
def IsRapiResponding(hostname): |
|
602 |
"""Connects to RAPI port and does a simple test. |
|
603 |
|
|
604 |
Connects to RAPI port of hostname and does a simple test. At this time, the |
|
605 |
test is GetVersion. |
|
606 |
|
|
607 |
@type hostname: string |
|
608 |
@param hostname: hostname of the node to connect to. |
|
609 |
@rtype: bool |
|
610 |
@return: Whether RAPI is working properly |
|
611 |
|
|
612 |
""" |
|
613 |
ssl_config = rapi.client.CertAuthorityVerify(constants.RAPI_CERT_FILE) |
|
614 |
rapi_client = \ |
|
615 |
rapi.client.GanetiRapiClient(hostname, |
|
616 |
config_ssl_verification=ssl_config) |
|
617 |
try: |
|
618 |
master_version = rapi_client.GetVersion() |
|
619 |
except rapi.client.CertificateError, err: |
|
620 |
logging.warning("RAPI Error: CertificateError (%s)", err) |
|
621 |
return False |
|
622 |
except rapi.client.GanetiApiError, err: |
|
623 |
logging.warning("RAPI Error: GanetiApiError (%s)", err) |
|
624 |
return False |
|
625 |
logging.debug("RAPI Result: master_version is %s", master_version) |
|
626 |
return master_version == constants.RAPI_VERSION |
|
627 |
|
|
628 |
|
|
598 | 629 |
def ParseOptions(): |
599 | 630 |
"""Parse the command line options. |
600 | 631 |
|
... | ... | |
668 | 699 |
# we are on master now |
669 | 700 |
utils.EnsureDaemon(constants.RAPI) |
670 | 701 |
|
702 |
# If RAPI isn't responding to queries, try one restart. |
|
703 |
logging.debug("Attempting to talk with RAPI.") |
|
704 |
if not IsRapiResponding(constants.LOCALHOST_IP_ADDRESS): |
|
705 |
logging.warning("Couldn't get answer from Ganeti RAPI daemon." |
|
706 |
" Restarting Ganeti RAPI.") |
|
707 |
utils.StopDaemon(constants.RAPI) |
|
708 |
utils.EnsureDaemon(constants.RAPI) |
|
709 |
logging.debug("Second attempt to talk with RAPI") |
|
710 |
if not IsRapiResponding(constants.LOCALHOST_IP_ADDRESS): |
|
711 |
logging.fatal("RAPI is not responding. Please investigate.") |
|
712 |
logging.debug("Successfully talked to RAPI.") |
|
713 |
|
|
671 | 714 |
try: |
672 | 715 |
watcher = Watcher(options, notepad) |
673 | 716 |
except errors.ConfigurationError: |
Also available in: Unified diff