Class: VMC::KNIFE::Application
- Inherits:
-
Object
- Object
- VMC::KNIFE::Application
- Defined in:
- lib/vmc_knife/vmc_knife.rb
Overview
Read/Write the JSON for an application. Does not map the actual JSON into a new ruby object.
Instance Attribute Summary collapse
-
#role_name ⇒ Object
Returns the value of attribute role_name.
-
#root ⇒ Object
Returns the value of attribute root.
-
#wrapped ⇒ Object
Returns the value of attribute wrapped.
Instance Method Summary collapse
- #env ⇒ Object
-
#initialize(root, data, role_name) ⇒ Application
constructor
A new instance of Application.
-
#log(folder, log_file_glob = nil) ⇒ Object
look for the log folder of the deployed app.
-
#log_shell(shell_cmd = nil, log_file_glob = nil) ⇒ Object
look for the most recent folder where we can find the stdout file.
- #memory ⇒ Object
-
#name ⇒ Object
Returns the application name (different from the application role name.).
-
#to_vcap_manifest ⇒ Object
Returns a vcap manifest that can be used to push/update an application to vcap’s cloud_controller.
- #uris ⇒ Object
Constructor Details
#initialize(root, data, role_name) ⇒ Application
Returns a new instance of Application.
146 147 148 149 150 |
# File 'lib/vmc_knife/vmc_knife.rb', line 146 def initialize(root, data, role_name) @root = root @wrapped = data @role_name = role_name end |
Instance Attribute Details
#role_name ⇒ Object
Returns the value of attribute role_name.
145 146 147 |
# File 'lib/vmc_knife/vmc_knife.rb', line 145 def role_name @role_name end |
#root ⇒ Object
Returns the value of attribute root.
145 146 147 |
# File 'lib/vmc_knife/vmc_knife.rb', line 145 def root @root end |
#wrapped ⇒ Object
Returns the value of attribute wrapped.
145 146 147 |
# File 'lib/vmc_knife/vmc_knife.rb', line 145 def wrapped @wrapped end |
Instance Method Details
#env ⇒ Object
161 162 163 |
# File 'lib/vmc_knife/vmc_knife.rb', line 161 def env() ApplicationEnvironment.new @wrapped['env'], self end |
#log(folder, log_file_glob = nil) ⇒ Object
look for the log folder of the deployed app. making the assumption we are on the same file system. will use the paas APIs later.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/vmc_knife/vmc_knife.rb', line 176 def log(folder,log_file_glob=nil) deployed_apps_folder="/home/ubuntu/cloudfoundry/deployed_apps" log_file_glob ||= "logs/*" if File.exist?(deployed_apps_folder) folder_nb=0 Dir.glob(File.join(deployed_apps_folder, "#{name()}-*")).each do |dir| fname="#{File.basename(dir)}" app_log_folder=File.join(folder,fname) FileUtils.mkdir_p(app_log_folder) if File.exist? "#{dir}/logs" FileUtils.cp(Dir.glob(File.join("#{dir}", "logs/*")), app_log_folder) end end end end |
#log_shell(shell_cmd = nil, log_file_glob = nil) ⇒ Object
look for the most recent folder where we can find the stdout file. fork to the shell with the ‘less’ command to display the contents of the file.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/vmc_knife/vmc_knife.rb', line 194 def log_shell(shell_cmd=nil,log_file_glob=nil) deployed_apps_folder="/home/ubuntu/cloudfoundry/deployed_apps" shell_cmd ||= "less" log_file_glob ||= File.join("logs","stdout.log") if File.exist?(deployed_apps_folder) ts_most_recent=0 most_recent_file=nil app_deployed=false Dir.glob(File.join(deployed_apps_folder, "#{name()}-*")).each do |dir| app_deployed=true Dir.glob(File.join("#{dir}", log_file_glob)).each do |logfile| ts=File.mtime(logfile).to_i if ts > ts_most_recent most_recent_file=logfile ts_most_recent = ts end end end if most_recent_file cmd = "#{shell_cmd} #{most_recent_file}" puts "#{cmd}" if VMC::Cli::Config.trace exec cmd elsif app_deployed raise "Could not find a log file #{log_file_glob} in the deployed app folder." else raise "Could not find a deployed application named #{name}" end else raise "Could not find the deployed application folder #{deployed_apps_folder}" end end |
#memory ⇒ Object
158 159 160 |
# File 'lib/vmc_knife/vmc_knife.rb', line 158 def memory() @wrapped['resources']['memory'] end |
#name ⇒ Object
Returns the application name (different from the application role name.)
152 153 154 |
# File 'lib/vmc_knife/vmc_knife.rb', line 152 def name() @wrapped['name'] end |
#to_vcap_manifest ⇒ Object
Returns a vcap manifest that can be used to push/update an application to vcap’s cloud_controller.
167 168 169 170 171 |
# File 'lib/vmc_knife/vmc_knife.rb', line 167 def to_vcap_manifest() # This is pretty much identical to the json wrapped here except for the environment variables. # if there are differences we will take care of them here. @wrapped end |
#uris ⇒ Object
155 156 157 |
# File 'lib/vmc_knife/vmc_knife.rb', line 155 def uris() @wrapped['uris'] end |