Class: Chef::Knife::OrganizationCreate

Inherits:
ChefWebui::Knife show all
Defined in:
lib/chef/knife/organization_create.rb

Instance Method Summary collapse

Methods inherited from ChefWebui::Knife

common_options, #init_config_variable, #webui_session

Instance Method Details

#configure_chefObject



14
15
16
17
# File 'lib/chef/knife/organization_create.rb', line 14

def configure_chef
  super
  init_config_variable(:validator_key_file)
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chef/knife/organization_create.rb', line 19

def run
  if name_args.length == 0
    ui.error("Must specify organization name to create as the first argument, i.e. knife organization create ORGNAME")
    exit 1
  end
  organization = name_args[0]

  output "Creating organization #{organization} ..."
  begin
    webui_session.create_org(organization)
    if Chef::Config[:validator_key_file]
      output "Creating validator file #{validator_key_file}"
      user_key = webui_session.regenerate_validator_key
      File.open(Chef::Config[:validator_key_file], 'w') do |file|
        file.write(user_key)
      end
    end
  rescue
  end
end