Name

global.CloudCMPPortalDiscovery

Description

This class contains all common methods that are used for the Discovery Datacenter/Scheduler frm the CMP Portal

Script

var CloudCMPPortalDiscovery = Class.create();
CloudCMPPortalDiscovery.prototype  = Object.extendsObject(CloudDiscovery, {
  initialize: function() {
  	this._isAllowed(this.type);
  },

  discoverDatacenter: function(accountSysId, ldcSysId) {
  	this._debug("discoverDataCenter->Start -", {"accountSysId":accountSysId, "ldcSysId":ldcSysId});
  	var accountGR = null;
  	var accountName = "";
  	var ldcGR = null;
  	var ldcName = "";
  	try{	
  		accountGR = this._getAccountGR(accountSysId);
  		ldcGR = this._getLdcGR(ldcSysId);
  		this._debug("discoverDataCenter->2 -", {"accountSysId":accountSysId, "ldcSysId":ldcSysId});
  	} catch(err) {
  		throw Error("discoverDataCenter Initialized of mandatory accountSysId, ldcSysId failed ->EXCEPTION -",  err);
  	}
  	accountName = String(accountGR.getValue('name'));
  	ldcName = String(ldcGR.getValue('name'));
  	
  	var patterns = this._getVendorPatterns( String(accountGR.datacenter_type) );
  	this._debug("discoverDataCenter->patterns -", patterns);
  	
  	var configObj = this._createEmptyConfigObj();
  	configObj.service_account.sys_id = String(accountSysId);
  	configObj.service_account.datacenter_type = String(accountGR.datacenter_type);
  	configObj.service_account.account_id	=  String(accountGR.account_id);
  	var msg = "Discovery of ["+accountName+"]["+ldcName+"]" ;
  	this.statusId = this._createDiscoveryStatus(msg, this.type);

  	//Set Discovery Status for the LDC.
  	new CloudResourceDiscoveryUtil().persistDiscoveryStatusToLDC(accountSysId, ldcSysId, this.statusId);
  	
  	var probeParams = {};	
  	var probeValues = {"computer": configObj.service_account.sys_id}; //This is the Service Account will be converted in the mid into computerSystem
  	var ppe = this._buildPPE(configObj.service_account.sys_id , ldcSysId);
  	var midName = this._getAutoMid(String(accountGR.datacenter_type));
  	
  	for (var patternId in patterns){
  		this._debug("discoverDataCenter->pattern-", {"pattern":patterns[patternId], "ldc":ldcName } );
  		probeParams["pattern_id"] = patternId;
  		probeParams["logical_datacenter_name"] = ldcName;
  		this._invokePhase(configObj, patternId, midName, probeParams, probeValues, ppe, msg);
  	}	
  	
  	return this.statusId;
  },
  
  _getVendorPatterns: function(datacenter_type) {
  	this._debug("_getVendorPatterns->Patterns datacenter_type-", datacenter_type);
  	var grExclude = new GlideRecord("sa_cloud_topology_discovery_pattern");
  	grExclude.addQuery("datacenter_type", datacenter_type);
  	grExclude.query();
  	
  	var excludedPatterns = {};
  	while (grExclude.next()) {
  		excludedPatterns[grExclude.pattern] = true;
  	}
  	this._debug("_getVendorPatterns->excludedPatterns-", excludedPatterns);
      var result = {};
  	var patternAppService = new SNC.PatternLibraryAppService();
  		
      var gr = new GlideRecord("sa_pattern");
  	gr.addQuery('active',true);
  	gr.addQuery("cpattern_type", "IN", "1,4");
      gr.addQuery("ndl", "CONTAINS", datacenter_type); 
      gr.query();

      while (gr.next()) {
  		// Omit patterns of included items
  		if (patternAppService.isIncludedPattern(gr.getUniqueValue())){
  			excludedPatterns[grExclude.pattern] = true;
  			continue;
  		}				

  		//LDC  & SubAccount
  		if (!excludedPatterns[String(gr.getUniqueValue())]){
  			result[gr.getUniqueValue()] = { "name": String(gr.getValue("name")), "invoke_per_account": Boolean(gr.getValue("invoke_per_account")) } ;
  		}
      }	
  	this._debug("_getVendorPatt_getVendorPatternsernsIds->Patterns result", {"excludedPatterns": excludedPatterns,  "result": result});
      return result;
  },
  
  type: 'CloudCMPPortalDiscovery'
});

Sys ID

2a10bba5c73c23000a1123622b97630e

Offical Documentation

Official Docs: