gitlab-fog-azure-rm 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.arclint +8 -0
- data/.codeclimate.yml +17 -0
- data/.gitignore +6 -0
- data/.gitlab-ci.yml +17 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +274 -0
- data/.travis.yml +49 -0
- data/CHANGELOG.md +414 -0
- data/CONTRIBUTING.md +40 -0
- data/CONTRIBUTORS.md +12 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +100 -0
- data/gitlab-fog-azure-rm.gemspec +31 -0
- data/lib/fog/azurerm.rb +30 -0
- data/lib/fog/azurerm/async_response.rb +44 -0
- data/lib/fog/azurerm/config.rb +1 -0
- data/lib/fog/azurerm/constants.rb +72 -0
- data/lib/fog/azurerm/credentials.rb +40 -0
- data/lib/fog/azurerm/custom_fog_errors.rb +52 -0
- data/lib/fog/azurerm/docs/storage.md +398 -0
- data/lib/fog/azurerm/docs/structure.md +53 -0
- data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
- data/lib/fog/azurerm/models/resources/azure_resources.rb +40 -0
- data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
- data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
- data/lib/fog/azurerm/models/resources/deployments.rb +30 -0
- data/lib/fog/azurerm/models/resources/provider.rb +27 -0
- data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
- data/lib/fog/azurerm/models/resources/resource_group.rb +34 -0
- data/lib/fog/azurerm/models/resources/resource_groups.rb +29 -0
- data/lib/fog/azurerm/models/storage/directories.rb +75 -0
- data/lib/fog/azurerm/models/storage/directory.rb +151 -0
- data/lib/fog/azurerm/models/storage/file.rb +265 -0
- data/lib/fog/azurerm/models/storage/files.rb +183 -0
- data/lib/fog/azurerm/models/storage/kind.rb +12 -0
- data/lib/fog/azurerm/models/storage/sku_name.rb +15 -0
- data/lib/fog/azurerm/models/storage/sku_tier.rb +12 -0
- data/lib/fog/azurerm/models/storage/storage_account.rb +92 -0
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +47 -0
- data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +32 -0
- data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +32 -0
- data/lib/fog/azurerm/requests/storage/check_container_exists.rb +30 -0
- data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
- data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
- data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
- data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
- data/lib/fog/azurerm/requests/storage/copy_object.rb +20 -0
- data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
- data/lib/fog/azurerm/requests/storage/create_container.rb +40 -0
- data/lib/fog/azurerm/requests/storage/create_disk.rb +62 -0
- data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
- data/lib/fog/azurerm/requests/storage/delete_blob.rb +32 -0
- data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/delete_container.rb +31 -0
- data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
- data/lib/fog/azurerm/requests/storage/delete_object_url.rb +30 -0
- data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
- data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +55 -0
- data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
- data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
- data/lib/fog/azurerm/requests/storage/get_container_properties.rb +41 -0
- data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
- data/lib/fog/azurerm/requests/storage/get_object_url.rb +21 -0
- data/lib/fog/azurerm/requests/storage/list_blobs.rb +168 -0
- data/lib/fog/azurerm/requests/storage/list_containers.rb +73 -0
- data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
- data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
- data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
- data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_object_url.rb +30 -0
- data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +30 -0
- data/lib/fog/azurerm/requests/storage/release_container_lease.rb +30 -0
- data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
- data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
- data/lib/fog/azurerm/storage.rb +126 -0
- data/lib/fog/azurerm/utilities/general.rb +186 -0
- data/lib/fog/azurerm/utilities/logger_messages.yml +19 -0
- data/lib/fog/azurerm/version.rb +5 -0
- data/rake-script.sh +10 -0
- data/rakefile +29 -0
- data/test/api_stub.rb +147 -0
- data/test/api_stub/models/storage/directory.rb +178 -0
- data/test/api_stub/models/storage/file.rb +181 -0
- data/test/api_stub/requests/storage/directory.rb +89 -0
- data/test/api_stub/requests/storage/file.rb +252 -0
- data/test/integration/README.md +14 -0
- data/test/integration/blob.rb +297 -0
- data/test/integration/container.rb +160 -0
- data/test/integration/credentials/azure.yml +5 -0
- data/test/integration/storage_account.rb +135 -0
- data/test/models/storage/test_directories.rb +74 -0
- data/test/models/storage/test_directory.rb +178 -0
- data/test/models/storage/test_file.rb +294 -0
- data/test/models/storage/test_files.rb +234 -0
- data/test/requests/storage/test_acquire_blob_lease.rb +36 -0
- data/test/requests/storage/test_acquire_container_lease.rb +36 -0
- data/test/requests/storage/test_check_container_exists.rb +18 -0
- data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
- data/test/requests/storage/test_compare_container_blobs.rb +36 -0
- data/test/requests/storage/test_copy_blob.rb +39 -0
- data/test/requests/storage/test_copy_blob_from_uri.rb +36 -0
- data/test/requests/storage/test_create_block_blob.rb +80 -0
- data/test/requests/storage/test_create_container.rb +36 -0
- data/test/requests/storage/test_create_disk.rb +70 -0
- data/test/requests/storage/test_create_page_blob.rb +34 -0
- data/test/requests/storage/test_delete_blob.rb +42 -0
- data/test/requests/storage/test_delete_blob_https_url.rb +32 -0
- data/test/requests/storage/test_delete_container.rb +42 -0
- data/test/requests/storage/test_delete_disk.rb +30 -0
- data/test/requests/storage/test_get_blob.rb +141 -0
- data/test/requests/storage/test_get_blob_http_url.rb +30 -0
- data/test/requests/storage/test_get_blob_https_url.rb +32 -0
- data/test/requests/storage/test_get_blob_properties.rb +47 -0
- data/test/requests/storage/test_get_blob_url.rb +75 -0
- data/test/requests/storage/test_get_container_acl.rb +37 -0
- data/test/requests/storage/test_get_container_properties.rb +45 -0
- data/test/requests/storage/test_get_container_url.rb +33 -0
- data/test/requests/storage/test_list_blobs.rb +77 -0
- data/test/requests/storage/test_list_containers.rb +54 -0
- data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
- data/test/requests/storage/test_put_blob_block.rb +34 -0
- data/test/requests/storage/test_put_blob_https_url.rb +32 -0
- data/test/requests/storage/test_put_blob_metadata.rb +36 -0
- data/test/requests/storage/test_put_blob_pages.rb +34 -0
- data/test/requests/storage/test_put_blob_properties.rb +39 -0
- data/test/requests/storage/test_put_container_acl.rb +34 -0
- data/test/requests/storage/test_put_container_metadata.rb +36 -0
- data/test/requests/storage/test_release_blob_lease.rb +34 -0
- data/test/requests/storage/test_release_container_lease.rb +34 -0
- data/test/requests/storage/test_save_page_blob.rb +115 -0
- data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
- data/test/smoke_tests/compute/test_resource_group_smoke.rb +37 -0
- data/test/test_credentials.rb +63 -0
- data/test/test_helper.rb +846 -0
- metadata +352 -0
@@ -0,0 +1,398 @@
|
|
1
|
+
# Storage
|
2
|
+
|
3
|
+
This document explains how to get started using Azure Storage Service with Fog. With this gem you can create, update, list or delete storage accounts.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
First of all, you need to require the Fog library by executing:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'fog/azurerm'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Create Connection
|
14
|
+
|
15
|
+
Next, create a connection to the Storage Service:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
fog_storage_service = Fog::Storage::AzureRM.new(
|
19
|
+
tenant_id: '<Tenant Id>', # Tenant Id of Azure Active Directory Application
|
20
|
+
client_id: '<Client Id>', # Client Id of Azure Active Directory Application
|
21
|
+
client_secret: '<Client Secret>', # Client Secret of Azure Active Directory Application
|
22
|
+
subscription_id: '<Subscription Id>', # Subscription Id of an Azure Account
|
23
|
+
azure_storage_account_name: '<Storage Account Name>', # Name of an Azure Storage Account
|
24
|
+
azure_storage_access_key: '<Storage Account Key>', # Key of an Azure Storage Account
|
25
|
+
environment: '<AzureCloud/AzureChinaCloud/AzureUSGovernment/AzureGermanCloud>' # Azure cloud environment. Default is AzureCloud.
|
26
|
+
)
|
27
|
+
```
|
28
|
+
|
29
|
+
If you only want to manage the storage accounts, you can create the connection without the storage account information:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
fog_storage_service = Fog::Storage::AzureRM.new(
|
33
|
+
tenant_id: '<Tenant Id>', # Tenant Id of Azure Active Directory Application
|
34
|
+
client_id: '<Client Id>', # Client Id of Azure Active Directory Application
|
35
|
+
client_secret: '<Client Secret>', # Client Secret of Azure Active Directory Application
|
36
|
+
subscription_id: '<Subscription Id>', # Subscription Id of an Azure Account
|
37
|
+
environment: '<AzureCloud/AzureChinaCloud/AzureUSGovernment/AzureGermanCloud>' # Azure cloud environment. Default is AzureCloud.
|
38
|
+
)
|
39
|
+
```
|
40
|
+
|
41
|
+
If you only want to manage the storage data, you can create the connection without the Azure subscription information:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
fog_storage_service = Fog::Storage::AzureRM.new(
|
45
|
+
azure_storage_account_name: '<Storage Account Name>', # Name of an Azure Storage Account
|
46
|
+
azure_storage_access_key: '<Storage Account Key>', # Key of an Azure Storage Account
|
47
|
+
environment: '<AzureCloud/AzureChinaCloud/AzureUSGovernment/AzureGermanCloud>' # Azure cloud environment. Default is AzureCloud.
|
48
|
+
)
|
49
|
+
```
|
50
|
+
|
51
|
+
## Check Name Availability
|
52
|
+
|
53
|
+
This operation checks that account name is valid and is not already in use. _Storage Account Type_ is an optional parameter
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
fog_storage_service.storage_accounts.check_name_availability('<Storage Account Name>', '<Storage Account Type>')
|
57
|
+
```
|
58
|
+
|
59
|
+
## Check Storage Account Existence
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
fog_storage_service.storage_accounts.check_storage_account_exists('<Resource Group Name>', '<Storage Account Name>')
|
63
|
+
```
|
64
|
+
|
65
|
+
## Create Storage Account
|
66
|
+
|
67
|
+
Create a new storage account. Replication attribute for Standard and Premium account types are as follows
|
68
|
+
|
69
|
+
##### Standard
|
70
|
+
|
71
|
+
1. LRS (Standard Locally-redundant storage)
|
72
|
+
2. ZRS (Standard Zone-redundant storage)
|
73
|
+
3. GRS (Standard Geo-redundant storage)
|
74
|
+
4. RAGRS (Standard Read access geo-redundant storage)
|
75
|
+
|
76
|
+
##### Premium
|
77
|
+
1. LRS (Premium Locally-redundant storage)
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
fog_storage_service.storage_accounts.create(
|
81
|
+
name: '<Storage Account name>',
|
82
|
+
location: '<Location>',
|
83
|
+
resource_group: '<Resource Group Name>',
|
84
|
+
account_type: '<Standard/Premium>', # [Optional] Default value 'Standard'. Allowed values can only be Standard or Premium
|
85
|
+
replication: '<Replication Type>', # [Optional] Default value 'LRS'
|
86
|
+
encryption: <True/False>, # [Optional] Enables encryption. Default is false.
|
87
|
+
tags: { key1: 'value1', key2: 'value2', keyN: 'valueN' } # [Optional]
|
88
|
+
)
|
89
|
+
```
|
90
|
+
Premium Storage account store data on solid state drives (SSDs). For more details on standard and premium storage accounts, see [Introduction to Microsoft Azure Storage](https://azure.microsoft.com/en-us/documentation/articles/storage-introduction/) and [Premium Storage: High-Performance Storage for Azure Virtual Machine Workloads](https://azure.microsoft.com/en-us/documentation/articles/storage-premium-storage/).
|
91
|
+
|
92
|
+
## List storage accounts
|
93
|
+
|
94
|
+
##### List storage accounts in a subscription
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
fog_storage_service.storage_accounts.each do |storage_acc|
|
98
|
+
puts "#{storage_acc.name}"
|
99
|
+
puts "#{storage_acc.location}"
|
100
|
+
end
|
101
|
+
```
|
102
|
+
##### List storage accounts in a resource group
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
storage_accounts = fog_storage_service.storage_accounts(resource_group: '<Resource Group Name>')
|
106
|
+
storage_accounts.each do |storage_acc|
|
107
|
+
puts "#{storage_acc.name}"
|
108
|
+
puts "#{storage_acc.location}"
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
## Retrieve a single Storage Account
|
113
|
+
|
114
|
+
Get a single record of Storage Account
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
storage_acc = fog_storage_service
|
118
|
+
.storage_accounts
|
119
|
+
.get('<Resource Group Name>', '<Storage Account Name>')
|
120
|
+
puts "#{storage_acc.name}"
|
121
|
+
```
|
122
|
+
|
123
|
+
## Enable encryption on Storage Account
|
124
|
+
|
125
|
+
Get a single record of Storage Account and enable encryption on that Storage Account
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
storage_acc = fog_storage_service
|
129
|
+
.storage_accounts
|
130
|
+
.get('<Resource Group Name>', '<Storage Account Name>')
|
131
|
+
|
132
|
+
storage_acc.update(encryption: true)
|
133
|
+
```
|
134
|
+
|
135
|
+
## Get Access Keys
|
136
|
+
|
137
|
+
Get access keys of a storage account
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
keys_hash = storage_acc.get_access_keys
|
141
|
+
keys_hash.each do |keys|
|
142
|
+
puts "#{keys.key_name}: #{keys.value}"
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
## Destroy a single Storage Account
|
147
|
+
|
148
|
+
Get storage account object from the get method and then destroy that storage account.
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
storage_acc.destroy
|
152
|
+
```
|
153
|
+
|
154
|
+
## Create a Disk
|
155
|
+
|
156
|
+
Create a Disk in storage account. _disk_size_in_gb_ must be an integer and the range is [1, 1023].
|
157
|
+
By default the disk will be created in the container 'vhds'. You can specify other container by set options[:container_name].
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
fog_storage_service.create_disk('<Data Disk Name>', disk_size_in_gb, options = {})
|
161
|
+
```
|
162
|
+
|
163
|
+
## Delete a Disk
|
164
|
+
|
165
|
+
Delete a Disk from a storage account. Disk must be in unlocked state i.e detached from server (virtual machine) to successfully perform this action.
|
166
|
+
By default the disk will be deleted from the container 'vhds'. You can specify other container by set options[:container_name].
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
fog_storage_service.delete_disk('<Data Disk Name>', options = {})
|
170
|
+
```
|
171
|
+
|
172
|
+
## Check Storage Container Existence
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
fog_storage_service.directories.check_container_exists('<Container Name>')
|
176
|
+
```
|
177
|
+
|
178
|
+
## Create a storage container
|
179
|
+
|
180
|
+
Create a storage container in the current storage account.
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
directory = fog_storage_service.directories.create(
|
184
|
+
key: '<Container Name>',
|
185
|
+
public: <True/False>
|
186
|
+
)
|
187
|
+
puts directory.key
|
188
|
+
```
|
189
|
+
|
190
|
+
## List storage containers
|
191
|
+
|
192
|
+
List all the storage containers in the current storage accounts.
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
fog_storage_service.directories.each do |directory|
|
196
|
+
puts directory.key
|
197
|
+
end
|
198
|
+
```
|
199
|
+
|
200
|
+
## Get the access control level of the storage container
|
201
|
+
|
202
|
+
Get the permissions for the specified container. The permissions indicate whether container data may be accessed publicly.
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
206
|
+
puts directory.acl
|
207
|
+
```
|
208
|
+
|
209
|
+
## Set the access control level of the storage container
|
210
|
+
|
211
|
+
Set the permissions for the specified container. The permissions indicate whether container data may be accessed publicly. The container permissions provide the following options for managing container access:
|
212
|
+
|
213
|
+
- ###### Container
|
214
|
+
|
215
|
+
Full public read access. Container and blob data can be read via anonymous request. Clients can enumerate blobs within the container via anonymous request, but cannot enumerate containers within the storage account.
|
216
|
+
|
217
|
+
- ###### Blob
|
218
|
+
|
219
|
+
Public read access for blobs only. Blob data within this container can be read via anonymous request, but container data is not available. Clients cannot enumerate blobs within the container via anonymous request.
|
220
|
+
|
221
|
+
- ###### Nil
|
222
|
+
|
223
|
+
No public read access. Container and blob data can be read by the account owner only.
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
227
|
+
directory.acl = '<Container Name>'
|
228
|
+
directory.save(is_create: <True/False>)
|
229
|
+
```
|
230
|
+
|
231
|
+
## Delete the storage container
|
232
|
+
|
233
|
+
Mark the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection.
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
237
|
+
puts directory.destroy
|
238
|
+
```
|
239
|
+
|
240
|
+
## Upload data as a block blob
|
241
|
+
```ruby
|
242
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
243
|
+
options = {
|
244
|
+
key: '<Blob Name>',
|
245
|
+
body: '<Blob Content>'
|
246
|
+
}
|
247
|
+
new_block_blob = directory.files.create(options)
|
248
|
+
puts new_block_blob.inspect
|
249
|
+
```
|
250
|
+
|
251
|
+
## Upload a local file as a block blob
|
252
|
+
```ruby
|
253
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
254
|
+
File.open('<File Path>') do |file|
|
255
|
+
options = {
|
256
|
+
key: '<Blob Name>',
|
257
|
+
body: file
|
258
|
+
}
|
259
|
+
new_block_blob = directory.files.create(options)
|
260
|
+
puts new_block_blob.inspect
|
261
|
+
end
|
262
|
+
```
|
263
|
+
|
264
|
+
## Upload VHD data as a page blob
|
265
|
+
```ruby
|
266
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
267
|
+
options = {
|
268
|
+
key: '<Blob Name>',
|
269
|
+
body: '<Blob Content>',
|
270
|
+
blob_type: '<Blob Type>'
|
271
|
+
}
|
272
|
+
new_page_blob = directory.files.create(options)
|
273
|
+
puts new_page_blob.inspect
|
274
|
+
```
|
275
|
+
|
276
|
+
## Upload a local VHD as a page blob
|
277
|
+
```ruby
|
278
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
279
|
+
File.open('<File Path>') do |file|
|
280
|
+
options = {
|
281
|
+
key: '<Blob Name>',
|
282
|
+
body: file,
|
283
|
+
blob_type: '<Blob Type>'
|
284
|
+
}
|
285
|
+
new_page_blob = directory.files.create(options)
|
286
|
+
puts new_page_blob.inspect
|
287
|
+
end
|
288
|
+
```
|
289
|
+
|
290
|
+
## Copy Blob from one container to another
|
291
|
+
```ruby
|
292
|
+
directory = fog_storage_service.directories.get('<Source Container Name>', max_keys: <Maximum No. of Keys Value>)
|
293
|
+
copied_blob = directory.files.head('<Source Blob Name>').copy('<Destination Container Name>', '<Destination Blob Name>')
|
294
|
+
puts copied_blob.inspect
|
295
|
+
```
|
296
|
+
|
297
|
+
## Copy Blob from one uri to self
|
298
|
+
```ruby
|
299
|
+
directory = fog_storage_service.directories.get('<Destination Container Name>', max_keys: <Maximum No. of Keys Value>)
|
300
|
+
copied_blob = directory.files.new(key: '<Destination Blob Name>')
|
301
|
+
copied_blob.copy_from_uri('<Source Blob Uri>')
|
302
|
+
puts copied_blob.inspect
|
303
|
+
```
|
304
|
+
|
305
|
+
## Download a small blob to a local file
|
306
|
+
```ruby
|
307
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
308
|
+
blob = directory.files.get('<Blob Name>')
|
309
|
+
File.open('<File Path>', 'wb') do |file|
|
310
|
+
file.write(blob.body)
|
311
|
+
end
|
312
|
+
puts "File Size: #{::File.size <File Path>}"
|
313
|
+
```
|
314
|
+
|
315
|
+
## Download a large blob to a local file
|
316
|
+
```ruby
|
317
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
318
|
+
File.open('<File Path>', 'wb') do |file|
|
319
|
+
directory.files.get('<Blob Name>') do |chunk, remaining_bytes, total_bytes|
|
320
|
+
puts "remaining_bytes: #{remaining_bytes}, total_bytes: #{total_bytes}"
|
321
|
+
file.write(chunk)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
puts "File Size: #{::File.size <File Path>}"
|
325
|
+
```
|
326
|
+
|
327
|
+
## Delete the storage blob
|
328
|
+
|
329
|
+
Mark the specified blob for deletion. The blob is later deleted during garbage collection.
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
333
|
+
blob = directory.files.head('<Blob Name>')
|
334
|
+
puts blob.destroy
|
335
|
+
```
|
336
|
+
|
337
|
+
## Set storage blob properties
|
338
|
+
|
339
|
+
Set the storage blob properties.
|
340
|
+
|
341
|
+
```ruby
|
342
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
343
|
+
blob = directory.files.head('<Blob Name>')
|
344
|
+
blob.content_language = '<Language>'
|
345
|
+
blob.content_disposition = '<Content Disposition Type>'
|
346
|
+
blob.save(update_body: <True/False>)
|
347
|
+
```
|
348
|
+
|
349
|
+
## Metadata
|
350
|
+
|
351
|
+
Metadata allows us to provide descriptive information about specific containers or blobs. This is simply providing name/value pairs of data we want to set on the container or blob.
|
352
|
+
|
353
|
+
### Get Blob Metadata
|
354
|
+
|
355
|
+
```ruby
|
356
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
357
|
+
blob = directory.files.head('<Blob Name>')
|
358
|
+
puts blob.metadata
|
359
|
+
```
|
360
|
+
|
361
|
+
### Set Blob Metadata
|
362
|
+
|
363
|
+
```ruby
|
364
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
365
|
+
blob = directory.files.head('<Blob Name>')
|
366
|
+
blob.metadata = {
|
367
|
+
Category: '<Category Value>',
|
368
|
+
Resolution: '<Resolution Value>'
|
369
|
+
}
|
370
|
+
blob.save(update_body: <True/False>)
|
371
|
+
```
|
372
|
+
|
373
|
+
### Get Container Metadata
|
374
|
+
|
375
|
+
```ruby
|
376
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
377
|
+
puts directory.metadata
|
378
|
+
```
|
379
|
+
|
380
|
+
### Set Container Metadata
|
381
|
+
|
382
|
+
```ruby
|
383
|
+
directory = fog_storage_service.directories.get('<Container Name>', max_keys: <Maximum No. of Keys Value>)
|
384
|
+
directory.metadata = {
|
385
|
+
CreatedBy: '<Username>',
|
386
|
+
SourceMachine: '<Machine Name>',
|
387
|
+
category: '<Category Value>',
|
388
|
+
docType: '<Document Type>'
|
389
|
+
}
|
390
|
+
directory.save(is_create: <True/False>)
|
391
|
+
```
|
392
|
+
|
393
|
+
## Support and Feedback
|
394
|
+
Your feedback is appreciated! If you have specific issues with the fog ARM, you should file an issue via Github.
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Fog
|
2
|
+
Whether you need compute, dns, storage, or a multitude of other services, fog provides an accessible entry point and facilitates cross service compatibility. Fog delivers the knowledge of cloud experts to you, helping you to bootstrap your cloud usage and guiding you as your own expertise develops.
|
3
|
+
|
4
|
+
By coding with fog from the start you avoid vendor lock-in and give yourself more flexibility to provide value. Whether you are writing a library, designing a software as a service product or just hacking on the weekend this flexibility is a huge boon.
|
5
|
+
|
6
|
+
# Structure
|
7
|
+
fog is the Ruby cloud computing library, top to bottom:
|
8
|
+
|
9
|
+
- Collections provide a simplified interface, making clouds easier to work with and switch between.
|
10
|
+
- Requests allow power users to get the most out of the features of each individual cloud.
|
11
|
+
- Mocks make testing and integrating a breeze.
|
12
|
+
|
13
|
+
#### Collections
|
14
|
+
Some collections are available across multiple providers:
|
15
|
+
- dns providers have `zones` and `records`
|
16
|
+
- compute providers have `images` and `servers`
|
17
|
+
|
18
|
+
Collections share basic CRUD type operations, such as:
|
19
|
+
- **all** - fetch every object of that type from the provider.
|
20
|
+
- **get** - fetch a single object by it’s identity from the provider.
|
21
|
+
|
22
|
+
#### Models
|
23
|
+
Many of the collection methods return individual objects, which also provide common methods:
|
24
|
+
- **destroy** - will destroy the persisted object from the provider.
|
25
|
+
- **save** - persist the object to the provider.
|
26
|
+
|
27
|
+
#### Requests
|
28
|
+
Requests allow you to dive deeper when the models just can’t cut it. You can see a list of available requests by calling `requests` on the connection object.
|
29
|
+
|
30
|
+
#### Mocks
|
31
|
+
As you might imagine, testing code using fog can be slow and expensive, constantly turning on and shutting down instances. Mocking allows skipping this overhead by providing an in-memory representation resources as you make requests.
|
32
|
+
|
33
|
+
# Fog Provider Directory Structure
|
34
|
+
```sh
|
35
|
+
Plugin Root
|
36
|
+
|--- lib
|
37
|
+
|--- fog
|
38
|
+
|--- azurerm.rb #registers provider
|
39
|
+
|--- azurerm
|
40
|
+
|--- compute.rb #registers all models, collections and requests
|
41
|
+
|--- dns.rb #registers all models, collections and requests
|
42
|
+
|--- storage.rb #registers all models, collections and requests
|
43
|
+
|--- models #models and collections
|
44
|
+
|--- compute #models and collections for compute
|
45
|
+
|--- dns
|
46
|
+
|--- storage
|
47
|
+
|--- requests #requests - includes Real and Mock Classes
|
48
|
+
|--- compute #requests for compute
|
49
|
+
|--- dns
|
50
|
+
|--- storage
|
51
|
+
```
|
52
|
+
|
53
|
+
For more information about fog structure [Click Here](http://fog.io/about/structure.html)
|