Class: SSC::Handler::Package

Inherits:
Base
  • Object
show all
Defined in:
lib/handlers/package.rb

Constant Summary

Constants inherited from Base

Base::API_URL

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Helper

included

Constructor Details

This class inherits a constructor from SSC::Handler::Base

Instance Method Details

#add(name) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/handlers/package.rb', line 86

def add(name)
  if options.remote?
    require_appliance do |appliance|
      response= appliance.add_package(name)
      say case response['state']
      when "changed"
        "Package Added. State: #{response['state']}"
      when "equal"
        "Package Not Added."
      when "broken"
        "Package Added. State: #{response['state']}. Please resolve dependencies"
      else
        "unknown code"
      end
    end
  else
    package_file= PackageFile.new
    package_file.push('add', name)
    package_file.save
    say "#{name} marked for addition"
  end
end

#ban(name) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/handlers/package.rb', line 129

def ban(name)
  if options.remote?
    require_appliance do |appliance|
      response= appliance.ban_package(name)
      response.collect{|key, val| "#{key}: #{val}"}
    end
  else
    package_file= PackageFile.new
    package_file.push('ban', name)
    package_file.save
    say "#{name} marked to be banned"
  end
end

#list(type) ⇒ Object

Raises:

  • (Thor::Error)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/handlers/package.rb', line 63

def list(type)
  package_file= PackageFile.new
  raise Thor::Error, "installed | selected package only"  unless ['installed', 'selected'].include?(type)
  out= if options.remote? || package_file.empty_list?
    require_appliance do |appliance|
      params= {:build_id => options.build_id} if options.build_id
      software= appliance.send("#{type}_software")
      formatted_list= software.collect do |package|
        version= package.version ? { "version" => package.version } : nil
        package_file.push('list', {package.name => version})
      end
      package_file.save
    end
  else
    package_file.read
  end
  say out.to_yaml
end

#remove(name) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/handlers/package.rb', line 112

def remove(name)
  if options.remote?
    require_appliance do |appliance|
      response= appliance.remove_package(name)
      say "State: #{response['state']}"
    end
  else
    package_file= PackageFile.new
    package_file.push('remove', name)
    package_file.save
    say "#{name} marked for removal"
  end
end

#search(search_string) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/handlers/package.rb', line 49

def search(search_string)
  require_appliance do |appliance|
    params= {:all_repos => options.all_repos} if options.all_repos
    software= appliance.search_software(search_string, params)
    software.collect do |software|
      say "#{software.name} v#{software.version}. Repo Id: #{software.repository_id}"
    end
  end
end

#unban(name) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/handlers/package.rb', line 146

def unban(name)
  if options.remote?
    require_appliance do |appliance|
      response= appliance.unban_package(name)
      response.collect{|key, val| "#{key}: #{val}"}
    end
  else
    package_file= PackageFile.new
    package_file.push('unban', name)
    package_file.save
    say "#{name} marked to be unbanned"
  end
end