Sha256: c6d888d2c3a07f089f2bf0769250172ccb88141809086f70e4e0ea2a9e156c6c

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

module Yao::Resources
  class ComputeServices < Base
    friendly_attributes  :status, :binary, :host, :zone, :state, :disabled_reason, :forced_down

    map_attributes_to_time :updated_at
    alias :updated :updated_at

    self.service        = "compute"
    self.resource_name  = "service"
    self.resources_name = "os-services"

    # return true if ComputeServices is enabled
    # @return [Bool]
    def enabled?
      status == 'enabled'
    end

    # return true if ComputeServices is disabled
    # @return [Bool]
    def disabled?
      status == 'disabled'
    end

    class << self
      # @param host [String]
      # @param binary [String]
      # @return [Yao::Resources::ComputeServices]
      def enable(host, binary)
        params = {
          "host" => host,
          "binary" => binary,
        }
        put("enable", params)
      end

      # @param host [String]
      # @param binary [String]
      # @param resason [String]
      # @return [Yao::Resources::ComputeServices]
      def disable(host, binary, reason = nil)
        params = {
          "host" => host,
          "binary" => binary,
        }
        if reason
          params["disabled_reason"] = reason
          put("disable-log-reason", params)
        else
          put("disable", params)
        end
      end

      private

      # @param path [String]
      # @param  params [Hash]
      # @return [Yao::Resources::ComputeServices]
      def put(path, params)
        res = PUT(create_url(path), params) do |req|
          req.body = params.to_json
          req.headers['Content-Type'] = 'application/json'
        end
        resource_from_json(res.body)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yao-0.19.0 lib/yao/resources/compute_services.rb