Class: VMC::KNIFE::VCAPUpdateAvahiAliases

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

Overview

This is really a server-side feature. This is deprecated; use the dns_publisher vcap module instead. Regenerates the urls to publish as aliases. use vmc apps to read the uris of each app and also the manifest.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(avahi_aliases_path = nil, manifest_path = nil, client = nil, uri_filter = nil) ⇒ VCAPUpdateAvahiAliases

Returns a new instance of VCAPUpdateAvahiAliases.



1365
1366
1367
1368
1369
1370
1371
# File 'lib/vmc_knife/vmc_knife.rb', line 1365

def initialize(avahi_aliases_path=nil, manifest_path=nil,client=nil,uri_filter=nil)
  @manifest_path = manifest_path
  @client = client
  @config = avahi_aliases_path
  @config ||= '/etc/avahi/aliases'
  @uri_filter = uri_filter||/\.local$/
end

Instance Attribute Details

#do_execObject

Returns the value of attribute do_exec.



1364
1365
1366
# File 'lib/vmc_knife/vmc_knife.rb', line 1364

def do_exec
  @do_exec
end

#uri_filterObject

Returns the value of attribute uri_filter.



1364
1365
1366
# File 'lib/vmc_knife/vmc_knife.rb', line 1364

def uri_filter
  @uri_filter
end

Instance Method Details

#all_urisObject



1405
1406
1407
1408
1409
1410
# File 'lib/vmc_knife/vmc_knife.rb', line 1405

def all_uris()
  uris = manifest_uris+apps_uris
  uris.uniq!
  uris.sort!
  uris
end

#already_published_urisObject



1411
1412
1413
1414
1415
1416
1417
1418
# File 'lib/vmc_knife/vmc_knife.rb', line 1411

def already_published_uris()
  already = IO.readlines @config
  already.collect! {|item| item.strip}
  already.select! {|item| !item.empty?}
  already.uniq!
  already.sort!
  already
end

#apps_urisObject



1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
# File 'lib/vmc_knife/vmc_knife.rb', line 1372

def apps_uris()
  return @apps_uris unless @apps_uris.nil?
  uris = Array.new
  return uris unless @client
  apps = @client.apps
  api_uri = URI.parse(@client.target).host
  uris << api_uri if @uri_filter =~ api_uri
  apps.each do |app|
    app[:uris].each do |uri|
      #only publish the uris in the local domain.
      uris << uri if @uri_filter =~ uri
    end
  end
  uris.uniq!
  uris.sort!
  @apps_uris = uris
  @apps_uris
end

#executeObject



1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
# File 'lib/vmc_knife/vmc_knife.rb', line 1419

def execute()
  return unless update_pending()
  # if the dns_publisher module is present let's not do this one.
  # the dns_publisher does a better job at mdns
  unless File.exist? "#{ENV['CLOUD_FOUNDRY_CONFIG_PATH']}/dns_publisher.yml"
    File.open(@config, "w") do |file|
      all_uris().each do |uri|
        file.puts uri + "\n"
      end
    end
    #configured so that we don't need root privileges on /etc/avahi/aliases:
    #the backticks don't work; system() works:
    system('avahi-publish-aliases') if @do_exec
  end
end

#manifest_urisObject



1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
# File 'lib/vmc_knife/vmc_knife.rb', line 1390

def manifest_uris()
  uris = Array.new
  return uris unless @manifest_path
  root = Root.new @manifest_path
  root.recipes.each do |recipe|
    recipe.applications.each do |application|
      application.uris.each do |uri|
        uris << uri if @uri_filter =~ uri
      end
    end
  end
  uris.uniq!
  uris.sort!
  uris
end

#update_pendingObject



1434
1435
1436
1437
1438
1439
1440
# File 'lib/vmc_knife/vmc_knife.rb', line 1434

def update_pending()
  already = already_published_uris()
  length_already = already.length
  allall = already + all_uris()
  allall.uniq!
  return length_already != allall.length
end