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

VmBackup.py: script doesn't work for me. Could You help, please #59

Open
Burzump opened this issue Nov 15, 2017 · 23 comments
Open

VmBackup.py: script doesn't work for me. Could You help, please #59

Burzump opened this issue Nov 15, 2017 · 23 comments

Comments

@Burzump
Copy link

Burzump commented Nov 15, 2017

Hi! Could someone help, please? What's wrong? Script doesn't work for me. No complite backup, no log in file.
Xenserver 7.0
VmBackup.py 3.22
Python 2.7.13

[root@Xen03 NAUbackup]# ./VmBackup.py XXXXXXXXXX OTRS preview
2017-11-15-(14:54:26) - VmBackup config loaded from: OTRS
2017-11-15-(14:54:26) - VmBackup.py running with these settings:
2017-11-15-(14:54:26) - backup_dir = /snapshots/BACKUPS
2017-11-15-(14:54:26) - status_log = /snapshots/NAUbackup/status.log
2017-11-15-(14:54:26) - compress = False
2017-11-15-(14:54:26) - max_backups = 2
2017-11-15-(14:54:26) - vdi_export_format = raw
2017-11-15-(14:54:26) - pool_db_backup = 0
2017-11-15-(14:54:26) - exclude (cnt)= 0
2017-11-15-(14:54:26) - exclude:
2017-11-15-(14:54:26) - vdi-export (cnt)= 0
2017-11-15-(14:54:26) - vdi-export:
2017-11-15-(14:54:26) - vm-export (cnt)= 1
2017-11-15-(14:54:26) - vm-export: OTRS
Traceback (most recent call last):
File "./VmBackup.py", line 1453, in
session.xenapi.login_with_password(username, password)
File "/snapshots/NAUbackup/XenAPI.py", line 248, in call
return self.__send(self.__name, args)
File "/snapshots/NAUbackup/XenAPI.py", line 141, in xenapi_request
self._login(methodname, params)
File "/snapshots/NAUbackup/XenAPI.py", line 165, in _login
result = _parse_result(getattr(self, 'session.%s' % method)(*params))
File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in call
return self.__send(self.__name, args)
File "/usr/lib64/python2.7/xmlrpclib.py", line 1587, in __request
verbose=self.__verbose
File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib64/python2.7/xmlrpclib.py", line 1301, in single_request
self.send_content(h, request_body)
File "/usr/lib64/python2.7/xmlrpclib.py", line 1448, in send_content
connection.endheaders(request_body)
File "/usr/lib64/python2.7/httplib.py", line 1013, in endheaders
self._send_output(message_body)
File "/usr/lib64/python2.7/httplib.py", line 864, in _send_output
self.send(msg)
File "/usr/lib64/python2.7/httplib.py", line 826, in send
self.connect()
File "/usr/lib64/python2.7/httplib.py", line 1236, in connect
server_hostname=sni_hostname)
File "/usr/lib64/python2.7/ssl.py", line 350, in wrap_socket
_context=self)
File "/usr/lib64/python2.7/ssl.py", line 611, in init
self.do_handshake()
File "/usr/lib64/python2.7/ssl.py", line 833, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)
[root@Xen03 NAUbackup]#

@thomasmck
Copy link

Try changing session = XenAPI.Session('https://localhost/') on line 1452 to session = XenAPI.Session('https://localhost/', ignore_ssl=True) and see if that fixes it.

@Burzump
Copy link
Author

Burzump commented Nov 15, 2017

Now get this:

Traceback (most recent call last):
File "./VmBackup.py", line 1452, in
session = XenAPI.Session('https://localhost/', ignore_ssl=True)
TypeError: init() got an unexpected keyword argument 'ignore_ssl'

@thomasmck
Copy link

Where did you get your version of XenAPI.py from? Can you try again with the XS 7.2 SDK version (They are backwards compatible) from https://www.citrix.com/downloads/xenserver/product-software/xenserver-72-standard-edition.html

@Burzump
Copy link
Author

Burzump commented Nov 15, 2017

Now use XenAPI.py from XS 7.2 SDK and get:

[root@Xen03 NAUbackup]# ./VmBackup.py XXXXXXXXXX OTRS preview
2017-11-15-(16:02:19) - VmBackup config loaded from: OTRS
2017-11-15-(16:02:19) - VmBackup.py running with these settings:
2017-11-15-(16:02:19) - backup_dir = /snapshots/BACKUPS
2017-11-15-(16:02:19) - status_log = /snapshots/NAUbackup/status.log
2017-11-15-(16:02:19) - compress = False
2017-11-15-(16:02:19) - max_backups = 2
2017-11-15-(16:02:19) - vdi_export_format = raw
2017-11-15-(16:02:19) - pool_db_backup = 0
2017-11-15-(16:02:19) - exclude (cnt)= 0
2017-11-15-(16:02:19) - exclude:
2017-11-15-(16:02:19) - vdi-export (cnt)= 0
2017-11-15-(16:02:19) - vdi-export:
2017-11-15-(16:02:19) - vm-export (cnt)= 1
2017-11-15-(16:02:19) - vm-export: OTRS
Traceback (most recent call last):
File "./VmBackup.py", line 1452, in
session = XenAPI.Session('https://localhost/', ignore_ssl=True)
File "/snapshots/NAUbackup/XenAPI.py", line 136, in init
verbose, allow_none, context=ctx)
TypeError: init() got an unexpected keyword argument 'context'
[root@Xen03 NAUbackup]#

If delete ignore_ssl=True from VmBackup.py, get at the end:

Traceback (most recent call last):
File "./VmBackup.py", line 1453, in
session.xenapi.login_with_password(username, password)
File "/snapshots/NAUbackup/XenAPI.py", line 262, in call
return self.__send(self.__name, args)
File "/snapshots/NAUbackup/XenAPI.py", line 149, in xenapi_request
self._login(methodname, params)
File "/snapshots/NAUbackup/XenAPI.py", line 186, in _login
raise e
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)
[root@Xen03 NAUbackup]#

@thomasmck
Copy link

ok well I'm fairly certain that the ignore_ssl=True part is needed to fix your original error (see xapi-project/xen-api#2100). From looking in XenAPI.py on line 136 we are calling the xmlrpclib. If that is not expecting the context argument then I imagine you are not using the correct version.

Looking at the xmlrpclib package page (https://docs.python.org/2/library/xmlrpclib.html) it looks like the context parameter was added in version 2.7.9 ("Changed in version 2.7.9: Added the context argument") so you will need to update to at least this version.

@Burzump
Copy link
Author

Burzump commented Nov 15, 2017

Ok. Will try to downgrade Python to 2.7.9 version. At now use Python 2.7.13.
Thanks, thomasmck!

@NAUbackup
Copy link
Owner

NAUbackup commented Nov 15, 2017

Thanks for your help on this, @thomasmck ... I will try to take a look soon to see what version of XenApi.py and python I am running for comparison. Appreciate the feedback. I'm still on 7.1 and tests on 7.2 provide valuable insights.
--Tobias

@styk-tv
Copy link

styk-tv commented Apr 2, 2018

So it actually works if you overwrite ssl settings before making the call, like this

        import ssl
        ssl._create_default_https_context = ssl._create_unverified_context
        self._xenSession = XenAPI.Session(self._dataXen.api_url)

3rd line is my session code, yours will be different.

@gfiasco
Copy link

gfiasco commented May 21, 2019

change line 1456

https://github.com/NAUbackup/VmBackup/blob/master/VmBackup.py#L1456

        session = XenAPI.Session('https://localhost/')

to

      session = XenAPI.Session('http://localhost/')

@dangbird
Copy link

@gfiasco Thanks for this change, it worked for me. No issues with XenServer 7.6 but Version 8.0 that was just released threw this error:
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)
changing to http://localhost from https allows the backup to run.

May need to add code to check version and switch from https to http or someone likely much smarter can advise a solution.

@NAUbackup
Copy link
Owner

NAUbackup commented Jun 21, 2019

I just released V3.24 and would be interested if this error still occurs. Thanks! If so, let me know and I can maybe catch the error and do a retry with http instead of https. Perhaps better, I could report this to Citrix as a bug.

@sniperkitten
Copy link

sniperkitten commented Jun 26, 2019

Hello!

Faced same issue today with Xen Server 8 and latest NAUbackup+XenAPI.py
Changing to http worked for me also: XenAPI.Session('http://localhost/')

Error messages before workaround:
Traceback (most recent call last): File "/snapshots/NAUbackup/VmBackup.py", line 1616, in <module> session.xenapi.login_with_password(username, password) File "/snapshots/NAUbackup/XenAPI.py", line 264, in __call__ return self.__send(self.__name, args) File "/snapshots/NAUbackup/XenAPI.py", line 151, in xenapi_request self._login(methodname, params) File "/snapshots/NAUbackup/XenAPI.py", line 188, in _login raise e ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)

Regards

@NAUbackup
Copy link
Owner

Sorry to hear that. I will take a look, perhaps create a fallback if https fails to then try http.
Thanks for the feedback! Citrix Hypervisor 8 seems to have some odd things happening in it, alas, and I'm sorry I have not had the time to thoroughly test the script out yet in that newer environment.

@NAUbackup
Copy link
Owner

NAUbackup commented Jun 26, 2019

Does importing also the ssl module near the top and changing the code to read

    ignore_ssl=True
    session = XenAPI.Session('https://localhost/')

still not work? Seems to at least under XS 7.X.

@sniperkitten
Copy link

sniperkitten commented Jun 27, 2019 via email

@LinKJeTT
Copy link

i have the same error too, i started to try the scripts yesterday on the citrix 8.0, only works with http protocol

@NAUbackup
Copy link
Owner

Try substituting that call with the following expanded code:

# acquire a xapi session by logging in
try:
    username = 'root'
    ignore_ssl=True
    # try SSL connection
    session = XenAPI.Session('https://localhost/')
    #print "session is: %s " % session
    if session != "<ServerProxy for localhost/>":
       # fall back to plain http
       session = XenAPI.Session('http://localhost/')

    session.xenapi.login_with_password(username, password)

@LinKJeTT
Copy link

i'm sorry but what lines should I replace?

@NAUbackup
Copy link
Owner

NAUbackup commented Jun 27, 2019

Put that in place of the lines:

try:
username = 'root'
session = XenAPI.Session('https://localhost/')
session.xenapi.login_with_password(username, password)

Also, make sure you add ", ssl" to the line

import sys, time, os, datetime, subprocess, re, shutil, XenAPI, smtplib, re, base64, socket, threading

so that it reads:
import sys, time, os, datetime, subprocess, re, shutil, XenAPI, smtplib, re, base64, socket, threading, ssl

@sniperkitten
Copy link

Hi

Tried extended code, still same error
Though I'm new to python and not very reliable tester - had IndentationErrors initially)

Regards,
Alex

@NAUbackup
Copy link
Owner

Thank you, Alex, for the feedback. It runs fine as such under 7.1. I will take another look. I really need to get an instance up and running on my 8.0 test pool. I'd have done so sooner except I have to get the NFS networking sorted out.
--Tobias

@dangbird
Copy link

If you would like I have 8.0 fully patched on a box, with a tiny VM that backs up in a few seconds, mounted to NFS that I can IP Gate to your IP via SSH. Happy to let you play with the script on this as some small way of saying thank-you for all the efforts... Not a problem if you would like let me know.

@NAUbackup
Copy link
Owner

Thank you, Dan, I will keep that in mind if I cannot get something rigged up here soon. Your offer is much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants