Skip to content

Instantly share code, notes, and snippets.

@jpda
Created June 14, 2019 22:14
Show Gist options
  • Save jpda/bc13691d4b24400a82eeab9f058ba7bc to your computer and use it in GitHub Desktop.
Save jpda/bc13691d4b24400a82eeab9f058ba7bc to your computer and use it in GitHub Desktop.
using System;
using System.Data;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace ConsoleApplication8
{
public struct VmSize
{
public string Name;
public int Cores;
public int MemoryMb;
public int DataDiskLimit;
//public string Label;
public string Tier;
public bool V2;
public string Size;
public bool PremiumDisk;
public string Series;
public bool Promo;
//"name": "Standard_M128s",
//"numberOfCores": 128,
//"osDiskSizeInMB": 1047552,
//"resourceDiskSizeInMB": 4096000,
//"memoryInMB": 2048000,
//"maxDataDiskCount": 64
public VmSize(DataRow row)
{
Name = row["InstanceSize"].ToString();
var n = Name.ToLower();
var np = n.Split('_');
var std = n.Contains("_");
Cores = int.Parse(row["Cores"].ToString());
MemoryMb = int.Parse(row["MemoryInMb"].ToString());
DataDiskLimit = int.Parse(row["MaxDataDiskCount"].ToString());
//Label = row["RoleSizeLabel"].ToString();
V2 = n.Contains("_v2");
Tier = std ? np[0] : "Standard";
Size = Name;
PremiumDisk = false;
if (std)
{
Size = np[1];
PremiumDisk = Size.ToLower().Contains("s");
}
Promo = Name.IndexOf("Promo", StringComparison.OrdinalIgnoreCase) > -1;
switch (np.Length)
{
case 1: // basic VM, e.g., A0
{
Series = np[0];
break;
}
case 2: // standard VM, e.g., Standard_DS2
{
Series = np[1];
break;
}
case 3: // standard versioned vm e.g., Standard_DS2_v2
{
Series = $"{np[1]}{np[2]}";
break;
}
case 4: // standard versioned vm special rate, e.g., Standard_DS2_v2_Promo
{
Series = $"{np[1]}{np[2]}";
break;
}
default:
{
Series = np[0];
break;
}
}
Console.WriteLine($"{n}:{Series}");
}
public VmSize(JToken row)
{
Name = row["name"].ToString();
var n = Name.ToLower();
var np = n.Split('_');
var std = n.Contains("_");
Cores = int.Parse(row["numberOfCores"].ToString());
MemoryMb = int.Parse(row["memoryInMB"].ToString());
DataDiskLimit = int.Parse(row["maxDataDiskCount"].ToString());
//Label = row["RoleSizeLabel"].ToString();
V2 = n.Contains("_v2");
Tier = std ? np[0] : "Standard";
Size = Name;
PremiumDisk = false;
Series = "";
if (std)
{
Size = string.Join("_", np.Skip(1));
PremiumDisk = Size.ToLower().Contains("s");
}
Promo = Name.IndexOf("Promo", StringComparison.OrdinalIgnoreCase) > -1;
switch (np.Length)
{
case 1: // basic VM, e.g., A0
{
Series = np[0];
break;
}
case 2: // standard VM, e.g., Standard_DS2
{
Series = np[1];
break;
}
case 3: // standard versioned vm e.g., Standard_DS2_v2
{
Series = $"{np[1]}{np[2]}";
break;
}
case 4: // standard versioned vm special rate, e.g., Standard_DS2_v2_Promo
{
Series = $"{np[1]}{np[2]}";
break;
}
default:
{
Series = np[0];
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment