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, line 274
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

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, line 305
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={}) 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, line 374
def add_package (name, options={})
        software_command "add_package",{:name => name}.merge(options)
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, line 397
def add_pattern (name, options={})
        software_command "add_pattern",{:name => name}.merge(options)
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, line 190
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) click to toggle source
# File lib/studio_api/appliance.rb, line 211
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_repository() click to toggle source

adds repository for user rpms

# File lib/studio_api/appliance.rb, line 200
def add_user_repository
  rq = GenericRequest.new self.class.studio_connection
  rq.post "/appliances/#{id}/cmd/add_user_repository"
end
background() click to toggle source
# File lib/studio_api/appliance.rb, line 246
def background
  request_str = "/appliances/#{id.to_i}/configuration/background"
  GenericRequest.new(self.class.studio_connection).get request_str
end
background=(logo) click to toggle source
# File lib/studio_api/appliance.rb, line 251
def background= (logo)
  request_str = "/appliances/#{id.to_i}/configuration/background"
  if logo.is_a?(IO) && logo.respond_to?(:path)
    GenericRequest.new(self.class.studio_connection).post request_str, :file => logo
  else
    File.open(logo.to_s) do |f| 
      GenericRequest.new(self.class.studio_connection).post request_str, :file => f
    end
  end
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, line 416
def ban_package(name)
        software_command "ban_package",:name => name
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, line 264
def configuration
  Configuration.studio_connection = self.class.studio_connection
  Configuration.find id
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, line 150
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 ) 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, line 296
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_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, line 287
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 = {}) 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, line 325
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
logo=(logo) click to toggle source
# File lib/studio_api/appliance.rb, line 235
def logo= (logo)
  request_str = "/appliances/#{id.to_i}/configuration/logo"
  if logo.is_a?(IO) && logo.respond_to?(:path)
    GenericRequest.new(self.class.studio_connection).post request_str, :file => logo
  else
    File.open(logo.to_s) do |f| 
      GenericRequest.new(self.class.studio_connection).post request_str, :file => f
    end
  end
end
manifest_file(build, options={}) click to toggle source
# File lib/studio_api/appliance.rb, line 223
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) 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, line 385
def remove_package (name)
        software_command "remove_package",:name => name
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, line 408
def remove_pattern (name)
        software_command "remove_pattern",:name => name
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, line 173
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) click to toggle source
# File lib/studio_api/appliance.rb, line 217
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
repositories() click to toggle source

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

# File lib/studio_api/appliance.rb, line 157
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={}) 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, line 360
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={}) 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, line 343
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_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, line 314
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
status() click to toggle source

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

# File lib/studio_api/appliance.rb, line 138
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) 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, line 424
def unban_package(name)
        software_command "unban_package",:name => name
end
users() click to toggle source
# File lib/studio_api/appliance.rb, line 205
def users
  request_str = "/appliances/#{id.to_i}/sharing"
  response = GenericRequest.new(self.class.studio_connection).get request_str
  handle_users_response response
end