Skip to content

Instantly share code, notes, and snippets.

View Satak's full-sized avatar

Sami Koskivaara Satak

View GitHub Profile
@Satak
Satak / cosmos_db.py
Created December 31, 2019 11:48
Example how to use Azure CosmosDB Python SDK
from os import getenv
from azure.cosmos import CosmosClient, PartitionKey
import uuid
AZ_DB_ENDPOINT = getenv('AZ_DB_ENDPOINT')
AZ_DB_PRIMARYKEY = getenv('AZ_DB_PRIMARYKEY')
DATABASE_NAME = 'Tasks'
CONTAINER_NAME = 'Items'
AZ_DB_CLIENT = CosmosClient(AZ_DB_ENDPOINT, AZ_DB_PRIMARYKEY)
@Satak
Satak / main.tf
Last active January 20, 2020 12:32
provider "vsphere" {
user = var.vsphere_user
password = var.vsphere_password
vsphere_server = var.vsphere_server
allow_unverified_ssl = true
}
data "vsphere_datacenter" "dc" {
name = var.datacenter
}
@Satak
Satak / tf.log
Created January 20, 2020 12:48
Terraform vcsim log
2020/01/20 14:48:01 [INFO] Terraform version: 0.12.18
2020/01/20 14:48:01 [INFO] Go runtime version: go1.12.13
2020/01/20 14:48:01 [INFO] CLI args: []string{"C:\\Program Files\\Terraform\\terraform.exe", "apply", "-auto-approve"}
2020/01/20 14:48:01 [DEBUG] Attempting to open CLI config file: C:\Users\a.fisamkosk3\AppData\Roaming\terraform.rc
2020/01/20 14:48:01 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/01/20 14:48:01 [INFO] CLI command args: []string{"apply", "-auto-approve"}
2020/01/20 14:48:01 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2020/01/20 14:48:01 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2020/01/20 14:48:01 [DEBUG] New state was assigned lineage "6d8caa9e-e384-7950-d2f5-228f87ae78f4"
2020/01/20 14:48:01 [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
@Satak
Satak / GitHub.md
Last active January 22, 2020 09:15
@Satak
Satak / eslint_prettier_airbnb.md
Last active April 20, 2020 20:12
ESLint, Prettier & Airbnb Setup

ServiceNow Extension for VSCode

Install ServiceNow® Extension for VS Code

Open VS Code and install this extension and follow the instructions how to authenticate and pull application from ServiceNow

Set Custom file types

Policy Rule Action Script (sn_cmp_pol_action_script) & Resource Pool Filter (sn_cmp_rp_filter) are custom file types which you need to explicitly import in your application. This can be done by adding the file config to the application & configuring the file to enable import and sync.

@Satak
Satak / app.py
Last active June 17, 2022 17:45
Python xml
import xml.etree.ElementTree as ET
def indent(elem, level=0):
i = "\n" + level*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
@Satak
Satak / vmware.ps1
Last active June 24, 2020 06:46
VMware REST API functions
$username = 'username'
$password = 'password'
$vcenter = 'localhost'
$authURL = "https://$vcenter/rest/com/vmware/cis/session"
$apiBaseURL = "https://$vcenter/rest/vcenter"
$vmAPIURL = $apiBaseURL + '/vm'
$ct = 'application/json'
$sec = ConvertTo-SecureString -AsPlainText $Password -Force
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $sec
@Satak
Satak / clientScript.js
Last active July 7, 2020 09:21
Password generator function
function onLoad() {
var generatePassword = new GlideAjax('x_fstfs_fj_cmp.TfSCMPClientUtils');
function setPassword (password) {
g_form.setValue('AWS_Windows_UserPassword', password);
}
generatePassword.addParam('sysparm_name', 'generateRandomPassword');
generatePassword.getXMLAnswer(setPassword);
}
@Satak
Satak / passwordGenerator.js
Created July 13, 2020 18:34
Random Password Generator
/**
* Generate string from ascii range
* @param {any} ranges - ASCII code
* @param {number} charsCount
* @param {string[]} allCharsTotal
* @return {string}
*/
function generateChars(ranges, charsCount, allCharsTotal) {
var allChars = [];
var i;

About MID server script includes

Developing and debugging MID server script include scripts, especially to CMP/Cloud Provisioning and Governance, can be a little tricky and slow since your native logging is done with the ms.log() function and you can't see the logs from the ServiceNow instance, but instead you need to grab the logs from MID server. Another problem is the script/function execution and context management (login to cloud provider, etc.).

Let's say you need to develop new REST API based functions (day 2 action, like change CPU and memory of a VM) to VMware. How would you develop and test your code?