Today we discuss, taking snapshots with instances in OpenStack. A backup is different from a snapshot in that a backup can be used to restore instance to its state where as a snapshot is a point of time capture of an instance, its filesystem but not its memory.
To take a live snapshot on Openstack, we can issue the following command:
nova image-create <instance name or uuid> <name of new image>
Openstack also provides snapshot APIs from the Images library which are as follows:
GET /v2/images
GET /v2/images/{image_id}
And
POST /v2/images
eg
curl -i -X POST -H "X-Auth-Token: $OS_AUTH_TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "Ubuntu 12.10", "tags": ["ubuntu", "12.10", "quantal"]}' \ $OS_IMAGE_URL/v2/images
which gives an output such as:
{ "id": "7b97f37c-899d-44e8-aaa0-543edbc4eaad", "name": "Ubuntu 12.10", "status": "queued", "visibility": "private", "protected": false, "tags": ["ubuntu", "12.10", "quantal"], "created_at": "2012-08-14T00:46:48Z", "updated_at": "2012-08-14T00:46:48Z", "file": "/v2/images/7b97f37c-899d-44e8-aaa0-543edbc4eaad/file", "self": "/v2/images/7b97f37c-899d-44e8-aaa0-543edbc4eaad", "schema": "/v2/schemas/image" }
Upload and download of raw image data can be done with:
PUT /v2/Images/{image_id}/file
GET /v2/Images/{image_id}/file
For example:
curl -i -X PUT -H "X-Auth-Token: $OS_AUTH_TOKEN" \ -H "Content-Type: application/octet-stream" \ -d @/home/glance/ubuntu-12.10.qcow2 \ $OS_IMAGE_URL/v2/images/7b97f37c-899d-44e8-aaa0-543edbc4eaad/file
and
curl -i -X GET -H "X-Auth-Token: $OS_AUTH_TOKEN" \ $OS_IMAGE_URL/v2/images/7b97f37c-899d-44e8-aaa0-543edbc4eaad/file
Notice that these APIs take an OAuth token for the administrator. In Openstack deployments, this may be very sensitive and not available for everyone’s consumption.
Instead these APIs can be made private and the API can be wrapped and exposed internally where a different authentication takes place on behalf of the users.
#codingexercise
Find the nearest element in a Binary Search Tree
GetNearest(Node root, int val, ref target)
{
if (root == null) { target = null; return;}
if (root.data == val) {target = root; return; }
if (val < root.data){
if (root.left == null) {target = root; return;}
GetNearest(root.left, val, target);
if (Math.abs(target.val - val) > Math.abs(root.val-val)){ target=root; return;}
}else{
if (root.right == null) {target = root; return;}
GetNearest(root.right, val, target);
if (Math.abs(target.val - val) > Math.abs(root.val-val)){ target=root; return;}
}
}
return null;
}
Find the nearest element in a Binary Search Tree
GetNearest(Node root, int val, ref target)
{
if (root == null) { target = null; return;}
if (root.data == val) {target = root; return; }
if (val < root.data){
if (root.left == null) {target = root; return;}
GetNearest(root.left, val, target);
if (Math.abs(target.val - val) > Math.abs(root.val-val)){ target=root; return;}
}else{
if (root.right == null) {target = root; return;}
GetNearest(root.right, val, target);
if (Math.abs(target.val - val) > Math.abs(root.val-val)){ target=root; return;}
}
}
return null;
}
Find the maximum sum root to leaf in a tree
Void GetLeafMax ( node root, int sum, ref int max, ref leaf)
{
If (root == null) return;
sum += root.data;
If (root.left == null && root.right == null)
{
If (sum > max){
sum = max;
leaf = root;
}
}
GetLeafmax (root.left, sum, max);
GetLeafmax (root.right, sum, max);
}
Bool PrintPath(Node root, node leaf)
{
If (root==null) return false;
If (root == leaf ||
PrintPath(Root.left, leaf) ||
PrintPath(root.right, leaf))
{
Console.Write(root.data);
Return true;
}
Return false;
}
Int maxSumPath(Node root)
{
If (root == null) return 0;
Node leaf;
Int max = INT_MIN;
GetLeafMax(node, 0, ref max, ref target_leaf);
return max;
}
Given a non-negative number represented as an array of digits, plus one to the number.
Given a non-negative number represented as an array of digits, plus one to the number.
void plusOne(ref List<int> digits, int position)
{
if (position > digits.Length) return;
if (position - 1 < 0) {// check INT_MIN underflow; digits.InsertAt(0, 1); return;}
if (digits[position] + 1 > 9)
plusOne(ref digits, position - 1);
else
digits[position] += 1;
}
No comments:
Post a Comment