-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c0c287
commit 7eb66d7
Showing
9 changed files
with
146 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
class VirtualMachine { | ||
static props = ['virtualMachineID', 'managedObjectID', 'uuid', 'hostID', 'nodeID', 'resourcePoolID', 'vMConfigFile', 'memoryConfigured', 'memoryShares', 'cPUShares', 'guestState', 'iPAddress', 'logDirectory', 'guestVmWareToolsVersion', 'guestVmWareToolsStatus', 'name', 'guestName', 'guestFamily', 'guestDnsName', 'nicCount', 'vDisksCount', 'processorCount', 'powerState', 'bootTime', 'configStatus', 'overallStatus', 'nodeStatus', 'networkUsageRate', 'networkTransmitRate', 'networkReceiveRate', 'cpuLoad', 'cpuUsageMHz', 'memUsage', 'memUsageMB', 'isLicensed', 'platformID', 'pollingSource', 'relativePath', 'datastoreIdentifier', 'cpuReady', 'swappedMemoryUtilization', 'swappedMemoryUtilizationPercent', 'balloonMemload', 'balloonMemloadPercent', 'iOPSTotal', 'iOPSRead', 'iOPSWrite', 'latencyTotal', 'latencyRead', 'latencyWrite', 'snapshotStorageSize', 'consumedMemLoad', 'consumedPercentMemLoad', 'lastActivityDate', 'totalStorageSize', 'totalStorageSizeUsed', 'volumeSummaryCapacity', 'volumeSummaryFreeSpace', 'volumeSummaryFreeSpacePercent', 'volumeSummaryCapacityDepletionDate', 'triggeredAlarmDescription', 'orionIdPrefix', 'orionIdColumn', 'runTime', 'cpuCostop', 'dynamicMemoryEnabled', 'snapshotSummaryCount', 'dateCreated', 'oldestSnapshotDate', 'heartBeat', 'snapshotDateModified', 'memoryAllocationLimit', 'virtualDiskDateModified', 'detailsUrl', 'status', 'statusDescription', 'statusLED', 'unManaged', 'unManageFrom', 'unManageUntil', 'image', 'ancestorDisplayNames', 'ancestorDetailsUrls', 'statusIconHint', 'displayName', 'description', 'instanceType', 'uri'] | ||
|
||
constructor(vm) { | ||
Object.keys(vm).forEach(key => { | ||
Object.assign(this, { [key]: vm[key] }) | ||
}) | ||
} | ||
|
||
os() { | ||
switch (this.guestFamily) { | ||
case 'windowsGuest': | ||
return 'Windows' | ||
case 'linuxGuest': | ||
return 'Linux' | ||
default: | ||
return 'Unknown' | ||
} | ||
} | ||
} | ||
|
||
export default VirtualMachine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env node | ||
|
||
import program from 'commander' | ||
import Table from 'easy-table' | ||
|
||
import { print, error } from './utils' | ||
import SolarWinds from './' | ||
|
||
const solarwinds = new SolarWinds() | ||
|
||
program | ||
.command('list') | ||
.alias('ls') | ||
.description('List all available virtual machines') | ||
.action(async () => { | ||
try { | ||
const vms = await solarwinds.virtualMachines.query() | ||
const table = new Table() | ||
|
||
vms.forEach(vm => { | ||
table.cell('ID', vm.virtualMachineID) | ||
table.cell('NAME', vm.name) | ||
table.cell('IP', vm.iPAddress) | ||
table.cell('OS', vm.os()) | ||
table.newRow() | ||
}) | ||
|
||
console.log(table.toString()) | ||
} catch (err) { | ||
error(err) | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
program | ||
.command('inspect <VM>') | ||
.description('Display detailed information about a virtual machine') | ||
.action(async (id) => { | ||
try { | ||
const vm = isNaN(id) ? await solarwinds.virtualMachines.findByName(id) : await solarwinds.virtualMachines.find(id) | ||
print(vm) | ||
} catch (err) { | ||
error(err) | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
program.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
import VirtualMachine from './models/virtualMachine' | ||
|
||
const props = [ | ||
'VirtualMachineID AS id', 'Name', 'IPAddress', 'NodeID', | ||
'StatusDescription', | ||
].join(', ') | ||
|
||
class VirtualMachines { | ||
props = VirtualMachine.props.join() | ||
table = 'Orion.VIM.VirtualMachines' | ||
|
||
constructor(client) { | ||
this.client = client | ||
} | ||
|
||
async query() { | ||
const vms = await this.client.query(`SELECT ${props} FROM Orion.VIM.VirtualMachines`) | ||
const vms = await this.client.query(` | ||
SELECT ${this.props} | ||
FROM ${this.table} | ||
ORDER BY VirtualMachineID | ||
`) | ||
|
||
return vms.map(x => new VirtualMachine(x)) | ||
} | ||
|
||
async find(id) { | ||
const res = await this.client.read(`Orion/${this.table}/VirtualMachineID=${id}`) | ||
|
||
return new VirtualMachine(res) | ||
} | ||
|
||
async findByName(name) { | ||
const res = await this.client.query(` | ||
SELECT TOP 1 ${this.props} | ||
FROM ${this.table} | ||
WHERE name LIKE '%${name.toLowerCase()}%' | ||
`) | ||
|
||
return new VirtualMachine(res[0]) | ||
} | ||
|
||
} | ||
|
||
export default VirtualMachines |