Skip to content

Instantly share code, notes, and snippets.

View vladwa's full-sized avatar
👨‍💻
Dev, Ops and everything in between

Vinayaka V Ladwa vladwa

👨‍💻
Dev, Ops and everything in between
View GitHub Profile
@vladwa
vladwa / azdelunattacheddisk.sh
Created November 11, 2020 07:59
Azure - Delete unattached/unused disks
unattachedDisk=`az disk list --query "[?diskState=='Unattached'].id" --output table | grep sub`
for diskId in ${unattachedDisk}
do
echo ${diskId}
az disk delete --ids ${diskId} --yes --no-wait
done
@vladwa
vladwa / gcpComputeInstanceDetails.py
Last active July 21, 2020 07:56
Python code snippet to fetch the compute instance details by connecting to Google API Client using Python client library for Google's discovery.
#vars
# SERVICE_ACCOUNT_FILE --> Service Account Json file
# project --> Gcp Project Name
# zone --> zone in which instance is created
# instance_name --> Instance name
from google.oauth2 import service_account
from googleapiclient import discovery
SCOPES = ["https://www.googleapis.com/auth/cloud-platform"]
@vladwa
vladwa / PST.py
Created December 31, 2017 07:38
Python snippet to get the PST time and date.
from datetime import datetime
from pytz import timezone
def get_pst_time():
date_format='%m_%d_%Y_%H_%M_%S_%Z'
date = datetime.now(tz=pytz.utc)
date = date.astimezone(timezone('US/Pacific'))
pstDateTime=date.strftime(date_format)
return pstDateTime
@vladwa
vladwa / SSH.py
Created December 31, 2017 07:30
Python code to execute command as a sudo user over ssh connection on a remote server using "paramiko" module. On The code snippet establishes connection and executes the command and return the status and output of the executed command.
import logging
import paramiko
class SSH:
def __init__(self):
pass
def get_ssh_connection(self, ssh_machine, ssh_username, ssh_password):
"""Establishes a ssh connection to execute command.
:param ssh_machine: IP of the machine to which SSH connection to be established.
@vladwa
vladwa / SSH.py
Last active December 31, 2017 07:29
Python code to execute command as a non sudo user over ssh connection on a remote server using "paramiko" module. On The code snippet establishes connection and executes the command and return the status and output of the executed command.
import logging
import paramiko
class SSH:
def __init__(self):
pass
def get_ssh_connection(self, ssh_machine, ssh_username, ssh_password):
"""Establishes a ssh connection to execute command.
:param ssh_machine: IP of the machine to which SSH connection to be established.
@vladwa
vladwa / SendEmail.py
Last active October 16, 2021 15:30
Python code to send an email with attachment and TLS protocol enabled.
'''
@author: vladwa
@Email : vinayakladwa@gmail.com
'''
# importing the smtplib library
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
@vladwa
vladwa / PostFileAttachment.py
Created December 30, 2017 12:14
Python snippet to invoke HTTP Post request with file attached(multipart/form-data) in the body of the request. This function returns Response object.
# importing the requests library
import requests
def postFileAttachment(url,fileName,contentType):
"""Sends a POST request.
:param url: URL for the new :class:`Request` object.
:param fileName: File to be sent/attached in the body of the request.
:return: :class:`Response <Response>` object.
"""
multipart = MultipartEncoder(
@vladwa
vladwa / GetRequest.py
Last active January 10, 2018 12:41
Python snippet to invoke HTTP get request. This function returns Response object.
# importing the requests library
import requests
def getResponse(url,header,contentType):
"""Sends a getRequest.
:param url: URL for the new :class:`Request` object.
:return: :class:`Response <Response>` object.
"""
headers1={'Authorization': headerToken}
response = requests.get(url, headers=headers1,timeout=5)
@vladwa
vladwa / PostRestReponse.py
Last active December 30, 2017 11:48
Python code to make HTTP post request. This function returns Response object.
# importing the requests library
import requests
def getPostRestResponse(restUrl,inputRequest,contentType):
"""Sends a POST request.
:param url: URL for the new :class:`Request` object.
:param inputRequest: Data to send in the body of the request.
:return: :class:`Response <Response>` object.
"""
content = {'content-type': contentType}