Class: Fission::Metadata

Inherits:
Object show all
Defined in:
lib/fission/metadata.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Public: Gets/Sets the content (Hash).



7
8
9
# File 'lib/fission/metadata.rb', line 7

def content
  @content
end

Class Method Details

.delete_vm_info(vm_path) ⇒ Object

Public: Deletes the Fusion metadata related to a VM. The VM should not be running when this method is called. It’s highly recommended to call this method without the Fusion GUI application running. If the Fusion GUI is running this method should succeed, but it’s been observed that Fusion will recreate the metadata which is deleted. This leads to ‘missing’ VMs in the Fusion GUI.

vm_path - The absolute path to the directory of a VM.

Examples

Fission::Metadata.delete_vm_info '/vms/foo.vmwarevm'

Returns nothing.



23
24
25
26
27
28
29
# File 'lib/fission/metadata.rb', line 23

def self.delete_vm_info(vm_path)
   = new
  .load
  .delete_vm_restart_document(vm_path)
  .delete_vm_favorite_entry(vm_path)
  .save
end

Instance Method Details

#delete_vm_favorite_entry(vm_path) ⇒ Object

Public: Deletes the VM information from the ‘favorites list’ metadata. The ‘favorites list’ dictates which VMs are displayed in the Fusion VM libarary.

vm_path - The absolute path to the directory of a VM.

Examples

.delete_favorite_entry '/vms/foo.vmwarevm'

Returns nothing.



87
88
89
90
91
92
93
94
# File 'lib/fission/metadata.rb', line 87

def delete_vm_favorite_entry(vm_path)
  if @content.has_key?('VMFavoritesListDefaults2')
    @content['VMFavoritesListDefaults2'].delete_if { |vm| vm['path'] == vm_path }
  end
  if @content.has_key?('fusionInitialSessions')
    @content['fusionInitialSessions'].delete_if {|vm| vm['documentPath'] == vm_path}
  end
end

#delete_vm_restart_document(vm_path) ⇒ Object

Public: Deletes the VM information from the ‘restart document path’ metadata. The ‘restart document path’ dictates which GUI consoles to display when Fusion starts.

vm_path - The absolute path to the directory of a VM.

Examples

.delete_vm_restart_document 'vms/foo.vmwarevm'

Returns nothing.



70
71
72
73
74
# File 'lib/fission/metadata.rb', line 70

def delete_vm_restart_document(vm_path)
  if @content.has_key?('PLRestartDocumentPaths')
    @content['PLRestartDocumentPaths'].delete_if { |p| p == vm_path }
  end
end

#loadObject

Public: Reads the configured metadata file and populates the content variable with native ruby types.

Examples

.load

Returns nothing.



39
40
41
42
# File 'lib/fission/metadata.rb', line 39

def load
  raw_data = CFPropertyList::List.new :file => Fission.config['plist_file']
  @content = CFPropertyList.native_types raw_data.value
end

#saveObject

Public: Saves a new version of the metadata file with the data in the content variable.

Examples

.save

Returns nothing.



52
53
54
55
56
57
# File 'lib/fission/metadata.rb', line 52

def save
  new_content = CFPropertyList::List.new
  new_content.value = CFPropertyList.guess @content
  new_content.save Fission.config['plist_file'],
                   CFPropertyList::List::FORMAT_BINARY
end