Class: Fhcap::Tasks::Cluster::Create

Inherits:
ClusterTaskBase show all
Defined in:
lib/fhcap/tasks/cluster/create.rb

Instance Attribute Summary collapse

Attributes inherited from ClusterTaskBase

#cluster_file

Attributes inherited from TaskBase

#config, #options, #thor, #verbose

Instance Method Summary collapse

Methods inherited from ClusterTaskBase

#checkout_repos, #chef_task_options, #template_as_object

Methods inherited from TaskBase

#ask_config, #color_pad, #exit_with_error, #set_color, #suppress_stdout, #table_header, #table_row, #with_progress

Methods included from KnifeHelper

#chef_server_config_for, #chef_server_config_hash_for, #chef_server_names, #knife_config, #knife_config_dir, #knife_config_file_for

Methods included from ProvidersHelper

#provider_availability_zones, #provider_config, #provider_credentials, #provider_for, #provider_names, #provider_names_for, #provider_regions, #provider_type, #providers_config

Methods included from ReposHelper

#find_cluster, #find_cluster_pwds, #find_cluster_pwds_with_repo, #find_cluster_with_repo, #find_data_bag, #find_data_bag_item, #find_environment, #find_repo_item, #find_role, #get_cookbook_deps, #get_cookbook_meta, #get_cookbook_versions, #get_cookbooks, #get_entry_dependencies, #get_modified_cookbooks, #is_dirty?, #modified?, #repo_cfg, #repo_clusters_dir, #repo_cookbook_paths, #repo_dir, #repo_names, #repo_paths, #repos_config, #repos_dir, #run_inside_repo_dir

Methods included from FhcapHelper

#cluster_template_names

Constructor Details

#initialize(options) ⇒ Create

Returns a new instance of Create.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fhcap/tasks/cluster/create.rb', line 17

def initialize(options)
  super(options, false)
  @template = options[:template]
  @repo = options[:'repo']
  @provider_config = options[:'provider-config'] || {}
  @gitref = options[:'git-ref']
  @domain = options[:domain]
  @ssl_cert = options[:'ssl-cert']
  @dns_provider_id = options[:'dns-provider-id']
  @chef_server = options[:'chef-server']
  @provider_id = options[:'provider-id']
  @skip_repo_checkout = options[:'skip-repo-checkout']
  @skip_cookbook_promote = options[:'skip-cookbook-promote']
  @skip_server_bootstrap = options[:'skip-server-bootstrap']
  @skip_dns_record = options[:'skip-dns-record']
  @skip_create = options[:'skip-create']
  @skip_provision = options[:'skip-provision']

  @cluster_config = {
      id: @name,
      template: @template,
      driver: "",
      domain: @domain,
      repo: @repo,
      chef_server: @chef_server,
      provider_id: @provider_id
  }.merge(@cluster_config)

  @cluster_config[:provider_config] = @cluster_config[:provider_config] || {}
  @cluster_config[:provider_config].merge!(@provider_config)
end

Instance Attribute Details

#cluster_configObject (readonly)

Returns the value of attribute cluster_config.



15
16
17
# File 'lib/fhcap/tasks/cluster/create.rb', line 15

def cluster_config
  @cluster_config
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/fhcap/tasks/cluster/create.rb', line 15

def name
  @name
end

Instance Method Details

#runObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fhcap/tasks/cluster/create.rb', line 49

def run
  thor.say "Cluster::Create: name = #{@name}", :yellow

  #Checkout repos
  checkout_repos unless @skip_repo_checkout

  #Generate cluster config
  generate_cluster_config

  #Create environment files
  create_cluster_environments

  #Write config to disk
  cluster_file = find_cluster(name) || File.join(repo_dir(cluster_config[:repo]), repo_clusters_dir(cluster_config[:repo]), "#{name}.json")
  thor.create_file(cluster_file, JSON.pretty_generate(cluster_config))

  #Chef Stuff
  #Promote cookbooks
  Chef::Environments::PromoteCookbooks.new(@options.dup.merge({:environments => cluster_environments})).run unless @skip_cookbook_promote

  #Bootstrap Server
  Chef::Server::Bootstrap.new(@options.dup.merge(chef_task_options.merge({:environments => cluster_environments}))).run unless @skip_server_bootstrap

  #Provisioning create
  Chef::Provisioning::Create.new(@options.dup.merge(chef_task_options)).run unless @skip_create

  create_dns_record unless @skip_dns_record
end