~ubuntu-branches/ubuntu/utopic/pacemaker/utopic-proposed

« back to all changes in this revision

Viewing changes to fencing/fence_false

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-08-15 11:27:07 UTC
  • mfrom: (1.1.12) (2.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20130815112707-5r864ink7jme3zl5
Tags: 1.1.10+git20130802-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/control: Build-Depends on libqb-dev; Depends on libheartbeat2.
* Corosync's pacemaker plugin is disabled, hence not built:
  - debian/licrmcluster4-dev.install: Do not install plugin.h.
  - debian/pacemaker.install: Do not install pacemaker.lcrso.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
# The Following Agent Has Been Tested On:
4
 
#
5
 
# Virsh 0.3.3 on RHEL 5.2 with xen-3.0.3-51
6
 
#
7
 
 
8
 
import sys, time, random
9
 
sys.path.append("/usr/share/fence")
10
 
from fencing import *
11
 
 
12
 
 
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
18
 
plug_status="on"
19
 
 
20
 
def get_outlets_status(conn, options):
21
 
    result={}
22
 
    global plug_status
23
 
 
24
 
    if options.has_key("-o") and options["-o"] == "on":
25
 
        plug_status = "off"
26
 
 
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!")
34
 
    else:
35
 
        port=options["-n"]
36
 
        result[port]=[plug_status, "fake"]
37
 
 
38
 
    return result
39
 
 
40
 
def get_power_status(conn, options):
41
 
    outlets=get_outlets_status(conn,options)
42
 
 
43
 
    if len(outlets) == 0 or options.has_key("-n") == 0:
44
 
        fail_usage("Failed: You have to enter existing machine!")
45
 
    else:
46
 
        return outlets[options["-n"]][0]
47
 
 
48
 
def set_power_status(conn, options):
49
 
    global plug_status
50
 
    plug_status = "unknown"
51
 
    if options.has_key("-o") and options["-o"] == "on":
52
 
        plug_status = "off"
53
 
 
54
 
def main():
55
 
    global all_opt
56
 
    device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug", "action", "port",
57
 
            "no_password", "power_wait", "power_timeout", "random_sleep_range"]
58
 
 
59
 
    all_opt["random_sleep_range"] = {
60
 
        "getopt" : "R:",
61
 
        "longopt" : "random_sleep_range",
62
 
        "help" : "--random_sleep_range=<seconds>Issue a sleep between 1 and <seconds>. Used for testing.",
63
 
        "order" : 1 }
64
 
 
65
 
    atexit.register(atexit_handler)
66
 
 
67
 
    pinput = process_input(device_opt)
68
 
 
69
 
    # Fake options to keep the library happy
70
 
    #pinput["-p"] = "none"
71
 
    pinput["-a"] = "localhost"
72
 
    pinput["-C"] = ","
73
 
 
74
 
    options = check_input(device_opt, pinput)
75
 
 
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)
81
 
        time.sleep(ran)
82
 
 
83
 
    if options.has_key("-o") and (options["-o"] == "monitor"):
84
 
        sys.exit(0)
85
 
 
86
 
    ## Defaults for fence agent
87
 
    docs = { }
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)
91
 
 
92
 
    ## Operate the fencing device
93
 
    result = fence_action(None, options, set_power_status, get_power_status, get_outlets_status)
94
 
    sys.exit(result)
95
 
 
96
 
if __name__ == "__main__":
97
 
    main()