Class: Chef::Knife::AppInstanceCreate

Inherits:
Bootstrap
  • Object
show all
Defined in:
lib/chef/knife/app_instance_create.rb

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ AppInstanceCreate

Returns a new instance of AppInstanceCreate.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chef/knife/app_instance_create.rb', line 13

def initialize arguments
  bootstrap = Chef::Knife::Bootstrap.new

  bootstrap.options.each do |name, args|
    AppInstanceCreate.option name, args
  end

  Chef::Knife::Bootstrap.load_deps

  super arguments
end

Instance Method Details

#runObject

This method will be executed when you run this knife command.



26
27
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
68
69
# File 'lib/chef/knife/app_instance_create.rb', line 26

def run

  # Get Arguments
  if @name_args.size < 1
    ui.info("Please specify an app_id")
    show_usage
    exit 1
  end

  app_id = {}
  @name_args[0].split(" ").each do |id_arg|
    key_value = id_arg.split("=")
    app_id[key_value.first] = key_value.last
  end

  properties = parse_properties @name_args[1, @name_args.size]

  db = Chapp.database
  provisioner = Chapp.provisioner

  app_config = db.app_config app_id

  # Provision the server and retrieve the host name
  host = provisioner.build_server app_config, properties

  properties.each do |key, value|
    @config[key.to_sym] = value
  end

  # Tells bootstrap what environment to use
  Chef::Config[:environment] = app_config.environment_name

  # Tells bootstrap what run_list to use
  @config[:run_list] = "role[#{app_config.role_name}]"

  # Tells bootstrap what node name to use
  @config[:chef_node_name] = host

  # Tells bootstrap what ip/fqdn to use
  @name_args = host

  # Runs bootstrap
  super
end