Class: StudioApi::Appliance

Inherits:
ActiveResource::Base
  • Object
show all
Extended by:
StudioResource
Defined in:
lib/studio_api/appliance.rb

Overview

Represents appliance in studio beside information about itself contains also information about its relative object like packages, signing keys etc Each method try to be ActiveResource compatible, so each can throw ConnectionError

Defined Under Namespace

Classes: Configuration, GpgKey, Repository, Status

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StudioResource

collection_path, element_path, extended, studio_connection, studio_connection=

Class Method Details

.clone(source_id, options = {}) ⇒ StudioApi::Appliance

clones appliance or template

Parameters:

  • source_id (#to_i)

    id of source appliance

  • options (Hash<String,String>) (defaults to: {})

    optional parameters to clone command

Returns:

See Also:

  • (StudioApi(StudioApi::TemplateSet)


272
273
274
275
276
277
278
279
280
281
# File 'lib/studio_api/appliance.rb', line 272

def self.clone source_id,options={}
  request_str = "/appliances?clone_from=#{source_id.to_i}"
  request_str = Util.add_options request_str, options, false
  response = GenericRequest.new(studio_connection).post request_str, options
  if defined? ActiveModel #we are in rails3, so set model persistent
    Appliance.new Hash.from_xml(response)["appliance"],true
  else
    Appliance.new Hash.from_xml(response)["appliance"]
  end
end

Instance Method Details

#add_gpg_key(name, key, options = {}) ⇒ StudioApi::Appliance::GpgKey

add GPG key to appliance

Returns:



303
304
305
306
307
# File 'lib/studio_api/appliance.rb', line 303

def add_gpg_key (name, key, options={})
  my_key = GpgKey.dup
  my_key.studio_connection = self.class.studio_connection
  my_key.create id, name, key, options
end

#add_package(name, options = {}) ⇒ Hash<String,String>

Return status after software change. It contains three keys - state, packages_added and packages_removed

Parameters:

  • options (Hash<#to_s,#to_s>) (defaults to: {})

    optional parameters for adding packages, see api documentation

Returns:

  • (Hash<String,String>)

    return status after software change. It contains three keys - state, packages_added and packages_removed



372
373
374
# File 'lib/studio_api/appliance.rb', line 372

def add_package (name, options={})
	software_command "add_package",{:name => name}.merge(options)
end

#add_pattern(name, options = {}) ⇒ Hash<String,String>

Return status after software change. It contains three keys - state, packages_added and packages_removed

Parameters:

  • options (Hash<#to_s,#to_s>) (defaults to: {})

    optional parameters for adding patterns, see api documentation

Returns:

  • (Hash<String,String>)

    return status after software change. It contains three keys - state, packages_added and packages_removed



395
396
397
# File 'lib/studio_api/appliance.rb', line 395

def add_pattern (name, options={})
	software_command "add_pattern",{:name => name}.merge(options)
end

#add_repository(*repo_ids) ⇒ Array<StudioApi::Repository>

adds repositories to appliance

Examples:

various way to add repo

appl = Appliance.find 1234
appl.add_repository 5678
appl.add_repository [5678,34,56,78,90]
appl.add_repository 5678,34,56,78,90

Parameters:

  • (#to_s, Array<#to_s>)

Returns:



188
189
190
191
192
193
194
195
# File 'lib/studio_api/appliance.rb', line 188

def add_repository (*repo_ids)
  response = nil
  repo_ids.flatten.each do |repo_id|
    rq = GenericRequest.new self.class.studio_connection
    response = rq.post "/appliances/#{id}/cmd/add_repository?repo_id=#{repo_id.to_i}"
  end
  Hash.from_xml(response)["repositories"].collect{ |r| Repository.new r }
end

#add_user(name) ⇒ Object



209
210
211
212
213
# File 'lib/studio_api/appliance.rb', line 209

def add_user name
  request_str = "/appliances/#{id.to_i}/sharing/#{CGI.escape name.to_s}"
  response = GenericRequest.new(self.class.studio_connection).post request_str
  handle_users_response response
end

#add_user_repositoryObject

adds repository for user rpms



198
199
200
201
# File 'lib/studio_api/appliance.rb', line 198

def add_user_repository
  rq = GenericRequest.new self.class.studio_connection
  rq.post "/appliances/#{id}/cmd/add_user_repository"
end

#backgroundObject



244
245
246
247
# File 'lib/studio_api/appliance.rb', line 244

def background
  request_str = "/appliances/#{id.to_i}/configuration/background"
  GenericRequest.new(self.class.studio_connection).get request_str
end

#background=(logo) ⇒ Object



249
250
251
252
253
254
255
256
257
258
# File 'lib/studio_api/appliance.rb', line 249

def background= ()
  request_str = "/appliances/#{id.to_i}/configuration/background"
  if .is_a?(IO) && .respond_to?(:path)
    GenericRequest.new(self.class.studio_connection).post request_str, :file => 
  else
    File.open(.to_s) do |f| 
      GenericRequest.new(self.class.studio_connection).post request_str, :file => f
    end
  end
end

#ban_package(name) ⇒ Hash<String,String>

Return status after software change. It contains three keys - state, packages_added and packages_removed

Returns:

  • (Hash<String,String>)

    return status after software change. It contains three keys - state, packages_added and packages_removed



414
415
416
# File 'lib/studio_api/appliance.rb', line 414

def ban_package(name)
	software_command "ban_package",:name => name
end

#configurationObject

Shortcut to find configuration of appliance. Always ask server for new one.

See Also:



262
263
264
265
# File 'lib/studio_api/appliance.rb', line 262

def configuration
  Configuration.studio_connection = self.class.studio_connection
  Configuration.find id
end

#file_content_from_build(build, src_path) ⇒ String

Gets file content from finished build.

Parameters:

  • build (StudioApi::Build, StudioApi::Appliance::Build)

    from which download file

  • src_path (#to_s)

    path in appliance fs to required file

Returns:

  • (String)

    content of file



148
149
150
151
# File 'lib/studio_api/appliance.rb', line 148

def file_content_from_build (build,src_path)
  rq = GenericRequest.new self.class.studio_connection
  rq.get "/appliances/#{id.to_i}/image_files?build_id=#{build.id.to_i}&path=#{CGI.escape src_path.to_s}"
end

#gpg_key(key_id) ⇒ StudioApi::Appliance::GpgKey?

Gets GPG key assigned to appliance with specified id

Parameters:

  • key_id (#to_s)

    id of requested key

Returns:



294
295
296
297
298
# File 'lib/studio_api/appliance.rb', line 294

def gpg_key( key_id )
  my_key = GpgKey.dup
  my_key.studio_connection = self.class.studio_connection
  my_key.find key_id, :params => { :appliance_id => id }
end

#gpg_keysArray<StudioApi::Appliance::GpgKey>

Gets all GPG keys assigned to appliance

Returns:



285
286
287
288
289
# File 'lib/studio_api/appliance.rb', line 285

def gpg_keys
  my_key = GpgKey.dup
  my_key.studio_connection = self.class.studio_connection
  my_key.find :all, :params => { :appliance_id => id }
end

#installed_software(options = {}) ⇒ Array<StudioApi::Package,StudioApi::Pattern>

Gets list of all installed (include dependencies) software (package and patterns) in appliance

Parameters:

  • hash (Hash)

    of options, see studio API

Returns:



323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/studio_api/appliance.rb', line 323

def installed_software (options = {})
  request_str = "/appliances/#{id.to_i}/software/installed"
  request_str = Util.add_options request_str, options
  response = GenericRequest.new(self.class.studio_connection).get request_str
  attrs = XmlSimple.xml_in response
			res = []
  return res unless attrs["repository"]
			attrs["repository"].each do |repo|
options = { "repository_id" => repo["id"].to_i }
  	res += convert_selectable repo["software"][0], options
			end
			res
end

#logoObject



228
229
230
231
# File 'lib/studio_api/appliance.rb', line 228

def 
  request_str = "/appliances/#{id.to_i}/configuration/logo"
  GenericRequest.new(self.class.studio_connection).get request_str
end

#logo=(logo) ⇒ Object



233
234
235
236
237
238
239
240
241
242
# File 'lib/studio_api/appliance.rb', line 233

def logo= ()
  request_str = "/appliances/#{id.to_i}/configuration/logo"
  if .is_a?(IO) && .respond_to?(:path)
    GenericRequest.new(self.class.studio_connection).post request_str, :file => 
  else
    File.open(.to_s) do |f| 
      GenericRequest.new(self.class.studio_connection).post request_str, :file => f
    end
  end
end

#manifest_file(build, options = {}) ⇒ Object



221
222
223
224
225
226
# File 'lib/studio_api/appliance.rb', line 221

def manifest_file (build, options={})
  build = build.image_type if build.respond_to?(:image_type)
  request_str = "/appliances/#{id.to_i}/software/manifest/#{CGI.escape build.to_s}"
  request_str = Util.add_options request_str, options
  GenericRequest.new(self.class.studio_connection).get request_str
end

#remove_package(name) ⇒ Hash<String,String>

Return status after software change. It contains three keys - state, packages_added and packages_removed

Returns:

  • (Hash<String,String>)

    return status after software change. It contains three keys - state, packages_added and packages_removed



383
384
385
# File 'lib/studio_api/appliance.rb', line 383

def remove_package (name)
	software_command "remove_package",:name => name
end

#remove_pattern(name) ⇒ Hash<String,String>

Return status after software change. It contains three keys - state, packages_added and packages_removed

Returns:

  • (Hash<String,String>)

    return status after software change. It contains three keys - state, packages_added and packages_removed



406
407
408
# File 'lib/studio_api/appliance.rb', line 406

def remove_pattern (name)
	software_command "remove_pattern",:name => name
end

#remove_repository(*repo_ids) ⇒ Array<StudioApi::Repository>

remove repositories from appliance

Examples:

various way to remove repo

appl = Appliance.find 1234
appl.remove_repository 5678
appl.remove_repository [5678,34,56,78,90]
appl.remove_repository 5678,34,56,78,90

Parameters:

  • (#to_s, Array<#to_s>)

Returns:



171
172
173
174
175
176
177
178
# File 'lib/studio_api/appliance.rb', line 171

def remove_repository (*repo_ids)
  response = nil
  repo_ids.flatten.each do |repo_id|
    rq = GenericRequest.new self.class.studio_connection
    response = rq.post "/appliances/#{id}/cmd/remove_repository?repo_id=#{repo_id.to_i}"
  end
  Hash.from_xml(response)["repositories"].collect{ |r| Repository.new r }
end

#remove_user(name) ⇒ Object



215
216
217
218
219
# File 'lib/studio_api/appliance.rb', line 215

def remove_user name
  request_str = "/appliances/#{id.to_i}/sharing/#{CGI.escape name.to_s}"
  response = GenericRequest.new(self.class.studio_connection).delete request_str
  handle_users_response response
end

#repositoriesStudioApi::Appliance::Repository

Gets all repositories assigned to appliance

Returns:



155
156
157
158
159
160
# File 'lib/studio_api/appliance.rb', line 155

def repositories
  my_repo = Repository.dup
  my_repo.studio_connection = self.class.studio_connection
  my_repo.appliance = self
  my_repo.find :all, :params => { :appliance_id => id }
end

#rpm_content(name, options = {}) ⇒ Object

Returns rpm file as String

Parameters:

  • name (#to_s)

    of rpm

  • options (Hash<#to_s,#to_s>) (defaults to: {})

    additional options, see API documentation



358
359
360
361
362
# File 'lib/studio_api/appliance.rb', line 358

def rpm_content(name, options={})
  request_str = "/appliances/#{id.to_i}/cmd/download_package?name=#{CGI.escape name.to_s}"
  request_str = Util.add_options request_str, options, false
  GenericRequest.new(self.class.studio_connection).get request_str
end

#search_software(search_string, options = {}) ⇒ Array<StudioApi::Package,StudioApi::Pattern>

Search software (package and patterns) in appliance

Parameters:

  • search_string (#to_s)

    string which is used for search

  • options (Hash<#to_s,#to_s>) (defaults to: {})

    optional parameters for search, see api documentation

Returns:



341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/studio_api/appliance.rb', line 341

def search_software (search_string,options={})
  request_str = "/appliances/#{id.to_i}/software/search?q=#{CGI.escape search_string.to_s}"
  request_str = Util.add_options request_str, options, false
  response = GenericRequest.new(self.class.studio_connection).get request_str
  attrs = XmlSimple.xml_in response
  return [] unless attrs["repository"]
			res = []
			attrs["repository"].each do |repo|
options = { "repository_id" => repo["id"].to_i }
  	res += convert_selectable repo["software"][0], options
			end
			res
end

#selected_softwareArray<StudioApi::Package,StudioApi::Pattern>

Gets list of all explicitelly selected software ( package and patterns) in appliance

Returns:



312
313
314
315
316
317
# File 'lib/studio_api/appliance.rb', line 312

def selected_software
  request_str = "/appliances/#{id.to_i}/software"
  response = GenericRequest.new(self.class.studio_connection).get request_str
  attrs = XmlSimple.xml_in response
  convert_selectable attrs
end

#statusStudioApi::Appliance::Status

gets status of appliance

Returns:



136
137
138
139
140
141
142
# File 'lib/studio_api/appliance.rb', line 136

def status
  my_status = Status#.dup FIXME this doesn't work well with AciveResource :(
  my_status.studio_connection = self.class.studio_connection
  #rails is so smart, that it ignores prefix for calls. At least it is good that we don't want to do such things from library users
  from = Util.join_relative_url( self.class.site.path,"appliances/#{id.to_i}/status")
  my_status.find :one, :from => from
end

#unban_package(name) ⇒ Hash<String,String>

Return status after software change. It contains three keys - state, packages_added and packages_removed

Returns:

  • (Hash<String,String>)

    return status after software change. It contains three keys - state, packages_added and packages_removed



422
423
424
# File 'lib/studio_api/appliance.rb', line 422

def unban_package(name)
	software_command "unban_package",:name => name
end

#usersObject



203
204
205
206
207
# File 'lib/studio_api/appliance.rb', line 203

def users
  request_str = "/appliances/#{id.to_i}/sharing"
  response = GenericRequest.new(self.class.studio_connection).get request_str
  handle_users_response response
end