Puppet

Configuration management tool.

Power BI DAX

01 CALCULATED COLUMN

When calculations is done on a row level

Revenue = [Price_USD] * [Sales]
02 CALCULATED MEASURES

When calculation is done on an aggregated level and don’t want to store information on a row level

Measure do not create physical values in your table. It does not increase the file size.

PySpark

Data

Filter customer data by type VIP/Regular

from pyspark.sql.functions import *  
customer=spark.sql("Select * FROM workspace.customerdata.customer")
display(customer)
df.printSchema()
df1=df.filter(df["customer_type"]=="VIP")
df0=customer.filter(col("customer_type")=="Regular")
display(df1)
# filter by customer_type and country
df1=customer.filter((customer.customer_type=="VIP") & (customer.country=='USA'))
# where condition
df2=customer.where((customer.customer_type=="VIP") & (customer.country=='USA'))
# or operator
df3=customer.where((customer.customer_type=="VIP") | (customer.country=='USA'))

Add new column withColumn Function

from pyspark.sql.functions import *  
customer=spark.sql("Select * FROM workspace.customerdata.customer")
customer =customer.withColumn("Salary", col("age")* 1000)
customer.printSchema()
display(customer)

# withColumn fuction
customer =customer.withColumn("Seniority", when(customer.age>50, "Senior").otherwise("Junior"))

OpenShift4

What is Openshift?

It is a platform as a service

oc explain

oc explain pod.spec.container.env

How to create pod

oc create -f pod.yaml

oc get pods

OC rsh

The oc rsh command in OpenShift allows you to “step inside” a running container and interact with it as if you were using a regular command prompt. It’s like opening a door to the container and being able to run commands and access files inside it.

  1. You need a tool called oc (OpenShift command-line tool) to use oc rsh. It helps you connect to an OpenShift cluster.
  2. You find the container you want to access within a group of containers called a “pod.”
  3. You use the oc rsh a command followed by the pod’s name to enter the container. It’s like opening the door to the container.
  4. Once inside, you can run commands and navigate the container’s files as if you were using a regular command prompt. You can check logs, run scripts, and do other things that the container allows.
  5. When you’re done, you exit the container by typing exit or pressing Ctrl+D. It’s like closing the door behind you.

Remember, it’s important to be careful when using oc rsh it because you can make changes that affect the container and the application running inside it.

OC delete

The oc delete command in OpenShift is used to delete various resources within an OpenShift cluster. It allows you to remove objects like pods, services, deployments, routes, and more.

oc delete <resource-type> <resource-name>

oc get pods –watch

How to access YAML variable in puppet bolt plan

yaml file

groups:
-name: test
targets:
-uri: test.abc.edu
vars:
server_short_name: test123
config:
transport: ssh

plan test:passvariablevalue(
 
TargetSpec $targets

){
    
    # Gather facts 
   $tragets.apply_prep
    
   get_targets('development').each | $traget | {
      $results= run_command ("touch /shiva/files/svc.test.${target.vars['server_short_name']}",$target, {_run_as => 
'root'})
      out::message ("${results}")
 
   }



}

Run plan

bolt plan run test:test:passvariablevalue -t test

IIS Authentication info using puppet

iis_application { 'myapp':
  ensure             => 'present',
  sitename           => 'mysite',
  physicalpath       => 'C:\\inetpub\\app',
  authenticationinfo => {
    'basic'     => true,
    'anonymous' => false,
  },
}

Download remote zip, extract zip and copy files using puppet in windows

#download file from repo
 download_file { 'Download dotnet 4.0' :
  url                   => 'https://repos.shivaprogramming.com/Myapp.ZIP',
  destination_directory => 'D:\downloadapp',
}

#extract zip
 exec { 'Unzip Folder':
        command =>'Expand-Archive -Path D:\downloadapp\Myapp.ZIP -DestinationPath D:\downloadapp\DEST',
        provider  => powershell,
        logoutput =>    true,
        subscribe => Download_file['Download dotnet 4.0'],
    } 
#copy resources to the destination
 
 file { 'D:\CA_Websites\MyApp':  #destination
 ensure    => 'directory',
 recurse   => true,
 source    => 'D:\downloadapp\DEST',
 subscribe => Exec['Unzip Folder'],
  }


Install IIS using puppet code

# copy IIS files into inetpub folder
file { 'C:\\inetpub\\minimal\\' :
ensure  => 'directory',
source  => 'C:\\moveto\\ACME',
recurse => true,
}

#create  application pool
iis_application_pool { 'ACME':
  ensure                  => 'present',
  state                   => 'started',
  managed_pipeline_mode   => 'Integrated',
  managed_runtime_version => 'v4.0',
} ->

# create Default Website
iis_site { 'Default Web Site':
  ensure          => 'started',
  #physicalpath    => 'C:\\inetpub',
  applicationpool => 'ACME',
} ->
#create IIS  application 
iis_application {'ACME':
  ensure          => present,
  applicationname => 'ACME', # <-- Does not need to match the title
  sitename        => 'Default Web Site',
  physicalpath => 'C:\\inetpub\\minimal',
} ->
#create IIS application  and convert to application
iis_application{'/ACME/UI':
  applicationpool => 'ACME',
  ensure          => 'present',
  sitename        => 'Default Web Site',
physicalpath => 'C:\\inetpub\\minimal\\UI'
}

Docker commands

docker ps -> List all the running docker processes. ps means the process starts

docker run hello-world => docker run image name

docker run – p 80:80 nginx

80:80=> Port 80 on host and port 80 container

nginx is a web server running on port 80

docker stop – container id

docker start container name

Create docker image

# Sample of docker file
# Use a container with Go pre-installed
FROM quay.io/projectquay/golang:1.17

# Copy our source file into the container
COPY src/hello-world.go /go/hello-world.go

# Set the default environment variables
ENV MESSAGE "Welcome! You can change this message by editing the MESSAGE environment variable."
ENV HOME /go

# Set permissions to the /go folder (for OpenShift)
RUN chgrp -R 0 /go && chmod -R g+rwX /go

# Just documentation.
# This container needs Docker or OpenShift to help with networking
EXPOSE 8080

# OpenShift picks up this label and creates a service
LABEL io.openshift.expose-services 8080/http

# OpenShift uses root group instead of root user
USER 1001

# Command to run when container starts up
CMD go run hello-world.go
docker build .

# . current directory
show list of images => docker images

Tag docker image

docker build -t shiva:v1 .

Check the Status of a docker image

docker ps   
#  show the running container check the status field

Remove the image

docker rmi image name

Adding port

# -p (host port):(container port)
docker run -it  -p 8080:8080  quay.io/practicalopenshift/hello-world

Running the docker help page offline

docker run -p 4000:4000 docs/docker.github.io

Add name and run interactive mode

docker run -p 4000:4000 -it --name shivadoc docs/docker.github.io

Find more info about container

docker inspect (container name or ID)
you can find the ip address of the container

Stop all the container

docker ps-q
docker stop $(docker ps -q)

Remove all the containers

docker ps -aq
docker rm $(docker ps-aq)
docker image prune 
docker volume ls
docker volume ls -f dangling=true

Deploy to Private Registry

docker run -d -p 1000:1000 -name regsitry register:version

docker image tag my-imagename localhost:1000/my-imagename

docker push localhost:1000/my-imagename

docker pull localhost:1000/my-imagename

dpocker pull 192.168.1.1:1000/my-imagename