Name
sn_cmp.ServiceAccountUIValidation
Description
checks if the Discover Datacenter UI Action should show up for the given service account. It will check for the datacenter_type and see if Discover Datacenter UI Action can be shown.
Script
var ServiceAccountUIValidation = Class.create();
ServiceAccountUIValidation.prototype = {
initialize: function() {},
showDiscoverDatacenterCheck: function(datacenter_type, is_master_account, accessor_account) {
var discoverDatacenterCheck = this.checkForDiscoverDatacenter(datacenter_type);
var notMasterAccessorAccountCheck = this.checkForMasterAccessorAccount(is_master_account, accessor_account);
var notMigratedFromCapiToPatternCheck = !this.checkForCapiToPatternMigration(datacenter_type);
return (discoverDatacenterCheck && notMasterAccessorAccountCheck && notMigratedFromCapiToPatternCheck);
},
checkForDiscoverDatacenter: function(datacenter_type) {
var gr = new GlideRecord('sn_cmp_rb_resourceblock');
gr.addQuery('refcitype', datacenter_type);
gr.setLimit(1);
gr.query();
return gr.hasNext();
},
checkForMasterAccessorAccount: function(is_master_account, accessor_account) {
return (is_master_account == false) && (accessor_account == '');
},
checkForCapiToPatternMigration: function(datacenter_type) {
var capiToPatternMigrationCheck = new sn_cmp.MigrationCapiToPatternCheck();
var migratedToPattern = false;
if (datacenter_type == 'cmdb_ci_aws_datacenter') {
return capiToPatternMigrationCheck.hasMigratedToPatternsForAws();
}
if (datacenter_type == 'cmdb_ci_azure_datacenter') {
return capiToPatternMigrationCheck.hasMigratedToPatternsForAzure();
}
return migratedToPattern;
},
/**
If there is no CMP support, then show the 'Create Schedule'
If there is CMP Support, then show only if the SA has atleast one datacenter under it
CMP support implies that there is a Discover Datacenter operation in the RB
*/
checkForCreateSchedule: function(datacenter_type) {
var gr = new GlideRecord('sn_cmp_rb_resourceblock');
gr.addQuery('refcitype', datacenter_type);
gr.setLimit(1);
gr.query();
return gr.hasNext() ? (new sn_cmp_api.DiscoveryServiceScript().getLdcs(current.sys_id).length >= 0) : true;
},
type: 'ServiceAccountUIValidation'
};
Sys ID
19651dcbdbede7003acf9cb8db96192c