methods/cc_client.rb
# Output Cloud Config/Init user data
Output Cloud Config/Init user data
Output Cloud Config / Init user data
def output_cc_user_data(options,user_data,exec_data,output_file)
  if !options['vm'].to_s.match(/mp|multipass/)
    in_target = "curtin in-target --target=/target -- "
  else
    in_target = ""
  end
  check_dir = File.dirname(output_file)
  check_dir_exists(options,check_dir)
  tmp_file  = "/tmp/user_data_"+options['name']
  file      = File.open(tmp_file, 'w')
  end_char  = "\n"
  user_data.each do |line|
    output = line+end_char
    file.write(output)
  end
  pkg_list = options['q_struct']['additional_packages'].value
  if options['vm'].to_s.match(/mp|multipass/)
    file.write("packages:\n")
    pkg_list.split(" ").each do |line|
      output = "  - "+line+"\n"
      file.write(output)
    end
    file.write("\n")
    file.write("runcmd:\n")
    exec_data.each do |line|
      output = "  - "+line+"\n"
      file.write(output)
    end
  else
    end_char = ""
    file.write("  late-commands:\n")
    file.write("    [")
    exec_data.each do |line|
      output = " \""+line+"\","+end_char
      file.write(output)
    end
    file.write(" \"#{in_target}apt update\",")
    output = " \"#{in_target}apt install -y "+pkg_list+"\","+end_char
    file.write(output)
    file.write(" \"date\" ]\n\n")
  end
  file.close
  message = "Creating:\tCloud user-data file "+output_file
  command = "cat #{tmp_file} >> #{output_file} ; rm #{tmp_file}"
  execute_command(options,message,command)
  print_contents_of_file(options,"",output_file)
  return
end
def output_cc_user_data ( options , user_data , exec_data , output_file ) if ! options [ 'vm' ] . to_s . match ( / mp|multipass / ) in_target = "curtin in-target --target=/target -- " else in_target = "" end check_dir = File . dirname ( output_file ) check_dir_exists ( options , check_dir ) tmp_file = "/tmp/user_data_" + options [ 'name' ] file = File . open ( tmp_file , 'w' ) end_char = "\n" user_data . each do | line | output = line + end_char file . write ( output ) end pkg_list = options [ 'q_struct' ] [ 'additional_packages' ] . value if options [ 'vm' ] . to_s . match ( / mp|multipass / ) file . write ( "packages:\n" ) pkg_list . split ( " " ) . each do | line | output = "  - " + line + "\n" file . write ( output ) end file . write ( "\n" ) file . write ( "runcmd:\n" ) exec_data . each do | line | output = "  - " + line + "\n" file . write ( output ) end else end_char = "" file . write ( "  late-commands:\n" ) file . write ( "    [" ) exec_data . each do | line | output = " \"" + line + "\"," + end_char file . write ( output ) end file . write ( " \"#{in_target}apt update\"," ) output = " \"#{in_target}apt install -y " + pkg_list + "\"," + end_char file . write ( output ) file . write ( " \"date\" ]\n\n" ) end file . close message = "Creating:\tCloud user-data file " + output_file command = "cat #{tmp_file} >> #{output_file} ; rm #{tmp_file}" execute_command ( options , message , command ) print_contents_of_file ( options , "" , output_file ) return end
Output Cloud Config/Init user data
Output Cloud Config / Init user data
options
<not_specific>
user_data
<not_specific>
exec_data
<not_specific>
output_file
<not_specific>