Skip to content

Commit f031deb

Browse files
committed
Merge branch 'misc_fixes'
2 parents 27461b3 + 0a41e11 commit f031deb

18 files changed

Lines changed: 22 additions & 62 deletions

checkvsphere/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ def main():
100100
sys.exit(3)
101101
else:
102102
sys.exit(e.code)
103-
except CheckVsphereTimeout as e:
103+
except CheckVsphereTimeout:
104104
print("UNKNOWN - Timeout reached")
105105
if int(os.environ.get("VSPHERE_DEBUG", "0")) > 0:
106106
traceback.print_exc(file=sys.stdout)
107107
sys.exit(3)
108-
except ConnectionRefusedError as e:
109-
print(f"UNKNOWN - Connection refused")
108+
except ConnectionRefusedError:
109+
print("UNKNOWN - Connection refused")
110110
raise SystemExit(2)
111111
except vim.fault.VimFault as e:
112112
if hasattr(e, 'msg'):

checkvsphere/tools/helper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
import re
18-
import os
1918
from pyVmomi import vim, vmodl
2019
from . import serviceutil
2120

checkvsphere/tools/service_instance.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@
2323
__author__ = "VMware, Inc."
2424

2525
import atexit
26-
import json
2726
import logging
2827
import os
29-
import ssl
30-
import time
31-
from pyVim.connect import SmartConnect, Disconnect, vim, GetStub
32-
from pyVmomi.SoapAdapter import SoapStubAdapter
28+
from pyVim.connect import SmartConnect, Disconnect
3329
from .. import VsphereConnectException
3430

3531

@@ -74,7 +70,7 @@ def connect(args):
7470
try:
7571
try:
7672
service_instance = SmartConnect(**params)
77-
except Exception as e:
73+
except Exception:
7874
if sessionId:
7975
logging.debug("retry without sessionId")
8076
del params["sessionId"]
@@ -90,7 +86,7 @@ def connect(args):
9086
if sessionfile:
9187
write_session_id(service_instance, args.sessionfile)
9288
else:
93-
logging.debug(f'add disconnect handler')
89+
logging.debug('add disconnect handler')
9490
# doing this means you don't need to remember to disconnect your script/objects
9591
atexit.register(Disconnect, service_instance)
9692

checkvsphere/vcmd/about.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import logging
2626
import os
2727
from monplugin import Status
28-
from ..tools.helper import find_entity_views
2928
from pyVmomi import vim
3029
from ..tools import cli, service_instance
31-
from .. import CheckVsphereException
3230

3331

3432
def run():
@@ -51,15 +49,15 @@ def run():
5149
if not args.skip_permission:
5250
try:
5351
clock = si.serverClock
54-
except Exception as e:
52+
except Exception:
5553
logging.debug("no server clock", exc_info=1)
5654
status = Status.CRITICAL
5755
clock = None
5856
if args.sessionfile:
5957
try:
6058
logging.debug(f"deleting {args.sessionfile}")
6159
os.unlink(args.sessionfile)
62-
except Exception as e:
60+
except Exception:
6361
logging.debug(f"unlink {args.sessionfile} failed", exc_info=1)
6462

6563
out = (

checkvsphere/vcmd/datastores.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from pyVmomi import vim, vmodl
2525
from monplugin import Check, Status, Threshold, Range
2626
from ..tools import cli, service_instance
27-
from .. import CheckVsphereException
2827
from ..tools.helper import (
2928
CheckArgument,
3029
find_entity_views,

checkvsphere/vcmd/hostnic.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121

2222
__cmd__ = 'host-nic'
2323

24-
import logging
2524
from pyVmomi import vim
2625
from monplugin import Check, Status
2726
from ..tools import cli, service_instance
2827
from ..tools.helper import find_entity_views, CheckArgument, isbanned
29-
from .. import CheckVsphereException
3028

3129
def run():
3230
parser = cli.Parser()
@@ -71,8 +69,6 @@ def run():
7169
except IndexError:
7270
check.exit(Status.UNKNOWN, f"host {args.vihost or ''} not found")
7371

74-
result = []
75-
7672
if vm['props']['runtime.inMaintenanceMode']:
7773
check.exit(
7874
Status[args.maintenance_state],
@@ -113,10 +109,7 @@ def run():
113109
else:
114110
check.add_message(Status.OK, f"{pnics[str(nic)].device} is ok")
115111

116-
117-
okmessage = "All nics connected"
118-
119-
(code, message) = check.check_messages(separator="\n", separator_all='\n')#, allok=okmessage)
112+
(code, message) = check.check_messages(separator="\n", separator_all='\n')
120113
check.exit(
121114
code=code,
122115
message=( message or "everything ok" )

checkvsphere/vcmd/hostruntime.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121

2222
__cmd__ = 'host-runtime'
2323

24-
import logging
2524
from pyVmomi import vim
2625
from monplugin import Check, Status
27-
from .. import CheckVsphereException
2826
from ..tools import cli, service_instance
2927
from ..tools.helper import find_entity_views, isbanned, isallowed, CheckArgument
3028

@@ -216,7 +214,7 @@ def check_health(check, vm, args, result):
216214
"no vim.Host.runtime.healthSystemRuntime.hardwareStatusInfo found"
217215
)
218216

219-
filterunknown = lambda x: x.status.key != "unknown"
217+
filterunknown = lambda x: x.status.key.lower() != "unknown"
220218
cpustatus = healthsystem.hardwareStatusInfo.cpuStatusInfo
221219
storagestatus = list(filter(filterunknown, healthsystem.hardwareStatusInfo.storageStatusInfo))
222220
memorystatus = list(filter(filterunknown, healthsystem.hardwareStatusInfo.memoryStatusInfo))

checkvsphere/vcmd/hostservice.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
__cmd__ = 'host-service'
2323

24-
import logging
2524
from pyVmomi import vim, vmodl
2625
from monplugin import Check, Status
2726
from ..tools import cli, service_instance
28-
from .. import CheckVsphereException
2927
from ..tools.helper import (
3028
CheckArgument,
3129
find_entity_views,

checkvsphere/vcmd/hoststorage.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
import re
2525
import itertools
2626
from pyVmomi import vim, vmodl
27-
from monplugin import Check, Status, Threshold, Range
27+
from monplugin import Check, Status
2828
from collections import namedtuple
2929

3030
from ..tools import cli, service_instance
31-
from .. import CheckVsphereException
3231
from ..tools.helper import (
3332
CheckArgument,
3433
find_entity_views,
@@ -154,11 +153,9 @@ def iter_lun():
154153

155154
def check_lun(check: Check, si: vim.ServiceInstance, storage):
156155
lun2disc = get_lun2disc(storage)
157-
count = {}
156+
count: dict[str, int] = {}
158157
luns = storage['storageDeviceInfo'].scsiLun
159158
for scsi in luns:
160-
canonicalName = scsi.canonicalName
161-
scsiId = scsi.uuid
162159
discKey = scsi.key.split("-")[-1]
163160
displayName = re.sub(r'[^][\w _().-]', '', scsi.displayName)
164161

@@ -195,7 +192,7 @@ def check_lun(check: Check, si: vim.ServiceInstance, storage):
195192

196193

197194
def check_adapter(check: Check, si: vim.ServiceInstance, storage):
198-
count = {}
195+
count: dict[str, int] = {}
199196
adapters = storage['storageDeviceInfo'].hostBusAdapter
200197
for dev in adapters:
201198
if (

checkvsphere/vcmd/listmetrics.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
__cmd__ = 'list-metrics'
2424

25-
import logging
2625
import textwrap
27-
from pyVmomi import vim
2826
from ..tools import cli, service_instance
2927

3028
def run():
@@ -39,7 +37,6 @@ def run():
3937
group = counter.groupInfo.key
4038
name = counter.nameInfo.key
4139
rollup = counter.rollupType
42-
id = counter.key
4340

4441
metrics.setdefault(str(group), {}) \
4542
.setdefault(str(name), {}) \

0 commit comments

Comments
 (0)