PageRenderTime 172ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/resource_management/azure_mgmt_resources/README.md

https://gitlab.com/pymevirtual/azure-sdk-for-ruby
Markdown | 106 lines | 67 code | 39 blank | 0 comment | 0 complexity | bd5096a39b11ce598d21db17fcabd8bd MD5 | raw file
  1. # Intro
  2. This project provides a Ruby gem for easy access to the Azure ARM Resources API. With this gem you can create/update/list/delete resources, resource groups, resource providers and deployments.
  3. # Supported Ruby Versions
  4. * Ruby 2+
  5. Note: x64 Ruby for Windows is known to have some compatibility issues.
  6. # Getting started
  7. ## Setting up the service principal
  8. First of all to start interacting with the ARM resources you will need to setup a service principal. Service principal is an Azure application which allows you to authenticate to Azure and access Azure services. The detailed steps of how to setup a service principal can be found in this article: http://aka.ms/cli-service-principal. In the result of setting up service principal you will get tenant id, client id and client secret data.
  9. ## Installation
  10. install the appropriate gem:
  11. ```
  12. gem install azure_mgmt_resources
  13. ```
  14. and reference it in your code:
  15. ```Ruby
  16. require 'azure_mgmt_resources'
  17. ```
  18. After that you should be ready to start using SDK!
  19. ## Authentication
  20. ```Ruby
  21. # Create authentication objects
  22. token_provider = MsRestAzure::ApplicationTokenProvider.new(tenant_id, client_id, secret)
  23. credentials = MsRest::TokenCredentials.new(token_provider)
  24. ```
  25. To get tenant_id, client_id and secret for your Azure application visit Azure portal or copy them from the powershell script from the article mentioned above.
  26. ## Creating resource group
  27. ```Ruby
  28. # Create a client - a point of access to the API and set the subscription id
  29. client = Azure::ARM::Resources::ResourceManagementClient.new(credentials)
  30. client.subscription_id = subscription_id
  31. # Create a model for resource group.
  32. resource_group = Azure::ARM::Resources::Models::ResourceGroup.new()
  33. resource_group.location = 'westus'
  34. promise = client.resource_groups.create_or_update('new_test_resource_group', resource_group)
  35. ```
  36. The SDK method returns a promise which you can utilize depending on your needs. E.g. if you need to get result immediately via sync blocking call - do the following:
  37. ```Ruby
  38. result = promise.value!
  39. ```
  40. If you need to follow async flow - provide a block which will be executed in off main thread:
  41. ```Ruby
  42. promise = promise.then do |result|
  43. # Handle the result
  44. end
  45. ```
  46. In both cases you're returned an instance of MsRestAzure::AzureOperationResponse which contains HTTP requests/response objects and response body. Response body is a deserialized object representing the received information. In case of code above - newly created resource group. To get data from it:
  47. ```Ruby
  48. resource_group = result.body
  49. p resource_group.name # 'new_test_resource_group'
  50. p resource_group.id # the id of resource group
  51. ```
  52. Congrats, you've create an ARM resource group. We encourage you to try more stuff and let us know your feedback!
  53. # Running tests
  54. ## Adding env variables
  55. To run the tests you would need to set the following environment variables with your real Azure data:
  56. * AZURE_TENANT_ID="your tenant id or domain"
  57. * AZURE_CLIENT_ID="your client id / application id"
  58. * AZURE_CLIENT_SECRET="your service principal secret"
  59. * AZURE_SUBSCRIPTION_ID="your subscription id"
  60. * run_long_tasks - set this to '1' only if you would like to run time consuming tests like VM creation.
  61. ## Starting tests
  62. Just run 'rspec' command from the current gem folder.
  63. # Contribution
  64. All the SDK code was generated by tool 'AutoRest' - https://github.com/Azure/autorest
  65. So if you have found a bug or have an idea for a new feature - suggest, discuss and contribute it into the AutoRest repository. After that SDK maintainers will update the sources and the gem.
  66. # Provide feedback
  67. Send email to the azsdkteam@microsoft.com or file new issue in this repository.