{"id":65,"date":"2014-03-20T12:23:00","date_gmt":"2014-03-20T10:23:00","guid":{"rendered":"http:\/\/www.cubeos.org\/blog\/2014\/03\/azure-from-the-linux-command-line-part-1\/"},"modified":"2014-03-20T12:23:00","modified_gmt":"2014-03-20T10:23:00","slug":"azure-from-the-linux-command-line-part-1","status":"publish","type":"post","link":"https:\/\/www.cubeos.org\/blog\/2014\/03\/azure-from-the-linux-command-line-part-1\/","title":{"rendered":"Azure from the Linux command line (part 1)"},"content":{"rendered":"<p>Hi!<\/p>\n<p>Since i&#8217;ve been gowing up IT-wise with a unix command shell, I tend to do a lot of things with it. Also managing my Azure deployments since there&#8217;s the great <a title=\"Azure command line interface documentation\" href=\"http:\/\/www.windowsazure.com\/en-us\/documentation\/articles\/xplat-cli\/\" target=\"_blank\"  rel=\"nofollow\" >Azure command line interface<\/a>&nbsp;or cross platform (&#8220;xplat&#8221;)&nbsp;CLI.<\/p>\n<p>(If you&#8217;re interested in the details, this is all open source, released under an Apache license, and on github: &nbsp;<a href=\"https:\/\/github.com\/WindowsAzure\/azure-sdk-tools-xplat\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/github.com\/WindowsAzure\/azure-sdk-tools-xplat<\/a>.)<\/p>\n<p>This blog post documents a few tricks I&#8217;ve been using to get up and running fast.<\/p>\n<p>First: You need to connect the xplat cli to your azure subscription. To do that simply&nbsp;run<\/p>\n<p>$ <span style=\"font-family: terminal,monaco\">azure download<\/span><\/p>\n<p>after installing the cli. If you&#8217;re on a remote machine via ssh, this will simply give you an URL to launch in your browser. Make sure you&#8217;re already logged into the azure portal, otherwise you will need to login first when going to this URL.<\/p>\n<p>The website will now give you a <span style=\"font-family: terminal,monaco\">.publishsettings<\/span> file for download. The same file is used when setting up a connection between Visual Studio and an Azure subscription.<\/p>\n<p>Now get this file to your linux box (and make sure you keep it safe in transit, this file contains a management certificate key that can manage your subscription!) and import it into xplat cli:<\/p>\n<p><span style=\"font-family: terminal,monaco\">$ azure account import &lt;publishsettingsfile&gt;<\/span><\/p>\n<p>And now you&#8217;re all set.<\/p>\n<p>Now let&#8217;s look around<\/p>\n<p><span style=\"font-family: terminal,monaco\">$ azure help<\/span><\/p>\n<p><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp; Executing command help<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _&nbsp;&nbsp;&nbsp; _____&nbsp;&nbsp; _ ___ ___<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/_&nbsp; |_&nbsp; \/ | | | _  __|<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ ___\/ _ __\/ \/| |_| |&nbsp;&nbsp; \/ _|___ _ _<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp; (___&nbsp; \/_\/ _\/___|___\/|_|____| _____)<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (_______ _ _)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ ______ _)_ _<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (______________ _ )&nbsp;&nbsp; (___ _ _)<\/span><br \/><span style=\"font-family: terminal,monaco\">info:<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp; Windows Azure: Microsoft&#8217;s Cloud Platform<\/span><br \/><span style=\"font-family: terminal,monaco\">info:<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp; Tool version 0.7.4<\/span><br \/><span style=\"font-family: terminal,monaco\">help:<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp; Display help for a given command<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; help [options] [command]<\/span><br \/><span style=\"font-family: terminal,monaco\">help:<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp; Open the portal in a browser<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portal [options]<\/span><br \/><span style=\"font-family: terminal,monaco\">help:<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp; Commands:<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; account&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your account information and publish settings<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your local settings<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hdinsight&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your HDInsight accounts<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mobile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your Mobile Services<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; network&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your Networks<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your Service Bus configuration<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your Cloud Services<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; site&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your Web Sites<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sql&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your SQL Server accounts<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; storage&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your Storage objects<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Commands to manage your Virtual Machines<\/span><br \/><span style=\"font-family: terminal,monaco\">help:<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp; Options:<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -h, &#8211;help&nbsp;&nbsp;&nbsp;&nbsp; output usage information<\/span><br \/><span style=\"font-family: terminal,monaco\">help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -v, &#8211;version&nbsp; output the application version<\/span><\/p>\n<p>That does not look to bad after all. Just remember <span style=\"font-family: terminal,monaco\">azure help &lt;command&gt;<\/span>,this is your first stop whenever you get stuck.<\/p>\n<p>So let&#8217;s set up a linux VM. First let&#8217;s check what pre-configured linux images are available.<\/p>\n<p>$ azure vm image list<\/p>\n<p>Now you should see a lot of images. When I just ran this, I got more that 200 lines of output. Image names look like this:<\/p>\n<p><span style=\"font-family: terminal,monaco\">&nbsp;b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_10-amd64-server-20140226-en-us-30GB<\/span><\/p>\n<p>Now we could copy this name to our clipboard and paste it into the next command, but let&#8217;s have the shell do that for us, here&#8217;s the idea:<\/p>\n<p><span style=\"font-family: terminal,monaco\">#!\/bin\/bash<\/span><br \/><span style=\"font-family: terminal,monaco\">IMAGENAME=`azure vm image list |grep -i Ubuntu-13_10-amd64-server |tail -1 | awk &#8216;{print $2}&#8217;`<\/span><\/p>\n<p>Get the list of VM images, just select the ones we&#8217;re interested in, then select the last (i.e. the most recent one) of that list and just give me the second string which is the image name. Easy, right? Note the back single quotes in the beginning and the end of that line, this is shell syntax for &#8220;take the output of that command and store it in that shell environment variable&#8221;.<\/p>\n<p>To use the VM, we need to login, so let&#8217;s use a password for now:<\/p>\n<p><span style=\"font-family: terminal,monaco\">PASSWORD=&#8221;AtotallySECRET!PA55W0RD&#8221;<\/span><br \/><span style=\"font-family: terminal,monaco\">echo Password is $PASSWORD<\/span><\/p>\n<p>Next, let&#8217;s create the VM:<\/p>\n<p><span style=\"font-family: terminal,monaco\">azure vm create -e -z extrasmall -l &#8220;West Europe&#8221; $1 $IMAGENAME&nbsp;azureuser &#8220;$PASSWORD&#8221;<\/span><\/p>\n<p>Here&#8217;s the output of running this shell script:<\/p>\n<p><span style=\"font-family: terminal,monaco\">$ bash create_ubuntu_vm.sh contosolinux<\/span><\/p>\n<p><span style=\"font-family: terminal,monaco\">Password is AtotallySECRET!PA55W0RD<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp; Executing command vm create<\/span><br \/><span style=\"font-family: terminal,monaco\">+ Looking up image b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_10-amd64-server-20140226-en-us-30GB<\/span><br \/><span style=\"font-family: terminal,monaco\">+ Looking up cloud service<\/span><br \/><span style=\"font-family: terminal,monaco\">+ Creating cloud service<\/span><br \/><span style=\"font-family: terminal,monaco\">+ Retrieving storage accounts<\/span><br \/><span style=\"font-family: terminal,monaco\">+ Creating VM<\/span><br \/><span style=\"font-family: terminal,monaco\">info:&nbsp;&nbsp;&nbsp; vm create command OK<\/span><\/p>\n<p>And&nbsp;after about two minutes&nbsp;I can ssh into contosolinux.cloudapp.net as &#8220;azureuser&#8221; with that super secret password.<\/p>\n<p>Hope it helps,<\/p>\n<p>H.<\/p>\n<p>ps: to get rid of the VM again, I just type <span style=\"font-family: terminal,monaco\">azure vm delete -b contosolinux<\/span><\/p>\n<p>pps: in case that&#8217;s too harsh, <span style=\"font-family: terminal,monaco\">azure vm shutdown contosolinux<\/span>, <span style=\"font-family: terminal,monaco\">azure vm start contosolinux<\/span> and <span style=\"font-family: terminal,monaco\">azure vm restart contosolinux<\/span> work as well. And <span style=\"font-family: terminal,monaco\">azure vm list<\/span> shows you what Azure thinks your VMs are doing right now.<\/p>\n<p>ppps: And in case you were wondering&nbsp;why there was no root password set: just&nbsp;run <span style=\"font-family: terminal,monaco\">sudo bash<\/span> from this initial user account.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"clear:both\"><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blogs.msdn.com\/aggbug.aspx?PostID=10509375\" width=\"1\" height=\"1\"><br \/>\nSource: msdn<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi! Since i&#8217;ve been gowing up IT-wise with a unix command shell, I tend to do a lot of things with it. Also managing my Azure deployments since there&#8217;s the great Azure command line interface&nbsp;or cross platform (&#8220;xplat&#8221;)&nbsp;CLI. (If you&#8217;re &hellip; <a href=\"https:\/\/www.cubeos.org\/blog\/2014\/03\/azure-from-the-linux-command-line-part-1\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-microsoft"],"_links":{"self":[{"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":0,"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cubeos.org\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}