Creates and downloads the technical support data for the respective UCSM.
		
		- pathPattern specifies the path of the tech support file to be downloaded. File should be a tar file.
		- ucsManager, if provided as True then technical support data for the entire UCSM instance will be created and downloaded.
		- ucsMgmt, if provided as True then technical support data for the entire UCSM management services(excluding fabric interconnects)
		  will be created and downloaded.
		- chassisId specifies the chassis Id.
		- cimcId for a specific chassis. Can be 'all' also.
		- adapterId for a specific chassis. Can be 'all' also.
		- iomId for a specific chassis. Can be 'all' also.
		- fexId specifies the Id of a fabric extender.
		- rackServerId specifies the Id of a rack server.
		- rackAdapterId specifies the adaptor Id for a specific rack server. Can be 'all' also.
		- timeoutSec specifies the time in seconds after that the operation will terminate.
		- removeFromUcs, if specified as True then the techincal support data file will be removed from the UCS.

def GetTechSupport(self, pathPattern, ucsManager=False, ucsMgmt=False, chassisId=None, cimcId=None, adapterId=None,
					   iomId=None, fexId=None, rackServerId=None, rackAdapterId=None, timeoutSec=600,
					   removeFromUcs=False, dumpXml=None):
		"""
		Creates and downloads the technical support data for the respective UCSM.
		
		- pathPattern specifies the path of the tech support file to be downloaded. File should be a tar file.
		- ucsManager, if provided as True then technical support data for the entire UCSM instance will be created and downloaded.
		- ucsMgmt, if provided as True then technical support data for the entire UCSM management services(excluding fabric interconnects)
		  will be created and downloaded.
		- chassisId specifies the chassis Id.
		- cimcId for a specific chassis. Can be 'all' also.
		- adapterId for a specific chassis. Can be 'all' also.
		- iomId for a specific chassis. Can be 'all' also.
		- fexId specifies the Id of a fabric extender.
		- rackServerId specifies the Id of a rack server.
		- rackAdapterId specifies the adaptor Id for a specific rack server. Can be 'all' also.
		- timeoutSec specifies the time in seconds after that the operation will terminate.
		- removeFromUcs, if specified as True then the techincal support data file will be removed from the UCS.
		"""
		from UcsBase import WriteUcsWarning, UcsUtils, ManagedObject, WriteObject, UcsUtils, UcsValidationException, \
			UcsException
		from Mos import SysdebugTechSupport, SysdebugTechSupportCmdOpt
		from Ucs import ConfigConfig
		import os

		if (self._transactionInProgress):
			raise UcsValidationException(
				"UCS transaction in progress. Cannot execute GetTechSupport. Complete or Undo UCS transaction.")
		# raise Exception("UCS transaction in progress. Cannot execute GetTechSupport. Complete or Undo UCS transaction.")

		if (pathPattern == None):
			raise UcsValidationException("pathPattern parameter is not provided.")
		# raise Exception("Please provide pathPattern parameter.")

		if not pathPattern.endswith('.tar'):
			raise UcsValidationException('pathPattern should end with .tar')

		directory = os.path.dirname(pathPattern)
		if not (os.path.exists(directory)):
			os.makedirs(directory)

		inConfig = ConfigConfig()
		techSupportObj = None

		dt1 = datetime.datetime(1970, 1, 1, 12, 0, 0, 0)
		dt2 = datetime.datetime.utcnow()

		ds = (dt2 - dt1)
		creationTS = (ds.microseconds / 1000000) + (
			ds.days * 24 * 60 * 60) + ds.seconds  # Converting timedelta in to total seconds for Python version compatibility.
		sysdebug = ManagedObject(NamingId.SYSDEBUG_TECH_SUPPORT)
		sysdebug.CreationTS = str(creationTS)
		dn = UcsUtils.MakeDn([ManagedObject(NamingId.TOP_SYSTEM).MakeRn(),
							  ManagedObject(NamingId.SYSDEBUG_TECH_SUP_FILE_REPOSITORY).MakeRn(), sysdebug.MakeRn()])

		sysdebugTechSupport = ManagedObject(NamingId.SYSDEBUG_TECH_SUPPORT)
		sysdebugTechSupport.DN = dn
		sysdebugTechSupport.AdminState = SysdebugTechSupport.CONST_ADMIN_STATE_START
		sysdebugTechSupport.CreationTS = str(creationTS)
		sysdebugTechSupport.Status = Status.CREATED

		sysdebugTechSupportCmdOpt = ManagedObject(NamingId.SYSDEBUG_TECH_SUPPORT_CMD_OPT)

		# Parameter Set UCSM
		if (ucsManager):
			sysdebugTechSupportCmdOpt.MajorOptType = SysdebugTechSupportCmdOpt.CONST_MAJOR_OPT_TYPE_UCSM
			sysdebugTechSupportCmdOpt.Rn = sysdebugTechSupportCmdOpt.MakeRn()

			sysdebugTechSupport.AddChild(sysdebugTechSupportCmdOpt)
		elif (ucsMgmt):
			sysdebugTechSupportCmdOpt.MajorOptType = SysdebugTechSupportCmdOpt.CONST_MAJOR_OPT_TYPE_UCSM_MGMT
			sysdebugTechSupportCmdOpt.Rn = sysdebugTechSupportCmdOpt.MakeRn()

			sysdebugTechSupport.AddChild(sysdebugTechSupportCmdOpt)
		elif (chassisId != None):
			if (cimcId != None):
				sysdebugTechSupportCmdOpt.ChassisCimcId = str(cimcId)
				sysdebugTechSupportCmdOpt.ChassisId = str(chassisId)
				sysdebugTechSupportCmdOpt.MajorOptType = SysdebugTechSupportCmdOpt.CONST_MAJOR_OPT_TYPE_CHASSIS
				if (adapterId == None):
					sysdebugTechSupportCmdOpt.CimcAdapterId = SysdebugTechSupportCmdOpt.CONST_CIMC_ADAPTER_ID_ALL
				else:
					sysdebugTechSupportCmdOpt.CimcAdapterId = str(adapterId)
				sysdebugTechSupportCmdOpt.Rn = sysdebugTechSupportCmdOpt.MakeRn()

				sysdebugTechSupport.AddChild(sysdebugTechSupportCmdOpt)
			elif (iomId != None):
				sysdebugTechSupportCmdOpt.ChassisIomId = str(iomId)
				sysdebugTechSupportCmdOpt.ChassisId = str(chassisId)
				sysdebugTechSupportCmdOpt.MajorOptType = SysdebugTechSupportCmdOpt.CONST_MAJOR_OPT_TYPE_CHASSIS
				sysdebugTechSupportCmdOpt.Rn = sysdebugTechSupportCmdOpt.MakeRn()

				sysdebugTechSupport.AddChild(sysdebugTechSupportCmdOpt)
		elif (rackServerId != None):
			sysdebugTechSupportCmdOpt.RACK_SERVER_ID = str(iomId)
			if (rackAdapterId == None):
				sysdebugTechSupportCmdOpt.RACK_SERVER_ADAPTER_ID = SysdebugTechSupportCmdOpt.CONST_RACK_SERVER_ADAPTER_ID_ALL
			else:
				sysdebugTechSupportCmdOpt.RACK_SERVER_ADAPTER_ID = str(rackAdapterId)
			sysdebugTechSupportCmdOpt.MajorOptType = SysdebugTechSupportCmdOpt.CONST_MAJOR_OPT_TYPE_SERVER
			sysdebugTechSupportCmdOpt.Rn = sysdebugTechSupportCmdOpt.MakeRn()

			sysdebugTechSupport.AddChild(sysdebugTechSupportCmdOpt)
		elif (fexId != None):
			sysdebugTechSupportCmdOpt.FAB_EXT_ID = str(iomId)
			sysdebugTechSupportCmdOpt.MajorOptType = SysdebugTechSupportCmdOpt.CONST_MAJOR_OPT_TYPE_FEX
			sysdebugTechSupportCmdOpt.Rn = sysdebugTechSupportCmdOpt.MakeRn()

			sysdebugTechSupport.AddChild(sysdebugTechSupportCmdOpt)

		if (sysdebugTechSupport.GetChildCount() == 0):
			sysdebugTechSupport = None
			sysdebugTechSupportCmdOpt = None
			inConfig = None
		else:
			inConfig.AddChild(sysdebugTechSupport)

		ccm = self.ConfigConfMo(dn=dn, inConfig=inConfig, inHierarchical=YesOrNo.FALSE, dumpXml=dumpXml)

		duration = timeoutSec
		poll_interval = 2
		crd = None
		if (ccm.errorCode == 0):
			# WriteUcsWarning('Waiting for the Tech Support file to become available (this may take several minutes).')
			status = False
			while (True):
				crd = self.ConfigResolveDn(dn, inHierarchical=YesOrNo.FALSE, dumpXml=dumpXml)
				if (crd.errorCode == 0):
					if (crd.OutConfig.GetChildCount() > 0):
						for techSupport in crd.OutConfig.GetChild():
							if (techSupport.OperState == SysdebugTechSupport.CONST_OPER_STATE_AVAILABLE):
								status = True
					else:
						raise UcsValidationException('Failed to create the TechSupport file.')
						# raise Exception('Failed to create the TechSupport file.')

				else:
					raise UcsException(crd.errorCode, crd.errorDescr)
				# raise Exception('[Error]: GetTechSupport [Code]:' + crd.errorCode + ' [Description]:' + crd.errorDescr)

				if (status):
					break

				time.sleep(min(duration, poll_interval))
				duration = max(0, (duration - poll_interval))

				if duration == 0:
					inConfig = ConfigConfig()
					sysdebugTechSupport = ManagedObject(NamingId.SYSDEBUG_TECH_SUPPORT)
					sysdebugTechSupport.DN = dn
					sysdebugTechSupport.Status = Status.DELETED
					inConfig.AddChild(sysdebugTechSupport)
					ccmi = self.ConfigConfMo(dn=dn, inConfig=inConfig, inHierarchical=YesOrNo.FALSE, dumpXml=dumpXml)
					if (ccmi.errorCode != 0):
						WriteUcsWarning(
							'[Error]: GetTechSupport [Code]:' + ccmi.errorCode + ' [Description]:' + ccmi.errorDescr)
					raise UcsValidationException('TechSupport file generation timed out')
					# raise Exception('TechSupport file generation timed out')

			# WriteObject(crd.OutConfig.GetChild())
			for item in crd.OutConfig.GetChild():
				fileSource = "techsupport/" + item.Name

				try:
					UcsUtils.DownloadFile(self, fileSource, pathPattern)
				except Exception, err:
					WriteUcsWarning(str(err))

				if (removeFromUcs):
					inConfig = ConfigConfig()
					sysdebugTechSupport = ManagedObject(NamingId.SYSDEBUG_TECH_SUPPORT)
					sysdebugTechSupport.DN = item.Dn
					sysdebugTechSupport.Status = Status.DELETED
					inConfig.AddChild(sysdebugTechSupport)
					ccmi = self.ConfigConfMo(dn=item.Dn, inConfig=inConfig, inHierarchical=YesOrNo.FALSE,
											 dumpXml=dumpXml)
					if (ccmi.errorCode != 0):
						raise UcsException(ccmi.errorCode, ccmi.errorDescr)
						# raise Exception('[Error]: GetTechSupport [Code]:' + ccmi.errorCode + ' [Description]:' + ccmi.errorDescr)

		else:
			raise UcsException(ccm.errorCode, ccm.errorDescr)
		# raise Exception('[Error]: GetTechSupport [Code]:' + ccm.errorCode + ' [Description]:' + ccm.errorDescr)

		return crd.OutConfig.GetChild()