Revision 4be4691d
b/lib/cmdlib.py | ||
---|---|---|
54 | 54 |
- implement BuildHooksEnv |
55 | 55 |
- redefine HPATH and HTYPE |
56 | 56 |
- optionally redefine their run requirements: |
57 |
REQ_MASTER: the LU needs to run on the master node |
|
58 | 57 |
REQ_BGL: the LU needs to hold the Big Ganeti Lock exclusively |
59 | 58 |
|
60 | 59 |
Note that all commands require root permissions. |
... | ... | |
63 | 62 |
HPATH = None |
64 | 63 |
HTYPE = None |
65 | 64 |
_OP_REQP = [] |
66 |
REQ_MASTER = True |
|
67 | 65 |
REQ_BGL = True |
68 | 66 |
|
69 | 67 |
def __init__(self, processor, op, context, rpc): |
... | ... | |
96 | 94 |
if attr_val is None: |
97 | 95 |
raise errors.OpPrereqError("Required parameter '%s' missing" % |
98 | 96 |
attr_name) |
99 |
|
|
100 |
if not self.cfg.IsCluster(): |
|
101 |
raise errors.OpPrereqError("Cluster not initialized yet," |
|
102 |
" use 'gnt-cluster init' first.") |
|
103 |
if self.REQ_MASTER: |
|
104 |
master = self.cfg.GetMasterNode() |
|
105 |
if master != utils.HostInfo().name: |
|
106 |
raise errors.OpPrereqError("Commands must be run on the master" |
|
107 |
" node %s" % master) |
|
97 |
self.CheckArguments() |
|
108 | 98 |
|
109 | 99 |
def __GetSSH(self): |
110 | 100 |
"""Returns the SshRunner object |
... | ... | |
116 | 106 |
|
117 | 107 |
ssh = property(fget=__GetSSH) |
118 | 108 |
|
109 |
def CheckArguments(self): |
|
110 |
"""Check syntactic validity for the opcode arguments. |
|
111 |
|
|
112 |
This method is for doing a simple syntactic check and ensure |
|
113 |
validity of opcode parameters, without any cluster-related |
|
114 |
checks. While the same can be accomplished in ExpandNames and/or |
|
115 |
CheckPrereq, doing these separate is better because: |
|
116 |
|
|
117 |
- ExpandNames is left as as purely a lock-related function |
|
118 |
- CheckPrereq is run after we have aquired locks (and possible |
|
119 |
waited for them) |
|
120 |
|
|
121 |
The function is allowed to change the self.op attribute so that |
|
122 |
later methods can no longer worry about missing parameters. |
|
123 |
|
|
124 |
""" |
|
125 |
pass |
|
126 |
|
|
119 | 127 |
def ExpandNames(self): |
120 | 128 |
"""Expand names for this LU. |
121 | 129 |
|
... | ... | |
1947 | 1955 |
|
1948 | 1956 |
""" |
1949 | 1957 |
_OP_REQP = [] |
1950 |
REQ_MASTER = False |
|
1951 | 1958 |
REQ_BGL = False |
1952 | 1959 |
|
1953 | 1960 |
def ExpandNames(self): |
Also available in: Unified diff