Skip to content

Commit

Permalink
Add disk and partitions info
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard authored and chris1984 committed Jun 22, 2023
1 parent 8efced7 commit ddc5f49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/fog/vsphere/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ module Shared
tools_version: 'guest.toolsVersionStatus',
memory_mb: 'config.hardware.memoryMB',
cpus: 'config.hardware.numCPU',
disks: 'config.hardware.device',
partitions: 'guest.disk',
corespersocket: 'config.hardware.numCoresPerSocket',
overall_status: 'overallStatus',
guest_id: 'config.guestId',
Expand Down Expand Up @@ -252,6 +254,8 @@ def props_to_attr_hash(vm_mob_ref, props)
end
}

attrs['disks'] = parse_disks(attrs['disks'])
attrs['partitions'] = parse_partitions(attrs['partitions'])
attrs['extra_config'] = parse_extra_config(attrs['extra_config'])
end
# This inline rescue catches any standard error. While a VM is
Expand Down Expand Up @@ -317,6 +321,20 @@ def parse_extra_config(vm_extra_config)
vm_extra_config.map { |entry| [entry[:key], entry[:value]] }.to_h
end

def parse_disks(vm_disks)
return unless vm_disks.is_a?(Array)
vm_disks.grep(RbVmomi::VIM::VirtualDisk).map do |d|
{ :label => d.deviceInfo.label, :capacity => d.capacityInBytes }
end
end

def parse_partitions(vm_partitions)
return unless vm_partitions.is_a?(Array)
vm_partitions.grep(RbVmomi::VIM::GuestDiskInfo).map do |p|
{ :path => p.diskPath, :free => p.freeSpace, :capacity => p.capacity }
end
end

# returns vmware managed obj id string
def managed_obj_id(obj)
obj.to_s.match(/\("([^"]+)"\)/)[1]
Expand Down
2 changes: 2 additions & 0 deletions lib/fog/vsphere/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Server < Fog::Compute::Server
attribute :path
attribute :memory_mb
attribute :cpus
attribute :disks
attribute :partitions
attribute :corespersocket
attribute :interfaces
attribute :volumes
Expand Down

0 comments on commit ddc5f49

Please sign in to comment.