hwakabh / gists Goto Github PK
View Code? Open in Web Editor NEWCollections of code snippets in GitHub Gist with git-subomodule.
Home Page: https://gist.github.com/hwakabh
Collections of code snippets in GitHub Gist with git-subomodule.
Home Page: https://gist.github.com/hwakabh
credentials.txt
as parameterWith #23 , currently only the features to kick/download vm-support
for ESXi host(s).
Need to add functions to kick vc-support
of vCenter Server and download them.
Print as stdout if user has missed some required file to the parent/child scripts:
settitngs.txt
esxi.secret
vcenter.secret
result.csv
For setHostMaintenaceMode.ps1
, exitHostMaintenanceMode.ps1
, and shutdownHosts.ps1
, implement interval after running command to each host with parameter waitIntervalSec
.
Since .gitignore file can be nested, need to separate gitignore files according to each subdirectories.
The actual contents of gitignore would be fetched from following options:
Opt-1: Fetched from personal dotfile repository
$ curl -s -X GET https://raw.githubusercontent.com/hwakabh/dotfiles/main/gitconf/Python.gitignore
Opt-2: Fetched responses of www.gitignore.io API
$ curl -s -X GET https://www.toptal.com/developers/gitignore/api/python
Opt-3: Fetched from GitHub hosted repository
$ curl -s -X GET https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
Get-Log
cmdlet with -Bundle
option, the log files should be expected to download local path where the scripts runningIn getVsphereLogs.ps1
, currently -DestinationPath
is implemented with hard codes.
For the requirements, needs to handle downloading path as command line argument and make user provide specified path where they like.
For security requirements, the scripts uses SecureString
objects of PowerShell functionalities.
Added README.md to some descriptions with procedures before running scripts.
parentScript.ps1
childScript.ps1
since the child script would be just kicked by parentScript.ps1
, and no need to show help menu.At least, we should add the data-type of arguments, which are specified by user-defined functions.
As user requirements, they need to collect relations between:
The expected formats of output is .csv
, so with Get-Cluster | Get-VMHost | Get-VM
cmdlets, exporting the mapping information of vSphere objects.
Currently when calling remote .ps1 script from parent server, the path of password.secret
would be set as $HOME\Documents\
, so that it could not retrieve proper credentials from SecureString objects same as in the password.secret
file.
Need fix to retrieve encrypted password from the file password.secret
on remote server by childScript.ps1
.
Set-PowerCLIConfiguration
cmdlet within rebootVm.ps1
or cp-rebootVm.ps1
Both in parentScript.ps1
and childScript.ps1
, implement logging functions in eventvrw
of Windows Server with New-EventLog
Cmdlet.
Event Levels/IDs
In case of disconnection of vCenter Server, following features should be added to cp-childScript.ps1
:
Add descriptions with scripts usage and pre-requirements of the script if needed.
startAllVms.ps1
, the user needs list file of virtual-machines to power on.Start-VM
only for listed VMCurrently Invoke-RestMethod
returns following errors when they would download each log-bundle after completing the jobs to kick tasks of collecting.
Invoke-RestMethod : Access to the path 'C:\vmware' is denied.
At C:\Users\Administrator\Documents\misc-snippets\PowerShell\vsphere_maintenances\getNsxLogs.ps1:99 char:5
+ Invoke-RestMethod -Uri $postUri -Method Post -Headers $header -Bo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
SSIA
Integrate childScript.ps1
and parentScript.ps1
with Invoke-Command
cmdlet.
For handling return codes by software, who would kick kickRebootVm.ps1
, the script should be return the codes according to the results of scripts.
For security requirements, implement encryption of user credentials.
Currently unavailable with simply cloning repository.
Should be executed npm init
with properly directory.
For handling rebootVm.ps1
behavior from kickRebootVm.ps1
, implement logics to throw back return codes to parentScript.ps1
By design, vCenter Server would reject to create hostProfiles whose name is same as the ones vCenter have already created.
PS /Users/hwakabayashi> Get-VMHostProfile -Server vcsa02.nfvlab.local
Name Description
---- -----------
default_test_profile
default_test_profile_01
PS /Users/hwakabayashi>
PS /Users/hwakabayashi>
PS /Users/hwakabayashi> Get-VMHostProfile -Server vcsa02.nfvlab.local |Select-Object -Property *
ServerId : /VIServer=vsphere.local\administrator@vcsa02.nfvlab.local:443/
Server : vcsa02.nfvlab.local
Description :
ReferenceHostId : HostSystem-host-106
ReferenceHost : esxi08.nfvlab.local
Name : default_test_profile
ExtensionData : VMware.Vim.HostProfile
Id : HostProfile-hostprofile-2
Uid : /VIServer=vsphere.local\administrator@vcsa02.nfvlab.local:443/VMHostProfile=HostProfile-hostprofile-2/
PS /Users/hwakabayashi>
PS /Users/hwakabayashi>
PS /Users/hwakabayashi> New-VMHostProfile -Name default_test_profile -ReferenceHost esxi08.nfvlab.local
New-VMHostProfile : 11/20/2019 15:59:27 New-VMHostProfile The name 'default_test_profile' already exists.
At line:1 char:1
+ New-VMHostProfile -Name default_test_profile -ReferenceHost esxi08.nf ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VMHostProfile], DuplicateName
+ FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_NewVMHostProfile_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.NewVMHostProfile
PS /Users/hwakabayashi>
To escape this issue, add the features to delete current hostProfiles if the name conflicts would occur, which would be run before getting/downloading hostProfiles.
Except password, all the credentials needed to run scripts should be exported as same configuration file, while password would be stored in encrypted file with PowerShell SecureString.
Considering generic usage of snips, need to use environemental variables to get target repository information.
Implementing variables below to determine target repository URL:
GH_USERNAME
GH_REPONAME
As almost all of the scripts are provided some command line arguments by user, such as name of clusters or virtual machines, implemented functions to check provided objects would truly exist on the system or not.
If not exists, in case that user would provide some wrong parameters, prompt to user that wrong arguments and stop to operations anymore.
Since user would not have clear requirements for command line parameters, -targetMgrs
and -targetEdges
should be optional ones.
With PowerShell Params()
options, made them as not mandatory args for running script.
function getVmPowerState ($vmname) {
Write-Host "WIP: Functions of getting VM power state..."
Write-Host "Getting power status of $vmname ..."
}
...
function restartVm ($vmname) {
Write-Host "WIP: Functions of restarting VM power state..."
Write-Host "Restarting $vmname ..."
}
For check server availabilities of childScript.ps1
from parentScript.ps1
, implement functions of testing network connections with Test-NetConnection
cmdlet with L4 connectivities.
credentials.txt
that which parameter each script would use.# Common
...
# Parameters for A.ps1
...
# Parameters for B.ps1
...
wait_interval
for running command to each ESXi host.
setHostsMaintenanceMode.ps1
exitHostsMaintenanceMode.ps1
shutdownHosts.ps1
startAllVms.ps1
Since [vsphere_maintenances] contains some scripts for multiple purpose/requirements, add README.md to brief descriptions of each script.
To make clear what the scripts do, rename filename of scripts:
rebootVm.ps1
on primary/secondary remote serverskickRebootVm.ps1
on main server.Currently no encrypted password file would be allocated on the script root directory.
Create password file with PowerShell SecureString, and decode them within the script.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.