Class: NCC
- Inherits:
-
Object
show all
- Defined in:
- lib/ncc/error.rb,
lib/ncc/config.rb,
lib/ncc/version.rb,
lib/ncc/instance.rb,
lib/ncc/connection.rb,
lib/ncc.rb
Defined Under Namespace
Classes: Config, Configurator, Connection, Error, Instance
Constant Summary
collapse
- VERSION =
'1.2.2'
- @@global_config =
NCC::Configurator.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config_path = nil, opt = {}) ⇒ NCC
Returns a new instance of NCC.
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/ncc.rb', line 47
def initialize(config_path=nil, opt={})
@logger = opt[:logger] || @@global_config.logger
config_path ||= @@global_config.config_path
config_path = [config_path] unless config_path.respond_to? :unshift
config_path.unshift(File.join(ENV['NCCAPI_HOME'], 'etc')) if
ENV['NCCAPI_HOME']
info "Loading configuration from: #{config_path.inspect}"
@config = NCC::Config.new(config_path, :logger => @logger)
@inventory = NOMS::CMDB.new(@config)
@clouds = { }
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
39
40
41
|
# File 'lib/ncc.rb', line 39
def config
@config
end
|
#inventory ⇒ Object
Returns the value of attribute inventory.
39
40
41
|
# File 'lib/ncc.rb', line 39
def inventory
@inventory
end
|
Class Method Details
43
44
45
|
# File 'lib/ncc.rb', line 43
def self.configure
yield @@global_config
end
|
Instance Method Details
#api_url ⇒ Object
118
119
120
121
122
123
124
|
# File 'lib/ncc.rb', line 118
def api_url
if @config['services'].has_key? 'v2api'
@config['services']['v2api']
else
'http://localhost/ncc_api/v2'
end
end
|
#clouds(cloud = nil, opt = {}) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/ncc.rb', line 86
def clouds(cloud=nil, opt={})
if cloud.nil?
@config[:clouds].keys
else
connect(cloud, :logger => @logger)
end
end
|
#connect(cloud, opt = {}) ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/ncc.rb', line 75
def connect(cloud, opt={})
if ! @config[:clouds].has_key? cloud
raise NCC::Error::NotFound, "Cloud #{cloud} not provided"
end
@clouds[cloud] ||= NCC::Connection.connect(self, cloud, opt)
if @clouds[cloud].nil? or ! @clouds[cloud].current?
@clouds[cloud] = NCC::Connection.connect(self, cloud, opt)
end
@clouds[cloud]
end
|
#debug(msg) ⇒ Object
59
60
61
62
63
|
# File 'lib/ncc.rb', line 59
def debug(msg)
if @logger and @logger.respond_to? :debug
@logger.debug "#{me}: #{msg}"
end
end
|
#images(image = nil) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/ncc.rb', line 106
def images(image=nil)
if image.nil?
@config[:images].to_array
else
if @config[:images].has_key? image
@config[:images][image].to_hash
else
raise NCC::Error::NotFound, "No such image #{image.inspect}"
end
end
end
|
#info(msg) ⇒ Object
65
66
67
68
69
|
# File 'lib/ncc.rb', line 65
def info(msg)
if @logger and @logger.respond_to? :info
@logger.info "#{me}: #{msg}"
end
end
|
#me ⇒ Object
71
72
73
|
# File 'lib/ncc.rb', line 71
def me
self.class
end
|
#sizes(size = nil) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/ncc.rb', line 94
def sizes(size=nil)
if size.nil?
@config[:sizes].to_array
else
if @config[:sizes].has_key? size
@config[:sizes][size].to_hash
else
raise NCC::Error::NotFound, "No such size #{size.inspect}"
end
end
end
|