3
# The Following Agent Has Been Tested On:
5
# Virsh 0.3.3 on RHEL 5.2 with xen-3.0.3-51
8
import sys, time, random
9
sys.path.append("/usr/share/fence")
13
#BEGIN_VERSION_GENERATION
14
RELEASE_VERSION="3.1.6"
15
BUILD_DATE="(built Mon Oct 24 12:14:08 UTC 2011)"
16
REDHAT_COPYRIGHT="Copyright (C) Red Hat, Inc. 2004-2010 All rights reserved."
17
#END_VERSION_GENERATION
20
def get_outlets_status(conn, options):
24
if options.has_key("-o") and options["-o"] == "on":
27
# This fake agent has no port data to list, so we have to make
28
# something up for the list action.
29
if options.has_key("-o") and options["-o"] == "list":
30
result["fake_port_1"]=[plug_status, "fake"]
31
result["fake_port_2"]=[plug_status, "fake"]
32
elif (options.has_key("-n") == 0):
33
fail_usage("Failed: You have to enter existing machine!")
36
result[port]=[plug_status, "fake"]
40
def get_power_status(conn, options):
41
outlets=get_outlets_status(conn,options)
43
if len(outlets) == 0 or options.has_key("-n") == 0:
44
fail_usage("Failed: You have to enter existing machine!")
46
return outlets[options["-n"]][0]
48
def set_power_status(conn, options):
50
plug_status = "unknown"
51
if options.has_key("-o") and options["-o"] == "on":
56
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "port",
57
"no_password", "power_wait", "power_timeout", "random_sleep_range"]
59
all_opt["random_sleep_range"] = {
61
"longopt" : "random_sleep_range",
62
"help" : "--random_sleep_range=<seconds>Issue a sleep between 1 and <seconds>. Used for testing.",
65
atexit.register(atexit_handler)
67
pinput = process_input(device_opt)
69
# Fake options to keep the library happy
70
#pinput["-p"] = "none"
71
pinput["-a"] = "localhost"
74
options = check_input(device_opt, pinput)
76
# random sleep for testing
77
if options.has_key("-R"):
78
val = int(options["-R"])
79
ran = random.randint(1, val)
80
sys.stderr.write("random sleep for %d seconds" % ran)
83
if options.has_key("-o") and (options["-o"] == "monitor"):
86
## Defaults for fence agent
88
docs["shortdesc"] = "Fake fence agent"
89
docs["longdesc"] = "fence_true is a fake Fencing agent which always reports failure without doing anything."
90
show_docs(options, docs)
92
## Operate the fencing device
93
result = fence_action(None, options, set_power_status, get_power_status, get_outlets_status)
96
if __name__ == "__main__":