Class: Rubber::Commands::Config

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/rubber/commands/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



15
16
17
# File 'lib/rubber/commands/config.rb', line 15

def self.description
  "Generate system files by transforming the files in the config/rubber tree"
end

.subcommand_descriptionObject



11
12
13
# File 'lib/rubber/commands/config.rb', line 11

def self.subcommand_description
  "Transform templates in the config/rubber tree"
end

.subcommand_nameObject



7
8
9
# File 'lib/rubber/commands/config.rb', line 7

def self.subcommand_name
  "config"
end

Instance Method Details

#executeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rubber/commands/config.rb', line 28

def execute
  cfg = Rubber::Configuration.get_configuration(Rubber.env)
  instance_alias = host || cfg.environment.current_host 
  instance = cfg.instance[instance_alias]
  if instance
    role_names = instance.role_names
    env = cfg.environment.bind(role_names, instance_alias)
    gen = Rubber::Configuration::Generator.new("#{Rubber.root}/config/rubber", role_names, instance_alias)
    gen.fake_root = fakeroot if fakeroot
  elsif ['development', 'test'].include?(Rubber.env)
    instance_alias = host || instance_alias
    role_names = roles || cfg.environment.known_roles
    role_items = role_names.collect do |r|
      Rubber::Configuration::RoleItem.new(r, r == "db" ? {'primary' => true} : {})
    end
    env = cfg.environment.bind(role_names, instance_alias)
    domain = env.domain
    instance = Rubber::Configuration::InstanceItem.new(instance_alias, domain, role_items,
                                                       'dummyid', 'm1.small', 'ami-7000f019', ['dummygroup'])
    instance.external_host = instance.full_name
    instance.external_ip = "127.0.0.1"
    instance.internal_host = instance.full_name
    instance.internal_ip = "127.0.0.1"
    cfg.instance.add(instance)
    gen = Rubber::Configuration::Generator.new("#{Rubber.root}/config/rubber", role_names, instance_alias)
    gen.fake_root = fakeroot || "#{Rubber.root}/tmp/rubber"
  else
    puts "Instance not found for host: #{instance_alias}"
    exit 1
  end
  
  if file
    gen.file_pattern = file
  end
  gen.no_post = no_post?
  gen.force = force?
  gen.stop_on_error_cmd = env.stop_on_error_cmd
  gen.run

end