Class: KnifeTopo::TopoCreate
Overview
Instance Attribute Summary
Attributes included from Loader
#loader, #ui
#msgs, #results
Instance Method Summary
collapse
Methods included from Loader
#auto_detect_format, #check_file, #create_topo_bag, #get_local_topo_path, #list_topo_bag, #load_local_topo_or_exit, #load_node_data, #load_topo_from_file_or_exit, #load_topo_from_server, #load_topo_from_server_or_exit, #priority_attrs, #topo_bag_name, #topologies_path
#do_node_updates, #update_attrs, #update_chef_env, #update_node, #update_node_with_values, #update_runlist, #update_tags
#check_chef_env, #initialize_cmd_args, #most_common, #resource_exists?, #run_cmd
#node_bootstrap, #report, #report_msg
#attributes_for_bootstrap, #delete_client_node, #run_bootstrap, #setup_bootstrap_args
Constructor Details
Returns a new instance of TopoCreate.
60
61
62
63
|
# File 'lib/chef/knife/topo_create.rb', line 60
def initialize(args)
super
@args = args
end
|
Instance Method Details
#bootstrap_msgs ⇒ Object
65
66
67
68
69
70
|
# File 'lib/chef/knife/topo_create.rb', line 65
def bootstrap_msgs
msgs = super.dup
msgs[:existed] = 'Updated but did not bootstrap %{num} existing nodes '\
"[ %{list} ].\n Specify --overwrite to re-bootstrap existing nodes. \n"
msgs
end
|
#bootstrap_or_update_node(node_data, merge) ⇒ Object
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/chef/knife/topo_create.rb', line 134
def bootstrap_or_update_node(node_data, merge)
node_name = node_data['name']
if @bootstrap
update_node(node_data, merge) unless node_bootstrap(node_data)
elsif update_node(node_data, merge)
@results[:existed] << node_name
else
@results[:skipped] << node_name
end
end
|
#confirm_and_update_topo ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'lib/chef/knife/topo_create.rb', line 125
def confirm_and_update_topo
version = @topo.topo_version
to_version_str = " to version #{version}"
msg = "Topology #{@topo_name} already exists - do you want to " \
"update it#{to_version_str if version}"
ui.confirm(msg, true, false)
@topo.save
end
|
#create_or_update_topo ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/chef/knife/topo_create.rb', line 105
def create_or_update_topo
@topo = load_local_topo_or_exit(@topo_name)
create_topo_bag
@topo.create
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^409/
confirm_and_update_topo
end
|
#non_bootstrap_msgs ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/chef/knife/topo_create.rb', line 72
def non_bootstrap_msgs
{
existed: 'Applied updates (if any) to %{num} nodes [ %{list} ]',
skipped_ssh: 'Unexpected error skipped_ssh',
skipped: 'Skipped %{num} nodes [ %{list} ] because they do not exist',
bootstrapped: 'Unexpected error bootstrapped',
failed: 'Unexpected error failed'
}
end
|
#run ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/chef/knife/topo_create.rb', line 82
def run
validate_args
create_or_update_topo
check_chef_env(@topo['chef_environment'])
upload_artifacts unless config[:disable_upload]
update_nodes
report
end
|
#update_nodes ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/chef/knife/topo_create.rb', line 117
def update_nodes
nodes = processor.generate_nodes
merge = @topo.merge_attrs
nodes.each do |node_data|
bootstrap_or_update_node(node_data, merge)
end
end
|
#upload_artifacts ⇒ Object
145
146
147
|
# File 'lib/chef/knife/topo_create.rb', line 145
def upload_artifacts
processor.upload_artifacts('cmd' => self, 'cmd_args' => @args)
end
|
#validate_args ⇒ Object
98
99
100
101
102
103
|
# File 'lib/chef/knife/topo_create.rb', line 98
def validate_args
super
@bootstrap = config[:bootstrap]
@msgs = @bootstrap ? bootstrap_msgs : non_bootstrap_msgs
config[:disable_editing] = true
end
|