ManageIQ/manageiq-providers-openstack

View on GitHub
lib/manageiq/providers/openstack/legacy/openstack_handle/compute_delegate.rb

Summary

Maintainability
A
40 mins
Test Coverage
A
94%
module OpenstackHandle
  class ComputeDelegate < DelegateClass(Fog::OpenStack::Compute)
    include OpenstackHandle::HandledList
    include Vmdb::Logging

    SERVICE_NAME = "Compute"

    attr_reader :name

    def initialize(dobj, os_handle, name)
      super(dobj)
      @os_handle = os_handle
      @name      = name
      @proxy     = openstack_proxy if openstack_proxy
    end

    def quotas_for_current_tenant
      if current_tenant.kind_of?(Hash)
        @tenant_id ||= current_tenant['id']
      else
        # Seems like keystone v3 has string in current_tenant
        @tenant_id ||= @os_handle.tenants.detect { |x| x.name == current_tenant }.id
      end
      q = get_quota(@tenant_id).body['quota_set']
      # looks like the quota id and the tenant id are the same,
      # but set the tenant id anyway, just in case.
      q.merge!('tenant_id' => @tenant_id, 'service_name' => SERVICE_NAME)
    end

    def quotas_for_accessible_tenants
      @os_handle.accessor_for_accessible_tenants(SERVICE_NAME, :quotas_for_current_tenant, 'id', false)
    end
  end
end