plugins/resource_management/app/helpers/resource_management/application_helper.rb
# Returns a pair of primary and secondary description of a resource (both
# may be empty strings).
Returns a pair of primary and secondary description of a resource (both
may be empty strings).
Returns a pair of primary and secondary description of a resource ( both may be empty strings ) .
def userfriendly_resource_description(resource)
      if resource.respond_to?(:name)
        resource_name = resource.name.to_s
      else
        resource_name = resource.to_s
      end
      if resource_name =~ /^instances_/
        flavor_name = resource_name.sub(/^instances_/, '')
        flavor = (@flavor_cache ||= cloud_admin.compute.flavors).find { |f| f.name == flavor_name }
        return '', '' if flavor.nil?
        @flavor_metadata_cache ||= {}
        m = (@flavor_metadata_cache[flavor.id] ||= cloud_admin.compute.find_flavor_metadata(flavor.id))
        return '', '' if m.nil?
        mib = Core::DataType.new(:bytes, :mega)
        gib = Core::DataType.new(:bytes, :giga)
        puts ">>>>> FLAVOR: #{flavor.inspect}"
        primary = []
        primary << "#{flavor.vcpus} cores" if flavor.vcpus
        primary << "#{mib.format(flavor.ram.to_i)} RAM" if flavor.ram
        primary << "#{gib.format(flavor.disk.to_i)} disk" if flavor.disk
        secondary = m.attributes['catalog:description'] || ''
        return primary.join(", "), secondary
      end
      return '', ''
    end
def userfriendly_resource_description ( resource ) if resource . respond_to? ( :name ) resource_name = resource . name . to_s else resource_name = resource . to_s end if resource_name =~ / ^instances_ / flavor_name = resource_name . sub ( / ^instances_ / , '' ) flavor = ( @flavor_cache ||= cloud_admin . compute . flavors ) . find { | f | f . name == flavor_name } return '' , '' if flavor . nil? @flavor_metadata_cache ||= { } m = ( @flavor_metadata_cache [ flavor . id ] ||= cloud_admin . compute . find_flavor_metadata ( flavor . id ) ) return '' , '' if m . nil? mib = Core :: DataType . new ( :bytes , :mega ) gib = Core :: DataType . new ( :bytes , :giga ) puts ">>>>> FLAVOR: #{flavor.inspect}" primary = [ ] primary << "#{flavor.vcpus} cores" if flavor . vcpus primary << "#{mib.format(flavor.ram.to_i)} RAM" if flavor . ram primary << "#{gib.format(flavor.disk.to_i)} disk" if flavor . disk secondary = m . attributes [ 'catalog:description' ] || '' return primary . join ( ", " ) , secondary end return '' , '' end
Returns a pair of primary and secondary description of a resource (both
may be empty strings).
Returns a pair of primary and secondary description of a resource ( both may be empty strings ) .
# special case: for per-flavor instance quotas, there is a description of # the flavor in the "catalog:description" extra-spec # map flavor name to ID # retrieve extraspecs # standard case: most stuff does not have a description
resource
<not_specific>