get physical disk for lvm usage?

31 views
Skip to first unread message

Jason McMahan

unread,
Oct 17, 2017, 7:46:26 AM10/17/17
to Puppet Users
Good day,
We were working on the lvm module from the forge and one item that came to mind was the ability to dynamically retrieve the disks then determine which ones may be used for Lvm.

For example sda,sdb,sdc are present. We would like to get the disk in an array or hash possibly and remove or ignore the first item (sda) then add sdb,sdc to lvm for usage.

I thought 
Facter disks like below but was a little unsure best option after that.

$disks = Facter['os']['disks']

{
  fd0 => {
    size => "4.00 KiB",
    size_bytes => 4096
  },
  sda => {
    model => "Virtual Disk",
    size => "128.00 GiB",
    size_bytes => 137438953472,
    vendor => "Msft"
  },
  sdb => {
    model => "Virtual Disk",
    size => "400.00 GiB",
    size_bytes => 429496729600,
    vendor => "Msft"
  },
  sdc => {
    model => "Virtual Disk",
    size => "100.00 GiB",
    size_bytes => 107374182400,
    vendor => "Msft"
  }
}

Suggestions to good information or help would be greatly appreciated.

Thank you

Martijn

unread,
Nov 1, 2017, 7:07:49 AM11/1/17
to Puppet Users
Well, if you do $disks = facts['os']['disks'] (note: facts, not facter), you'll have a hash of all disks in $disks. Some of the functions in puppetlabs-stdlib let you modify hashes. Take a look at delete to drop keys like 'fd0' and 'sda' from the hash, then you can use the remaining hash as input for the LVM module.

Regards, Martijn

jcbollinger

unread,
Nov 1, 2017, 8:51:50 AM11/1/17
to Puppet Users


On Wednesday, November 1, 2017 at 6:07:49 AM UTC-5, Martijn wrote:
Well, if you do $disks = facts['os']['disks'] (note: facts, not facter), you'll have a hash of all disks in $disks. Some of the functions in puppetlabs-stdlib let you modify hashes. Take a look at delete to drop keys like 'fd0' and 'sda' from the hash, then you can use the remaining hash as input for the LVM module.


I have always thought that the stdlib docs are a bit colloquial and imprecise where they describe functions that supposedly modify an array or hash.  What they actually do, I think, is create a new array or hash whose contents match the original, except for the specified modifications.  This is the same distinction as between Ruby's Array.reject! and Array.reject, and although it's a bit subtle, it makes a tremendous difference.  It therefore behooves us to be as clear as possible.


John

Reply all
Reply to author
Forward
0 new messages