public async Task <ClusterOperationStatus> GetClusterStatusAsync(string name) { string token = await this.GetAuthorizationTokenAsync(); TokenCloudCredentials credential = new TokenCloudCredentials(this.settings.SubscriptionID.ToUnsecureString(), token); DeploymentGetResult dpResult; ResourceGroupGetResult rgResult; using (ResourceManagementClient templateDeploymentClient = new ResourceManagementClient(credential)) { DeploymentExistsResult exists = templateDeploymentClient.Deployments.CheckExistence(name, name + "dp"); if (!exists.Exists) { // This might also imply that the cluster never existed in the first place. return(ClusterOperationStatus.ClusterNotFound); } dpResult = templateDeploymentClient.Deployments.Get(name, name + "dp"); rgResult = templateDeploymentClient.ResourceGroups.Get(name); } //Either the resource group might exists, but resources are being added or deleted via the template, or the RG itself might be getting created or deleted. //This means we have to seaparate out the provisioning states of both the RG along with teh template deployment to get a cluster status. //string result = dpResult.Deployment.Properties.ProvisioningState + rgResult.ResourceGroup.ProvisioningState; //result = result.Replace("Succeeded", ""); if (rgResult.ResourceGroup.ProvisioningState.Contains("Failed")) { return(ClusterOperationStatus.DeleteFailed); } if (rgResult.ResourceGroup.ProvisioningState.Contains("Deleting")) { return(ClusterOperationStatus.Deleting); } if (dpResult.Deployment.Properties.ProvisioningState.Contains("Accepted") || dpResult.Deployment.Properties.ProvisioningState.Contains("Running")) { return(ClusterOperationStatus.Creating); } if (dpResult.Deployment.Properties.ProvisioningState.Contains("Failed")) { return(ClusterOperationStatus.CreateFailed); } if (dpResult.Deployment.Properties.ProvisioningState.Contains("Succeeded")) { return(ClusterOperationStatus.Ready); } return(ClusterOperationStatus.Unknown); }
public static bool Exists(this DeploymentExistsResult result) { return(result.Exists); }