A frequently requested feature from customers and partners have been around the Storage Profile APIs and with the upcoming vSphere 5.5 release, it will now be possible to automate the management and consumption of Storage Profiles. In vSphere 5.5, Storage Profiles has been renamed to VM Storage Policy and they have been enhanced from the previous version of Storage Profile. VM Storage Policy introduces new concept of a rule set also known as a sub-profile or sub-policy from an API perspective.
A VM Storage Policy can contain multiple rule sets which describes a requirement for a virtual machine storage resource. Each rule can either be an underlying storage capability or a user defined vSphere Tag.
One important thing to note about the VM Storage Policy API (SOAP API), is that it is exposed as a separate API endpoint (similar to how the SMS API is exposed) on vCenter Server and it will not be accessible through the normal vSphere API. To consume this API, you will need to connect to the PBM (Policy Based Management) Server which requires an authenticated vCenter Server session. A great way to learn and explore the new SPBM API is to check out the SPBM MOB.
Here is the high level workflow for connecting to the PBM Server:
- Login to vCenter Server
- Extract the session cookie
- Add vCenter Server session cookie & connect to PBM Server
Once connected to the PBM Server, you will have access to PBM ServiceInstance with following three managed objects:
-
- ProfileProfileManager (not a typo, repeat of Profile for some reason)
- PlacementSolver
- ComplianceManager
As mentioned earlier, a VM Storage Policy can be made up of several rule sets and each rule set contains a property rule. Here is the specification for what the VM Storage Policy looks like from an API perspective:
For managing and creating VM Storage Policies, you will need use the new VM Storage Policy API and for consuming and assigning VM Storage Policies to a virtual machine, you will need to use the vSphere API. When provisioning or cloning a virtual machine, there is a new profile property that denotes the MoRef ID for a particular VM Storage Policy.
As part of the VM Storage Policy API, there will be a Java SDK that includes a programming guide that goes over the VM Storage Policy API in greater detail as well as several sample programs exercising the various API methods. Since the VM Storage Policy API is a SOAP API similar to the vSphere API, the WSDL will also be available if you wish to generate your own language binding to the API.
Here is a screenshot of the available sample programs leveraging the new VM Storage Policy API:
Here is an example of one of the sample programs which lists all the VM Storage Policies for a given vCenter Server:
run.bat ListProfiles --vcurl https://[VC-IP]/sdk/vimService --ssourl https://[VC-IP]:7444/ims/STSService --spbmurl https://[VC-IP]/pbm --username *protected email* --password vmware --ignorecert
In the screenshot, you will see four VM Storage Policy being shown, one which I had created earlier and there others which are VM Storage Policies created by VSAN. You will notice that you will need three pieces of information when connecting: vCenter Server endpoint, SSO Server endpoint and PBM Server endpoint. You can find more details by referring to the VM Storage Policy Programming Guide and VM Storage Policy API reference.
jorg gray says
A frequently requested feature from customers and partners have been around the Storage Profile APIs and with the upcoming vSphere 5.5 release, it will now be possible to automate the management and consumption of Storage Profiles. http://www.paylessforstorage.co.uk/
Shahar says
hi
first of all,Thanks, very helpful article.
However, i tried to connect to the pbm service as suggested (but with c# code).
I manged to get the token from the ssl service
I manged to connect with it to the vimService and retrieve the cookie.
When i tried to connect (Retrieve service) to the pbm service with the cookie, i'm getting "vim25:SecurityErrorr".
Any ideas?
Thanks in advanced.
Shahar
Kenny says
Did you ever get this to work Shahar? I am having the same issue... been trying for awhile now.
Shahar says
yes, i did...
the problem was with where I set the cookie.
my first assumption was:
_pbmService.CookieContainer = new CookieContainer();
_pbmService.CookieContainer.Add(cookie);
However, this is not the only place we need to add the cookie.
we need to add the cookie to the header.
to do so, we need to add custom header to the c# class we generate from the wsdl
see: http://dotnetslackers.com/articles/aspnet/Securing-ASP-Net-Web-Services-with-Forms-Authentication.aspx
and then use it in our code:
vcSessionCookieCustomHeader header = new vcSessionCookieCustomHeader();
header.cookie = cookie.Value;
_pbmservice.vcSessionHeader = header;
Kenny says
Thank you very much for the quick reply! and of course the solution!!! I had tried each individually but not together. So happy I can stop banging my head on this... thank you again!
Kenny says
One more question if have the time, I must be missing something... how are you applying the custom soap header in the class generated from the wsdl? Also, for the cookie being added did you have to change the key from vmware_soap_session to vcSessionCookie as they did in the java samples?
var pbmService = new PbmService() { Url = url };
var cookieContainer = new CookieContainer();
cookie.Name = "vcSessionCookie"; // change from vmware_soap_session to vcSessionCookie
cookieContainer.Add(cookie);
pbmService.CookieContainer = cookieContainer;
var header = new VcSessionCookieCustomHeader();
header.cookie = cookie.Value;
pbmService.vcSessionHeader = header;
public class VcSessionCookieCustomHeader : System.Web.Services.Protocols.SoapHeader
{
public string cookie;
}
public partial class PbmService : Microsoft.Web.Services3.WebServicesClientProtocol
{
public VcSessionCookieCustomHeader vcSessionHeader { get; set; }
Are you using the SoapHeader attribute? For example...
[System.Web.Services.Protocols.SoapHeader("vcSessionHeader", Direction = SoapHeaderDirection.Out)]
public PbmServiceInstanceContent PbmRetrieveServiceContent(ManagedObjectReference _this)
Thank you!
feng.zhang says
Hi, did you change the key from vmware_soap_session to vcSessionCookie as they did in the java samples?
and Are you using the SoapHeader attribute? [System.Web.Services.Protocols.SoapHeader(“vcSessionHeader”, Direction = SoapHeaderDirection.Out)]
i got vim25:NoPermission for PbmQueryProfile after pbmService.PbmRetrieveServiceContent finished,
do you have some ideas?
Kenny says
I figured it out, thanks for the help. For anyone else that may run across this...
[XmlRootAttribute(ElementName = "vcSessionCookie", DataType = "string", IsNullable = false)]
public class vcSessionCookieCustomHeader : System.Web.Services.Protocols.SoapHeader
{
[System.Xml.Serialization.XmlTextAttribute()]
public string cookie;
}
Shahar says
sorry, i wasn't working the last two days.
you are right, the XmlTextAttribute() will do the trick.
Shahar says
hi Kenny.
Did you ever get the next exception:
"the session is not authenticated"
i tried to reconnect to vim service (and succeeded), and add the new cookie, but it didn't help...
any thought?
Thanks
Shahar.
Kenny says
Hi,
I have not ran across that yet, though I am still developing so haven't had the vSphere(vimservice) session open long enough at this point for the session to time out. Is your session timing out to vSphere and the pbmService session is still active during that time the scenario, or are you opening up a new pbmService after the vSphere session was reconnected?
Ken
Atoka Sema says
Hi,
Thank you for this helpful article. I have couple of questions related to VM Storage Policy that I would like to ask.
Is there a way to list all the VM Storage Policies using vSphere API?
As you mentioned, we can do it using VM Storage Policy API, but what I am trying to do is to use vSphere SDK to get the Id of already created profile and assign it to a VM's Virtual Disk.
Also can we create a VM Storage Policy with Rule-Set using VM Storage Policy API? I don't PbmProfileProfileManager.PbmCreate API taking any Rule-Set related parameter.
Thanks.
J Xu says
For vsphere 6.7, the command used should be -
run.bat ListProfiles --vcurl https://[VC-IP]/sdk/vimService --ssourl https://[VC-IP]/sts/STSService --spbmurl https://[VC-IP]/pbm --username *protected email* --password vmware --ignorecert