Class: HCloud::StorageBoxSubaccount

Inherits:
Resource
  • Object
show all
Defined in:
lib/hcloud/resources/storage_box_subaccount.rb

Overview

Represents a storage box’s subaccount

List all subaccounts

storage_box = HCloud::StorageBox.find(1)
storage_box.subaccounts
# => [#<HCloud::StorageBox::Subaccount id: 1, ...>, ...]

Search subaccounts

storage_box = HCloud::StorageBox.find(1)
storage_box.subaccounts.where(label_selector: "environment=production")
# => #<HCloud::StorageBox::Subaccount id: 1, ...>

Find subaccount by ID

storage_box = HCloud::StorageBox.find(1)
storage_box.subaccounts.find(1)
# => #<HCloud::StorageBox::Subaccount id: 1, ...>

Create subaccount

storage_box = HCloud::StorageBox.find(1)
subaccount = storage_box.subaccounts.new(password: "my_password", description: "my_subaccount", home_directory: "backup/", access_settings: { samba_enabled: false, ssh_enabled: true, webdav_enabled: false, readonly: false, reachable_externally: false })
subaccount.create
subaccount.created?
# => false

Note: this method returns a {HCloud::Action} instance rather than the created resource itself, as the subaccount is created asynchronously.
Reload the subaccount to check if it was created successfully.

subaccount.reload
subaccount.created?
# => true

subaccount = storage_box.subaccounts.create(password: "my_password", description: "my_subaccount", home_directory: "backup/", access_settings: { samba_enabled: false, ssh_enabled: true, webdav_enabled: false, readonly: false, reachable_externally: false })
# => #<HCloud::Action id: 1, ...>

Note: this method returns a {HCloud::Action} instance rather than the created resource itself

subaccount = HCloud::StorageBox::Subaccount.create(storage_box: 1, password: "my_password", description: "my_subaccount", home_directory: "backup/", access_settings: { samba_enabled: false, ssh_enabled: true, webdav_enabled: false, readonly: false, reachable_externally: false })
# => #<HCloud::Action id: 1, ...>

Note: this method returns a {HCloud::Action} instance rather than the created resource itself

Update subaccount

storage_box = HCloud::StorageBox.find(1)
subaccount = storage_box.subaccounts.find(1)
subaccount.description = "another_subaccount"
subaccount.update

Delete subaccount

storage_box = HCloud::StorageBox.find(1)
subaccount = storage_box.subaccounts.find(1)
subaccount.delete
# => #<HCloud::Action id: 1, ...>

subaccount.deleted?
# => true

Note: this method returns a {HCloud::Action} instance rather than the deleted resource itself

Resource-specific actions

Reset password

storage_box = HCloud::StorageBox.find(1)
subaccount = storage_box.subaccounts.find(1)
subaccount.reset_subaccount_password(password: "mypassword")
# => #<HCloud::Action id: 1, ...>

Update access settings

storage_box = HCloud::StorageBox.find(1)
subaccount = storage_box.subaccounts.find(1)
subaccount.update_access_settings(samba_enabled: false, ssh_enabled: true, webdav_enabled: false, zfs_enabled: false, reachable_externally: false)
# => #<HCloud::Action id: 1, ...>

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #initialize, #inspect, #to_h

Constructor Details

This class inherits a constructor from HCloud::Resource

Class Method Details

.clientObject



125
126
127
# File 'lib/hcloud/resources/storage_box_subaccount.rb', line 125

def self.client
  HCloud::Client.connection.storage_box_client
end

.resource_nameObject



121
122
123
# File 'lib/hcloud/resources/storage_box_subaccount.rb', line 121

def self.resource_name
  "subaccount"
end

Instance Method Details

#creatable_attributesObject



113
114
115
# File 'lib/hcloud/resources/storage_box_subaccount.rb', line 113

def creatable_attributes
  [:password, :home_directory, :description, :labels, :access_settings]
end

#updatable_attributesObject



117
118
119
# File 'lib/hcloud/resources/storage_box_subaccount.rb', line 117

def updatable_attributes
  [:description, :labels]
end