Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken fence_xenapi.py #559

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions agents/xenapi/fence_xenapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ def connect_and_login(options):
username = options["--username"]
password = options["--password"]

# Allow bypassing SSL verification for hosts without SSL certificates
skipVerification = False
if "--ssl-insecure" in options:
skipVerification = True

try:
# Create the XML RPC session to the specified URL.
session = XenAPI.Session(url)
session = XenAPI.Session(url, None, None, 0, 1, skipVerification)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Session() doesnt appear to have a parameter for skipVerification:
https://github.com/ClusterLabs/fence-agents/blob/main/lib/XenAPI.py.py#L121

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the XenAPI library bundled in this repo is significantly outdated. The latest version from https://github.com/xapi-project/xen-api/blob/master/scripts/examples/python/XenAPI/XenAPI.py should be loaded instead.

# Login using the supplied credentials.
session.xenapi.login_with_password(username, password)
except Exception as exn:
Expand Down Expand Up @@ -191,23 +196,42 @@ def return_vm_reference(session, options):
# to the VM).
raise Exception("VM_LOGIC_ERROR")

def define_new_opts():
all_opt["uuid"] = {
"getopt" : ":",
"longopt" : "uuid",
"help" : "--uuid=[VM UUID] The VM UUID.",
"default" : "",
"required" : "0",
"shortdesc" : "The VM UUID",
"order" : 2}
all_opt["plug-separator"] = {
"getopt" : ":",
"longopt" : "plug-separator",
"help" : "--plug-separator=separator The saparator for multiple plugs.",
"default" : ":",
"required" : "0",
"shortdesc" : "The saparator for multiple plugs",
"order" : 3}

def main():

device_opt = ["login", "passwd", "port", "no_login", "no_password", "session_url", "web"]
device_opt = ["login", "passwd", "port", "no_login", "no_password", "session_url", "web", "ssl", "uuid", "plug_separator"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plug_separator is included in "port" from fencing.py, so you can remove that and it's definition above.

uuid isnt neither either, as the fencing library sets it based on the --plug/-n parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get it to work without these two parameters. Maybe I'm just testing it wrong? This way works for me and I have no way of validating other solutions, so someone else might need to take over this pull request (or just delete it if you prefer).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need to update your systems fencing library (usually located in /usr/share/fence).


atexit.register(atexit_handler)
define_new_opts()

options = check_input(device_opt, process_input(device_opt))

docs = {}
docs["shortdesc"] = "Fence agent for Citrix XenServer over XenAPI"
docs["longdesc"] = "\
fence_cxs is an I/O Fencing agent used on Citrix XenServer hosts. \
fence_xenapi is an I/O Fencing agent used on Citrix XenServer and XCP-ng hosts. \
It uses the XenAPI, supplied by Citrix, to establish an XML-RPC session \
to a XenServer host. Once the session is established, further XML-RPC \
commands are issued in order to switch on, switch off, restart and query \
the status of virtual machines running on the host."
docs["vendorurl"] = "http://www.xenproject.org"
docs["vendorurl"] = "https://xenproject.org"
show_docs(options, docs)

run_delay(options)
Expand Down
Loading