Skip to content

Commit 162db13

Browse files
Noah MeyerhansNoah Meyerhans
authored andcommitted
ebsnvme-id: support python3
No functional changes Signed-off-by: Noah Meyerhans <nmeyerha@amzn.com>
1 parent 54c15aa commit 162db13

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

ebsnvme-id

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2.7
1+
#!/usr/bin/env python
22

33
# Copyright 2017 Amazon.com, Inc. and its affiliates. All Rights Reserved.
44
#
@@ -106,26 +106,26 @@ class ebs_nvme_device:
106106
alen = id_len,
107107
cdw10 = 1)
108108

109-
with open(self.device, "rw") as nvme:
109+
with open(self.device, "r+") as nvme:
110110
ioctl(nvme, NVME_IOCTL_ADMIN_CMD, admin_cmd)
111111

112112
def ctrl_identify(self):
113113
self.id_ctrl = nvme_identify_controller()
114114
self._nvme_ioctl(addressof(self.id_ctrl), sizeof(self.id_ctrl))
115115

116-
if self.id_ctrl.vid != AMZN_NVME_VID or self.id_ctrl.mn.strip() != AMZN_NVME_EBS_MN:
116+
if self.id_ctrl.vid != AMZN_NVME_VID or self.id_ctrl.mn.decode().strip() != AMZN_NVME_EBS_MN:
117117
raise TypeError("[ERROR] Not an EBS device: '{0}'".format(self.device))
118118

119119
def get_volume_id(self):
120-
vol = self.id_ctrl.sn
120+
vol = self.id_ctrl.sn.decode()
121121

122122
if vol.startswith("vol") and vol[3] != "-":
123123
vol = "vol-" + vol[3:]
124124

125125
return vol
126126

127127
def get_block_device(self, stripped=False):
128-
dev = self.id_ctrl.vs.bdev.strip()
128+
dev = self.id_ctrl.vs.bdev.decode().strip()
129129

130130
if stripped and dev.startswith("/dev/"):
131131
dev = dev[5:]
@@ -155,10 +155,10 @@ if __name__ == "__main__":
155155
try:
156156
dev = ebs_nvme_device(args.device[0])
157157
except (IOError, TypeError) as err:
158-
print >> sys.stderr, err
158+
print(err, file=sys.stderr)
159159
sys.exit(1)
160160

161161
if get_all or args.volume:
162-
print "Volume ID: {0}".format(dev.get_volume_id())
162+
print("Volume ID: {0}".format(dev.get_volume_id()))
163163
if get_all or args.block_dev or args.udev:
164-
print dev.get_block_device(args.udev)
164+
print(dev.get_block_device(args.udev))

0 commit comments

Comments
 (0)