Something to enjoy with Prim Pro (X-Play) and Python

Something to enjoy with Prim Pro (X-Play) and Python

Introduction

Thing you want to do

===========< id
uid=1000(nutanix) gid=1000(nutanix) groups=1000(nutanix),160(snmp),600(java),990(docker)context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

===========< uname -a
Linux ntnx-20sm6k250202-c-cvm 3.10.0-1062.12.1.el7.nutanix.20200216.cvm.x86_64 #1 SMP Sun Feb 16 07:02:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

===========< hostssh date
============= 10.55.87.27 ============
Sat Dec 12 11:17:09 UTC 2020
============= 10.55.87.25 ============
Sat Dec 12 11:17:10 UTC 2020
============= 10.55.87.26 ============
Sat Dec 12 11:17:10 UTC 2020

===========< hostssh uptime
============= 10.55.87.27 ============
 11:17:12 up 1 day,  9:40,  0 users,  load average: 1.90, 2.36, 2.38
============= 10.55.87.25 ============
 11:17:12 up 1 day,  9:41,  0 users,  load average: 6.04, 6.07, 5.98
============= 10.55.87.26 ============
 11:17:12 up 1 day,  9:41,  0 users,  load average: 1.47, 1.69, 1.80

===========< ncli cluster info
    Cluster Id                : 0005b626-72dd-8051-3f5b-ac1f6b3d7d4b::4565431898213285195
    Cluster Uuid              : 0005b626-72dd-8051-3f5b-ac1f6b3d7d4b
    Cluster Name              : RTP-POC087
    Cluster Version           : 5.15
    Cluster Full Version      : el7.3-release-euphrates-5.15-stable-4fbdd4d9de331230bb468b3549f530e80ab53bb9

・ ・ ・ The following is omitted

What is X-Play?

X-Play setting method image

Script linkage (Powershell)

List of commands you want to get

id
uname -a
hostssh date
hostssh uptime
ncli cluster info
ncli host ls
ncli cluster get-domain-fault-tolerance-status type=node
ncli alert history duration=14
ncli license get-license
ncli license get-allowances
cluster status
zeus_config_printer
id
uname -a
/usr/local/nutanix/cluster/bin/hostssh date
/usr/local/nutanix/cluster/bin/hostssh uptime
/home/nutanix/prism/cli/ncli cluster info
/home/nutanix/prism/cli/ncli host ls
/home/nutanix/prism/cli/ncli cluster get-domain-fault-tolerance-status type=node
/home/nutanix/prism/cli/ncli alert history duration=14
/home/nutanix/prism/cli/ncli license get-license
/home/nutanix/prism/cli/ncli license get-allowances
/usr/local/nutanix/cluster/bin/cluster status
/usr/local/nutanix/bin/zeus_config_printer

Script to execute

Arrangement of various scripts

X-Play settings (Prism Central)

The result of calling Powershell from X-Play

Summary

bonus. Actual script

id
uname -a
/usr/local/nutanix/cluster/bin/hostssh date
/usr/local/nutanix/cluster/bin/hostssh uptime
/home/nutanix/prism/cli/ncli cluster info
/home/nutanix/prism/cli/ncli host ls
/home/nutanix/prism/cli/ncli cluster get-domain-fault-tolerance-status type=node
/home/nutanix/prism/cli/ncli alert history duration=14
/home/nutanix/prism/cli/ncli license get-license
/home/nutanix/prism/cli/ncli license get-allowances
/usr/local/nutanix/cluster/bin/cluster status
/usr/local/nutanix/bin/zeus_config_printer
{
	"cluster_address": "10.55.87.31",
	"user_name": "nutanix",
	"cvm_password": "nutanix/4u"
}
import json
import my_command

#Read file
fin = open('command_list.txt', 'r')
json_open = open('cvm_info.json', 'r')

#Read command list
fin = open('command_list.txt', 'r')
command = fin.readlines()
fin.close()

#Read server information
sv_info = json.load(json_open)
cluster_ip = sv_info['cluster_address']
user_name = sv_info['user_name']
password = sv_info['cvm_password']

##Command execution (main processing)
def main():
	for name in command:
		print('===========<', name)
		remote_obj = my_command.RemoteCommand()
		ret = remote_obj.get_df(cluster_ip, user_name, password, name)
		print(ret)

##Main processing (magic)
if __name__ == '__main__':
  main()


import paramiko

class RemoteCommand:
	def get_df(self, ip, user, password, command):
  		client = paramiko.SSHClient()
  		client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  		client.connect(ip, username=user, password=password, timeout=3.0)
  		(stdin, stdout, stderr) = client.exec_command(command, get_pty=True)
  		output = stdout.read().decode()
  		client.close()
   	
   	    return output
cmd.exe /c "c:\scripts\get_cvm_cmd.bat"
@echo off
set yyyy=%date:~0,4%
set mm=%date:~5,2%
set dd=%date:~8,2%
 
set time2=%time: =0%
 
set hh=%time2:~0,2%
set mn=%time2:~3,2%
set ss=%time2:~6,2%
 
set filename=%yyyy%-%mm%%dd%-%hh%%mn%%ss%
 
cmd.exe /c "c:\scripts\get_cvm_cmd.py > logs\log_%filename%.txt

Recommended Posts

Something to enjoy with Prim Pro (X-Play) and Python
Fractal to make and play with Python
Scraping tabelog with python and outputting to CSV
MessagePack-Try to link Java and Python with RPC
How to enjoy programming with Minecraft (Ruby, Python)
Procedure to load MNIST with python and output to png
I want to handle optimization with python and cplex
Try to operate DB with Python and visualize with d3
Programming with Python and Tkinter
Connect to BigQuery with Python
Python and hardware-Using RS232C with Python-
Connect to Wikipedia with Python
Post to slack with Python 3
Switch python to 2.7 with alternatives
Write to csv with Python
python with pyenv and venv
Works with Python and R
Easy to use Nifty Cloud API with botocore and python
screen and split screen with python and ssh login to remote server
A collection of competitive pro techniques to solve with Python
[Python] How to play with class variables with decorator and metaclass
Send experiment results (text and images) to slack with Python
Try to bring up a subwindow with PyQt5 and Python
How to do Bulk Update with PyMySQL and notes [Python]
[Let's play with Python] Image processing to monochrome and dots
Convert video to black and white with ffmpeg + python + opencv
Get additional data to LDAP with python (Writer and Reader)
How to log in to AtCoder with Python and submit automatically
Communicate with FX-5204PS with Python and PyUSB
Shining life with Python and OpenCV
Python: How to use async with
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
Neural network with OpenCV 3 and Python 3
Link to get started with python
[Introduction to Python3 Day 1] Programming and Python
Scraping with Node, Ruby and Python
[Python] Write to csv file with Python
Create folders from '01' to '12' with python
Nice to meet you with python
Scraping with Python, Selenium and Chromedriver
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
Try to operate Facebook with Python
Output to csv file with Python
Scraping with Python and Beautiful Soup
Linking Python and Arduino to display IME On / Off with LED
How to make a surveillance camera (Security Camera) with Opencv and Python
Convert list to DataFrame with python
MP3 to WAV conversion with Python
To do tail recursion with Python2
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
I tried to make a periodical process with Selenium and Python
What to do with PYTHON release?
Unable to install Python with pyenv
How to deal with errors when installing Python and pip with choco
Try to display google map and geospatial information authority map with python
How to use FTP with Python
I played with PyQt5 and Python3
I tried to easily detect facial landmarks with python and dlib