Name
sn_itom_pattern.CapiMigrateToPatterns
Description
No description available
Script
var CapiMigrateToPatterns = Class.create();
CapiMigrateToPatterns.prototype = Object.extendsObject(CapiToPatternPrerequisiteScript, {
capiName : {
AWS: 'Aws',
AZURE: 'Azure',
ALL: 'All'
},
runScript: function(param) {
var resultLog, migrationHelper;
switch (param) {
case "prereq":
this.runAllPrerequisitesCheck();
break;
case "all":
this.runAll();
break;
case "aws":
this.startLogRecord(this.capiName.AWS + " CAPI Migration");
this.runMigration(new sn_cmp.DiscoveryAwsMigrationHelper(), this.capiName.AWS, this.awsPatternArray);
break;
case "azure":
this.startLogRecord(this.capiName.AZURE + " CAPI Migration");
this.runMigration(new sn_cmp.DiscoveryAzureMigrationHelper(), this.capiName.AZURE, this.azurePatternArray);
break;
default:
this.startLogRecord("CAPI Migration Parameter Failure");
this.saveLogs("Parameter check FAILED for value: " + param + " - Please check capi_to_pattern UI Page to see if you are passing in correct values");
this.endLogs();
}
},
runAll : function() {
this.startLogRecord(this.capiName.ALL + " CAPI Migration");
this.runMigration(new sn_cmp.DiscoveryAwsMigrationHelper(), this.capiName.AWS, this.awsPatternArray);
this.runMigration(new sn_cmp.DiscoveryAzureMigrationHelper(), this.capiName.AZURE, this.azurePatternArray);
},
runMigration : function(migrationHelper, capiName, patternArray) {
this.disableCAPIDiscovery(migrationHelper, capiName);
this.updateCloudPatterns(patternArray, capiName, true);
},
disableCAPIDiscovery: function(migScript, capiName) {
this.saveLogs(this.introMessage("Toggling " + capiName + " CAPI Steps"));
var resultLog = migScript._disableCAPIDiscovery();
this.saveLogs(resultLog + this.newLine + this.dash);
},
updateCloudPatterns: function (patternArray, capiName, state) {
this.saveLogs("Toggling " + capiName + " Cloud Patterns" + this.newLine + this.dash);
var patterns = new GlideRecord('sa_pattern');
for (var x = 0; x < patternArray.length; x++) {
var patternSysId = patternArray[x].sysId;
var patternName = patternArray[x].name;
if (patterns.get('sys_id', patternSysId)) {
patterns.setValue('active', state);
patterns.update();
this.setReplaceOnUpgradeToTrue(patternSysId);
this.saveLogs(this.newLine + "Updated Pattern: " + patternName + "(" + patternSysId + ") - set Active to " + state);
}
}
this.saveLogs(this.dash + this.newLine + capiName + " Migration Complete" + this.newLine);
this.endLogs();
},
// Functionality to be able to update global sys_update_xml record from sn_itom_pattern scope
setReplaceOnUpgradeToTrue: function(patternId) {
var patternXmlName = 'sa_pattern_' + patternId;
var updateScript = "var updateGr = new GlideRecord('sys_update_xml');"
+ "updateGr.addQuery('name', '" + patternXmlName + "');"
+ "updateGr.orderByDesc('sys_updated_on');"
+ "updateGr.query();"
+ "if (updateGr.next()) { "
+ "updateGr.setValue('replace_on_upgrade', 'true');"
+ "updateGr.update(); }";
this.runJob(updateScript);
},
type: 'CapiMigrateToPatterns'
});
Sys ID
b6d01b8af1c5d810f8777a03e16e7ec3