//********************************************************************* /// /// <summary> /// /// </summary> /// <returns></returns> /// //********************************************************************* public AzureAdminClientLib.HttpResponse GetOsImageList() { var url = string.Format(URLTEMPLATE_GETOSIMAGES, _Connection.SubcriptionID); var hi = new HttpInterface(_Connection); return(hi.PerformRequest(HttpInterface.RequestType_Enum.GET, url)); }
//********************************************************************* /// /// <summary> /// /// </summary> /// <param name="vNetName"></param> /// <returns></returns> /// //********************************************************************* public VirtualNetworkSites FetchVnetInfo(string vNetName) { try { var url = string.Format(URLTEMPLATE_GETVNETCONFIG, Connection.SubcriptionID); var hi = new HttpInterface(Connection); var resp = hi.PerformRequest(HttpInterface.RequestType_Enum.GET, url); var vNets = Utilities.DeSerialize(typeof(VirtualNetworkSites), resp.Body, true) as VirtualNetworkSites; if (null == vNets) { throw new Exception("Bad or missing VNet config returned from Azure"); } return(vNets); } catch (Exception ex) { throw new Exception("Exception in GetVnetInfo() :" + Utilities.UnwindExceptionMessages(ex)); } }
public IEnumerable <AzureSku> GetSkuList(string location, string publisher, string offer) { var url = string.Format(URLTEMPLATE_GETSKUS, _Connection.SubcriptionID, location, publisher, offer); var hi = new HttpInterface(_Connection); HttpResponse response = hi.PerformRequestArm(HttpInterface.RequestType_Enum.GET, url); int startIndex = response.Body.IndexOf('['); int endIndex = response.Body.IndexOf(']'); string jsonString = response.Body.Substring(startIndex, endIndex - startIndex + 1); return(Utilities.DeSerializeJson <IEnumerable <AzureSku> >(jsonString)); }
//********************************************************************* /// /// <summary> /// Makes a call to Azure API to get a set of VmSize objects based on /// a region /// </summary> /// <returns>A list of VmSize objects</returns> /// //********************************************************************* public IEnumerable <AzureVmSizeArmData> GetVmSizeList(string location) { var url = string.Format(URLTEMPLATE_GETAZUREVMSIZES, _Connection.SubcriptionID, location); var hi = new HttpInterface(_Connection); HttpResponse response = hi.PerformRequestArm(HttpInterface.RequestType_Enum.GET, url); int startIndex = response.Body.IndexOf('['); int endIndex = response.Body.IndexOf(']'); string processedJsonString = response.Body.Substring(startIndex, endIndex - startIndex + 1); return(AzureVmSizeArmData.DeserializeJsonVmSize(processedJsonString)); }
//********************************************************************* /// /// <summary> /// Makes a call to Azure API to get a set of Location objects based on /// a subscription ID. /// </summary> /// <returns>A list of Location objects</returns> /// //********************************************************************* public IEnumerable <AzureLocationArmData> GetAzureLocationsList() { var url = string.Format(URLTEMPLATE_GETAZUREREGIONS, _Connection.SubcriptionID); var hi = new HttpInterface(_Connection); HttpResponse response = hi.PerformRequestArm(HttpInterface.RequestType_Enum.GET, url); int startIndex = response.Body.IndexOf('['); int endIndex = response.Body.IndexOf(']'); string processedJsonString = response.Body.Substring(startIndex, endIndex - startIndex + 1); return(Utilities.DeSerializeJson <IEnumerable <AzureLocationArmData> >(processedJsonString)); }
//********************************************************************* /// /// <summary> /// /// </summary> /// <returns></returns> /// http://msdn.microsoft.com/en-us/library/azure/dn592118.aspx /// //********************************************************************* public List <string> GetAvailAddrList(string vNetName, string subnetName, string testAddr) { try { var subnetAddrs = GetSubnetAddrs(vNetName, subnetName, 0); if (0 == subnetAddrs.Count) { if (null == subnetName) { throw new Exception(string.Format("No subnets found on vnet '{0}'", vNetName)); } else { throw new Exception(string.Format("Requested subnet '{0}' not found on vnet '{1}'", subnetName, vNetName)); } } var url = string.Format(URLTEMPLATE_GETAVAILIPADDRS, Connection.SubcriptionID, vNetName, subnetAddrs[0]); var hi = new HttpInterface(Connection); var resp = hi.PerformRequest(HttpInterface.RequestType_Enum.GET, url); var availInfo = Utilities.DeSerialize(typeof(AddressAvailabilityResponse), resp.Body, true) as AddressAvailabilityResponse; if (null == availInfo) { throw new Exception("Bad or missing AddressAvailabilityResponse returned from Azure"); } var addrList = new List <string>(); if (availInfo.IsAvailable) { addrList.Add(subnetAddrs[0]); } else { addrList.AddRange(availInfo.AvailableAddresses); } return(addrList); } catch (Exception ex) { throw new Exception("Exception in GetAvailAddrList() : " + Utilities.UnwindExceptionMessages(ex)); } }
//********************************************************************* /// /// <summary> /// /// </summary> /// <param name="url">Example: https://management.azure.com/subscriptions/00f885db-ef1d-4545-ad2d-64c0caf93384/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp ge '2015-8-18T16:0:9.0Z' and correlationId eq '6b4ced55-7c65-46c1-b20c-57e66341cf30'</param> /// <param name="exceptionList"></param> /// <returns></returns> /// //********************************************************************* public string FetchEvents(string url, out List <AzureException> exceptionList) { try { var hi = new HttpInterface(_connection); var res = hi.PerformRequestArm(HttpInterface.RequestType_Enum.GET, url, null); exceptionList = ExtractEventExceptions(res.Body); return(res.Body); } catch (Exception ex) { throw new Exception("Exception in FetchEvents() : " + Utilities.UnwindExceptionMessages(ex)); } }
//********************************************************************* /// /// <summary> /// /// </summary> /// <returns></returns> /// //********************************************************************* public HttpResponse FetchVnetListArm() { try { var url = string.Format(URLTEMPLATE_GETVNETLISTARM, Connection.SubcriptionID, ARM_API_VERSION); var hi = new HttpInterface(Connection); var ret = hi.PerformRequestArm(HttpInterface.RequestType_Enum.GET, url, null); return(ret.Body.Contains("(404) Not Found") ? null : ret); } catch (Exception ex) { throw new Exception("Exception in FetchVnetListArm() :" + Utilities.UnwindExceptionMessages(ex)); } }
//********************************************************************* /// /// <summary> /// /// </summary> /// <returns></returns> /// //********************************************************************* public List <ResourceUsageStruct> FetchResourceUsage(string region) { try { var url = string.Format(URLTEMPLATE_FETCHREGIONRESOURCEUSAGE_ARM, _Connection.SubcriptionID, "westus", "2015-06-15"); var hi = new HttpInterface(_Connection); var resp = hi.PerformRequestArm(HttpInterface.RequestType_Enum.GET, url); if (resp.HadError) { throw new Exception("Error in Azure response : " + resp.Body); } var ul = Utilities.FetchJsonValue(resp.Body, "value") as Newtonsoft.Json.Linq.JArray; var usageList = new List <ResourceUsageStruct>(); if (null != ul) { foreach (var usage in ul) { usageList.Add(new ResourceUsageStruct() { Region = region, Unit = Utilities.FetchJsonValue(usage.ToString(), "unit") as string, Value = Convert.ToInt32(Utilities.FetchJsonValue(usage.ToString(), "currentValue")), Limit = Convert.ToInt32(Utilities.FetchJsonValue(usage.ToString(), "limit")), Name = Utilities.FetchJsonValue(usage.ToString(), new[] { "name", "value" }) as string, LocalName = Utilities.FetchJsonValue(usage.ToString(), new[] { "name", "localizedValue" }) as string }); } } return(usageList); } catch (Exception ex) { throw new Exception("Exception in SubscriptionOps.FetchResourceUsage() : " + Utilities.UnwindExceptionMessages(ex)); } }
public AzureAdminClientLib.HttpResponse CreateImage(ImageInfo imageInfo) { var url = string.Format(URLTEMPLATE_CREATEIMAGE, _Connection.SubcriptionID); var body = string.Copy(BODYTEMPLATE_CREATEIMAGE); body = body.Replace("{Description}", imageInfo.Description); body = body.Replace("{EULA}", imageInfo.EULA); body = body.Replace("{Family}", imageInfo.Family); body = body.Replace("{ImageName}", imageInfo.ImageName); body = body.Replace("{IsGallery}", imageInfo.IsGallery ? "true" : "false"); body = body.Replace("{IsPremium}", imageInfo.IsPremium ? "true" : "false"); body = body.Replace("{label}", imageInfo.label); body = body.Replace("{Language}", imageInfo.Language); body = body.Replace("{MediaLink}", imageInfo.MediaLink); body = body.Replace("{OS}", imageInfo.OS.ToString()); body = body.Replace("{PublishedDate}", imageInfo.PublishedDate.ToShortTimeString()); body = body.Replace("{RecommendedSize}", imageInfo.RemommendedSize.ToString()); var hi = new HttpInterface(_Connection); return(hi.PerformRequest(HttpInterface.RequestType_Enum.POST, url, body)); }