从命令行管理云

I blogged about the Windows Azure cloud a few weeks ago. I'm digging the new stuff and trying different scenarios on Macs, PCs and Linux (I prefer Ubuntu). As a long time PowerShell and Command Line fan I'm always looking for ways to do stuff "in text mode" as well as scripting site creations and deployments.

几周前,写了关于Windows Azure云的博客。 我正在挖掘新东西,并尝试在Mac,PC和Linux(我更喜欢Ubuntu)上使用不同的方案。 作为PowerShellCommand Line的长期支持者,我一直在寻找“以文本模式”做事以及编写网站创建和部署脚本的方法。

Turns out there are a mess of ways to access Azure from the command line - more than even I thought. There's a JSON-based Web API that these tools end up talking to. You could certainly call that API directly if you wanted, but the command line tools are damn fun.

事实证明,从命令行访问Azure的方式很多种,甚至比我想的还要多。 这些工具最终都与基于JSON的Web API进行了交谈。 当然,如果需要,您当然可以直接调用该API,但是命令行工具非常有趣。

You can install the Mac Azure SDK installer to get the tools and more on a Mac, or if you install node.js on Windows or Mac or Linux you can use the Node Package Manager (npm) to install Azure tools like this:

您可以安装Mac Azure SDK安装程序在Mac上获得这些工具以及更多工具,或者,如果在Windows或Mac或Linux上安装node.js,则可以使用节点包管理器(npm)来安装Azure工具,如下所示:

npm install azure-cli --global

You can also use apt-get or other repository commands. After this, you can just run "azure" which gives you these commands that you link together in a very intuitive way, "azure topic(noun)verb option" so "azure site list" or "azure vm disk create" and the like.

您还可以使用apt-get或其他存储库命令。 之后,您可以运行“ azure”,它以非常直观的方式为您提供这些命令的链接,它们是“ azure topic(noun)verb选项”,例如“ azure站点列表”或“ azure vm disk create”等。 。

There's even ASCII art, and who doesn't like that. ;)

甚至还有ASCII艺术,谁不喜欢。 ;)

Seriously, though, it's slick. Here's a sample interaction I did just now. I trimmed some boring stuff but this is starting from a fresh machine with no tools and ending with me interacting with my Windows Azure account.

严重的是,它很光滑。 这是我刚才进行的示例交互。 我整理了一些无聊的内容,但这是从一台没有工具的新机器开始的,直到我与Windows Azure帐户进行交互为止。

scott@hanselmac:~$ npm install azure-cli
npm http GET https://registry.npmjs.org/azure
...bunch of GETS...
scott@hanselmac:~$ azure
info: _ _____ _ ___ ___
info: /_\ |_ / | | | _ \ __|
info: _ ___/ _ \__/ /| |_| | / _|___ _ _
info: (___ /_/ \_\/___|\___/|_|_\___| _____)
info: (_______ _ _) _ ______ _)_ _
info: (______________ _ ) (___ _ _)
info:
info: Windows Azure: Microsoft's Cloud Platform
info:
info: Tool version 0.6.0
...bunch of help stuff...

scott@hanselmac:~$ azure account download
info: Executing command account download
info: Launching browser to http://go.microsoft.com/fwlink/?LinkId=254432
help: Save the downloaded file, then execute the command
help: account import
info: account download command OK
scott@hanselmac:~$ cd ~
scott@hanselmac:~$ cd Downloads/
scott@hanselmac:~/Downloads$ ls
3-Month Free Trial.publishsettings
scott@hanselmac:~/Downloads$ azure account import 3-Month\ Free\ Trial.publishsettings
info: Executing command account import
info: Setting service endpoint to: management.core.windows.net
info: Setting service port to: 443
info: Found subscription: 3-Month Free Trial
info: Setting default subscription to: 3-Month Free Trial
warn: Remember to delete it now that it has been imported.
info: Account publish settings imported successfully
info: account import command OK
scott@hanselmac:~/Downloads$ azure site list
info: Executing command site list
+ Enumerating locations
+ Enumerating sites
data: Name State Host names
data: ----------------- ------- -------------------------------------------------------------
data: superawesome Running superawesome.azurewebsites.net,www.acustomdomain.com
info: site list command OK
scott@hanselmac:~/Downloads$ azure site list --json
[
{
"AdminEnabled": "true",
"AvailabilityState": "Normal",
"EnabledHostNames": [
"superawesome.azurewebsites.net",
"www.acustomdomain.com"
],
"HostNames": [
"ratchetandthegeek.azurewebsites.net",
"www.ratchetandthegeek.com"
"State": "Running",
"UsageState": "Normal",
"WebSpace": "eastuswebspace"
}
]

Here's how I can create and start a VM from the command line. First I'll list the available images I can start with, then I create it. I wait for it to get ready, then it's started and ready to remote (RDP, SSH, etc) into.

这是我可以从命令行创建和启动VM的方法。 首先,我将列出可用的可用图像,然后创建它。 我等待它准备就绪,然后启动并准备好远程(RDP,SSH等)。

scott@hanselmac:~$ azure vm image list
info: Executing command vm image list
+ Fetching VM images
data: Name Category OS
data: -------------------------------------------------------------------------- --------- -------
data: CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd Canonical Linux
data: MSFT__Windows-Server-2012-RC-June2012-en-us-30GB.vhd Microsoft Windows
data: MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd Microsoft Windows
data: MSFT__Win2K8R2SP1-120514-1520-141205-01-en-us-30GB.vhd Microsoft Windows
data: OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd OpenLogic Linux
data: SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd SUSE Linux
data: SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd SUSE Linux
info: vm image list command OK
scott@hanselmac:~$ azure vm create hanselvm MSFT__Windows-Server-2012-RC-June2012-en-us-30GB.vhd scott superpassword --location "West US"
info: Executing command vm create
+ Looking up image
+ Looking up cloud service
+ Creating cloud service
+ Retrieving storage accounts
+ Creating VM
info: vm create command OK
scott@hanselmac:~$ azure vm list
info: Executing command vm list
+ Fetching VMs
data: DNS Name VM Name Status
data: --------------------- -------- ------------
data: hanselvm.cloudapp.net hanselvm Provisioning
info: vm list command OK

That's the command line tool for Mac, Linux, and optionally Windows (if you install node and run "npm install azure --global") and there's PowerShell commands for the Windows admin. It's also worth noting that you can check out all the code for these as they are all open source and up on github at http://github.com/windowsazure. The whole command line app is written in JavaScript, in fact.

这是Mac,Linux和Windows(如果您安装节点并运行“ npm install azure --global”)的命令行工具,并且Windows管理员可以使用PowerShell命令。 还值得注意的是,您可以检出所有这些代码,因为它们都是开源的,可以在github上找到,网址http://github.com/windowsazure 。 实际上,整个命令行应用程序都是用JavaScript编写的

Just as the command line version of the management tools has a very specific and comfortable noun/verb/options style, the cmdlets are very "PowerShelly" and will feel comfortable folks who are used to PowerShell. The documentation and tools are in a Preview mode and are under ongoing development, so you'll find some holes in the documentation.

就像管理工具的命令行版本具有非常特定且舒适的名词/动词/选项样式一样,这些cmdlet非常“ PowerShelly”,并且会习惯使用PowerShell的用户。 文档和工具处于“预览”模式,并且正在开发中,因此您会在文档中发现一些漏洞

The PowerShell commands all work together and data is passed between them. Here a new Azure VM configuration is created while the VM Name is pull from the list, then the a provisioning config object is passed into New-AzureVM.

PowerShell命令全部协同工作,并在它们之间传递数据。 在此处,从列表中提取VM名称时,将创建一个新的Azure VM配置,然后将配置配置对象传递到New-AzureVM中。

C:\PS>New-AzureVMConfig -Name "MySUSEVM2" -InstanceSize ExtraSmall -ImageName (Get-AzureVMImage)[7].ImageName 
` | Add-AzureProvisioningConfig –Linux –LinuxUser $lxUser -Password $adminPassword
` | New-AzureVM

Next, I want to figure out how I can spin up a whole farm of websites from the command line, deploy an app to the new web farm, configure the farm for traffic, then load test it hard, all from the command line. Such fun!

接下来,我想弄清楚如何从命令行启动整个网站服务器场,将应用程序部署到新的Web服务器场,配置服务器场的流量,然后从命令行进行艰难的负载测试。 好好玩!

Sponsor: I want to thank the folks at DevExpress for sponsoring this week's feed. Check out their DXperience tools, they are amazing. You can create web-based iPad apps with ASP.NET and Web Forms. I was personally genuinely impressed. Introducing DXperience 12.1 by DevExpress - The technology landscape is changing and new platforms are emerging. New tools by DevExpress deliver next-generation user experiences on the desktop, on the Web or across a broad array of Touch-enabled mobile devices.

赞助商:我要感谢DevExpress的人们赞助了本周的提要。 查看他们的DXperience工具,它们很棒。 您可以使用ASP.NET和Web窗体创建基于Web的iPad应用。 我个人真的很感动。 由DevExpress的引入DXperience 12.1 -技术前景正在发生变化,新的平台不断涌现。 DevExpress的工具可在台式机,Web或支持触摸功能的移动设备上提供下一代用户体验。

翻译自: https://www.hanselman.com/blog/managing-the-cloud-from-the-command-line

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值