# File lib/cimi/model/machine.rb, line 120 def self.attach_volumes(volumes, context) volumes.each do |vol| context.driver.attach_storage_volume(context.credentials, {:id=>vol[:volume].name, :instance_id=>context.params[:id], :device=>vol[:attachment_point]}) end self.find(context.params[:id], context) end
# File lib/cimi/model/machine.rb, line 110 def self.create_entity_metadata(context) cimi_entity = self.name.split("::").last metadata = EntityMetadata.metadata_from_deltacloud_features(cimi_entity, :instances, context) unless metadata.includes_attribute?(:name) metadata.attributes << {:name=>"name", :required=>"false", :constraints=>"Determined by the cloud provider", :type=>"xs:string"} end metadata end
# File lib/cimi/model/machine.rb, line 71 def self.create_from_json(body, context) json = JSON.parse(body) hardware_profile_id = xml['machineTemplate']['machineConfig']["href"].split('/').last image_id = xml['machineTemplate']['machineImage']["href"].split('/').last instance = context.create_instance(context.credentials, image_id, { :hwp_id => hardware_profile_id }) from_instance(instance, context) end
# File lib/cimi/model/machine.rb, line 79 def self.create_from_xml(body, context) xml = XmlSimple.xml_in(body) machine_template = xml['machineTemplate'][0] hardware_profile_id = machine_template['machineConfig'][0]["href"].split('/').last image_id = machine_template['machineImage'][0]["href"].split('/').last additional_params = {} if machine_template.has_key? 'MachineAdmin' additional_params[:keyname] = machine_template['machineAdmin'][0]["href"].split('/').last end instance = context.driver.create_instance(context.credentials, image_id, { :hwp_id => hardware_profile_id }.merge(additional_params)) from_instance(instance, context) end
# File lib/cimi/model/machine.rb, line 106 def self.delete!(id, context) context.driver.destroy_instance(context.credentials, id) end
# File lib/cimi/model/machine.rb, line 128 def self.detach_volumes(volumes, context) volumes.each do |vol| context.driver.detach_storage_volume(context.credentials, {:id=>vol[:volume].name, :instance_id => context.params[:id]}) end self.find(context.params[:id], context) end
# File lib/cimi/model/machine.rb, line 59 def self.find(id, context) instances = [] if id == :all instances = context.driver.instances(context.credentials) instances.map { |instance| from_instance(instance, context) }.compact else instance = context.driver.instance(context.credentials, :id => id) raise CIMI::Model::NotFound unless instance from_instance(instance, context) end end
# File lib/cimi/model/machine.rb, line 94 def perform(action, context, &block) begin if context.driver.send(:"#{action.name}_instance", context.credentials, self.name) block.callback :success else raise "Operation failed to execute on given Machine" end rescue => e block.callback :failure, e.message end end
Generated with the Darkfish Rdoc Generator 2.