class StudioApi::Appliance

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

Public Class Methods

clone(source_id,options={}) click to toggle source

clones appliance or template @see (StudioApi::TemplateSet) @param (to_i) source_id id of source appliance @param (Hash<String,String>) options optional parameters to clone command @return (StudioApi::Appliance) resulted appliance

    # File lib/studio_api/appliance.rb
274 def self.clone source_id,options={}
275   request_str = "/appliances?clone_from=#{source_id.to_i}"
276   request_str = Util.add_options request_str, options, false
277   response = GenericRequest.new(studio_connection).post request_str, options
278   if defined? ActiveModel #we are in rails3, so set model persistent
279     Appliance.new Hash.from_xml(response)["appliance"],true
280   else
281     Appliance.new Hash.from_xml(response)["appliance"]
282   end
283 end

Private Class Methods

custom_method_collection_url(method_name,options = {}) click to toggle source
    # File lib/studio_api/appliance.rb
440 def self.custom_method_collection_url(method_name,options = {})
441   prefix_options, query_options = split_options(options)
442   "#{prefix(prefix_options)}#{collection_name}#{query_string query_options}"
443 end

Public Instance Methods

add_gpg_key(name, key, options={}) click to toggle source

add GPG key to appliance @params (see GpgKey#create) @return [StudioApi::Appliance::GpgKey] created key

    # File lib/studio_api/appliance.rb
305 def add_gpg_key (name, key, options={})
306   my_key = GpgKey.dup
307   my_key.studio_connection = self.class.studio_connection
308   my_key.create id, name, key, options
309 end
add_package(name, options={}) click to toggle source

Select new package to be installed in appliance.

Dependencies is automatic resolved, but its repository have to be already included in appliance @param(to_s) name of package @param (Hash<#to_s,#to_s>) options optional parameters for adding packages, see api documentation @return [Hash<String,String>] return status after software change. It contains

three keys - state, packages_added and packages_removed
    # File lib/studio_api/appliance.rb
374 def add_package (name, options={})
375         software_command "add_package",{:name => name}.merge(options)
376 end
add_pattern(name, options={}) click to toggle source

Select new pattern to be installed in appliance.

Dependencies is automatic resolved, but its repositories have to be already included in appliance @param(to_s) name of pattern @param (Hash<#to_s,#to_s>) options optional parameters for adding patterns, see api documentation @return [Hash<String,String>] return status after software change. It contains

three keys - state, packages_added and packages_removed
    # File lib/studio_api/appliance.rb
397 def add_pattern (name, options={})
398         software_command "add_pattern",{:name => name}.merge(options)
399 end
add_repository(*repo_ids) click to toggle source

adds repositories to appliance @param (to_s,Array<#to_s>) @return (Array<StudioApi::Repository>) list of all repositories including new one @example 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
    # File lib/studio_api/appliance.rb
190 def add_repository (*repo_ids)
191   response = nil
192   repo_ids.flatten.each do |repo_id|
193     rq = GenericRequest.new self.class.studio_connection
194     response = rq.post "/appliances/#{id}/cmd/add_repository?repo_id=#{repo_id.to_i}"
195   end
196   Hash.from_xml(response)["repositories"].collect{ |r| Repository.new r }
197 end
add_user(name) click to toggle source
    # File lib/studio_api/appliance.rb
211 def add_user name
212   request_str = "/appliances/#{id.to_i}/sharing/#{CGI.escape name.to_s}"
213   response = GenericRequest.new(self.class.studio_connection).post request_str
214   handle_users_response response
215 end
add_user_repository() click to toggle source

adds repository for user rpms

    # File lib/studio_api/appliance.rb
200 def add_user_repository
201   rq = GenericRequest.new self.class.studio_connection
202   rq.post "/appliances/#{id}/cmd/add_user_repository"
203 end
background() click to toggle source
    # File lib/studio_api/appliance.rb
246 def background
247   request_str = "/appliances/#{id.to_i}/configuration/background"
248   GenericRequest.new(self.class.studio_connection).get request_str
249 end
background=(logo) click to toggle source
    # File lib/studio_api/appliance.rb
251 def background= (logo)
252   request_str = "/appliances/#{id.to_i}/configuration/background"
253   if logo.is_a?(IO) && logo.respond_to?(:path)
254     GenericRequest.new(self.class.studio_connection).post request_str, :file => logo
255   else
256     File.open(logo.to_s) do |f| 
257       GenericRequest.new(self.class.studio_connection).post request_str, :file => f
258     end
259   end
260 end
ban_package(name) click to toggle source

Bans package ( so it cannot be installed even as dependency). @param(to_s) name of package @return [Hash<String,String>] return status after software change. It contains

three keys - state, packages_added and packages_removed
    # File lib/studio_api/appliance.rb
416 def ban_package(name)
417         software_command "ban_package",:name => name
418 end
configuration() click to toggle source

Shortcut to find configuration of appliance. Always ask server for new one. @see StudioApi::Appliance::Configuration

    # File lib/studio_api/appliance.rb
264 def configuration
265   Configuration.studio_connection = self.class.studio_connection
266   Configuration.find id
267 end
file_content_from_build(build,src_path) click to toggle source

Gets file content from finished build. @param [StudioApi::Build, StudioApi::Appliance::Build] build from which download file @param [#to_s] src_path path in appliance fs to required file @return [String] content of file

    # File lib/studio_api/appliance.rb
150 def file_content_from_build (build,src_path)
151   rq = GenericRequest.new self.class.studio_connection
152   rq.get "/appliances/#{id.to_i}/image_files?build_id=#{build.id.to_i}&path=#{CGI.escape src_path.to_s}"
153 end
gpg_key( key_id ) click to toggle source

Gets GPG key assigned to appliance with specified id @param (to_s) key_id id of requested key @return [StudioApi::Appliance::GpgKey,nil] found key or nil if it is not found

    # File lib/studio_api/appliance.rb
296 def gpg_key( key_id )
297   my_key = GpgKey.dup
298   my_key.studio_connection = self.class.studio_connection
299   my_key.find key_id, :params => { :appliance_id => id }
300 end
gpg_keys() click to toggle source

Gets all GPG keys assigned to appliance @return [Array<StudioApi::Appliance::GpgKey>] included keys

    # File lib/studio_api/appliance.rb
287 def gpg_keys
288   my_key = GpgKey.dup
289   my_key.studio_connection = self.class.studio_connection
290   my_key.find :all, :params => { :appliance_id => id }
291 end
installed_software(options = {}) click to toggle source

Gets list of all installed (include dependencies) software (package and patterns) in appliance @param (Hash) hash of options, see studio API @return (Array<StudioApi::Package,StudioApi::Pattern>) list of installed packages and patterns

    # File lib/studio_api/appliance.rb
325 def installed_software (options = {})
326   request_str = "/appliances/#{id.to_i}/software/installed"
327   request_str = Util.add_options request_str, options
328   response = GenericRequest.new(self.class.studio_connection).get request_str
329   attrs = XmlSimple.xml_in response
330                     res = []
331   return res unless attrs["repository"]
332                     attrs["repository"].each do |repo|
333                             options = { "repository_id" => repo["id"].to_i }
334     res += convert_selectable repo["software"][0], options
335                     end
336                     res
337 end
logo=(logo) click to toggle source
    # File lib/studio_api/appliance.rb
235 def logo= (logo)
236   request_str = "/appliances/#{id.to_i}/configuration/logo"
237   if logo.is_a?(IO) && logo.respond_to?(:path)
238     GenericRequest.new(self.class.studio_connection).post request_str, :file => logo
239   else
240     File.open(logo.to_s) do |f| 
241       GenericRequest.new(self.class.studio_connection).post request_str, :file => f
242     end
243   end
244 end
manifest_file(build, options={}) click to toggle source
    # File lib/studio_api/appliance.rb
223 def manifest_file (build, options={})
224   build = build.image_type if build.respond_to?(:image_type)
225   request_str = "/appliances/#{id.to_i}/software/manifest/#{CGI.escape build.to_s}"
226   request_str = Util.add_options request_str, options
227   GenericRequest.new(self.class.studio_connection).get request_str
228 end
remove_package(name) click to toggle source

Deselect package from appliance.

Dependencies is automatic resolved (so unneeded dependencies not installed), but unused repositories is kept @param(to_s) name of package @return [Hash<String,String>] return status after software change. It contains

three keys - state, packages_added and packages_removed
    # File lib/studio_api/appliance.rb
385 def remove_package (name)
386         software_command "remove_package",:name => name
387 end
remove_pattern(name) click to toggle source

Deselect pattern from appliance.

Dependencies is automatic resolved (so unneeded dependencies not installed), but unused repositories is kept @param(to_s) name of pattern @return [Hash<String,String>] return status after software change. It contains

three keys - state, packages_added and packages_removed
    # File lib/studio_api/appliance.rb
408 def remove_pattern (name)
409         software_command "remove_pattern",:name => name
410 end
remove_repository(*repo_ids) click to toggle source

remove repositories from appliance @param (to_s,Array<#to_s>) @return (Array<StudioApi::Repository>) list of remaining repositories @example 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
    # File lib/studio_api/appliance.rb
173 def remove_repository (*repo_ids)
174   response = nil
175   repo_ids.flatten.each do |repo_id|
176     rq = GenericRequest.new self.class.studio_connection
177     response = rq.post "/appliances/#{id}/cmd/remove_repository?repo_id=#{repo_id.to_i}"
178   end
179   Hash.from_xml(response)["repositories"].collect{ |r| Repository.new r }
180 end
remove_user(name) click to toggle source
    # File lib/studio_api/appliance.rb
217 def remove_user name
218   request_str = "/appliances/#{id.to_i}/sharing/#{CGI.escape name.to_s}"
219   response = GenericRequest.new(self.class.studio_connection).delete request_str
220   handle_users_response response
221 end
repositories() click to toggle source

Gets all repositories assigned to appliance @return [StudioApi::Appliance::Repository] assigned repositories

    # File lib/studio_api/appliance.rb
157 def repositories
158   my_repo = Repository.dup
159   my_repo.studio_connection = self.class.studio_connection
160   my_repo.appliance = self
161   my_repo.find :all, :params => { :appliance_id => id }
162 end
rpm_content(name, options={}) click to toggle source

Returns rpm file as String @param (to_s) name of rpm @param (Hash<#to_s,#to_s>) options additional options, see API documentation

    # File lib/studio_api/appliance.rb
360 def rpm_content(name, options={})
361   request_str = "/appliances/#{id.to_i}/cmd/download_package?name=#{CGI.escape name.to_s}"
362   request_str = Util.add_options request_str, options, false
363   GenericRequest.new(self.class.studio_connection).get request_str
364 end
search_software(search_string,options={}) click to toggle source

Search software (package and patterns) in appliance @param (to_s) search_string string which is used for search @param (Hash<#to_s,#to_s>) options optional parameters for search, see api documentation @return (Array<StudioApi::Package,StudioApi::Pattern>) list of installed packages and patterns

    # File lib/studio_api/appliance.rb
343 def search_software (search_string,options={})
344   request_str = "/appliances/#{id.to_i}/software/search?q=#{CGI.escape search_string.to_s}"
345   request_str = Util.add_options request_str, options, false
346   response = GenericRequest.new(self.class.studio_connection).get request_str
347   attrs = XmlSimple.xml_in response
348   return [] unless attrs["repository"]
349                     res = []
350                     attrs["repository"].each do |repo|
351                             options = { "repository_id" => repo["id"].to_i }
352     res += convert_selectable repo["software"][0], options
353                     end
354                     res
355 end
selected_software() click to toggle source

Gets list of all explicitelly selected software ( package and patterns) in appliance @return (Array<StudioApi::Package,StudioApi::Pattern>) list of selected packages and patterns

    # File lib/studio_api/appliance.rb
314 def selected_software
315   request_str = "/appliances/#{id.to_i}/software"
316   response = GenericRequest.new(self.class.studio_connection).get request_str
317   attrs = XmlSimple.xml_in response
318   convert_selectable attrs
319 end
status() click to toggle source

gets status of appliance @return [StudioApi::Appliance::Status] resource of status

    # File lib/studio_api/appliance.rb
138 def status
139   my_status = Status#.dup FIXME this doesn't work well with AciveResource :(
140   my_status.studio_connection = self.class.studio_connection
141   #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
142   from = Util.join_relative_url( self.class.site.path,"appliances/#{id.to_i}/status")
143   my_status.find :one, :from => from
144 end
unban_package(name) click to toggle source

Unbans package ( so then it can be installed). @param(to_s) name of package @return [Hash<String,String>] return status after software change. It contains

three keys - state, packages_added and packages_removed
    # File lib/studio_api/appliance.rb
424 def unban_package(name)
425         software_command "unban_package",:name => name
426 end
users() click to toggle source
    # File lib/studio_api/appliance.rb
205 def users
206   request_str = "/appliances/#{id.to_i}/sharing"
207   response = GenericRequest.new(self.class.studio_connection).get request_str
208   handle_users_response response
209 end

Private Instance Methods

convert_selectable(attrs, preset_options = {}) click to toggle source
    # File lib/studio_api/appliance.rb
445 def convert_selectable attrs, preset_options = {}
446   res = []
447   (attrs["pattern"]||[]).each do |pattern|
448     res << create_model_based_on_attrs(Pattern, pattern, preset_options)
449   end
450   (attrs["package"]||[]).each do |package|
451     res << create_model_based_on_attrs( Package, package, preset_options)
452   end
453   res
454 end
create_model_based_on_attrs(model, attrs, preset_options) click to toggle source

generic factory to create model based on attrs which can be string of hash of options + content which is same as string

    # File lib/studio_api/appliance.rb
457 def create_model_based_on_attrs model, attrs, preset_options
458   case attrs
459   when Hash
460       name = attrs.delete "content"
461       model.new(name, preset_options.merge(attrs))
462   when String
463       model.new(attrs)
464   else
465       raise "Unknown format of element #{model}"
466   end
467 end
custom_method_element_url(method_name,options = {}) click to toggle source

studio post method for clone is special, as it sometime doesn't have element inside

    # File lib/studio_api/appliance.rb
435 def custom_method_element_url(method_name,options = {})
436   prefix_options, query_options = split_options(options)
437   method_string = method_name.blank? ? "" : "/#{method_name}"
438   "#{self.class.prefix(prefix_options)}#{self.class.collection_name}#{method_string}#{self.class.send :query_string,query_options}"
439 end
handle_users_response(response) click to toggle source
    # File lib/studio_api/appliance.rb
476 def handle_users_response response
477   tree = XmlSimple.xml_in(response)
478   users = tree["read_users"][0]
479   return [] if users["count"].to_i == 0
480   users["username"].reduce([]) do |acc,u|
481     acc << u
482   end
483 end
new?() click to toggle source

internal overwrite of ActiveResource::Base methods

    # File lib/studio_api/appliance.rb
430 def new?
431   false #Appliance has only POST method
432 end
software_command(type, options={}) click to toggle source
    # File lib/studio_api/appliance.rb
469           def software_command type, options={}
470 request_str = "/appliances/#{id.to_i}/cmd/#{type}"
471                   request_str = Util.add_options request_str, options
472 response = GenericRequest.new(self.class.studio_connection).post request_str, options
473 Hash.from_xml(response)["success"]["details"]["status"]
474           end