Class: Knifecosmic::CosmicTemplateCreate

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::KnifecosmicBase
Defined in:
lib/chef/knife/cosmic_template_create.rb

Instance Method Summary collapse

Methods included from Chef::Knife::KnifecosmicBase

included

Instance Method Details

#runObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/chef/knife/cosmic_template_create.rb', line 87

def run
  validate_base_options

  Chef::Log.debug("Validate hostname and options")
  if  locate_config_value(:name)
    templatename = locate_config_value(:name)
  else
    templatename = @name_args.first
    unless /^[a-zA-Z0-9][a-zA-Z0-9_\-#]*$/.match templatename then
      ui.error "Invalid templatename. Please specify a simple name without any spaces"
      exit 1
    end
  end

  print "#{ui.color("Creating template: #{templatename}", :magenta)}\n"

  params = {
    'command' => 'createTemplate',
    'name' => templatename,
    'displaytext' => locate_config_value(:displaytext),
    'ostypeid' => locate_config_value(:ostypeid),
    'volumeid' => locate_config_value(:volumeid),
    'hypervisor' => locate_config_value(:hypervisor)
  }
  params['ispublic'] = locate_config_value(:ispublic) if locate_config_value(:ispublic)
  params['isfeatured'] = locate_config_value(:isfeatured) if locate_config_value(:isfeatured)
  params['optimisefor'] = locate_config_value(:optimisefor) if locate_config_value(:optimisefor)
  params['passwordenabled'] = locate_config_value(:passwordenabled) if locate_config_value(:passwordenabled)
  params['isextractable'] = locate_config_value(:extractable) if locate_config_value(:extractable)
  json = connection.send_request(params)

  if ! json then
    ui.error("Unable to create template")
	exit 1
  end

  print "Template #{json['id']} is being created in the background\n";

  return json['id']
end