Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
# File lib/cimi/models/machine.rb, line 106 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/models/machine.rb, line 48 def self.create_from_json(body, context) json = JSON.parse(body) machine_template = json['machineTemplate'] hardware_profile_id = machine_template['machineConfig']["href"].split('/').last image_id = machine_template['machineImage']["href"].split('/').last additional_params = {} additional_params[:name] = json['name'] if json['name'] if machine_template.has_key? 'credential' additional_params[:keyname] = machine_template['credential']["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/models/machine.rb, line 64 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 = {} additional_params[:name] = xml['name'][0] if xml['name'] if machine_template.has_key? 'credential' additional_params[:keyname] = machine_template['credential'][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/models/machine.rb, line 96 def self.create_resource_metadata(context) cimi_resource = self.name.split("::").last metadata = CIMI::Model::ResourceMetadata.metadata_from_deltacloud_features(cimi_resource, :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/models/machine.rb, line 92 def self.delete!(id, context) context.driver.destroy_instance(context.credentials, id) end
# File lib/cimi/models/machine.rb, line 114 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/models/machine.rb, line 36 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/models/machine.rb, line 80 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