Skip to content

Commit 6deddfd

Browse files
Tim SmithTimSmithCtx
Tim Smith
authored andcommitted
CP-308219 Separate resetvdis script
The resetvdis compatibility library is no longer required. Instead, the executable part of resetvdis.py needs to move under /usr/libexec with a symlink from the old name for compatiblility Signed-off-by: Tim Smith <[email protected]>
1 parent d8ec45e commit 6deddfd

File tree

4 files changed

+81
-63
lines changed

4 files changed

+81
-63
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ SM_LIBEXEC_PY_CMDS :=
9595
SM_LIBEXEC_PY_CMDS += cleanup
9696
SM_LIBEXEC_PY_CMDS += lvhdutil
9797
SM_LIBEXEC_PY_CMDS += mpathcount
98+
SM_LIBEXEC_PY_CMDS += resetvdis
9899
SM_LIBEXEC_PY_CMDS += sr_health_check
99100
SM_LIBEXEC_PY_CMDS += verifyVHDsOnSR
100101

@@ -174,7 +175,6 @@ SM_COMPAT_LIBS += ipc
174175
SM_COMPAT_LIBS += srmetadata
175176
SM_COMPAT_LIBS += metadata
176177
SM_COMPAT_LIBS += lvmanager
177-
SM_COMPAT_LIBS += resetvdis
178178
SM_COMPAT_LIBS += trim_util
179179
SM_COMPAT_LIBS += pluginutil
180180
SM_COMPAT_LIBS += constants

compat-libs/resetvdis.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/sm/resetvdis.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
# Clear the attach status for all VDIs in the given SR on this host.
1818
# Additionally, reset the paused state if this host is the master.
1919

20+
import XenAPI # pylint: disable=import-error
2021
from sm import cleanup
2122
from sm.core import util
2223
from sm.core import lock
23-
import sys
24-
import XenAPI # pylint: disable=import-error
2524

2625

2726
def reset_sr(session, host_uuid, sr_uuid, is_sr_master):
@@ -127,62 +126,3 @@ def reset_vdi(session, vdi_uuid, force, term_output=True, writable=True):
127126
if term_output:
128127
print(msg)
129128
return clean
130-
131-
132-
def usage():
133-
print("Usage:")
134-
print("all <HOST UUID> <SR UUID> [--master]")
135-
print("single <VDI UUID> [--force]")
136-
print()
137-
print("*WARNING!* calling with 'all' on an attached SR, or using " + \
138-
"--force may cause DATA CORRUPTION if the VDI is still " + \
139-
"attached somewhere. Always manually double-check that " + \
140-
"the VDI is not in use before running this script.")
141-
sys.exit(1)
142-
143-
if __name__ == '__main__':
144-
import sys
145-
import atexit
146-
147-
if len(sys.argv) not in [3, 4, 5]:
148-
usage()
149-
150-
session = XenAPI.xapi_local()
151-
session.xenapi.login_with_password('root', '', '', 'SM')
152-
atexit.register(session.xenapi.session.logout)
153-
154-
mode = sys.argv[1]
155-
if mode == "all":
156-
if len(sys.argv) not in [4, 5]:
157-
usage()
158-
host_uuid = sys.argv[2]
159-
sr_uuid = sys.argv[3]
160-
is_master = False
161-
if len(sys.argv) == 5:
162-
if sys.argv[4] == "--master":
163-
is_master = True
164-
else:
165-
usage()
166-
reset_sr(session, host_uuid, sr_uuid, is_master)
167-
elif mode == "single":
168-
vdi_uuid = sys.argv[2]
169-
force = False
170-
if len(sys.argv) == 4 and sys.argv[3] == "--force":
171-
force = True
172-
reset_vdi(session, vdi_uuid, force)
173-
elif len(sys.argv) in [3, 4]:
174-
# backwards compatibility: the arguments for the "all" case used to be
175-
# just host_uuid, sr_uuid, [is_master] (i.e., no "all" string, since it
176-
# was the only mode available). To avoid having to change XAPI, accept
177-
# the old format here as well.
178-
host_uuid = sys.argv[1]
179-
sr_uuid = sys.argv[2]
180-
is_master = False
181-
if len(sys.argv) == 4:
182-
if sys.argv[3] == "--master":
183-
is_master = True
184-
else:
185-
usage()
186-
reset_sr(session, host_uuid, sr_uuid, is_master)
187-
else:
188-
usage()

utils/resetvdis

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/python3
2+
#
3+
# Copyright (C) Citrix Systems Inc.
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU Lesser General Public License as published
7+
# by the Free Software Foundation; version 2.1 only.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public License
15+
# along with this program; if not, write to the Free Software Foundation, Inc.,
16+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
#
18+
# Clear the attach status for all VDIs in the given SR on this host.
19+
# Additionally, reset the paused state if this host is the master.
20+
import sys
21+
import atexit
22+
23+
import XenAPI # pylint: disable=import-error
24+
from sm import resetvdis
25+
26+
def usage():
27+
print("Usage:")
28+
print("all <HOST UUID> <SR UUID> [--master]")
29+
print("single <VDI UUID> [--force]")
30+
print()
31+
print("*WARNING!* calling with 'all' on an attached SR, or using " + \
32+
"--force may cause DATA CORRUPTION if the VDI is still " + \
33+
"attached somewhere. Always manually double-check that " + \
34+
"the VDI is not in use before running this script.")
35+
sys.exit(1)
36+
37+
if __name__ == '__main__':
38+
if len(sys.argv) not in [3, 4, 5]:
39+
usage()
40+
41+
session = XenAPI.xapi_local()
42+
session.xenapi.login_with_password('root', '', '', 'SM')
43+
atexit.register(session.xenapi.session.logout)
44+
45+
mode = sys.argv[1]
46+
if mode == "all":
47+
if len(sys.argv) not in [4, 5]:
48+
usage()
49+
host_uuid = sys.argv[2]
50+
sr_uuid = sys.argv[3]
51+
is_master = False
52+
if len(sys.argv) == 5:
53+
if sys.argv[4] == "--master":
54+
is_master = True
55+
else:
56+
usage()
57+
resetvdis.reset_sr(session, host_uuid, sr_uuid, is_master)
58+
elif mode == "single":
59+
vdi_uuid = sys.argv[2]
60+
force = False
61+
if len(sys.argv) == 4 and sys.argv[3] == "--force":
62+
force = True
63+
resetvdis.reset_vdi(session, vdi_uuid, force)
64+
elif len(sys.argv) in [3, 4]:
65+
# backwards compatibility: the arguments for the "all" case used to be
66+
# just host_uuid, sr_uuid, [is_master] (i.e., no "all" string, since it
67+
# was the only mode available). To avoid having to change XAPI, accept
68+
# the old format here as well.
69+
host_uuid = sys.argv[1]
70+
sr_uuid = sys.argv[2]
71+
is_master = False
72+
if len(sys.argv) == 4:
73+
if sys.argv[3] == "--master":
74+
is_master = True
75+
else:
76+
usage()
77+
resetvdis.reset_sr(session, host_uuid, sr_uuid, is_master)
78+
else:
79+
usage()

0 commit comments

Comments
 (0)