Category: virtualisation

How to update, change and delete a storage Profile with VCloud Director REST API

Recently I was tasked with removing a few attached storage profiles from a number of VDC's in vCloud Director. The task would have been a long and arduous manual task.

Fortunately vCloud Director has a REST API (A flippen good one).
The reason I say it is good is that it makes proper used of HTTP verbs to do certains tasks and returns the correct error codes and good error messages.

For example if you make a GET to a resource path that only allows PUT you will get a 415 METHOD NOT ALLOWED. So it helps to guide you - it is self documenting.

The only shit thing is that it is application/xml only right now, but xml isn't that bad to be fair.

You when you make a bad request (400) you will get extra info in the error message - ie. it will say what fields it expected or it didn't expect and you can correct the payload.

Remember the main page for the VCloud Director Rest documentation. I am using vCloud Director 9.5 (Cloud API 31.0 ) .

Changing a Storage Profile

The first thing I reliased is that you cannot just delete a storage profile. The profile must not be the default profile and it must be disabled first.

Unfortunately the documentation only gave examples on how to add or delete a storage profile - no way of updating it.

If you look at the service provider documentation and the Update Organization VDC Storage Profiles docs, you see there is no info about updating a profile.

If you look at the xml for a storage profile you will see it looks like this:

<AdminVdcStorageProfile href="https://{my_vcd_base_url}/api/admin/vdcStorageProfile/{uuid}...
<Link href="https://{my_vcd_base_url}/api/admin/vdcStorageProfile/{uuid}" rel="edit" type="application/vnd.vmware.admin.vdcStorageProfile+xml"/>

You will see there is an edit relation for that url.
After a bit of trial and error I saw that you could send it a PUT with the Storage profile object and it would update:

response = client.session.put(
            f'https://{my_vcd_base_url}/api/admin/vdcStorageProfile/{uuid}',
            data=f'''<?xml version="1.0" encoding="utf-8"?>
                <AdminVdcStorageProfile name="{storage_profile_name}" xmlns="http://www.vmware.com/vcloud/v1.5">
                    <Enabled>false</Enabled>
                    <Units>MB</Units>
                    <Limit>50000</Limit>
                    <Default>false</Default>
                    <ProviderVdcStorageProfile.../>
                </AdminVdcStorageProfile>
            ''',
            headers={
                'content-type': 'application/vnd.vmware.admin.vdcStorageProfile+xml'
            }
        )

that worked

So now I could set a storage profile as disabled and change it from being the default.

Deleting the storage Profile

Now deleting is as per the recent documentation on updating storage profile on the VDC. Importantly you need to add a RemoveStorageProfile element and not a DeleteStorageProfile element as per earlier docs.

Another thing, is the url you are posting to is the vdc's storage profile endpoint and there must be at least an href attribute on the RemoveStorageProfile element - the one you want to remove.

response = client.session.post(
        f'https://{my_vcd_base_url}/api/admin/vdc/{vdc_uuid}/vdcStorageProfiles',
        data=f'''<?xml version="1.0" encoding="UTF-8"?>
            <UpdateVdcStorageProfiles
            xmlns="http://www.vmware.com/vcloud/v1.5" >
                <RemoveStorageProfile href="{storage_profile_url}">
                </RemoveStorageProfile>
            </UpdateVdcStorageProfiles>
        ''',
        headers={
            'content-type': 'application/vnd.vmware.admin.updateVdcStorageProfiles+xml'
        }
    )

The response returns a task.
Which has a URL that you can use to check if the delettion was successful.

That's it. Hopefully this will help to automate some of the tasks you require.

Virtual Environment Utilities and Resources

I've been looking at what is available to help manage a virtual environment, that favours open source.

It is important to know the difference between a VM, VPS and Container.

VM - Full VIrtual Machine, has it's own kernel.

VPS - VPSs always run on the same OS kernel as the host system

Container -

Virtual Environments

Hypervisors

vSphere on ESXi - VmWare owned.

KVM - RedHat owned - Kernel-based Virtual Machine.

Hyper-V - Microsoft owned.

Containers

OpenVZ - Each VPS has it's own kernel - full isolation from the guest. OS-level virtualization - sharing the same instance as the host OS.

LXD - designed for hosting virtual environments that “will typically be long running and based on a clean distribution image (Only runs on linux and favours ubuntu). Create an environment similar to Linux installation without the need for separate kernel. Check this video of LXD vs KVM.

LXC is a lightweight virtualization tool integrated into Linux kernel to run multiple virtual units

LXD is a container hypervisor which is built on top of LXC to improve the experience of the user

Docker - focuses on ephemeral, stateless, minimal containers that won’t typically get upgraded or re-configured but instead just be replaced entirely

CoreOS

Management Systems

OpenNebula

virtLyst

oVirt

ProxMox - tightly linked with KVM and LXD

VirtManager

LibVirt

openStack - Seems to be able to manage a variety of things: containers, VM's, bare metal, functions, storage and networking

LXDUI

A list of available management tools for KVM

Research

From a research paper comparing the performance of OpenVZ vs LXC during a live migration

Results show that containers outperformed VMs due to its better utilization of resources. Containers can be used for application distribution to diminish resource overhead while VMs can be utilized for running application with critical businessdata.

From the results,it can be analyzed that LXC has lower downtime when compared to OpenVZ.

A comparison of virtualisation solutions

Helpers

Cloud Init - A set of scripts and utilities to make cloud images all they can be - whatever that means....

Kcli - Interacting with existing virtualisation providers

Creating Lab (Test) Environments

VMWare Autoloab

William Lam's Prebuilt Appliance