Name
sn_cmp.CloudResourceDiscoveryLaunch
Description
No description available
Script
var CloudResourceDiscoveryLaunch = Class.create();
CloudResourceDiscoveryLaunch.prototype = Object.extendsObject(global.DiscoveryLaunch, {
initialize: function(status, schedule) {
global.DiscoveryLaunch.prototype.initialize.call(this, status, schedule);
},
launch: function() {
// get resource types to be discovered
var resTypes = [];
var resGr = new GlideRecord('cmp_discovery_res_type_config');
var datacenterGr;
resGr.addActiveQuery();
resGr.addQuery('discovery_schedule', ''+this.schedule.sysID);
resGr.query();
while (resGr.next()) {
resTypes.push(resGr.ci_type);
}
// get LDCs to be discovered
var ldcs = [];
var ldcGr = new GlideRecord('cmp_discovery_ldc_config');
ldcGr.addActiveQuery();
ldcGr.addQuery('discovery_schedule', ''+this.schedule.sysID);
// Filter the LDCs whose associated service account's 'exclude_from_discovery'
// is "false" so that we can avoid discovery run over non-discoverable SA(s).
ldcGr.addQuery('service_account.exclude_from_discovery', false);
ldcGr.query();
var ds = new sn_cmp_api.DiscoveryServiceScript();
var defaultBatch = 500;
var ldcBatchSize = +(gs.getProperty('glide.discovery.cloud.datacenter_batch', defaultBatch));
// In case of bad config which may cause issues with splice
if (ldcBatchSize < 1)
ldcBatchSize = defaultBatch;
// This indicates whether ECC queues were created!
var finalState = false;
while (ldcGr.next()) {
datacenterGr = new GlideRecord('cmdb_ci_logical_datacenter');
if (ldcGr.ldc.nil()) {
// no LDC specified, get all of them
var ldcList = ds.getLdcs(ldcGr.service_account);
if (ldcList) {
for (var i=0; i<ldcList.length; i++) {
ldcs.push(''+ldcList[i]);
}
}
datacenterGr.addQuery('sys_id', 'IN', ldcList);
datacenterGr.query();
} else {
ldcs.push(ldcGr.ldc + '');
datacenterGr.get(ldcGr.ldc + '');
}
datacenterGr.setValue('discovery_status', this.status.sysID + '');
datacenterGr.updateMultiple();
// Adding execution here so ldcs array won't hold too many strings
// ds.discover() MUST be first in this OR condition so it will always execute
if (ldcs.length >= ldcBatchSize)
finalState = ds.discover(ldcs.splice(0, ldcBatchSize), resTypes, '' + this.status.sysID) || finalState;
}
/*
* Technically speaking, since maximum LDCs in an account is no more than 50, this section should run one time
* on <=500 items [property's default value]
* However, if the property is set to a really low number, this may cause leftovers to be greater than
* the property's value, which is why a while is needed
*/
while (ldcs.length > 0)
finalState = ds.discover(ldcs.splice(0, ldcBatchSize), resTypes, '' + this.status.sysID) || finalState;
return finalState;
},
type: 'CloudResourceDiscoveryLaunch'
});
Sys ID
941dd5d5eba32200979aa5115206fe61