Skip to content

Commit

Permalink
Merge pull request #5668 from ashwin9390/private/ashwin/CP-49681
Browse files Browse the repository at this point in the history
#PR2- CP-47869-Update XAPI code to python3.
  • Loading branch information
liulinC committed Jun 12, 2024
2 parents fff26e5 + 23ed63d commit ccf4431
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/setup-xapi-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ runs:
shell: bash
run: sudo apt-get update

- name: Install python2
- name: Install python3
shell: bash
run: sudo apt-get install python2
run: sudo apt-get install python3

- name: Use disk with more space for TMPDIR and XDG_CACHE_HOME
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion doc/content/xapi/storage/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ From this interface we generate
and appear in the` _build/default/python/xapi/storage/api/v5`
directory.
- On a XenServer host, they are stored in the
`/usr/lib/python2.7/site-packages/xapi/storage/api/v5/`
`/usr/lib/python3.6/site-packages/xapi/storage/api/v5/`
directory

### SMAPIv3 Plugins
Expand Down
2 changes: 1 addition & 1 deletion ocaml/doc/wire-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ XML-RPC and JSON-RPC client libraries.
First, initialise python:

```bash
$ python2.7
$ python3
>>>
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
sys.path.append("/home/vagrant/djs55/dbus-test/python")
Expand All @@ -17,10 +17,10 @@ if __name__ == "__main__":
args = vars(parser.parse_args())

if not(args['json']):
print "Not implemented"
print("Not implemented")
sys.exit(1)

dispatcher = d.Datapath_server_dispatcher(Implementation())
request = json.loads(sys.stdin.readline(),)
request = json.loads(sys.stdin.readline())
results = dispatcher.activate(request)
print json.dumps(results)
print(json.dumps(results))
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
sys.path.append("/home/vagrant/djs55/dbus-test/python")

import xapi, d

import argparse, json, urlparse
import argparse, json, urllib.parse

class Implementation(d.Datapath_skeleton):
def attach(self, dbg, uri, domain):
u = urlparse.urlparse(uri)
u = urllib.parse.urlparse(uri)
return {
'implementations': [ ['XenDisk', {"backend_type":"vbd", "extra":{}, "params":u.path}], ['BlockDevice', {"path":u.path}] ]
}
Expand All @@ -20,10 +20,10 @@ if __name__ == "__main__":
args = vars(parser.parse_args())

if not(args['json']):
print "Not implemented"
print("Not implemented")
sys.exit(1)

dispatcher = d.Datapath_server_dispatcher(Implementation())
request = json.loads(sys.stdin.readline(),)
request = json.loads(sys.stdin.readline())
results = dispatcher.attach(request)
print json.dumps(results)
print(json.dumps(results))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
sys.path.append("/home/vagrant/djs55/dbus-test/python")
Expand All @@ -17,10 +17,10 @@ if __name__ == "__main__":
args = vars(parser.parse_args())

if not(args['json']):
print "Not implemented"
print("Not implemented")
sys.exit(1)

dispatcher = d.Datapath_server_dispatcher(Implementation())
request = json.loads(sys.stdin.readline(),)
request = json.loads(sys.stdin.readline())
results = dispatcher.deactivate(request)
print json.dumps(results)
print(json.dumps(results))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
sys.path.append("/home/vagrant/djs55/dbus-test/python")
Expand All @@ -17,10 +17,10 @@ if __name__ == "__main__":
args = vars(parser.parse_args())

if not(args['json']):
print "Not implemented"
print("Not implemented")
sys.exit(1)

dispatcher = d.Datapath_server_dispatcher(Implementation())
request = json.loads(sys.stdin.readline(),)
request = json.loads(sys.stdin.readline())
results = dispatcher.detach(request)
print json.dumps(results)
print(json.dumps(results))
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PREFIX?=/usr
PYTHON?=python2
PYTHON?=python3

.PHONY: build release clean install uninstall

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright (C) Citrix Systems Inc.
# Copyright (C) Cloud Software Group.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
Expand All @@ -15,10 +15,10 @@
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from __future__ import print_function

import os
import sys
import urlparse
import urllib.parse

import xapi.storage.api.v5.datapath
from xapi.storage.common import call
Expand Down Expand Up @@ -64,8 +64,8 @@ def activate(self, dbg, uri, domain):
pass

def attach(self, dbg, uri, domain):
parsed_url = urlparse.urlparse(uri)
query = urlparse.parse_qs(parsed_url.query)
parsed_url = urllib.parse.urlparse(uri)
query = urllib.parse.parse_qs(parsed_url.query)

file_path = os.path.realpath(parsed_url.path)

Expand Down Expand Up @@ -97,7 +97,7 @@ def deactivate(self, dbg, uri, domain):
pass

def detach(self, dbg, uri, domain):
parsed_url = urlparse.urlparse(uri)
parsed_url = urllib.parse.urlparse(uri)

file_path = os.path.realpath(parsed_url.path)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright (C) Citrix Systems Inc.
# Copyright (C) Cloud Software Group,Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright (C) Citrix Systems Inc.
# Copyright (C) Cloud Software Group, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright (C) Citrix Systems Inc.
# Copyright (C) Cloud Software Group, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
Expand All @@ -18,8 +18,9 @@
from __future__ import print_function
import os
import sys
import urllib
import urlparse
import urllib.request
import urllib.parse
import urllib.error

import xapi.storage.api.v5.volume
from xapi import InternalError
Expand Down Expand Up @@ -66,12 +67,12 @@ def attach(self, dbg, configuration):
# As a simple "stateless" implementation, encode all the
# configuration into the URI returned. This is passed back
# into volume interface APIs and the stat and ls operations.
return urlparse.urlunparse((
return urllib.parse.urlunparse((
'file',
'',
configuration['path'],
'',
urllib.urlencode(configuration, True),
urllib.parse.urlencode(configuration, True),
None))

def detach(self, dbg, sr):
Expand All @@ -96,8 +97,8 @@ def stat(self, dbg, sr):
[stat sr] returns summary metadata associated with [sr]. Note this
call does not return details of sub-volumes, see SR.ls.
"""
parsed_url = urlparse.urlparse(sr)
config = urlparse.parse_qs(parsed_url.query)
parsed_url = urllib.parse.urlparse(sr)
config = urllib.parse.parse_qs(parsed_url.query)

description = (config['description'][0]
if 'description' in config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Copyright (C) Citrix Systems Inc.
# Copyright (C) Cloud Software Group, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
Expand All @@ -21,8 +21,9 @@
import os
import sys
import uuid
import urllib
import urlparse
import urllib.request
import urllib.parse
import urllib.error

import xapi.storage.api.v5.volume
from xapi.storage import log
Expand All @@ -31,8 +32,8 @@
class Implementation(xapi.storage.api.v5.volume.Volume_skeleton):

def parse_sr(self, sr_uri):
parsed_url = urlparse.urlparse(sr_uri)
config = urlparse.parse_qs(parsed_url.query)
parsed_url = urllib.parse.urlparse(sr_uri)
config = urllib.parse.parse_qs(parsed_url.query)
return parsed_url, config

def create_volume_data(self, name, description, size, uris, uuid):
Expand All @@ -50,8 +51,8 @@ def create_volume_data(self, name, description, size, uris, uuid):
}

def volume_uris(self, sr_path, name, size):
query = urllib.urlencode({'size': size}, True)
return [urlparse.urlunparse(
query = urllib.parse.urlencode({'size': size}, True)
return [urllib.parse.urlunparse(
('loop+blkback', None, os.path.join(sr_path, name),
None, query, None))]

Expand Down Expand Up @@ -187,7 +188,7 @@ def ls(self, dbg, sr):
"""
[ls sr] lists the volumes from [sr]
"""
parsed_url = urlparse.urlparse(sr)
parsed_url = urllib.parse.urlparse(sr)
sr_path = parsed_url.path
files = glob.glob(os.path.join(sr_path, '*.inf'))
log.debug('files to list {}'.format(files))
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi-storage/python/xapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

"""
Copyright (c) 2013-2018, Citrix Inc.
Copyright (c) 2013-2024, Cloud Software Group,Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/api/v5/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
2 changes: 1 addition & 1 deletion ocaml/xapi-storage/python/xapi/storage/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

from xapi.storage import log
import xapi
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,9 @@ expected_to_fail = [
# SSLSocket.send() only accepts bytes, not unicode string as argument:
"scripts/examples/python/exportimport.py",
# Other fixes needed:
"scripts/examples/python/mini-xenrt.py",
"scripts/examples/python/XenAPI/XenAPI.py",
"scripts/examples/python/monitor-unwanted-domains.py",
"scripts/examples/python/shell.py",
"scripts/examples/smapiv2.py",
"scripts/static-vdis",
"scripts/plugins/extauth-hook-AD.py",
]
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/python/mini-xenrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def make_operation_list(vm):
print(" -- performs parallel operations on VMs with the specified other-config key")
sys.exit(1)

x = xmlrpc.client.server(sys.argv[1])
x = xmlrpc.client.ServerProxy(sys.argv[1])
key = sys.argv[2]
session = x.session.login_with_password("root", "xenroot", "1.0", "xen-api-scripts-minixenrt.py")["Value"]
vms = x.VM.get_all_records(session)["Value"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/python/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ def setProvisionSpec(session, vm, ps):
txt2 = printProvisionSpec(ps)
print(txt2)
if txt != txt2:
raise AssertionError("Sanity-check failed: print(parse(print(x))) <> print(x)")
raise AssertionError("Sanity-check failed: print(parse(print(x))) != print(x)")
print("* OK: print(parse(print(x))) == print(x)")
2 changes: 1 addition & 1 deletion scripts/examples/smapiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def reopenlog(log_file):
if log_file:
try:
log_f = open(log_file, "a")
except FilenotFoundError:
except FileNotFoundError:
log_f = open(log_file, "w")
else:
log_f = open(os.dup(sys.stdout.fileno()), "a")
Expand Down

0 comments on commit ccf4431

Please sign in to comment.