Class: Chef::Knife::LparCreate

Inherits:
Chef::Knife show all
Includes:
LparBase
Defined in:
lib/chef/knife/lpar_create.rb

Instance Method Summary collapse

Methods included from LparBase

#get_password, #print_with_output, #run_remote_command

Instance Method Details

#create_lparObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/chef/knife/lpar_create.rb', line 132

def create_lpar
  Net::SSH.start(@name_args[0], "hscroot", :password => @password) do |ssh|
    # some background checks
    # check for existing lpar with name
    ui.info "Searching for existing lpar with name: #{config[:name]}"
    command = "lssyscfg -m #{config[:virtual_server]} -F name -r lpar | grep #{config[:name]}"
    output = run_remote_command(ssh, command)
    unless output.nil?
      ui.fatal "An lpar already exists with the name #{config[:name]}"
      exit 1
    end
    ui.info "lpar not found, creation imminent"

    # find the last vscsi device number
    ui.info "Looking for next device number in sequence"
    command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"lsdev -type disk -virtual -field name\" | tail -1"
    last_vscsi = run_remote_command(ssh, command)
    ui.info "Found existing device - #{last_vscsi}"

    # use the vscsi number to find the actual physical ID so we can find which vios slot it's in
    ui.info "Finding vios mapping for device - #{last_vscsi}"
    command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"lsdev -dev #{last_vscsi} -field physloc -fmt \\\":\\\"\""
    last_vscsi_phy_loc = run_remote_command(ssh, command)
    prev_loc = last_vscsi_phy_loc.match('.*-C(\d+)-.*')[1]
    ui.info "Found vios mapping #{prev_loc}"
    new_virt_loc = prev_loc.to_i + 1
    ui.info "Will use new mapping #{new_virt_loc}"

    # create the new lpar
    ui.info "Creating new lpar #{config[:name]}"
    command = "mksyscfg -m #{config[:virtual_server]} -r lpar \
-i \"name=#{config[:name]}, \
profile_name=#{config[:profile]}, \
lpar_env=aixlinux, \
min_mem=#{config[:min_mem]}, \
desired_mem=#{config[:desired_mem]}, \
max_mem=#{config[:max_mem]}, \
proc_mode=shared, \
min_procs=#{config[:min_procs]}, \
desired_procs=#{config[:desired_procs]}, \
max_procs=#{config[:max_procs]}, \
min_proc_units=#{config[:min_proc_units]}, \
desired_proc_units=#{config[:desired_proc_units]}, \
max_proc_units=#{config[:max_proc_units]}, \
sharing_mode=uncap, uncap_weight=128, \
boot_mode=norm, max_virtual_slots=10, \
\\\"virtual_eth_adapters=3/0/1//0/0\\\", \
\\\"virtual_scsi_adapters=2/client//#{config[:vios]}/#{new_virt_loc}/1\\\"\""
    output = run_remote_command(ssh, command)
    ui.info "Creation Successful"

    # now we have to figure out what LPAR we just created
    ui.info "Finding vhost name"
    command = "lssyscfg -m #{config[:virtual_server]} --filter \"lpar_names=#{config[:name]}\" -F lpar_id -r lpar"
    output = run_remote_command(ssh, command)
    # and of course it doesn't match, 0 based vs 1 based counting
    vhost = output.to_i - 1
    vhost_name = "vhost#{vhost}"
    ui.info "#{config[:name]} is #{vhost_name}"

    # Add the virtual io server vscsi mapping
    ui.info "Mapping #{new_virt_loc} between #{config[:vios]} and #{config[:name]}"
    command = "chhwres -r virtualio -m #{config[:virtual_server]} -o a -p #{config[:vios]} --rsubtype scsi -s #{new_virt_loc} -a \"adapter_type=server, remote_lpar_name=#{config[:name]}, remote_slot_num=2\""
    output = run_remote_command(ssh, command)
    ui.info "Mapping Successful"

    # make a file backed optical drive
    ui.info "Creating virtual file backed optical device"
    command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"mkvdev -fbo -vadapter #{vhost_name}\""
    vopt_name = run_remote_command(ssh, command).split(" ")[0]
    ui.info "Created device #{vopt_name}"

    # load the iso
    ui.info "Loading disk in optical drive"
    command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"loadopt -vtd #{vopt_name} -disk #{config[:disk_name]}\""
    output = run_remote_command(ssh, command)
    ui.info "Loading Successful"

    # create logical volume
    ui.info "Creating logical volume"
    command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"mklv -lv #{config[:name]} rootvg 50G\""
    lv_name = run_remote_command(ssh, command)
    ui.info "Created logical volume #{lv_name}"

    # attach it
    ui.info "Attaching lv to lpar"
    command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"mkvdev -vdev #{config[:name]} -vadapter #{vhost_name}\""
    vtscsi_name = run_remote_command(ssh, command).split(" ")[0]
    ui.info "Attach Successful as #{vtscsi_name}"

    # save the virtual io server profile
    ui.info "Activating virtual io server profile"
    command = "mksyscfg -r prof -m #{config[:virtual_server]} -o save -p #{config[:vios]} -n `lssyscfg -r lpar -m #{config[:virtual_server]} --filter \"lpar_names=#{config[:vios]}\" -F curr_profile` --force"
    output = run_remote_command(ssh, command)
    ui.info "Activation Successful"

    # reload the lpar so it knows it has new devices
    ui.info "Reload virtual io server to re-read devices"
    command = "viosvrcmd -m #{config[:virtual_server]} -p #{config[:vios]} -c \"cfgdev\""
    output = run_remote_command(ssh, command)
    ui.info "Reload Successful"

    # could start it up here, we'll see
    ui.info "Boot lpar in SMS mode"
    command = "chsysstate -r lpar -m #{config[:virtual_server]} -o on -f #{config[:profile]} -b sms -n #{config[:name]}"
    output = run_remote_command(ssh, command)
    unless output.nil?
      ui.info output.to_s
    end
    ui.info "Boot Successful"
  end
end

#read_and_validate_paramsObject

Reads the input parameters and validates them. Will exit if it encounters an error



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/chef/knife/lpar_create.rb', line 113

def read_and_validate_params
  if @name_args.length < 1
    show_usage
    exit 1
  end

  if config[:name].nil? ||
      config[:vios].nil? ||
      config[:virtual_server].nil? ||
      config[:disk_name].nil?
    show_usage
    exit 1
  end

  if config[:profile].nil?
    config[:profile] = config[:name]
  end
end

#runObject

Run the plugin



103
104
105
106
107
# File 'lib/chef/knife/lpar_create.rb', line 103

def run
  read_and_validate_params
  @password = get_password
  create_lpar
end