Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ServiceSizingPolicy #180

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/aptible/api/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Account < Resource
has_many :metric_drains
has_many :vhosts
has_many :backup_retention_policies
has_many :service_sizing_policies
embeds_many :log_drains

field :id
Expand Down
1 change: 1 addition & 0 deletions lib/aptible/api/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def root_url
require 'aptible/api/permission'
require 'aptible/api/release'
require 'aptible/api/service'
require 'aptible/api/service_sizing_policy'
require 'aptible/api/source'
require 'aptible/api/vhost'
require 'aptible/api/ssh_portal_connection'
Expand Down
16 changes: 16 additions & 0 deletions lib/aptible/api/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Service < Resource
has_many :operations
has_many :releases
has_many :disk_attachments
has_one :service_sizing_policy

field :id
field :handle
Expand All @@ -21,6 +22,21 @@ class Service < Resource
field :instance_class
field :created_at, type: Time
field :updated_at, type: Time

def create_service_sizing_policy!(params)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necesary because of the level of indirection we created in deploy-api

params = { token: token }.merge(params)

# First create a link object so we know where to go
link = HyperResource::Link.new(
self,
'href' => "#{href}/service_sizing_policies"
)

# Now create the policy
link.create(
self.class.normalize_params(params)
)
end
end
end
end
33 changes: 33 additions & 0 deletions lib/aptible/api/service_sizing_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Aptible
module Api
class ServiceSizingPolicy < Resource
belongs_to :account
has_many :services

field :id
field :created_at, type: Time
field :updated_at, type: Time

field :scaling_enabled
field :default_policy
field :metric_lookback_seconds
field :percentile
field :post_scale_up_cooldown_seconds
field :post_scale_down_cooldown_seconds
field :post_release_cooldown_seconds
field :mem_cpu_ratio_r_threshold
field :mem_cpu_ratio_c_threshold
field :mem_scale_up_threshold
field :mem_scale_down_threshold
field :minimum_memory
field :disable_recommendations
field :maximum_memory
field :cpu_consideration_threshold
field :autoscaling
field :min_cpu_threshold
field :max_cpu_threshold
field :min_containers
field :max_containers
end
end
end