Module: Skytapify::ActsAsSkytapConfig::LocalInstanceMethods

Defined in:
lib/skytapify/acts_as_skytap_config.rb

Instance Method Summary collapse

Instance Method Details

#generate_new_configObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/skytapify/acts_as_skytap_config.rb', line 20

def generate_new_config
  begin
    build_configuration(lab.template_id, "#{user.try(:first_name)} #{user.try(:last_name)} - #{lab.name}")
    assign_configuration(user.skytap_id) if user.skytap_id.present?
    rename_configuration_vms
    build_publish_sets(lab.publish_set_access)
    build_start_stop_schedule if lab.next_start_datetime
    build_auto_delete_schedule if lab.auto_delete
  rescue => e
    delete_configuration
    raise RuntimeError, e
  end
end

#get_configObject



35
36
37
# File 'lib/skytapify/acts_as_skytap_config.rb', line 35

def get_config
  configuration_id ? api_call(organization, "configuration show #{configuration_id}") : false
end

#halt_vm(vm_id) ⇒ Object



47
48
49
# File 'lib/skytapify/acts_as_skytap_config.rb', line 47

def halt_vm(vm_id)
  configuration_id ? api_call(organization, "vm update #{vm_id}", {runstate: 'halted'}) : false
end

#rdp_archiveObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/skytapify/acts_as_skytap_config.rb', line 69

def rdp_archive
  Struct.new("ZipContents", :filename, :contents) unless defined? Struct::ZipContents
  files_to_zip = []
  get_config['vms'].each do |vm|
    rdp = rdp_by_vm_id(vm['id'])
    files_to_zip << Struct::ZipContents.new("#{vm['name'].gsub(/[^0-9A-Za-z\-]/, '_')}.rdp", rdp)
  end   
  zip = Zip::ZipOutputStream::write_buffer do |z|
    files_to_zip.each do |zc|
      z.put_next_entry(zc.filename)
      z.write(zc.contents)
    end
  end
  zip.rewind
  zip.sysread
end

#refresh_configurationObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/skytapify/acts_as_skytap_config.rb', line 51

def refresh_configuration
  if configuration_id
    delete_vms
    add_vms_from_template(lab.template_id)
    add_vms_to_publish_sets(lab.publish_set_access)
    rename_configuration_vms
  else
    generate_new_config_without_delay
  end
end

#regenerate_schedulesObject



62
63
64
65
66
# File 'lib/skytapify/acts_as_skytap_config.rb', line 62

def regenerate_schedules
  delete_all_schedules
  build_start_stop_schedule if lab.next_start_datetime
  build_auto_delete_schedule if lab.auto_delete
end

#runstateObject



39
40
41
# File 'lib/skytapify/acts_as_skytap_config.rb', line 39

def runstate
  configuration_id ? get_config['runstate'] : false
end

#runstate=(new_state) ⇒ Object



43
44
45
# File 'lib/skytapify/acts_as_skytap_config.rb', line 43

def runstate=(new_state)
  configuration_id ? api_call(organization, "configuration update #{configuration_id}", {runstate: new_state}) : false
end