Class: VMC::KNIFE::VCAPUpdateCloudControllerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vmc_knife/vmc_knife.rb

Overview

This is really a server-side vcap admin feature.

Instance Method Summary collapse

Constructor Details

#initialize(uri, cloud_controller_config = nil) ⇒ VCAPUpdateCloudControllerConfig

Returns a new instance of VCAPUpdateCloudControllerConfig.



1205
1206
1207
1208
1209
1210
# File 'lib/vmc_knife/vmc_knife.rb', line 1205

def initialize(uri, cloud_controller_config=nil)
  @config = cloud_controller_config
  @config ||="#{ENV['HOME']}/cloudfoundry/config/cloud_controller.yml"
  @uri = uri
  raise "The config file #{@config} does not exist." unless File.exists? @config
end

Instance Method Details

#executeObject



1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
# File 'lib/vmc_knife/vmc_knife.rb', line 1240

def execute()
  @changed = false
  @changed_gateways = Array.new
  # look for the line that starts with external_uri:
  # replace it with the new uri if indeed there was a change.
  lines = IO.readlines @config
  File.open(@config, "w") do |file|
    lines.each do |s|
      if /^[\s]*external_uri:/ =~ s
        @changed = true unless /#{@uri}[\s]*$/ =~ s
        file.puts "external_uri: #{@uri}\n"
      else
        file.puts s
      end
    end
  end
  if @changed
    #update the gateways too.
    @changed_gateways = Array.new
    yaml_files = Dir.glob File.join(File.dirname(@config), "*_gateway.yml")
    yaml_files.each do |path|
      if update_gateway(path)
        gateway = File.basename(path, '.yml')
        @changed_gateways << gateway
      end
    end
    cc_yml = File.open( @config ) { |yf| YAML::load( yf ) }
    pid = cc_yml['pid']
    if pid!=nil && File.exists?(pid)
      display "Restarting the reconfigured cloud_controller"
      #assuming that the vcap symlink is in place. maker sure the aliases
      # will be resolved.
      #`shopt -s expand_aliases; vcap restart cloud_controller`
      #TODO: something that looks nicer?
      system ". ~/.bashrc;\n vcap restart cloud_controller"
      @changed_gateways.each do |gateway|
        system ". ~/.bashrc;\n vcap restart #{gateway}"
      end
    end
  end
end

#update_gateway(config) ⇒ Object

look for

cloud_controller_uri: http://api.intalio.me

and replace it with the new one.



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'lib/vmc_knife/vmc_knife.rb', line 1225

def update_gateway(config)
  changed = false
  lines = IO.readlines config
  File.open(config, "w") do |file|
    lines.each do |s|
      if /^[\s]*cloud_controller_uri:/ =~ s
        changed = true unless /#{@uri}[\s]*$/ =~ s
        file.puts "cloud_controller_uri: http://#{@uri}\n"
      else
        file.puts s
      end
    end
  end
  changed
end

#update_pendingObject



1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
# File 'lib/vmc_knife/vmc_knife.rb', line 1211

def update_pending()
  res = false
  File.open(@config, "r") do |file|
    file.each_line do |s|
      if /^[\s]*external_uri:/ =~ s
        res = true unless /#{@uri}[\s]*$/ =~ s
      end
    end
  end
  return res
end

#was_changedObject



1281
1282
1283
# File 'lib/vmc_knife/vmc_knife.rb', line 1281

def was_changed()
  @changed
end