Class: NOMS::CMDB

Inherits:
HttpClient show all
Defined in:
lib/noms/cmdb.rb

Defined Under Namespace

Classes: Mock

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HttpClient

#allow_partial_updates, #allow_put_to_create, #dbg, #default_content_type, #handle_mock, #ignore_content_type, #initialize, #ltrim, #method_missing, mock!, #myconfig, #opt, #rtrim, #trim

Constructor Details

This class inherits a constructor from NOMS::HttpClient

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NOMS::HttpClient

Class Method Details

.mockeryObject



27
28
29
# File 'lib/noms/cmdb.rb', line 27

def self.mockery
    NOMS::CMDB::Mock
end

Instance Method Details

#config_keyObject



31
32
33
# File 'lib/noms/cmdb.rb', line 31

def config_key
  'cmdb'
end

#create(type, obj, key = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/noms/cmdb.rb', line 64

def create(type, obj, key=nil)
    keyfield = key_field_of(type)
    objkey = obj[keyfield]

    if key.nil? and objkey.nil?
        raise NOMS::Error, "Must specify a key value or imply it in the object's #{key_field_of(type)} value"
    end
    if (obj.has_key?(keyfield) and (! key.nil?) and obj[keyfield] != key)
        raise NOMS::Error, "You specified different keys for a new #{type} object: #{objkey} in the object vs. #{key}"
    end
    newobj = { keyfield => (objkey || key) }.merge obj
    do_request(:POST => type, :body => newobj)
end

#create_environment(env, attrs) ⇒ Object



94
95
96
97
# File 'lib/noms/cmdb.rb', line 94

def create_environment(env, attrs)
    do_request :POST => "environments", :body => attrs.merge({ :name => env })
    environment env
end

#create_service(env, service, attrs) ⇒ Object

CMDB API bug means use this endpoint to create TODO needs update as this bug is no longer present



118
119
120
121
122
123
124
# File 'lib/noms/cmdb.rb', line 118

def create_service(env, service, attrs)
    attrs[:name] = service
    attrs[:environment_name] = env
    do_request :POST => "service_instance", :body => attrs
    do_request :PUT => "environments/#{env}/services/#{service}",
        :body => attrs
end

#delete_environment(env) ⇒ Object



99
100
101
# File 'lib/noms/cmdb.rb', line 99

def delete_environment(env)
    do_request :DELETE => "environments/#{env}"
end

#delete_service(env, service) ⇒ Object



126
127
128
# File 'lib/noms/cmdb.rb', line 126

def delete_service(env, service)
    do_request :DELETE => "environments/#{env}/services/#{service}"
end

#environment(env) ⇒ Object



90
91
92
# File 'lib/noms/cmdb.rb', line 90

def environment(env)
  do_request :GET => "environments/#{env}"
end

#environmentsObject



86
87
88
# File 'lib/noms/cmdb.rb', line 86

def environments
  do_request :GET => 'environments'
end

#get_or_assign_system_name(serial) ⇒ Object



60
61
62
# File 'lib/noms/cmdb.rb', line 60

def get_or_assign_system_name(serial)
    do_request(:GET => "pcmsystemname/#{serial}")
end

#help(type) ⇒ Object



39
40
41
# File 'lib/noms/cmdb.rb', line 39

def help(type)
    do_request(:GET => type, :query => 'help')
end

#key_field_of(type) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/noms/cmdb.rb', line 43

def key_field_of(type)
    case type
    when 'system'
        'fqdn'
    else
        'id'
    end
end

#query(type, *condlist) ⇒ Object



35
36
37
# File 'lib/noms/cmdb.rb', line 35

def query(type, *condlist)
  do_request(:GET => "#{type}", :query => URI.encode(condlist.join('&')))
end

#service(env, service) ⇒ Object



107
108
109
# File 'lib/noms/cmdb.rb', line 107

def service(env, service)
  do_request :GET => "environments/#{env}/services/#{service}"
end

#services(env) ⇒ Object



103
104
105
# File 'lib/noms/cmdb.rb', line 103

def services(env)
  do_request :GET => "environments/#{env}/services"
end

#system(hostname) ⇒ Object



52
53
54
# File 'lib/noms/cmdb.rb', line 52

def system(hostname)
  do_request(:GET => "system/#{hostname}")
end

#system_audit(hostname) ⇒ Object



56
57
58
# File 'lib/noms/cmdb.rb', line 56

def system_audit(hostname)
  do_request(:GET => "inv_audit", :query => "entity_key=#{hostname}")
end

#tc_post(obj) ⇒ Object



83
84
85
# File 'lib/noms/cmdb.rb', line 83

def tc_post(obj)
    do_request(:POST => "fact", :body => obj)
end

#update(type, obj, key = nil) ⇒ Object



78
79
80
81
# File 'lib/noms/cmdb.rb', line 78

def update(type, obj, key=nil)
    key ||= obj[key_field_of(type)]
    do_request(:PUT => "#{type}/#{key}", :body => obj)
end

#update_service(env, service, attrs) ⇒ Object



111
112
113
114
# File 'lib/noms/cmdb.rb', line 111

def update_service(env, service, attrs)
    do_request :PUT => "environments/#{env}/services/#{service}",
        :body => attrs
end