noms-client 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/control.m4 ADDED
@@ -0,0 +1,8 @@
1
+ Package: noms-client
2
+ Version: __VERSION__-__RELEASE__
3
+ Architecture: all
4
+ Section: Miscellaneous
5
+ Priority: optional
6
+ Maintainer: Evernote Operations <ops@evernote.com>
7
+ Description: This package is the Evernote-specific noms-client build
8
+
data/etc/noms.conf ADDED
@@ -0,0 +1,11 @@
1
+ { "cmdb": {
2
+ "url": "https://cmdb/cmdb_api/v1",
3
+ "username":"",
4
+ "password":""
5
+ },
6
+ "nagui": {
7
+ "url": "https://nagios/nagui/nagios_live.cgi",
8
+ "username":"",
9
+ "password":""
10
+ }
11
+ }
data/lib/ncc/client.rb ADDED
@@ -0,0 +1,108 @@
1
+ #!ruby
2
+ # /* Copyright 2014 Evernote Corporation. All rights reserved.
3
+ # Copyright 2013 Proofpoint, Inc. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ # */
17
+
18
+
19
+ require 'noms/httpclient'
20
+
21
+ class NCC
22
+
23
+ end
24
+
25
+ class NCC::Client < NOMS::HttpClient
26
+
27
+ def config_key
28
+ 'ncc'
29
+ end
30
+
31
+ # ncc-api (probably due to nginx) returns bad content-types
32
+ def ignore_content_type
33
+ true
34
+ end
35
+
36
+ def info
37
+ do_request :GET => ''
38
+ end
39
+
40
+ def list(cloud=nil)
41
+ if cloud.nil?
42
+ clouds = do_request "clouds"
43
+ clouds.map do |c|
44
+ list c
45
+ end.flatten
46
+ else
47
+ do_request :GET => "clouds/#{cloud}/instances"
48
+ end
49
+ end
50
+
51
+ def instance(cloud, id)
52
+ do_request :GET => "clouds/#{cloud}/instances/#{id}"
53
+ end
54
+
55
+ def clouds(cloudname=nil)
56
+ unless cloudname
57
+ cloudnames = do_request :GET => "clouds"
58
+ cloudnames.map do |cloudname|
59
+ if cloudname.respond_to? :keys
60
+ cloudname
61
+ else
62
+ do_request :GET => "clouds/#{cloudname}"
63
+ end
64
+ end
65
+ else
66
+ do_request :GET => "clouds/#{cloudname}"
67
+ end
68
+ end
69
+
70
+ def create(cloud, attrs)
71
+ do_request :POST => "clouds/#{cloud}/instances",
72
+ :body => attrs
73
+ end
74
+
75
+ def delete(cloud, attrs)
76
+ if attrs.has_key? :id
77
+ do_request :DELETE => "clouds/#{cloud}/instances/#{attrs[:id]}"
78
+ elsif attrs.has_key? :name
79
+ # For now I have to do this--not optimal, should be in NCC-API
80
+ instobj = find_by_name(cloud, attrs[:name])
81
+ if instobj
82
+ do_request :DELETE => "clouds/#{cloud}/instances/#{instobj['id']}"
83
+ else
84
+ raise "No instance found in cloud #{cloud} with name #{attrs[:name]}"
85
+ end
86
+ else
87
+ raise "Need to delete instance by name or id"
88
+ end
89
+ end
90
+
91
+ def find_by_name(cloud, name)
92
+ instobj = (list cloud).find { |i| i['name'] == name }
93
+ end
94
+
95
+ def create(cloud, attrs)
96
+ do_request :POST => "clouds/#{cloud}/instances",
97
+ :body => attrs
98
+ end
99
+
100
+ def instance(cloud, id)
101
+ do_request :GET => "clouds/#{cloud}/instances/#{id}"
102
+ end
103
+
104
+ def console(cloud, id)
105
+ do_request :GET => "clouds/#{cloud}/instances/#{id}/console"
106
+ end
107
+
108
+ end
@@ -0,0 +1,7 @@
1
+ class NOMS
2
+
3
+ end
4
+
5
+ class NOMS::Client
6
+ VERSION = '1.9.0'
7
+ end
data/lib/noms/cmdb.rb ADDED
@@ -0,0 +1,136 @@
1
+ #!ruby
2
+ # /* Copyright 2014 Evernote Corporation. All rights reserved.
3
+ # Copyright 2013 Proofpoint, Inc. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ # */
17
+
18
+ require 'noms/httpclient'
19
+ require 'uri'
20
+
21
+ class NOMS
22
+
23
+ end
24
+
25
+ class NOMS::CMDB < NOMS::HttpClient
26
+
27
+ def self.mockery
28
+ NOMS::CMDB::Mock
29
+ end
30
+
31
+ def config_key
32
+ 'cmdb'
33
+ end
34
+
35
+ def query(type, *condlist)
36
+ do_request(:GET => "#{type}", :query => URI.encode(condlist.join('&')))
37
+ end
38
+
39
+ def help(type)
40
+ do_request(:GET => type, :query => 'help')
41
+ end
42
+
43
+ def key_field_of(type)
44
+ case type
45
+ when 'system'
46
+ 'fqdn'
47
+ else
48
+ 'id'
49
+ end
50
+ end
51
+
52
+ def system(hostname)
53
+ do_request(:GET => "system/#{hostname}")
54
+ end
55
+
56
+ def system_audit(hostname)
57
+ do_request(:GET => "inv_audit", :query => "entity_key=#{hostname}")
58
+ end
59
+
60
+ def get_or_assign_system_name(serial)
61
+ do_request(:GET => "pcmsystemname/#{serial}")
62
+ end
63
+
64
+ def update(type, obj, key=nil)
65
+ key ||= obj[key_field_of(type)]
66
+ do_request(:PUT => "#{type}/#{key}", :body => obj)
67
+ end
68
+
69
+ def tc_post(obj)
70
+ do_request(:POST => "fact", :body => obj)
71
+ end
72
+ def environments
73
+ do_request :GET => 'environments'
74
+ end
75
+
76
+ def environment(env)
77
+ do_request :GET => "environments/#{env}"
78
+ end
79
+
80
+ def create_environment(env, attrs)
81
+ do_request :POST => "environments", :body => attrs.merge({ :name => env })
82
+ environment env
83
+ end
84
+
85
+ def delete_environment(env)
86
+ do_request :DELETE => "environments/#{env}"
87
+ end
88
+
89
+ def services(env)
90
+ do_request :GET => "environments/#{env}/services"
91
+ end
92
+
93
+ def service(env, service)
94
+ do_request :GET => "environments/#{env}/services/#{service}"
95
+ end
96
+
97
+ def update_service(env, service, attrs)
98
+ do_request :PUT => "environments/#{env}/services/#{service}",
99
+ :body => attrs
100
+ end
101
+
102
+ # CMDB API bug means use this endpoint to create
103
+ def create_service(env, service, attrs)
104
+ attrs[:name] = service
105
+ attrs[:environment_name] = env
106
+ do_request :POST => "service_instance", :body => attrs
107
+ do_request :PUT => "environments/#{env}/services/#{service}",
108
+ :body => attrs
109
+ end
110
+
111
+ def delete_service(env, service)
112
+ do_request :DELETE => "environments/#{env}/services/#{service}"
113
+ end
114
+
115
+ end
116
+
117
+ class NOMS::CMDB::Mock < NOMS::HttpClient::RestMock
118
+
119
+ @@machine_id = 0
120
+
121
+ def handle_mock(method, uri, opt)
122
+ if m = Regexp.new('/pcmsystemname/([^/]+)').match(uri.path)
123
+ serial = m[1]
124
+ @@machine_id += 1
125
+ name = "m-%03d.mock" % @@machine_id
126
+ do_request :PUT => "system/#{name}",
127
+ :body => {
128
+ 'serial' => serial,
129
+ 'fqdn' => name
130
+ }
131
+ else
132
+ false
133
+ end
134
+ end
135
+
136
+ end
@@ -0,0 +1,11 @@
1
+ class NOMS
2
+
3
+ end
4
+
5
+ class NOMS::Error < StandardError
6
+
7
+ end
8
+
9
+ class NOMS::Error::Config < NOMS::Error
10
+
11
+ end