File: storage_accounts.rb

package info (click to toggle)
ruby-gitlab-fog-azure-rm 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 756 kB
  • sloc: ruby: 5,926; sh: 9; makefile: 4
file content (47 lines) | stat: -rw-r--r-- 1,850 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Fog
  module AzureRM
    class Storage
      # This class is giving implementation of all/list, get and
      # check name availability for storage account.
      class StorageAccounts < Fog::Collection
        model Fog::AzureRM::Storage::StorageAccount
        attribute :resource_group

        def all
          accounts = []
          if !resource_group.nil?
            requires :resource_group
            hash_of_storage_accounts = service.list_storage_account_for_rg(resource_group)
          else
            hash_of_storage_accounts = service.list_storage_accounts
          end
          hash_of_storage_accounts.each do |account|
            accounts << Fog::AzureRM::Storage::StorageAccount.parse(account)
          end
          load(accounts)
        end

        def get(resource_group_name, storage_account_name)
          storage_account = service.get_storage_account(resource_group_name, storage_account_name)
          storage_account_fog = Fog::AzureRM::Storage::StorageAccount.new(service: service)
          storage_account_fog.merge_attributes(Fog::AzureRM::Storage::StorageAccount.parse(storage_account))
        end

        def check_name_availability(name, type = 'Microsoft.Storage/storageAccounts')
          service.check_storage_account_name_availability(name, type)
        end

        def delete_storage_account_from_tag(resource_group_name, tag_key, tag_value)
          storage_accounts = service.storage_accounts(resource_group: resource_group_name)
          storage_accounts.each do |account|
            account.destroy if account.tags[tag_key].eql? tag_value
          end
        end

        def check_storage_account_exists(resource_group_name, storage_account_name)
          service.check_storage_account_exists(resource_group_name, storage_account_name)
        end
      end
    end
  end
end