DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Power of Azure B Series Virtual Machines
  • Azure Virtual Machines
  • Keep Your Application Secrets Secret
  • What Is Azure Site Recovery Service?

Trending

  • Optimizing Serverless Computing with AWS Lambda Layers and CloudFormation
  • When Airflow Tasks Get Stuck in Queued: A Real-World Debugging Story
  • How to Introduce a New API Quickly Using Micronaut
  • Is Big Data Dying?
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Exporting and Importing VM Settings with Azure Command-Line Tools

Exporting and Importing VM Settings with Azure Command-Line Tools

By 
Larry Franks user avatar
Larry Franks
·
Oct. 29, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
6.1K Views

Join the DZone community and get the full member experience.

Join For Free

We've talked previously about the Windows Azure command-line tools, and have used them in a few posts such as Brian's Migrating Drupal to a Windows Azure VM. While the tools are generally useful for tons of stuff, one of the things that's been painful to do with the command-line is export the settings for a VM, and then recreate the VM from those settings.

You might be wondering why you'd want to export a VM and then recreate it. For me, cost is the first thing that comes to mind. It costs more to keep a VM running than it does to just keep the disk in storage. So if I had something in a VM that I'm only using a few hours a day, I'd delete the VM when I'm not using it and recreate it when I need it again. Another potential reason is that you want to create a copy of the disk so that you can create a duplicate virtual machine.

The export process used to be pretty arcane stuff; using the azure vm show command with a --json parameter and piping the output to file. Then hacking the .json file to fix it up so it could be used with the azure vm create-from command. It was bad. It was so bad, the developers added a new export command to create the .json file for you.

Here's the basic process:

Create a VM

VM creation has been covered multiple ways already; you're either going to use the portal or command line tools, and you're either going to select an image from the library or upload a VHD. In my case, I used the following command:

azure vm create larryubuntu CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd larry NotaRe

This command creates a new VM in the East US data center, enables SSH on port 22 and then stores a disk image for this VM in a blob. You can see the new disk image in blob storage by running:

azure vm disk list

The results should return something like:

info: Executing command vm disk list 
+ Fetching disk images 
data: Name                                     OS 
data: ---------------------------------------- ------- 
data: larryubuntu-larryubuntu-0-20121019170709 Linux 
info: vm disk list command OK

That's the actual disk image that is mounted by the VM.

Export and Delete the VM

Alright, I've done my work and it's the weekend. I need to export the VM settings so I can recreate it on Monday, then delete the VM so I won't get charged for the next 48 hours of not working. To export the settings for the VM, I use the following command:

azure vm export larryubuntu c:\stuff\vminfo.json

This tells Windows Azure to find the VM named larryubuntu and export its settings to c:\stuff\vminfo.json. The .json file will contain something like this:

{
	"RoleName":"larryubuntu",
	"RoleType":"PersistentVMRole",
	"ConfigurationSets":
	[
		{
			"ConfigurationSetType":"NetworkConfiguration",
			"InputEndpoints":
			[
				{
					"LocalPort":"22",
			  		"Name":"ssh",
			  		"Port":"22",
			  		"Protocol":"tcp",
			  		"Vip":"168.62.177.227"
			  	}
			  ],
		  	"SubnetNames":[]
		}
	],
	"DataVirtualHardDisks":[],
	"OSVirtualHardDisk":
	{
		"HostCaching":"ReadWrite",
		"DiskName":"larryubuntu-larryubuntu-0-20121024155441",
		"OS":"Linux"
	},
	"RoleSize":"Small"
}

If you're like me, you'll immediately start thinking "Hrmmm, I wonder if I can mess around with things like RoleSize." And yes, you can. If you wanted to bump this up to medium, you'd just change that parameter to medium. If you want to play around more with the various settings, it looks like the schema is maintained at https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/services/serviceManagement/models/roleschema.json.

Once I've got the file, I can safely delete the VM by using the following command.

azure vm delete larryubuntu

It spins a bit and then no more VM.

Recreate the VM

Ugh, Monday. Time to go back to work, and I need my VM back up and running. So I run the following command:

azure vm create-from larryubuntu c:\stuff\vminfo.json --location "East US"

It takes only a minute or two to spin up the VM and it's ready for work.

That's it - fast, simple, and far easier than the old process of generating the .json settings file. Note that I haven't played around much with the various settings described in the schema for the json file that I linked above. If you find anything useful or interesting that can be accomplished by hacking around with the .json, leave a comment about it.

Virtual Machine azure

Published at DZone with permission of Larry Franks, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Power of Azure B Series Virtual Machines
  • Azure Virtual Machines
  • Keep Your Application Secrets Secret
  • What Is Azure Site Recovery Service?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!