GithubHelp home page GithubHelp logo

isabella232 / media-services-ruby-manage-services Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/media-services-ruby-manage-services

0.0 0.0 0.0 8 KB

Sample shows how to manage Azure media services using Ruby client

License: MIT License

Ruby 100.00%

media-services-ruby-manage-services's Introduction

services platforms author
media-services
ruby
vishrutshah

Manage Azure media services with Ruby

This sample demonstrates how to manage Azure media services using the Ruby SDK.

Manage Azure resources and resource groups with Ruby

On this page

Run this sample

  1. If you don't already have it, install Ruby and the Ruby DevKit.

  2. If you don't have bundler, install it.

    gem install bundler
    
  3. Clone the repository.

    git clone https://github.com/Azure-Samples/media-services-ruby-manage-services.git
    
  4. Install the dependencies using bundle.

    cd media-services-ruby-manage-services
    bundle install
    
  5. Create an Azure service principal either through Azure CLI, PowerShell or the portal.

  6. Set the following environment variables using the information from the service principle that you created.

    export AZURE_TENANT_ID={your tenant id}
    export AZURE_CLIENT_ID={your client id}
    export AZURE_CLIENT_SECRET={your client secret}
    export AZURE_SUBSCRIPTION_ID={your subscription id}
    

    [AZURE.NOTE] On Windows, use set instead of export.

  7. Run the sample.

    bundle exec ruby example.rb
    

What is example.rb doing?

The sample walks you through several media service management operations. It starts by setting up ResourceManagementClient, StorageManagementClient, and MediaServiceManagementClient objects using your subscription and credentials.

#
# Create the Resource Manager Client with an Application (service principal) token provider
#
subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] || '11111111-1111-1111-1111-111111111111' # your Azure Subscription Id
provider = MsRestAzure::ApplicationTokenProvider.new(
    ENV['AZURE_TENANT_ID'],
    ENV['AZURE_CLIENT_ID'],
    ENV['AZURE_CLIENT_SECRET'])
credentials = MsRest::TokenCredentials.new(provider)

# resource client
resource_client = Azure::ARM::Resources::ResourceManagementClient.new(credentials)
resource_client.subscription_id = subscription_id

# storage client
storage_client = Azure::ARM::Storage::StorageManagementClient.new(credentials)
storage_client.subscription_id = subscription_id

# media services client
media_services_client = Azure::ARM::MediaServices::MediaServicesManagementClient.new(credentials)
media_services_client.subscription_id = subscription_id

It registers the subscription for the "Microsoft.Media" namespace and creates a resource group and a storage account where the media services will be managed.

#
# Register subscription for 'Microsoft.Media' namespace
#
provider = resource_client.providers.register('Microsoft.Media')

#
# Create a resource group
#
resource_group_params = Azure::ARM::Resources::Models::ResourceGroup.new.tap do |rg|
    rg.location = REGION
end

resource_group = resource_client.resource_groups.create_or_update(RESOURCE_GROUP_NAME, resource_group_params)

#
# Create a storage account
#
param = Azure::ARM::Storage::Models::StorageAccountCreateParameters.new.tap do |acc|
    acc.sku = Azure::ARM::Storage::Models::Sku.new.tap do |sku|
        sku.name = Azure::ARM::Storage::Models::SkuName::StandardLRS
        sku.tier = Azure::ARM::Storage::Models::SkuTier::Standard
    end
    acc.kind = Azure::ARM::Storage::Models::Kind::Storage
    acc.location = REGION
end
storage_account = storage_client.storage_accounts.create(RESOURCE_GROUP_NAME, STORAGE_ACC_NAME, param)

There are a couple of supporting functions (print_item and print_properties) that print a resource group and it's properties. With that set up, the sample lists all resource groups for your subscription, it performs these operations.

param = Azure::ARM::MediaServices::Models::MediaService.new
param.location = REGION
param.tags = {
    :tag1 => 'tag1'
}
storage_acc = Azure::ARM::MediaServices::Models::StorageAccount.new.tap do |acc|
    acc.id = storage_account.id
    acc.is_primary = true
end
param.storage_accounts = [storage_acc]

media_service = media_services_client.media_service_operations.create(RESOURCE_GROUP_NAME, MEDIA_SERVICE_NAME, param)

media_service_collection = media_services_client.media_service_operations.list_by_resource_group(RESOURCE_GROUP_NAME)

media_services_client.media_service_operations.delete(RESOURCE_GROUP_NAME, MEDIA_SERVICE_NAME)

media-services-ruby-manage-services's People

Contributors

acomsmpbot avatar allclark avatar devigned avatar sarangan12 avatar vishrutshah avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.