/// <summary> /// Kick off asynchronous request. /// </summary> /// <param name="session">Client session</param> /// <param name="req">API command</param> /// <returns>Asynchronous task job id.</returns> public static string StartAsyncJob(Client session, APIRequest req) { XDocument resp = session.SendRequest(req); XElement jobid = resp.Descendants("jobid").FirstOrDefault(); if (jobid == null || string.IsNullOrEmpty(jobid.Value)) { throw new CloudStackException("Async command failed to return jobid", req.ToString(), resp); } return jobid.Value; }
/// <summary> /// Start a job, wait for it to complete and return the resulting resource id /// </summary> /// <param name="session">the session</param> /// <param name="req">the request object</param> /// <returns>resource id</returns> public static string WaitForResourceIdFromAsyncJob(Client session, APIRequest req) { string jobid = StartAsyncJob(session, req); XDocument asyncResult = WaitForAsyncJobResult(session, jobid); XElement id = asyncResult.Descendants("id").FirstOrDefault(); if (id == null || string.IsNullOrEmpty(id.Value)) { throw new CloudStackException("Failed to obtain new resource id after async job", req.ToString(), asyncResult); } return id.Value; }