class KnifeTopo::TopoCreate

knife topo create

Public Class Methods

new(args) click to toggle source
Calls superclass method KnifeTopo::TopoBootstrap::new
# File lib/chef/knife/topo_create.rb, line 60
def initialize(args)
  super
  @args = args
end

Public Instance Methods

bootstrap_msgs() click to toggle source
Calls superclass method KnifeTopo::TopoBootstrap#bootstrap_msgs
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/chef/knife/topo_create.rb, line 105
def create_or_update_topo
  # Load the topology data & create the topology bag
  @topo = load_local_topo_or_exit(@topo_name)
  create_topo_bag

  # Add topology item to the data bag on the server
  @topo.create
rescue Net::HTTPServerException => e
  raise unless e.to_s =~ /^409/
  confirm_and_update_topo
end
non_bootstrap_msgs() click to toggle source
# 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
processor() click to toggle source
# File lib/chef/knife/topo_create.rb, line 94
def processor
  @processor ||= KnifeTopo::Processor.for_topo(@topo)
end
run() click to toggle source
# File lib/chef/knife/topo_create.rb, line 82
def run
  validate_args
  create_or_update_topo

  # make sure env and cookbooks are in place
  check_chef_env(@topo['chef_environment'])
  upload_artifacts unless config[:disable_upload]
  update_nodes

  report
end
update_nodes() click to toggle source
# 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() click to toggle source
# File lib/chef/knife/topo_create.rb, line 145
def upload_artifacts
  processor.upload_artifacts('cmd' => self, 'cmd_args' => @args)
end
validate_args() click to toggle source
Calls superclass method KnifeTopo::TopoBootstrap#validate_args
# 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