private static string GenerateAzureDocument(ClusterCreateParametersV2 clusterCreateParameters)
        {
            if (clusterCreateParameters == null)
            {
                throw new ArgumentNullException("clusterCreateParameters");
            }

            string document = VersionToDocumentMapper.GetAzureCsmDocument(!String.IsNullOrEmpty(clusterCreateParameters.SshPassword));
            AzureCsmDocumentManager azureCsmDocumentManager = new AzureCsmDocumentManager(document);

            // Set basic cluster parameters
            azureCsmDocumentManager.SetDnsName(clusterCreateParameters.Name);
            azureCsmDocumentManager.SetLocation(clusterCreateParameters.Location);
            azureCsmDocumentManager.SetWorkerNodeCount(clusterCreateParameters.ClusterSizeInNodes);
            azureCsmDocumentManager.SetHeadNodeVMSize(String.IsNullOrEmpty(clusterCreateParameters.HeadNodeSize) ? NodeVMSize.Large.ToString() : clusterCreateParameters.HeadNodeSize);
            azureCsmDocumentManager.SetDataNodeVMSize(String.IsNullOrEmpty(clusterCreateParameters.DataNodeSize) ? NodeVMSize.Large.ToString() : clusterCreateParameters.DataNodeSize);

            // Set SSH parameters
            if (!String.IsNullOrEmpty(clusterCreateParameters.SshUserName))
            {
                if (!String.IsNullOrEmpty(clusterCreateParameters.SshPassword))
                {
                    azureCsmDocumentManager.SetSshProfile(clusterCreateParameters.SshUserName, clusterCreateParameters.SshPassword);
                }
                else
                {
                    var x509cert = GetOpenSshCertificate(clusterCreateParameters.SshPublicKey, String.Format("CN={0}", clusterCreateParameters.Name));
                    azureCsmDocumentManager.SetSshProfile(clusterCreateParameters.SshUserName, x509cert);
                }
            }

            return(azureCsmDocumentManager.Document);
        }
        public static ClusterDetails CreateClusterDetailsFromGetClustersResult(IaasCluster clusterDetailsFromServer)
        {
            if (clusterDetailsFromServer == null)
            {
                throw new ArgumentNullException("clusterDetailsFromServer");
            }

            ClusterDetails clusterDetails = new ClusterDetails();

            clusterDetails.CreatedDate  = clusterDetailsFromServer.CreatedDate;
            clusterDetails.Location     = clusterDetailsFromServer.Location;
            clusterDetails.Name         = clusterDetailsFromServer.Id;
            clusterDetails.Version      = clusterDetailsFromServer.HdiVersion;
            clusterDetails.StateString  = clusterDetailsFromServer.State.ToString();
            clusterDetails.DeploymentId = clusterDetailsFromServer.TenantId.ToString() ?? string.Empty;

            if (!string.IsNullOrEmpty(clusterDetails.Version))
            {
                clusterDetails.VersionNumber = new PayloadConverter().ConvertStringToVersion(clusterDetails.Version);
                clusterDetails.VersionStatus = VersionFinderClient.GetVersionStatus(clusterDetails.Version);
            }
            else
            {
                clusterDetails.VersionNumber = new Version(0, 0);
            }

            clusterDetails.Version = clusterDetails.VersionNumber.ToString();

            // TODO: Determine this from the documents?
            clusterDetails.ClusterType = ClusterType.Hadoop;

            // This code will only run for IaasCluster which only supports Linux today
            // We would need to put this information in one of the documents at some point
            clusterDetails.OSType = OSType.Linux;

            if (clusterDetailsFromServer.Errors != null && clusterDetailsFromServer.Errors.Any())
            {
                // Populate error details with the most recent one. These occur if the deployment workflow errors out
                string errorDescription = string.Join(", ", clusterDetailsFromServer.Errors.Select(x => string.Format("{0} : {1}", x.ErrorCode, x.ErrorDescription)));
                clusterDetails.Error = new ClusterErrorStatus(0, errorDescription, string.Empty);
            }

            AzureCsmDocumentManager            azureCsmDocumentManager            = new AzureCsmDocumentManager(clusterDetailsFromServer.DeploymentDocuments[IaasClusterDocumentTypes.EmbeddedAzureConfigurationDocument]);
            AmbariConfigurationDocumentManager ambariConfigurationDocumentManager = new AmbariConfigurationDocumentManager(clusterDetailsFromServer.DeploymentDocuments[IaasClusterDocumentTypes.EmbeddedAmbariConfigurationDocument]);

            // Populate user name, passowrd, and server address information
            clusterDetails.HttpUserName = "******";
            clusterDetails.HttpPassword = ambariConfigurationDocumentManager.GetPassword();
            if (clusterDetailsFromServer.ConnectivityEndpoints != null)
            {
                foreach (var endpoint in clusterDetailsFromServer.ConnectivityEndpoints)
                {
                    var webEndPoint = endpoint as WebConnectivityEndpoint;
                    if (webEndPoint != null)
                    {
                        clusterDetails.ConnectionUrl = String.Format("https://{0}{1}", webEndPoint.Location, webEndPoint.Port > 0 ? String.Format(":{0}", webEndPoint.Port) : "");
                        break;
                    }
                }
            }

            clusterDetails.DefaultStorageAccount = ambariConfigurationDocumentManager.GetDefaultStorageAccount();

            // Populate additional Storage Accounts
            clusterDetails.AdditionalStorageAccounts = ambariConfigurationDocumentManager.GetAdditionalStorageAccounts();

            // Populate Data Node Count
            clusterDetails.ClusterSizeInNodes = azureCsmDocumentManager.GetWorkerNodeCount();

            return(clusterDetails);
        }