Maintenance is complete- We've moved from the saas.hpe.com domain to softwaregrp.com click to read more
As part of our journey to complete our separation work and our future integration with Micro Focus, we've now updated our domain for the community. This is an interim step, which will be followed by a series of future update / improvements: - Piloting Idea boards - Refreshing the entire UI. (more to come later) - and more
Server Automation Practitioners Forum
cancel

Custom OGFS Script During Build Plan

Dimiter Todorov
Honored Contributor.

Custom OGFS Script During Build Plan

Hi,

 

Has anyone done custom OGFS scripts during buildtime.

For example, how would I set a Custom Field on a server.

Another script I tried is the following which attempts to attach a policy based on Manufacturer.

 

However it fails for me. with the error at the bottom.

 

#!/usr/bin/python
# -*- mode: Python; tab-width: 4; indent-tabs-mode: nil; -*-
# ex: set tabstop=4 :
# Please do not change the two lines above. See PEP 8, PEP 263.
#
"""
(c) Copyright 2013 Dimiter Todorov
Assigns SW policies based on Manufacturer platform.
"""
import optparse
import re
import sys

#2 lines below for testing/development only.
#sys.path.append("/opt/opsware/pylibs2")
#sys.path.append("/opsw/apx/runtime/script/osprov.run_os_build_plan_papx")
from pytwist import twistserver
from pytwist.com.opsware.server import ServerService, ServerRef
from pytwist.com.opsware.swmgmt import SoftwarePolicyRef
from pytwist.com.opsware.custattr import NoSuchFieldException

from osprov.osbp import ThisTargetServer
from osprov.osbp.TargetServer import WinPE32TargetServer, WinPE64TargetServer
from osprov.errors import ShowErrorMessage


EC_USAGE = 1
EC_EXCEPTION = 2
EC_TARGET_SERVER = 5
EC_CUST_ATTR = 6

# #PRODUCTION
# HP_POLICIES = 78610001
# IBM_POLICIES = 78620001
# VMWARE_POLICIES = 78630001
#LAB
HP_POLICIES = 68420001
IBM_POLICIES = 68430001
VMWARE_POLICIES = 68440001



HP_PATTERN="HP|HEWLETT"
IBM_PATTERN="IBM"
VMWARE_PATTERN="VMW"


class PlatformBasedPolicyAttacher(object):

	def __init__(self,twistServer,targetServer,dryRun=False):
		self.twistServer = twistServer
		self.targetServer = targetServer
		self.serverRef = targetServer.serverRef
		#self.serverRef = targetServer
		self.dryRun=dryRun
	


	def attachManufacturerPolicies(self):
		serverVO=self.twistServer.server.ServerService.getServerVO(self.serverRef)
		manufacturer=serverVO.manufacturer
		
		if re.match(HP_PATTERN,manufacturer):
			self.attachPolicy(HP_POLICIES)
			return
		elif re.match(IBM_PATTERN,manufacturer):
			self.attachPolicy(IBM_POLICIES)
			return
		elif re.match(VMWARE_PATTERN,manufacturer):
			self.attachPolicy(VMWARE_POLICIES)
			return
		else:
			return False

	def attachPolicy(self,policy):
		policyRefs=list()
		pref=SoftwarePolicyRef(policy)
		polvo=self.twistServer.swmgmt.SoftwarePolicyService.getSoftwarePolicyVO(pref)
		sys.stdout.write(polvo.name)
		policyRefs.append(pref)
		self.twistServer.server.ServerService.attachPolicies(self.serverRef,policyRefs)
		return

def main():
	

	twistServer = twistserver.TwistServer()
	
	targetServer = ThisTargetServer()
	
	#targetServer=ServerRef(35640001)
	policyAttacher = PlatformBasedPolicyAttacher(twistServer, targetServer)
	try:
		policyAttacher.attachManufacturerPolicies()
		return 0
	except Exception, ex:
	 	print "Error Assigning Policy"
	 	print ex
	 	return 3

if __name__ == "__main__":
	sys.exit(main())

 

 

Step 2 of 20: Run OGFS Script 'OGFS-ATTACH POLICY'
IBM Hardware
OGFS-ATTACH POLICY failed with exit code 1.


STANDARD ERROR (the last 10 KB):

Errors from step 2 'OGFS-ATTACH POLICY':
Traceback (most recent call last):
  File "/tmp/OGFSScriptiqssSs", line 105, in ?
    sys.exit(main())
  File "/tmp/OGFSScriptiqssSs", line 97, in main
    policyAttacher.attachManufacturerPolicies()
  File "/tmp/OGFSScriptiqssSs", line 67, in attachManufacturerPolicies
    self.attachPolicy(IBM_POLICIES)
  File "/tmp/OGFSScriptiqssSs", line 81, in attachPolicy
    self.twistServer.server.ServerService.attachPolicies(self.serverRef,policyRefs)
  File "build/pytwist/twistserver.py", line 317, in __call__
  File "build/pytwist/twistserver.py", line 298, in _makeCall
  File "build/pytwist/twistserver.py", line 273, in _makeCall
  File "build/pytwist/twistserver.py", line 243, in _makeCall
pytwist.com.opsware.acm.PlatformConstraintException: PlatformConstraintException:ID:   HPSA-1018
Code:   com.opsware.acm.ACMMessageSpec.PLATFORM_CONSTRAINT

Details: Platform constraint. Details Server and SoftwarePolicy Platform Not Match while attach policy null to server null.

Remote Traceback:
File "ServerRequest.java", line 205, in sendReceive