Penny Pinching在云中:使用Windows Azure管理库和.NET自动化一切

Even though I work for the Azure and ASP.NET team, I still pay for my own Azure account. Frankly, if I did get free cloud time not only would I likely abuse it, but I also wouldn't be using the cloud in the way it's meant to be used! From my perspective, a good cloud is a cheap cloud. I use CDNs, caching, and focus on a balance of cheap resources and compute that work for me when I need them, and are asleep (and not costing me money) when I don't.

即使我为Azure和ASP.NET团队工作,我仍然需要为自己的Azure帐户付费。 坦白说,如果我确实获得了免费的云时间,那我不仅会滥用它,而且我也不会以其应有的方式使用云! 在我看来,好的云就是便宜的云。 我使用CDN,进行缓存,并专注于平衡廉价资源,并在需要时计算对我有用的内容,而当我不需要时则处于睡眠状态(不花钱)。

There's things like auto-scale for websites, for example, based on either CPU or a schedule, but the one thing that gets me into trouble (sometimes) is leaving big virtual machines on. I manage most of my Azure assets from the command line, so I can just "azure vm list" to see what's running and I'll see this:

例如,可以基于CPU或计划来进行网站自动缩放等事情,但是(有时)使我陷入麻烦的一件事是打开大型虚拟机。 我通过命令行管理我的大多数Azure资产,因此我可以仅“ azure vm list”来查看正在运行的内容,然后将看到以下内容:

C:\Users\scottha                                                                                      
λ azure vm list
info: Executing command vm list
+ Getting virtual machines
data: Name Status Location DNS Name
data: -------------------- ------------------ -------- -------------------------------
data: VSinTheSky StoppedDeallocated West US vsinthesky.cloudapp.net
data: hanselmandiscourse StoppedDeallocated West US discourse.cloudapp.net
data: hanselmansendy ReadyRole West US sendy.cloudapp.net
data: hanselmanlinuxfarm StoppedDeallocated West US linuxfarm.cloudapp.net
data: hanselmanlinuxfarm-2 StoppedDeallocated West US linuxfarm.cloudapp.net
data: hanselmanlinuxfarm-3 StoppedDeallocated West US linuxfarm.cloudapp.net
data: hanselmanmysql ReadyRole West US mysql.cloudapp.net
info: vm list command OK

If I want to shut one down I can use the command line, the Azure Portal, or even manage VMs within Visual Studio itself:

如果要关闭某个服务器,可以使用命令行,Azure门户,甚至可以在Visual Studio本身中管理VM

Managing Azure within Visual Studio

But sometimes I have custom apps to manage Azure resources, perhaps WinForms or WPF apps, MSBuild Tasks, or I want to add cloud management to an existing process. I'll want to not just turn off VMs, but also manage WebSites, create resources, upload things to storage and more.

但是有时候我有一些自定义应用程序来管理Azure资源,例如WinForms或WPF应用程序,MSBuild Tasks,或者我想将云管理添加到现有流程中。 我不仅要关闭虚拟机,还要管理网站,创建资源,将内容上传到存储等等。

I just learned from Brady Gaster that there's now Windows Azure Management Libraries for .NET as part of the Azure SDK. Basically this means that you can call the same backend REST APIs that the Azure Portal calls now, except now with a simple wrapper around them that makes it rather a bit easier in .NET.

我刚刚从Brady Gaster那里了解到,现在用于.NET的Windows Azure管理库是Azure SDK的一部分。 基本上,这意味着您可以调用与Azure Portal现在调用的后端REST API相同的后端REST API(现在除外),因为它们周围有一个简单的包装,这使得在.NET中变得更加简单。

Brady has a lot of info on his blog about this libraries. Here's some of the best highlights:

Brady在他的博客上有很多有关此库的信息。 以下是一些最佳亮点:

  • Supports Portable Class Libraries (PCL)

    支持便携式类库(PCL)
  • Ships as a set of focused NuGet packages with minimal dependencies to simplify versioning

    作为一组具有重点的NuGet软件包提供,这些软件包具有最小的依赖关系以简化版本
  • Supports async/await-based task asynchrony (with easy synchronous overloads)

    支持基于异步/等待的任务异步(具有轻松的同步重载)
  • Has a shared infrastructure for common error handling, tracing, configuration, and HTTP pipeline manipulation

    具有用于常见错误处理,跟踪,配置和HTTP管道操作的共享基础结构
  • Is factored for easy testability and mocking

    易于测试和嘲弄
  • Is built on top of popular libraries such as HttpClient and Json.NET

    建立在诸如HttpClient和Json.NET的流行库之上
  • Is all open source and on GitHub.

    全部开源并且在GitHub上

They are on NuGet as a group of packages but you can get them separately if you want to just manage VMs, for example. Here's the version I'm using from NuGet. Note it's prerelease as of the date of this writing. https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.Libraries 

它们作为一组软件包放在NuGet上,但是,例如,如果您只想管理VM,则可以单独获得它们。 这是我从NuGet使用的版本。 请注意,在撰写本文时,它是预发行版。 https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.Libraries

png

Azure authentication and authorization is based on X509 Certificates, so you'll use those to initially talk to your Azure instance. You can download your certificates from an authenticated session here and your certificates and subscription id are inside.

Azure身份验证和授权基于X509证书,因此您将使用这些证书最初与Azure实例进行通信。 您可以从此处通过身份验证的会话下载证书,并且证书和订阅ID都在其中。

I can list out, for example, all my running websites in all their locations (web spaces):

例如,我可以列出我所有正在运行的网站的所有位置(网站空间):

using (var client = new WebSiteManagementClient(creds)) {
var spaces = client.WebSpaces.List();
foreach (var space in spaces) {
Console.WriteLine("Space: {0}", space.Name);

var sites = client.WebSpaces.ListWebSites(space.Name, new WebSiteListParameters{ PropertiesToInclude = { "Name" }});
foreach (var site in sites) {
Console.WriteLine(" " + site.Name);
}
}
}

This little app gives me this output:

这个小应用程序给了我这个输出:

Space: eastuswebspace
SmallestDotNet
Space: northcentraluswebspace
Hanselminutes
Space: northeuropewebspace
Space: westuswebspace
babysmash
nerddinnerofficial
ratchetandthegeek
speakinghacks
thisdeveloperslife
hanselmanlyncrelay
HanselmanGhost
anglebrackets
lostphonescreen
loggingtest
GetInvolved
keysleft

I can go and update sites, disable (stop) them, make web farms, scale them, create, configure and generally do everything I can from the command line. Very slick. Now I can manage Azure stuff from PowerShell, from .NET, from node and the cross platform command line, Visual Studio, and the Azure Portal.

我可以去更新站点,禁用(停止)它们,创建Web场,对其进行缩放,创建,配置以及通常可以从命令行执行的所有操作。 很好吃现在,我可以从PowerShell,.NET,节点和跨平台命令行,Visual Studio和Azure门户管理Azure内容。

Go read all about Windows Azure Management Libraries on Brady's blog, get them on NuGet, or read the code and enter issues on GitHub.

在Brady的博客上阅读有关Windows Azure管理库的所有信息在NuGet上获取它们,或者阅读代码并在GitHub上输入问题

if you link your MSDN and Azure accounts and you can get up to $150 a month in Azure credits, so up to two free VMs running all day for a month.

如果您将MSDN和Azure帐户关联起来,则每月最多可获得$ 150的Azure信用额,因此最多两个免费VM可以全天运行一个月。

I've done a few posts on "Penny Pinching in the Cloud" that you may enjoy.

我已经发表了一些您可能会喜欢的文章“ Penny Pinching in the Cloud”。

Also, I encourage you to check out Azure Friday, a new show I'm doing at http://friday.azure.com. Azure Friday also on iTunes as a downloadable podcast in HD!

此外,我鼓励您在http://friday.azure.com上查看我正在做的新节目Azure Friday。 iTunes上的Azure Friday也可以下载为高清高清播客!

Sponsor: Thanks to Aspose for sponsoring the blog feed this week! Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and a host of other file formats in your applications. Curious? Start a free trial today!

赞助商:感谢Aspose本周赞助了博客提要! .NET的Aspose.Total具有您在应用程序中创建,处理和转换Microsoft Office文档所需的所有API以及许多其他文件格式。 好奇? 立即开始免费试用

翻译自: https://www.hanselman.com/blog/penny-pinching-in-the-cloud-automating-everything-with-the-windows-azure-management-libraries-and-net

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值