Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the NLBTask For Adding And Removing VMs from Load Balancer #3086

Merged
merged 13 commits into from
Dec 9, 2016

Conversation

asranja
Copy link
Contributor

@asranja asranja commented Nov 15, 2016

No description provided.

@@ -0,0 +1,92 @@
{
"id": "e94f1750-a6a8-11e6-be69-bdf37a7b15d8",
"name": "NLBTask",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change name to AzureNLBManagement

{
"id": "e94f1750-a6a8-11e6-be69-bdf37a7b15d8",
"name": "NLBTask",
"friendlyName": "NetworkLoadBalancer Task",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure Network Load Balancer

"id": "e94f1750-a6a8-11e6-be69-bdf37a7b15d8",
"name": "NLBTask",
"friendlyName": "NetworkLoadBalancer Task",
"description": "Add/Remove a virtual machine's nic to the Load Balancer",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add/Remove a Azure virtual machine's network interface to Load Balancer

"friendlyName": "NetworkLoadBalancer Task",
"description": "Add/Remove a virtual machine's nic to the Load Balancer",
"author": "Microsoft Corporation",
"helpMarkDown": "Replace with markdown to show in help",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the help Mark down properly. Give a Fwd Link.

"category": "Utility",
"visibility": [
"Build",
"Release"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Preview to Visibility

"messages": {
"CouldNotFetchNicDetails": "Could Not Fetch NIC Configuration details for the VM : %s",
"NicDetailsFetched": "NIC Configuration Details obtained for VM : %s",
"GettingAllNetworkInterfacesInTheResourceGroup": "Getting All Network Interfaces In The Resource Group : %s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The messages start with Caps for every word. Have the user facing messages corrected with appropriate casing.

"messages": {
"CouldNotFetchNicDetails": "Could Not Fetch NIC Configuration details for the VM : %s",
"NicDetailsFetched": "NIC Configuration Details obtained for VM : %s",
"GettingAllNetworkInterfacesInTheResourceGroup": "Getting All Network Interfaces In The Resource Group : %s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The messages start with Caps for every word. Have the user facing messages corrected with appropriate casing. Do it for all relevant messages here.

if (operation == "Add") {
tl._writeLine("Adding VM to LB");
var lb = await nlbUtility.getLoadBalancer(SPN, endpointUrl, resourceGroupName, loadBalancerName);
obj = lb.properties.backendAddressPools;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't call it obj. Name the variable meaningfully.

obj = lb.properties.backendAddressPools;
}
else {
tl._writeLine("Removing VM from LB");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, if this is user facing message, this should come from resource in task.json. Modify the message similar to the comment given above for Add.

return ipv4Address;
}

async function getNetworkInterface(SPN, endpointUrl: string, resourceGroupName: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic won't scale if a VM has multiple IPv4 valid NIC cards. Would it be better to list the NICs for selected resource group in drop down and let user pick which NIC he needs to be added or removed?

deferred.resolve(JSON.parse(body).access_token);
}
else {
deferred.reject("Could not fetch access token. Request ended with status code : " + response.statusCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can u print response.statusMessage too ?

export async function getNetworkInterfaces(SPN, endpointUrl: string, resourceGroupName: string) {

var deferred = Q.defer<any>();
var restUrl = "https://management.azure.com/subscriptions/" + SPN.subscriptionId + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/networkInterfaces?api-version=" + azureApiVersion;
Copy link
Contributor

@vincent1173 vincent1173 Nov 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure Rest call may provide nextLink attribute, which then need to be queried to get the actual result.

export async function getLoadBalancer(SPN, endpointUrl: string, resourceGroupName: string, name: string) {

var deferred = Q.defer<any>();
var restUrl = "https://management.azure.com/subscriptions/" + SPN.subscriptionId + "/resourceGroups/" + resourceGroupName + "/providers/Microsoft.Network/loadBalancers/" + name + "?api-version=" + azureApiVersion;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check for Azure Rest Call , NextLink attribute.

"friendlyName": "Azure Network Load Balancer (Preview)",
"description": "Connect/Disconnect an Azure virtual machine's network interface to a Load Balancer's backend address pool",
"author": "Microsoft Corporation",
"helpMarkDown": "Replace with markdown to show in help",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle this before check-in.

"Patch": "0"
},
"minimumAgentVersion": "1.95.0",
"instanceNameFormat": "Azure Network Load Balancer: $(Action) VMs from $(LoadBalancer)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with PM on the resource here. This should be meaningful for both connect and disconnect actions.

"required": true,
"options": {
"AutoDetectNic": "Auto select primary network interface",
"CustomNic": "Custom - virtual machine : network interface"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Custom just good enough. Do we need the mapping format in this drop down label?

"Disconnect": "Disconnect Network Interface",
"Connect": "Connect Network Interface"
},
"helpMarkDown": "Connect: Adds the virtual machine’s network interface to load balancer backend pool. So that it starts receiving network traffic based on the load balancing rules for the load balancer resource.\n\nDisconnect: Removes the virtual machine’s network interface from the load balancer’s backend pool. So that it stops receiving network traffic."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the help mark down for connect and Disconnect be in same order as the Options list.

},
"defaultValue": "AutoDetectNic",
"helpMarkDown": "Custom: Specify mapping virtual machine and the network interface associated with the virtual machine to be added/removed from load balancer backend pool. The format to specify is: `<virtual machine1>:<network interface name1> <virtual machine2>:<network interface name2>`… and so on.\n\nAuto select: Will select the primary network interface of the virtual machine to perform the Action of connecting/disconnecting from load balancer's backend address pool."
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can autodetect be first in the help markdown. That being default option in drop down, let's match the order.

tl.debug("Retrying after " + sleepTime/1000 + " sec");
setTimeout(putNetworkInterface, sleepTime);
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you correct the formatting here.

"Authorization": 'Bearer ' + accessToken
};

tl._writeLine("Setting the network interface");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not a debug statement, this has to be localized.

}
}
else {
// Handle custom vm:nic mapping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the VM name given in input helpful? We don't seem to make use of that input for ensuring the NIC belongs to the VM. Our logic is to enumerate nics and compare mac.

else {
// Handle custom vm:nic mapping
var nicVmMap = {};
var temp = vmNicMapping.split(" ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to validate that vmNicMapping input is in right format. Any improper input with wrong : or wrong spaces can lead to failure below while you use the split out as index to arrays.

@@ -0,0 +1,102 @@
import * as tl from 'vsts-task-lib/task';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include L0 tests in the PR.

var accessToken = await getAccessToken(SPN, endpointUrl);

var requestHeader = {
authorization: 'Bearer ' + accessToken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are bypassing REST Client and using HTTP client, you are missing out filling the Accept header.

var accessToken = await getAccessToken(SPN, endpointUrl);

var requestHeader = {
authorization: 'Bearer ' + accessToken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are bypassing REST Client and using HTTP client, you are missing out filling the Accept header. This comment is applicable to all other places as well.

var accessToken = await getAccessToken(SPN, endpointUrl);

var requestHeader = {
authorization: 'Bearer ' + accessToken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are bypassing REST Client and using HTTP client, you are missing out filling the Accept header. This comment is applicable to all other places as well. If the issue of using REST client is only in SetNetworkInterface, why can't you use REST client in other places?

var networkInterfaces = os.networkInterfaces();
Object.keys(networkInterfaces).forEach( (interfaceName) => {
networkInterfaces[interfaceName].forEach( (interFace) => {
if (interFace.family !== 'IPv4' || interFace.internal !== false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need IPV4 check anymore, given that you are depending on MAC.

@asranja asranja merged commit a28ad5e into master Dec 9, 2016
@bryanmacfarlane bryanmacfarlane deleted the users/asranja/nlbtask branch January 31, 2018 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants