Skip to content

Commit 22b8b28

Browse files
committed
updated Health appliance sample
cleaned up health appliance sample Signed-off-by: aspurohit <[email protected]> Removed unused objects Signed-off-by: aspurohit <[email protected]> modified as per sample_template_basic updated as per review comments
1 parent 1b7897f commit 22b8b28

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed
Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
"""
33
* *******************************************************
4-
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
4+
* Copyright (c) VMware, Inc. 2019. All Rights Reserved.
55
* SPDX-License-Identifier: MIT
66
* *******************************************************
77
*
@@ -13,67 +13,65 @@
1313
"""
1414

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

19-
from samples.vsphere.common import sample_cli
20-
from samples.vsphere.common import sample_util
21-
from samples.vsphere.common import vapiconnect
22-
from com.vmware.appliance_client import Health
18+
from samples.vsphere.common import (sample_cli, sample_util)
19+
from com.vmware.appliance_client import Health
2320
from com.vmware.vapi.std_client import LocalizableMessage
21+
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

25-
class HealthMessages(object) :
25+
26+
class HealthMessages(object):
2627
"""
27-
Demonstrates getting Health messages for various health items
28+
Demonstrates getting Health messages for memory, storage and cpu
2829
2930
Retrieves Health messages details from vCenter and prints the data
3031
3132
"""
3233

33-
3434
def __init__(self):
3535
self.item = None
36-
self.stub_config = None
37-
38-
def setup(self):
36+
self.client = None
3937
parser = sample_cli.build_arg_parser()
38+
4039
parser.add_argument(
4140
'--item',
4241
required=True,
4342
action='store',
44-
choices=['memory', 'cpu' , 'storage'],
43+
choices=['memory', 'cpu', 'storage'],
4544
help='Specify the name of health item to view the messages')
45+
4646
args = sample_util.process_cli_args(parser.parse_args())
4747
self.item = args.item
48-
49-
# Connect to vAPI services
50-
self.stub_config = vapiconnect.connect(
51-
host=args.server,
52-
user=args.username,
53-
pwd=args.password,
54-
skip_verification=args.skipverification)
55-
56-
self.health_client = Health(self.stub_config)
48+
# Connect to vAPI services
49+
session = get_unverified_session() if args.skipverification else None
50+
self.client = create_vsphere_client(server=args.server,
51+
username=args.username,
52+
password=args.password,
53+
session=session)
54+
self.health_client = Health(self.client._stub_config)
5755

5856
def run(self):
5957
message_list = self.health_client.messages(self.item)
60-
print(" Health Alarams")
58+
print("Health Alarams")
6159
print("-------------------\n")
6260
if not message_list:
6361
print("No health alarms for : " + self.item)
6462
else:
65-
for message in message_list :
66-
print("Alert time : " + message.getTime())
67-
print("Alert message Id: " + message.getId())
68-
msg = message.getMessage()
69-
def_message = LocalizableMessage(msg.default_message)
70-
print("Alert message : "+ def_message)
63+
for message in message_list:
64+
print("Alert time : {}".format(message.time))
65+
print("Alert message Id: " + message.id)
66+
local_message = message.message
67+
default_msg = local_message.default_message
68+
print("Alert message : " + default_msg)
7169

7270

7371
def main():
7472
health_sample = HealthMessages()
75-
health_sample.setup()
7673
health_sample.run()
7774

75+
7876
if __name__ == '__main__':
7977
main()

0 commit comments

Comments
 (0)