File: spec_helper.rb

package info (click to toggle)
ruby-azure-sdk 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 22,400 kB
  • ctags: 12,388
  • sloc: ruby: 168,299; sh: 6; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 3,212 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

require File.join(File.dirname(__FILE__), '../../../vcr_helper')
require 'azure_mgmt_resources'
require 'azure_mgmt_datalake_store'
require 'azure_mgmt_datalake_analytics'
require 'ms_rest_azure'

include MsRest
include MsRestAzure
include Azure::ARM::Resources
include Azure::ARM::DataLakeStore
include Azure::ARM::DataLakeAnalytics

class ResourceHelper
  @@resource_group_name = 'RubySDKTest_azure_mgmt_dl_analytics'

  attr_reader :resource_client, :dls_acc_client, :dla_acc_client

  def initialize
    tenant_id = ENV['AZURE_TENANT_ID']
    client_id = ENV['AZURE_CLIENT_ID']
    secret = ENV['AZURE_CLIENT_SECRET']
    @subscription_id = ENV['AZURE_SUBSCRIPTION_ID']

    token_provider = ApplicationTokenProvider.new(tenant_id, client_id, secret)
    @credentials = TokenCredentials.new(token_provider)
  end

  def resource_client
    if @resource_client.nil?
      @resource_client = ResourceManagementClient.new(@credentials)
      @resource_client.subscription_id = @subscription_id
      @resource_client.long_running_operation_retry_timeout = ENV.fetch('RETRY_TIMEOUT', 30).to_i
    end
    @resource_client
  end

  def dls_acc_client
    if @dls_acc_client.nil?
      @dls_acc_client = Azure::ARM::DataLakeStore::DataLakeStoreAccountManagementClient.new(@credentials)
      @dls_acc_client.subscription_id = @subscription_id
      @dls_acc_client.long_running_operation_retry_timeout = ENV.fetch('RETRY_TIMEOUT', 30).to_i
    end
    @dls_acc_client
  end

  def dla_acc_client
    if @dla_acc_client.nil?
      @dla_acc_client = Azure::ARM::DataLakeAnalytics::DataLakeAnalyticsAccountManagementClient.new(@credentials)
      @dla_acc_client.subscription_id = @subscription_id
      @dla_acc_client.long_running_operation_retry_timeout = ENV.fetch('RETRY_TIMEOUT', 30).to_i
    end
    @dla_acc_client
  end

  def create_resource_group
    params = Azure::ARM::Resources::Models::ResourceGroup.new()
    params.location = 'East US 2'

    resource_client.resource_groups.create_or_update(@@resource_group_name, params)
  end

  def delete_resource_group(name)
    resource_client.resource_groups.delete(name)
  end

  def create_datalake_store_account(name)
    dsl_acc = Azure::ARM::DataLakeStore::Models::DataLakeStoreAccount.new
    dsl_acc.name = name
    dsl_acc.location = 'East US 2'
    dls_acc_client.account.create(@@resource_group_name, name, dsl_acc)
  end

  def create_datalake_analysis_account(analytics_acc_name, store_acc_name)
    analytics_acc = Models::DataLakeAnalyticsAccount.new
    analytics_acc.name = analytics_acc_name
    analytics_acc.location = 'East US 2'

    dla_acc_prop = Models::DataLakeAnalyticsAccountProperties.new
    dla_acc_prop.default_data_lake_store_account = store_acc_name
    dla_acc_info = Models::DataLakeStoreAccountInfo.new
    dla_acc_info.name = store_acc_name

    dla_acc_prop.data_lake_store_accounts = [dla_acc_info]
    analytics_acc.properties = dla_acc_prop

    dla_acc_client.account.create(@@resource_group_name, analytics_acc_name, analytics_acc)
  end
end