Sha256: 146371ef08697b1a23d1ce88d94064d42c0368c9000e20904d9b097e8c52eadf

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

# 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.

module HardwareProfilesHelper

  def format_hardware_property(prop)
    return "∅" unless prop
    u = hardware_property_unit(prop)
    case prop.kind
      when :range
      "#{prop.first} #{u} - #{prop.last} #{u} (default: #{prop.default} #{u})"
      when :enum
      prop.values.collect{ |v| "#{v} #{u}"}.join(', ') + " (default: #{prop.default} #{u})"
      else
      "#{prop.value} #{u}"
    end
  end

  def format_instance_profile(ip)
    o = ip.overrides.collect do |p, v|
      u = hardware_property_unit(p)
      "#{p} = #{v} #{u}"
    end
    if o.empty?
      ""
    else
      "with #{o.join(", ")}"
    end
  end

  private
  def hardware_property_unit(prop)
    u = ::Deltacloud::HardwareProfile::unit(prop)
    u = "" if ["label", "count"].include?(u)
    u = "vcpus" if prop == :cpu
    u
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deltacloud-core-0.5.0 lib/deltacloud/helpers/hardware_profiles_helper.rb
deltacloud-core-0.4.1 lib/deltacloud/helpers/hardware_profiles_helper.rb
deltacloud-core-0.4.0 lib/deltacloud/helpers/hardware_profiles_helper.rb
deltacloud-core-0.3.0 lib/deltacloud/helpers/hardware_profiles_helper.rb