public void ConfigurationState_Deserialize() { const string configName = "MyConfig"; const string configUrl = "http://blah.com"; const string configVpnId = "1234ABCD"; var config = new SkytapConfiguration { Name = configName, ConfigurationUrl = configUrl, VpnId = configVpnId }; ConfigurationStateTestHelper configState = null; try { configState = new ConfigurationStateTestHelper(); configState.Serialize(config); var deserializedConfigState = configState.Deserialize(configName); var output = deserializedConfigState.ToString(); Assert.IsNotNull(deserializedConfigState); StringAssert.StartsWith(deserializedConfigState.Name, configName); StringAssert.StartsWith(deserializedConfigState.ConfigurationUrl, configUrl); StringAssert.StartsWith(deserializedConfigState.VpnId, configVpnId); Assert.IsFalse(string.IsNullOrEmpty(output)); } finally { // Make sure to clean-up any files that were left around by this test. if (configState != null && File.Exists(configState.GetPath())) { File.Delete(configState.GetPath()); } } }
/// <summary> /// Create a new Skytap configuration based on the specified template and provide an optional name. /// </summary> /// <param name="credentials">Username and password for the user making the request.</param> /// <param name="templateId">ID of the template to base the new configuration on.</param> /// <param name="configName">Optional name of the new configuration.</param> /// <returns></returns> public static SkytapConfiguration CreateConfiguration(Credentials credentials, string templateId, string configName = null) { var logger = LoggerFactory.GetLogger(); logger.LogInfo("Enter {0}... \n", MethodBase.GetCurrentMethod().Name); logger.LogInfo("Creating configuration based on template ID = {0}", templateId); var newSkytapConfiguration = new SkytapConfiguration(); var url = _configParams.SkytapHostUrl + "/configurations/"; logger.LogInfo("Request URL = {0}", url); var request = CreateSkytapWebRequest(credentials, url); request.Method = WebRequestMethods.Http.Post; // FUTURE: This likely can be simplified to include "?template_id=<id>" on the URL instead of this. // Do this once good automated tests are in place to validate. var webRequestContent = string.Format("<template_id>{0}</template_id>", templateId); byte[] rbPostData = Encoding.UTF8.GetBytes(webRequestContent); request.ContentLength = rbPostData.Length; var dataStream = request.GetRequestStream(); dataStream.Write(rbPostData, 0, rbPostData.Length); dataStream.Close(); var responseContent = Retry.Execute(() => SendSkytapHttpRequest(request), _configParams.RetryNumRetries, _configParams.RetryWaitTime); logger.LogInfo("{0}: RESPONSE = {1}\n", MethodBase.GetCurrentMethod().Name, responseContent); var xmldoc = new XmlDocument(); xmldoc.LoadXml(responseContent); var configUrlXmlNode = xmldoc.SelectSingleNode("/configuration/url"); Debug.Assert(configUrlXmlNode != null); newSkytapConfiguration.ConfigurationUrl = configUrlXmlNode.InnerText; var configNetworkIdNode = xmldoc.SelectSingleNode("//networks/network/id"); Debug.Assert(configNetworkIdNode != null); newSkytapConfiguration.ConfigurationNetworkId = configNetworkIdNode.InnerText; // Change the name of Configuration if a name has been provided if (configName != null) { newSkytapConfiguration.Name = configName; UpdateConfigurationName(credentials, newSkytapConfiguration.ConfigurationUrl, configName); } return newSkytapConfiguration; }