Sha256: 4fd2b8604bff673ab1ed3a73e7bbcda1230f8b3628f8d5c98d4b76ae7d00f6ca

Contents?: true

Size: 1.68 KB

Versions: 53

Compression:

Stored size: 1.68 KB

Contents

class Ey::Core::Client::Provider < Ey::Core::Model
  extend Ey::Core::Associations

  identity :id, type: :integer

  attribute :cancelled_at, type: :time
  attribute :created_at,   type: :time
  attribute :credentials
  attribute :provisioned_id
  attribute :shared,       type: :boolean
  attribute :type
  attribute :updated_at,   type: :time

  has_one :account

  has_many :provider_locations
  has_many :servers
  has_many :storages
  has_many :untracked_servers

  def possible_locations(provider_type = self.type)
    self.connection.get_possible_provider_locations(provider_type).body["locations"].map { |l| l["id"] }
  end

  def database_server_snapshots
    connection.database_server_snapshots.load(connection.get_database_server_snapshots("provider" => self.id).body["database_server_snapshots"])
  end

  def discover_database_server_snapshots
    connection.requests.new(connection.discover_database_server_snapshots("provider" => self.id).body["request"])
  end

  # @return [Ey::Core::Client::Account]
  def account
    self.connection.accounts.new(self.connection.get_account("url" => self.account_url).body["account"])
  end

  def destroy!
    connection.requests.new(self.connection.destroy_provider(self.id).body["request"])
  end

  def save
    params = {
      "url"      => self.collection.url,
      "account"  => self.account_id,
      "provider" => {
        "credentials"    => self.credentials,
        "provisioned_id" => self.provisioned_id,
        "type"           => self.type,
      },
    }
    if new_record?
      connection.requests.new(self.connection.create_provider(params).body["request"])
    else raise NotImplementedError # update
    end
  end

  alias save! save
end

Version data entries

53 entries across 53 versions & 3 rubygems

Version Path
ey-core-3.1.11 lib/ey-core/models/provider.rb
ey-core-3.1.10 lib/ey-core/models/provider.rb
ey-core-3.1.9 lib/ey-core/models/provider.rb
ey-core-3.1.8 lib/ey-core/models/provider.rb
ey-core-3.1.7 lib/ey-core/models/provider.rb
ey-core-3.1.6 lib/ey-core/models/provider.rb
ey-core-3.1.5 lib/ey-core/models/provider.rb
ey-core-3.1.4 lib/ey-core/models/provider.rb
ey-core-3.1.3 lib/ey-core/models/provider.rb
ey-core-3.1.2 lib/ey-core/models/provider.rb
ey-core-3.1.1 lib/ey-core/models/provider.rb
ey-core-3.1.0 lib/ey-core/models/provider.rb
ey-core-3.0.5 lib/ey-core/models/provider.rb
ey-core-3.0.4 lib/ey-core/models/provider.rb
ey-core-3.0.3 lib/ey-core/models/provider.rb
ey-core-3.0.2 lib/ey-core/models/provider.rb
ey-core-3.0.1 lib/ey-core/models/provider.rb
ey-core-3.0.0 lib/ey-core/models/provider.rb
ey-pro-cli-0.0.17 lib/vendor/core/ey-core/models/provider.rb
ey-pro-cli-0.0.16 lib/vendor/core/ey-core/models/provider.rb