From de4ef52ce1393d979a22908bf3ec1e9c15890576 Mon Sep 17 00:00:00 2001 From: nammiesgal Date: Mon, 19 Mar 2018 22:38:37 +1000 Subject: [PATCH] Add snapshot id to snapshot listing and cpu and memory hot add enabled option to vm find (#424) * Test * Revert Change * Add snapshot creation timestamp to snapshot listing to allow users to not only see the current tree of snapshots but to also view the snapshots creation timestamp. Also added option --snapshot-descr DESCR to allow users to add a description when creating a snapshot. Currently, the descripton field is hardcode to an empty string. * fixed 11 violations identified by Hound * fixed 2 violations identified by Hound * Fixed CHANGELOG to use GitHub account name and replaced double quotes around newline character with single quotes. * Refactored display_node method to output snapshot tree hierarchy in json and various other formats. Also added snapshot description to the snapshot info that is outputted. * fix issues identified by hound * fix more changes identified by hound * Fix code to use map when listing snapshots. Removed the shift statement in display_node method as it is no longer required as we are now storing the list of snapshots in a data structure. * fix issues identified by Hound * fix issues identified by Hound * add snapshot id to snapshot listing and cpu and memory hot add enabled to vm find command * Added the flags --cpu-hot-add-enabled and --memory-hot-add-enabled to the readme file --- CHANGELOG | 3 ++- README.md | 4 +++- lib/chef/knife/vsphere_vm_find.rb | 16 ++++++++++++++++ lib/chef/knife/vsphere_vm_snapshot.rb | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3333b090..d20bf358 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,8 @@ knife-vsphere changelog 2.0.4 nammiesgal - Refactored display_node method in vsphere_vm_snapshot.rb to output list of snapshots in a tree hierarchy that can be output in various formats using ui.output. - - Add additional snapshot information to the tree hierarchy + - Add additional snapshot information to the tree hierarchy + - Add cpu and memory hot add enabled flags to vsphere_vm_find.rb 2.0.3 swalberg - If the node exists prior to clone, move to bootstrap 2.0.2 nammiesgal - Add snapshot creation timestamp to snapshot listing. diff --git a/README.md b/README.md index 55d96a79..00f34f6e 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ currently supports the following: * datastore * resource pool -Note: For Windows guests we can run sysprep +Note: For Windows guests we can run FIELDS ## Basic Examples: @@ -211,6 +211,7 @@ FIELDS: ```bash --alarms show alarm status --cpu Show cpu +--cpu-hot-add-enabled Show cpu hot add enabled flag --esx-disk Show esx disks --full-path Show full path --hostname show hostname @@ -220,6 +221,7 @@ FIELDS: --os Show os details --os-disks Show os disks --ram Show ram +--memory-hot-add-enabled Show memory hot add enabled flag --snapshots Show snapshots --tools show tools status ``` diff --git a/lib/chef/knife/vsphere_vm_find.rb b/lib/chef/knife/vsphere_vm_find.rb index 1b15093c..e44b06f9 100644 --- a/lib/chef/knife/vsphere_vm_find.rb +++ b/lib/chef/knife/vsphere_vm_find.rb @@ -39,6 +39,14 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand long: '--cpu', description: 'Show cpu' + option :cpu_hot_add_enabled, + long: '--cpu_hot_add_enabled', + description: 'Show cpu hot add enabled' + + option :memory_hot_add_enabled, + long: '--memory_hot_add_enabled', + description: 'Show memory hot add enabled' + option :ram, long: '--ram', description: 'Show ram' @@ -235,6 +243,14 @@ def run thisvm['ram'] = vm.summary.config.memorySizeMB end + if get_config(:cpu_hot_add_enabled) + thisvm['cpu_hot_add_enabled'] = vm.config.cpuHotAddEnabled + end + + if get_config(:memory_hot_add_enabled) + thisvm['memory_hot_add_enabled'] = vm.config.memoryHotAddEnabled + end + if get_config(:cpu) thisvm['cpu'] = vm.summary.config.numCpu end diff --git a/lib/chef/knife/vsphere_vm_snapshot.rb b/lib/chef/knife/vsphere_vm_snapshot.rb index 30fec0b7..97a37fd8 100644 --- a/lib/chef/knife/vsphere_vm_snapshot.rb +++ b/lib/chef/knife/vsphere_vm_snapshot.rb @@ -147,6 +147,7 @@ def find_node(tree, name) def display_node(node, current) children = node.childSnapshotList.map { |item| display_node(item, current) } snapshot_tree = { 'SnapshotName' => node.name, + 'SnapshotId' => node.id, 'SnapshotDescription' => node.description, 'SnapshotCreationDate' => node.createTime.iso8601, 'Children' => children }