vMotion and Clone using REST APIs with vSphere 7.0

Couple of weeks back vSphere 7.0 released & if you ask me, it is a massive release with several cool features and capabilities including “vSphere with Kubernetes”. I was going through all the REST APIs introduced as part of multiple features shipped in this release and I see that this is the first release, where REST APIs are hands down dominating traditional SOAP based APIs. New capabilities have not only been exposed through REST APIs but also some of the older capabilities have provided REST API support as well. In this series of posts, I would like to introduce you these REST APIs as I did for vSphere Supervisor Cluster last week. In this post, I will touch upon new APIs introduced as part of “Virtual Machine” Management & demonstrate them using Postman client and Python.

Where do I get REST API documentation? This is available as part of H5C API Explorer itself since vSphere 6.5: H5C >> Menu >> Developer center >> API explorer or you can look documentation at VMware {code} site as well.

Since vSphere 6.5, when it comes to REST APIs with respect to VM life cycle, only minimal support was available i.e. Get, Create (POST call) and Delete VMs. With vSphere 7.0, I see there is huge progress made with respect to supporting key capabilities such as relocate, normal clone, instant clone & register VMs operations. Traditionally automating these VM life cycle ops have been challenging for several users using SOAP APIs, now with REST API support, it has drastically simpler to consume/automate these capabilities. Below is how its POST call URLs look like

Relocate ops:
POST https://{server}/rest/vcenter/vm/{vm}?action=relocate
POST https://{server}/rest/vcenter/vm/{vm}?vmw-task=true&action=relocate

Only difference between them is that 2nd API also returns task object, which will help user track the progress of the operation.

Clone ops:
POST https://{server}/rest/vcenter/vm?action=clone
POST https://{server}/rest/vcenter/vm?vmw-task=true&action=clone

Similar to relocate API, second API returns task object.

Instant clone ops:
POST https://{server}/rest/vcenter/vm?action=instant-clone

Register ops
POST https://{server}/rest/vcenter/vm?action=register
POST https://{server}/rest/vcenter/vm/{vm}?action=unregister


Note that there is no change to existing SOAP APIs for all the existing capabilities, it should continue to work fine without any impact

Let us now understand one of the APIs in more detail. Without a doubt, it should be all time famous capability i.e. vMotion (relocate).

POST https://{server}/rest/vcenter/vm/{vm}?action=relocate

Below is how payload for this API look like

{
    "spec" : {
        "disks" : [
            {
                "value" : {
                    "datastore" : "datastore_moid"
                },
                "key" : "disk key"
            }
        ],
        "placement" : {
            "cluster" : "cluster_moid",
            "folder" : "folder_moid",
            "datastore" : "datastore_moid",
            "host" : "host_moid",
            "resource_pool" : "resourcepool_moid"
        }
    }
}


let us understand each of the parameter being passed in brief. For detailed documentation, please refer official documentation from API Explorer or from vmware {code} portal.

disks []: This spec has 2 values such as datastore and key as follows, it is required field to pass details for all the VM disks.

datastore : required: This parameter under “disks[]” should be the destination datastore for the VM disks. This should be datastore_moid and moid found using existing REST API:
GET https://{server}/rest/vcenter/datastore
sample value : “datastore-21”

key: required: this must be the disk key(s) for the VM to be migrated and it can be found using existing REST API. sample value : “2000”
GET https://{server}/rest/vcenter/vm/{vm}/hardware/disk

placement : destination spec

cluster: this should be cluster moid. This can be specified if we would like DRS to find the right host for placement. This can be optional param. moid can be found using API: sample value : “domain-c9”
GET https://{server}/rest/vcenter/cluster

folder: destination VM folder. This is optional param. moid can be found using API. sample value : “group-v4”
GET https://{server}/rest/vcenter/folder

datastore: This is under placement_spec: This is required if you want relocate VM configuration folders/files to destination. The “datastore” property briefed before above is for VM disks.

host: destination host. It is optional if cluster or resource pool is passed. sample value : “host-32”
moid can be found using API: GET https://{server}/rest/vcenter/host

resource_pool: destination resource pool. This is not required if host or cluster is specified. sample value : “resgroup-34”
moid can be found using API: GET https://{server}/rest/vcenter/resource-pool

Note that there are couple of noteworthy points wrt relocate and clone REST APIs. As of vSphere 7.0, it does not give an option to specify destination network & it does not support cross vCenter migration/clone as well . I hope in future releases, both of these key aspects will be supported through REST APIs

Let us invoke this API. I did it using both postman REST client and Python.

Postman way:

Note: In my case, I am relocating the VM from one cluster to other DRS enabled cluster. If you do not have DRS enabled cluster, you can go with passing destination host instead. I passed just enough params as shown below in Postman client but you may pass as per your requirement.

Here is the payload passed for easy copy paste.

{
    “spec” : {
        “disks” : [
            {
                “value” : {
                    “datastore” : “datastore-57”
                },
                “key” : “2000”
            }
        ],
        “placement” : {
            “cluster” : “domain-c9”,
            “datastore” : “datastore-57”
        }
    }
}

Python way:

Here is the equivalent python script for the same on my github repo. Below is how you would execute this python script


You can see API returned 200 ok response. how cool is that!

I hope you enjoyed this post. Please stay tuned for next post in this REST API series.

References:
– How to get started guide on REST APIs using Postman and python
– Introduction to vSphere Supervisor cluster APIs



	

84 thoughts on “vMotion and Clone using REST APIs with vSphere 7.0

  1. We’re a bunch of volunteers and opening a new scheme in our
    community. Your site provided us with valuable information to
    work on. You have performed an impressive job and our whole group will likely be thankful to you.

  2. This design is incredible! You definitely know how to keep a reader amused.
    Between your wit and your videos, I was almost moved to start my
    own blog (well, almost…HaHa!) Fantastic job.
    I really enjoyed what you had to say, and more than that,
    how you presented it. Too cool!

    My web blog – jackpot king855 (918kiss-m.com)

  3. I’ve been exploring for a bit for any high-quality
    articles or weblog posts in this kind of area .
    Exploring in Yahoo I at last stumbled upon this website.

    Reading this info So i am satisfied to show that I have a
    very good uncanny feeling I found out exactly what I needed.
    I such a lot indisputably will make sure to do not fail to remember this web site and
    provides it a look on a constant basis.

    My web page – 918kiss xe88

  4. You actually make it seem so easy with your presentation but I find this topic to be really something which I think I would
    never understand. It seems too complex and extremely broad for me.
    I’m looking forward for your next post, I will try to get the hang of it!

  5. Hello! I know this is kind of off topic but I was wondering
    which blog platform are you using for this
    website? I’m getting sick and tired of WordPress because I’ve had problems with hackers and I’m
    looking at options for another platform. I would be
    great if you could point me in the direction of a good platform.

    Here is my page – test id club suncity

  6. Hey! I know this is kind of off topic but I was wondering which blog platform are you
    using for this site? I’m getting fed up of WordPress
    because I’ve had problems with hackers and I’m looking at alternatives for another platform.
    I would be fantastic if you could point me in the
    direction of a good platform.

    my webpage :: test 918kaya (918Kiss-M.com)

  7. Magnificent beat ! I wish to apprentice at the same time as you amend your web site, how could i subscribe
    for a weblog web site? The account helped me a acceptable deal.
    I were tiny bit familiar of this your broadcast provided vivid transparent concept

    my page: id live22

  8. Hey! I understand this is kind of off-topic but I needed to ask.
    Does managing a well-established website like yours take a
    lot of work? I’m completely new to blogging however I
    do write in my diary every day. I’d like to start a blog so I can share my
    own experience and views online. Please let me know
    if you have any recommendations or tips for brand new aspiring bloggers.
    Thankyou!

    Here is my site :: free download game lpe88; Bert,

  9. Thanks for another informative blog. The place else may
    just I get that type of info written in such a perfect manner?

    I’ve a undertaking that I am simply now operating on, and I’ve been on the
    glance out for such info.

    my site; id ntc33

  10. Hey there! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to
    get my blog to rank for some targeted keywords but I’m not
    seeing very good gains. If you know of any please share.

    Appreciate it!

    my blog … joker688 (918kiss-m.com)

  11. Its like you read my mind! You appear to know so much about
    this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but other than that, this is great blog.
    A fantastic read. I’ll certainly be back.

    Feel free to visit my web site Kiosk Wukong333 Vip

  12. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog?
    My blog site is in the exact same area of interest as yours and my visitors would genuinely benefit from a lot of the information you present here.

    Please let me know if this alright with you. Regards!

  13. Thanks for one’s marvelous posting! I certainly enjoyed reading it, you might be a great author.

    I will remember to bookmark your blog and will eventually come back down the road.
    I want to encourage one to continue your great posts, have a
    nice afternoon!

  14. When someone writes an piece of writing he/she retains the idea of a user in his/her mind that
    how a user can understand it. Thus that’s why this piece of writing is perfect.
    Thanks!

  15. Hey! I could have sworn I’ve been to this website before but after
    browsing through some of the post I realized it’s new to me.
    Anyhow, I’m definitely glad I found it and I’ll be book-marking and checking back
    frequently!

  16. Woԝ that was odd. I ϳust wrοte an veгy long comment but after I clicked sᥙbmit my comment didn’t
    sһow up. Grrrr… well I’m not writing all that over again.
    Anyway, just wanted to say greаt blog!

  17. Good day! I could have sworn I’ve been to this web site before but after going through a few of the posts I realized it’s new
    to me. Anyways, I’m definitely pleased I stumbled upon it and I’ll be bookmarking it and checking back frequently!

  18. Thank you for the auspicious writeup. It in truth was a enjoyment account it.

    Look complex to far added agreeable from you! However,
    how could we communicate?

  19. Definitely believe that which you said. Your favorite justification appeared to be on the net the simplest
    thing to be aware of. I say to you, I definitely
    get annoyed while people think about worries that they plainly don’t know about.

    You managed to hit the nail upon the top as well as defined
    out the whole thing without having side effect , people can take a
    signal. Will probably be back to get more. Thanks

  20. Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s tough to get that “perfect balance” between user friendliness
    and appearance. I must say you have done a superb job with this.
    Also, the blog loads extremely quick for me on Safari. Exceptional Blog!

  21. Hi there! I’m at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading your blog and look forward
    to all your posts! Keep up the great work!

  22. Heyа thhis is kinda of offf topic but I was wanting to know іf blogs use WYSIᎳYG editors or if you have
    to manually code withh HTML. I’m starting a bⅼߋg soon but have no coding know-how so
    I wanted to get guіdance frlm someone with exрerience.

    Any help would be enormously appreciated!

  23. Saya akan segera rebut rss feed Anda karena saya tidak bisa
    Wow, tulisan ini bagus , adik perempuan saya sedang menganalisis hal-hal seperti , jadi saya akan
    beri tahu dia.

    Feel free to surf to my web blog – Joker888 test [Josephine]

  24. Hello! Do you know if they make any plugins to assist with SEO?
    I’m trying to get my blog to rank for some targeted keywords
    but I’m not seeing very good success. If you know of any please share.
    Cheers!

  25. Hello, i read your blog from time to time and i own a similar
    one and i was just wondering if you get a lot of spam feedback?
    If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it’s driving me crazy so any assistance is very much
    appreciated.

  26. I just like the valuable information you supply to your articles.
    I will bookmark your weblog and check again right here regularly.
    I’m rather sure I will be told many new stuff right here!
    Best of luck for the following!

  27. Ahaa, its pleasant discussion on the topic of this piece of writing
    here at this blog, I have read all that, so now me also commenting here.

  28. My brother recommended I might like this blog.

    He was totally right. This post truly made my day. You cann’t imagine
    simply how much time I had spent for this information! Thanks!

  29. Useful info. Lucky me I discovered your web site by chance, and
    I am stunned why this twist of fate did not happened in advance!
    I bookmarked it.

  30. Saya akan segera genggam rss feed Anda karena saya tidak bisa
    Ini waktu tepat untuk membuat beberapa rencana untuk masa depan dan sekarang waktu
    untuk bahagia. Saya pelajari kirim ini dan jika saya boleh saya ingin
    merekomendasikan Anda beberapa menarik hal atau saran .

    Mungkin Anda bisa menulis artikel berikutnya yang berhubungan dengan
    artikel ini. Saya ingin membaca lebih lagi hal
    tentang itu!

    my blog post – Joker123 pro

  31. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get
    four emails with the same comment. Is there any way you can remove people from that service?
    Appreciate it!

  32. Wonderful goods from you, man. I have understand your stuff previous to and you’re just extremely fantastic.
    I actually like what you have acquired here, really like what you’re saying
    and the way in which you say it. You make it enjoyable and you still take care of to keep it
    smart. I cant wait to read much more from you.
    This is actually a tremendous website.

  33. My brother recommended I would possibly like this blog.
    He was once entirely right. This submit actually made my day.
    You cann’t imagine simply how so much time I had spent for
    this information! Thanks!

  34. Thanks for your personal marvelous posting!
    I truly enjoyed reading it, you could be a great author.I will be sure to bookmark your blog and may come back someday.
    I want to encourage you to definitely continue your great work, have a nice day!

  35. Hi I am so excited I found your blog page, I really found you by error, while I was looking on Yahoo for something else, Anyways I am here now and would just like to say thanks a lot for a
    remarkable post and a all round entertaining blog (I also love the theme/design), I don’t have time to look over
    it all at the moment but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up
    the awesome job.

  36. This is a very good tip particularly to those new to the blogosphere.
    Brief but very accurate info… Many thanks for sharing
    this one. A must read article!

  37. I think this is among the so much important info for me.
    And i am glad reading your article. But wanna remark on few general things, The web site style is wonderful, the articles is in point of fact great : D.
    Just right process, cheers

  38. When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from
    now on every time a comment is added I recieve 4 emails
    with the exact same comment. Is there a means you are able to remove
    me from that service? Cheers!

  39. I am now not sure the place you’re getting your information, but
    great topic. I needs to spend some time finding out more or working out
    more. Thanks for excellent info I was looking for this info for my mission.

  40. I was suggested this blog by my cousin. I am not sure whether this
    post is written by him as nobody else know
    such detailed about my trouble. You’re amazing! Thanks!

  41. I think this is one of the most important info for me.
    And i am glad reading your article. But want
    to remark on few general things, The web site style is ideal, the articles is really excellent : D.
    Good job, cheers

  42. It’s appropriate time to make a few plans for the future and
    it is time to be happy. I have read this publish and if
    I could I want to recommend you few attention-grabbing things or suggestions.

    Perhaps you can write subsequent articles relating to this
    article. I want to read more things about it!

  43. Of course you’ve probably lost a large volume of traffic but at least you can stop on your own from losing anymore.
    Weblog allows for you to achieve a potentially infinite
    number of consumers for your businesses.

  44. I was very pleased to uncover this great site.
    I need to to thank you for ones time for this particularly wonderful read!!
    I definitely really liked every part of it and I have you book
    marked to see new things on your web site.

  45. Thanks on your marvelous posting! I seriously enjoyed reading it, you could be a great author.
    I will be sure to bookmark your blog and definitely will come back later on. I want to encourage
    that you continue your great work, have a nice morning!

Leave a Reply

Your email address will not be published. Required fields are marked *