Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Wednesday, 26 December 2018

Microsoft Azure: Implementing Internet Facing Load Balancer

 

Microsoft Azure: Implementing Internet Facing Load Balancers using Azure Resource Manager

 

In this Video, I will show you How to create an External Load balancer using Azure Resource Manager. We will create two load balanced web-servers publicly accessible through a common IP address.

Then we will test that load balancer through a common IP

 

Step 1: Create a VM in one region

Step 2: Create another VM in that region

Step 3: Create a Load Balancer

Step 4: Test Load Balancer

Create a new resource group

 

 

Create a new Virtual network

Create a Virtual Machine

 

Create a Availability Set

Select appropriate VM compute resources

 

 

 

Create another VM and add in same region and availability set

                               

 

Create a Load Balancer for both VM

 

Create a new Probe

Add rule to redirect load balancer port

 

Test Load Balancer:

Test the LB by turnoff one VM

Thursday, 20 December 2018

Vnet-Vnet Between Different Region and Different Subscripiton

Overview:

 

This article helps you connect virtual networks (VNets) by using the VNet-to-VNet connection type. Virtual networks can be in different regions and from different subscriptions. When you connect VNets from different subscriptions, the subscriptions don't need to be associated with the same Active Directory tenant.

SetUp a xyz company network

 

Create a new Resource group :

 

 

Create a Virtual Network :

 

Create a Gateway Subnet :

 

 

 

Create a VM in your Virtual Network .

Create a Virtual Network Gateway

 

 

SetUp a ABC Company network

 

Create New resource group for abc company

 

 

Create a Virtual Network

Add SubNet

 

Create a new VM

Create a Virtual Network Gateway

Connect Abc and Xyz Virtual Network Gateway using Powershell CLI

 

Fetch the id for Vnet-Gateway using command :

 

az network vnet-gateway show -n xyz-vnet-gateway -g xyz-resgroup

 

Execute below command in Subscription 1:

 

az network vpn-connection create -n xyzvnet-abcvnet -g xyz-resgroup --vnet-gateway1 /subscriptions/subscription-id2/resourceGroups/xyz-resgroup/providers/Microsoft.Network/virtualNetworkGateways/xyz-vnet-gateway -l "West US 2" --shared-key "eeffgg" --vnet-gateway2 /subscriptions/subscription-id/resourceGroups/abc-resgroup/providers/Microsoft.Network/virtualNetworkGateways/abc-vnet-gateway

Execute below command in Subscription 2:

 

az network vpn-connection create -n abcvnet-xyzvnet -g abc-resgroup --vnet-gateway1 /subscriptions/subscription-id/resourceGroups/abc-resgroup/providers/Microsoft.Network/virtualNetworkGateways/abc-vnet-gateway -l "East US 2" --shared-key "eeffgg" --vnet-gateway2 /subscriptions/subscription-id2/resourceGroups/xyz-resgroup/providers/Microsoft.Network/virtualNetworkGateways/xyz-vnet-gateway

Test the connection :

Test the RDP using private IP from one machine to another machine.


 

Monday, 3 December 2018

Create a logic apps for receiving a json array (Employee records) using Rest end point and save each record in Azure SQL database

Create a logic apps for receiving a json array (Employee records) using Rest end point  and save each record in Azure SQL database .
Create Logic Apps
Create a Azure SQL database and database server.
3 resources created in your resource group now
Create Table in your database using Azure Query editor
Query:
CREATE TABLE [dbo].[Employee](
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [UserId] [nvarchar](50) NULL,
      [JobTitleName] [nvarchar](50) NULL,
      [FirstName] [nvarchar](50) NULL,
      [LastName] [nvarchar](50) NULL,
      [PreferredFullName] [nvarchar](50) NULL,
      [EmployeeCode] [nvarchar](50) NULL,
      [PhoneNumber] [nvarchar](50) NULL,
      [EmailAddress] [nvarchar](50) NULL
     
 CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
(
      [ID] ASC
))
Design Logic App using a blank logic app
We are using HTTP end point as trigger so that you can trigger or call your logic apps through a URL.
Employess sample JSON Payload
{
"Employees" : [
{
"userId":"rirani",
"jobTitleName":"Developer",
"firstName":"Romin",
"lastName":"Irani",
"preferredFullName":"Romin Irani",
"employeeCode":"E1",
"region":"CA",
"phoneNumber":"408-1234567",
"emailAddress":"romin.k.irani@gmail.com"
}
]
}
Next choose foreach control
Now add action inside foreach loop (SQL Connection).
Map json with Table Column
Save the logic app .
It will generate the end point for your logic app .
Test Logic app using postman (must set content type as json ).
Create API gateway for logic apps using Azure API Management.
Create API in API management and point to logic apps

Tuesday, 24 May 2016

Angular - Azure VM Explorer and Dashboard




Azure VM Explorer

Introduction

This application allow to explore Virtual machine of your azure subscription. The application is using Azure active directory to authenticate user.
This sample demonstrates:

  • ·         The use of ADAL for JavaScript for securing an AngularJS based application.
  • ·         The use of Azure REST API for fetching subscription information.
  • ·         Perform operation on Azure VM’s .

Technology Used


  • ·         Angular JS
  • ·         Azure Subscription
  • ·         azure-active directory-library-for-js: Active Directory Authentication Library for JavaScript (ADAL JS) helps you to use Azure AD for handling authentication in your applications . Refer


Step By Step:

Step 1: Register the sample with your Azure Active Directory tenant

  1. Sign in to the Azure management portal.
  2. Click on Active Directory in the left hand nav.
  3. Click the directory tenant where you wish to register the sample application.
  4. Click the Applications tab.
  5. In the drawer, click Add.
  6. Click "Add an application my organization is developing".
  7. Enter a friendly name for the application, for example "Azure VM Explorer app", select "Web Application and/or Web API", and click next.
  8. For the sign-on URL, enter the base URL for the sample, which is by default https://localhost:44326/.
  9. For the App ID URI, enter https ://<your_tenant_name>/ Azure VM Explorer app, replacing <your_tenant_name> with the name of your Azure AD tenant.
All done! Before moving on to the next step, you need to find the Client ID of your application.
  1. While still in the Azure portal, click the Configure tab of your application.
  2. Find the Client ID value and copy it to the clipboard.

Step 2: Enable the OAuth2 implicit grant for your application

By default, applications provisioned in Azure AD are not enabled to use the OAuth2 implicit grant. In order to run this sample, you need to explicitly opt in.
  1. From the former steps, your browser should still be on the Azure management portal - and specifically, displaying the Configure tab of your application's entry.
  2. Using the Manage Manifest button in the drawer, download the manifest file for the application and save it to disk.
  3. Open the manifest file with a text editor. Search for the oauth2AllowImplicitFlow property. You will find that it is set to false; change it to true and save the file.
  4. Using the Manage Manifest button, upload the updated manifest file. Save the configuration of the app.

Step 3: Create angular JS application for Azure Virtual Machine explore

Include references to angular.js libraries, adal.js, adal-angular.js in your main app page.
Include a reference to adal module
angular.module('AzureApp', ['ngRoute','AdalAngular'])

Step 4: Initialize adal with the AAD Client Id and Tenant id .


adalProvider.init({
        instance: 'https://login.microsoftonline.com/',
        tenant: < Your Tenant Id: XXXXXXXXXXXXhotmail.onmicrosoft.com > ',
        clientId: 'Your Client Id : XXXXXXX-XXXXXXXXX,
        extraQueryParameter: 'nux=1',
        loginResource: 'https://management.azure.com/' //to set AUDIENCE
            //cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
    },
    $httpProvider
);

Step 5: Create MasterController for your Angular application


'use strict';
angular.module('AzureApp').controller('MasterController', ['$scope', 'adalAuthenticationService', '$location', function($scope, adalService, $location) {
    var subscriptionId = ‘Azure Subscription Id ';
    $scope.ErrorMessage = '';
    $scope.VMList = [];
    $scope.login = function() {
        adalService.login();
        $scope.$apply();
    };
    $scope.logout = function() {
        adalService.logOut();
        $scope.$apply();
    };
    $scope.ListAllVM = function() {
        $scope.VMList = [];
        var resource = adalService.getResourceForEndpoint('https://management.azure.com/');
        var tokenStored = adalService.getCachedToken(resource);
        $.ajax({
            url: 'https://management.azure.com/subscriptions/' + subscriptionId + '/resources?api-version=2015-11-01',
            type: 'GET',
            success: function(data) {
                // $scope.VMList = data.value;
                $scope.$apply(function() {
                    angular.forEach(data.value, function(value) {
                        if (value.type == 'Microsoft.ClassicCompute/virtualMachines') {
                            //$scope.VMList.push(value);
                            $scope.GetVMInfo(value);
                        }
                    });
                });
                //do something to data
            },
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Authorization', "Bearer " + tokenStored);
            },
            error: function(rcvData) {
                $scope.$apply(function() {
                    console.log(rcvData.responseText);
                    $scope.ErrorMessage = eval("(" + rcvData.responseText + ")");
                    console.log($scope.ErrorMessage.error.message)
                });
            }
        });
    };
    $scope.VMOperation = function(vm, Operation) {
        console.log(vm);
        var resource = adalService.getResourceForEndpoint('https://management.azure.com/');
        //var tokenStored = authService.getCachedToken(resource);
        var tokenStored = adalService.getCachedToken(resource);
        var _URL = 'https://management.azure.com/' + vm.id + '/' + Operation + '?api-version=2016-04-01';
        var _TYPE = 'POST';
        if (Operation == 'Delete') {
            var _URL = 'https://management.azure.com/' + vm.id + '?api-version=2016-04-01';
            var _TYPE = 'DELETE';
        } else {
            var _URL = 'https://management.azure.com/' + vm.id + '/' + Operation + '?api-version=2016-04-01';
            var _TYPE = 'POST';
        }
        $.ajax({
            url: _URL,
            type: _TYPE,
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Authorization', "Bearer " + tokenStored);
            },
            error: function(rcvData) {
                $scope.$apply(function() {
                    console.log(rcvData.responseText);
                    $scope.ErrorMessage = eval("(" + rcvData.responseText + ")");
                    console.log($scope.ErrorMessage.message)
                });
            },
            success: function(data) {
                $scope.$apply(function() {
                    $scope.ErrorMessage = 'VM Operation Success';
                });
            }
        });
    };
    // Get VM Information
    //START
    $scope.GetVMInfo = function(vm) {
        var resource = adalService.getResourceForEndpoint('https://management.azure.com/');
        //var tokenStored = authService.getCachedToken(resource);
        var tokenStored = adalService.getCachedToken(resource);
        var _URL = 'https://management.azure.com/' + vm.id + '?api-version=2016-04-01';
        var _TYPE = 'GET';
        $.ajax({
            url: _URL,
            type: _TYPE,
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Authorization', "Bearer " + tokenStored);
            },
            error: function(rcvData) {
                $scope.$apply(function() {
                    console.log(rcvData.responseText);
                    $scope.ErrorMessage = eval("(" + rcvData.responseText + ")");
                    console.log($scope.ErrorMessage.error.message)
                });
            },
            success: function(data) {
                $scope.$apply(function() {
                    vm.status = data.properties.instanceView.status;
                    $scope.VMList.push(vm);
                });
            }
        });
    };
}]);

Step 6: Create View for your Angular App.


 






<div ng-init="ListAllVM()">
    <div class="alert alert-danger" ng-show="ErrorMessage">
                                {{ErrorMessage.message}}
                                                                                                                                {{ErrorMessage.error.message}}
</div>
    <div class="panel">
        <table class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Location</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <tr data-ng-repeat="item in VMList">
                    <td>
                        <a href="#" ng-click="GetVMInfo(item)">
                            <p> {{item.name}}</p>
                            <a/>
                        </td>
                        <td>
                            <p> {{item.location}}</p>
                        </td>
                        <td>
                            <p> {{item.status}}</p>
                        </td>
                        <td>
                            <a href="#/VMList" ng-disabled="{{item.status != 'StoppedDeallocated'}}" class="form-control">
                                <i class="fa fa-play fa-fw" ng-click="VMOperation(item,'start')"></i>
                            </a>
                        </td>
                        <td>
                            <a href="#/VMList" ng-disabled="{{item.status != 'ReadyRole'}}" ng-click="VMOperation(item,'powerOff')" class="form-control">
                                <i class="fa fa-stop fa-fw"></i>
                                <a/>
                            </td>
                            <td>
                                <a href="#/VMList" ng-disabled="" ng-click="VMOperation(item,'restart')" class="form-control">
                                    <i class="fa fa-refresh fa-fw"></i>
                                    <a/>
                                </td>
                                <td>
                                    <a href="#/VMList" ng-disabled="" ng-click="VMOperation(item,'deallocate')" class="form-control">
                                        <i class="fa fa-stop fa-fw"></i>(Deallocate)
                                        <a/>
                                    </td>
                                    <td>
                                        <a href="#/VMList" ng-click="VMOperation(item,'Delete')" class="form-control">
                                            <i class="fa fa-remove fa-fw"></i>
                                            <a/>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

Code

Please download source code from location .