Skip to content

Commit be0ad5f

Browse files
committed
modified as per sample_template_basic
1 parent 099a92d commit be0ad5f

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

samples/vsphere/appliances/health_messages.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
"""
1414

1515
__author__ = 'VMware, Inc.'
16-
__copyright__ = 'Copyright 2019 VMware, Inc. All rights reserved.'
1716
__vcenter_version__ = '6.7+'
1817

19-
from datetime import datetime, date
20-
from samples.vsphere.common import (sample_cli, sample_util, vapiconnect)
18+
from samples.vsphere.common import (sample_cli, sample_util)
2119
from com.vmware.appliance_client import Health
2220
from com.vmware.vapi.std_client import LocalizableMessage
2321
from com.vmware.appliance_client import Notification
22+
from vmware.vapi.vsphere.client import create_vsphere_client
23+
from samples.vsphere.common.ssl_helper import get_unverified_session
2424

2525

2626
class HealthMessages(object):
@@ -35,9 +35,7 @@ class HealthMessages(object):
3535

3636
def __init__(self):
3737
self.item = None
38-
self.stub_config = None
39-
40-
def setup(self):
38+
self.client = None
4139
parser = sample_cli.build_arg_parser()
4240

4341
parser.add_argument(
@@ -48,20 +46,21 @@ def setup(self):
4846
help='Specify the name of health item to view the messages')
4947

5048
args = sample_util.process_cli_args(parser.parse_args())
51-
self.item = args.item
49+
if args.item:
50+
self.item = args.item
51+
self.cleardata = args.cleardata
5252

5353
# Connect to vAPI services
54-
self.stub_config = vapiconnect.connect(
55-
host=args.server,
56-
user=args.username,
57-
pwd=args.password,
58-
skip_verification=args.skipverification)
59-
60-
self.health_client = Health(self.stub_config)
54+
session = get_unverified_session() if args.skipverification else None
55+
self.client = create_vsphere_client(server=args.server,
56+
username=args.username,
57+
password=args.password,
58+
session=session)
59+
self.health_client = Health(self.client._stub_config)
6160

6261
def run(self):
6362
message_list = self.health_client.messages(self.item)
64-
print(" Health Alarams")
63+
print("Health Alarams")
6564
print("-------------------\n")
6665
if not message_list:
6766
print("No health alarms for : " + self.item)
@@ -76,7 +75,6 @@ def run(self):
7675

7776
def main():
7877
health_sample = HealthMessages()
79-
health_sample.setup()
8078
health_sample.run()
8179

8280

0 commit comments

Comments
 (0)