Advertisement
treydock

Untitled

May 5th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.78 KB | None | 0 0
  1. ENV['FOREMAN_YML'] ||= File.expand_path(File.join(File.dirname(__FILE__), 'foreman.yml'))
  2.  
  3. require 'foreman_api'
  4. require 'pry'
  5. require 'rest_client'
  6. require 'yaml'
  7. require 'json'
  8. require 'pp'
  9.  
  10. config = YAML.load(File.read(ENV['FOREMAN_YML']))
  11.  
  12. options = {
  13.   :base_url => config['url'],
  14.   :username => config['username'],
  15.   :password => config['password'],
  16. }
  17.  
  18. SmartClassParameter = ForemanApi::Resources::SmartClassParameter.new(options)
  19. ib_interfaces = SmartClassParameter.index(:search => 'puppetclass = infiniband and key = interfaces')[0]['results'].first
  20. ib_interfaces_id = ib_interfaces['id']
  21.  
  22. ib_interface_data = {
  23.   'override_value'  => {
  24.     'match' => 'fqdn=c0936.brazos.tamu.edu',
  25.     'value' => {'ib0'=>{'ipaddr'=>'192.168.209.98','netmask'=>'255.255.252.0'}},
  26.   }
  27. }
  28.  
  29. pp ib_interface_data
  30.  
  31. =begin
  32. {"override_value"=>
  33.   {"match"=>"fqdn=c0936.brazos.tamu.edu",
  34.    "value"=>{"ib0"=>{"ipaddr"=>"192.168.209.98", "netmask"=>"255.255.252.0"}}}}
  35. =end
  36.  
  37. rest_opts = {
  38.   :content_type => 'application/json',
  39.   :accept => 'application/json;version=2',
  40. }
  41.  
  42. rest_url_base = "https://#{config['username']}:#{config['password']}@foreman.brazos.tamu.edu"
  43.  
  44. response = RestClient.post("#{rest_url_base}/api/smart_class_parameters/#{ib_interfaces_id}/override_values", ib_interface_data.to_json, rest_opts)
  45.  
  46. data = JSON.parse(response)
  47.  
  48. pp data
  49.  
  50. =begin
  51. {"id"=>372,
  52.  "match"=>"fqdn=c0936.DOMAIN_OMITTED",
  53.  "value"=>{"ib0"=>{"ipaddr"=>"192.168.209.98", "netmask"=>"255.255.252.0"}},
  54.  "created_at"=>"2014-05-05T16:49:11Z",
  55.  "updated_at"=>"2014-05-05T16:49:11Z"}
  56. =end
  57.  
  58. exit 0
  59.  
  60. =begin
  61. Value in Foreman:
  62.  
  63. --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  64. ib0: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  65.   ipaddr: 192.168.209.98
  66.   netmask: 255.255.252.0
  67.  
  68. =end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement