Skip to content

Instantly share code, notes, and snippets.

@joemiller
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save joemiller/f9cd00277403d5f80381 to your computer and use it in GitHub Desktop.

Select an option

Save joemiller/f9cd00277403d5f80381 to your computer and use it in GitHub Desktop.
rackspace cell ID (sorta) in ohai v7
# Test:
# $ ohai -d `pwd` rackspace
#
# this plugin adds the rackspace cell to the rackspace cloud data
def private_gateway
_, stdout, _ = run_command(no_status_check: true, command: "ip route show | grep eth1 | grep via | head -1 | awk '{print $3}'")
if stdout.length > 0
return stdout
else
return nil
end
rescue Ohai::Exceptions::Exec
return nil
end
# Get rackspace cloud "cell".
def find_cell
cell_map = {
'10.223.240.1' => 'ord-a0001',
'10.223.224.1' => 'ord-a0002',
'10.223.192.1' => 'ord-a0003',
'10.223.176.1' => 'ord-a0004',
'10.223.144.1' => 'ord-a0005',
'10.223.96.1' => 'ord-a0006',
'10.209.64.1' => 'ord-b0001',
'10.209.96.1' => 'ord-b0002',
'10.209.128.1' => 'ord-b0003',
'10.209.160.1' => 'ord-b0004',
'10.210.32.1' => 'ord-b0005',
'10.210.64.1' => 'ord-b0006',
'10.210.0.1' => 'ord-b0007',
'10.210.96.1' => 'ord-b0008',
'10.210.128.1' => 'ord-b0009',
'10.210.192.1' => 'ord-b0010',
'10.211.0.1' => 'ord-b0011',
'10.176.160.1' => 'ord-c0001',
'10.177.0.1' => 'ord-c0002',
'10.176.192.1' => 'ord-c0003',
'10.176.128.1' => 'ord-c0004',
'10.176.96.1' => 'ord-c0005',
'10.177.128.1' => 'ord-c0006',
'10.178.0.1' => 'ord-c0007',
'10.178.128.1' => 'ord-c0008',
'10.178.192.1' => 'ord-c0009',
'10.208.0.1' => 'ord-c0010',
'10.208.128.1' => 'ord-c0011',
'10.209.0.1' => 'ord-c0012'
}
cell_map[private_gateway] || private_gateway
end
Ohai.plugin(:RackspaceCell) do
provides 'rackspace/cell'
depends 'rackspace'
collect_data do
unless rackspace.nil?
Ohai::Log.info('Rackspace_cell: rackspace detected, adding cell to OHAI data')
rackspace[:cell] = find_cell
Ohai::Log.info("ohai 'cloud' data: #{cloud.inspect}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment