Search the VMware Knowledge Base (KB)
View by Article ID

Hms_Jar_Edit.py Python Script (2149103)

  • 0 Ratings

Details

After configuring vSphere Replication Appliance, you need to download the Hms_Jar_Edit.py Python script.

Solution

#!/usr/bin/env python

from subprocess import PIPE,Popen
import zipfile
import shutil
import re
import sys
import time

t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)

IP_PATTERN = '((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'
PATTERN = '((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9]):\d{1,5}'

archive_old = '/opt/vmware/hms/libs/hms.jar'
archive_new = '/opt/vmware/hms/libs/hms_new.jar'
archive_bkp = '/opt/vmware/hms/libs/hms.jar.' + timestamp + '.bkp'

if len(sys.argv) == 2:
    new_ip = sys.argv[1]
else:
    print "Please enter the HCM IP:\n\n\t>>> python hcm_jar_edit.py <HCM-IP>"
    exit(1)

while re.match(IP_PATTERN, new_ip) == None:
	print "Invalid IP...Please enter a valid one."
	new_ip = raw_input("Enter valid HCM IP: ")

print 'IP Validated...Adding IP into META-INF/hms.xml file...'
new_port = '443'
new_host = new_ip+":"+new_port

shutil.copy2(archive_old, archive_bkp)

zf_in = zipfile.ZipFile(archive_old,mode='r')
zf_out = zipfile.ZipFile(archive_new,mode='w')

for item in zf_in.infolist():
	if "hms.xml" not in item.filename:
		buf = zf_in.read(item.filename)
		zf_out.writestr(item, buf)
zf_out.close()

try:
	f = zf_in.read('META-INF/hms.xml')
	replace = re.sub(PATTERN,new_host,f)
finally:
	zf_in.close()

zf_out = zipfile.ZipFile(archive_new,mode='a')
try:
	zf_out.writestr('META-INF/hms.xml',replace)
finally:
    zf_out.close()

shutil.move(archive_new, archive_old)
print 'Successfully added HCM IP into META-INF/hms.xml file...'

print 'stopping VCTA service'
proc = Popen(['service', 'vmware-vcd', 'stop'], stdout=PIPE)
print proc.communicate()[0]

print 'Disabling VCTA service'
proc = Popen(['chkconfig', 'vmware-vcd', 'off'], stdout=PIPE)
print proc.communicate()[0]

print 'Stopping HMS service...'
proc = Popen(['service', 'hms', 'stop'], stdout=PIPE)
print proc.communicate()[0]

print 'Starting HMS service...'
proc = Popen(['service', 'hms', 'start'], stdout=PIPE)
print proc.communicate()[0]

Request a Product Feature

To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.

Feedback

  • 0 Ratings

Did this article help you?
This article resolved my issue.
This article did not resolve my issue.
This article helped but additional information was required to resolve my issue.

What can we do to improve this information? (4000 or fewer characters)




Please enter the Captcha code before clicking Submit.
  • 0 Ratings
Actions
KB: