diff --git a/OneAndOne.Client/Endpoints/Common/Common.cs b/OneAndOne.Client/Endpoints/Common/Common.cs new file mode 100644 index 0000000..be1d202 --- /dev/null +++ b/OneAndOne.Client/Endpoints/Common/Common.cs @@ -0,0 +1,90 @@ +using Newtonsoft.Json; +using OneAndOne.POCO.Response.Common; +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.Client.Endpoints.Common +{ + public class Common : ResourceBase + { + public Common(object _apiUrl = null, object _apiKey = null) + : base(_apiUrl, _apiKey) { } + /// + /// Returns prices for all available resources in Cloud Panel + /// + public PricingResponse GetPricing() + { + try + { + var request = new RestRequest("/pricing", Method.GET); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return JsonConvert.DeserializeObject(result.Content); + } + catch + { + throw; + } + } + + /// + /// Returns true if the API is running + /// + public bool Ping() + { + try + { + bool value = false; + var request = new RestRequest("/ping", Method.GET); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + return value; + } + if (result.Content == "[\"PONG\"]") + { value = true; } + return value; + } + catch + { + return false; + } + } + + /// + /// Returns true if the API is running and the token is valid + /// + public bool PingAuthentication() + { + try + { + bool value = false; + var request = new RestRequest("/ping_auth", Method.GET); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + return value; + } + if (result.Content == "[\"PONG\"]") + { value = true; } + return value; + } + catch + { + return false; + } + } + + } +} diff --git a/OneAndOne.Client/Endpoints/DataCenter/DataCenters.cs b/OneAndOne.Client/Endpoints/DataCenter/DataCenters.cs new file mode 100644 index 0000000..d595f19 --- /dev/null +++ b/OneAndOne.Client/Endpoints/DataCenter/DataCenters.cs @@ -0,0 +1,92 @@ +using Newtonsoft.Json; +using OneAndOne.POCO.Response.DataCenters; +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.Client.Endpoints.DataCenter +{ + public class DataCenters : ResourceBase + { + public DataCenters(object _apiUrl = null, object _apiKey = null) + : base(_apiUrl, _apiKey) { } + /// + /// Returns information about available datacenters to create your resources. + /// + /// Allows to use pagination. Sets the number of servers that will be shown in each page. + /// Current page to show. + /// Allows to sort the result by priority:sort=name retrieves a list of elements ordered by their names.sort=-creation_date retrieves a list of elements ordered according to their creation date in descending order of priority. + /// Allows to search one string in the response and return the elements that contain it. In order to specify the string use parameter q: q=My server + /// Returns only the parameters requested: fields=id,name,description,hardware.ram + public List Get(int? page = null, int? perPage = null, string sort = null, string query = null, string fields = null) + { + try + { + string requestUrl = "/datacenters?"; + if (page != null) + { + requestUrl += string.Format("&page={0}", page); + } + if (perPage != null) + { + requestUrl += string.Format("&per_page={0}", perPage); + } + if (!string.IsNullOrEmpty(sort)) + { + requestUrl += string.Format("&sort={0}", sort); + } + if (!string.IsNullOrEmpty(query)) + { + requestUrl += string.Format("&q={0}", query); + } + if (!string.IsNullOrEmpty(fields)) + { + requestUrl += string.Format("&fields={0}", fields); + } + var request = new RestRequest(requestUrl, Method.GET); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return JsonConvert.DeserializeObject>(result.Content); + } + catch + { + throw; + } + } + + + /// + /// Returns information about a datacenter + /// + /// Appliance's ID + /// + public DataCenterResponse Show(string id) + { + try + { + var request = new RestRequest("/datacenters/{id}", Method.GET); + request.AddUrlSegment("id", id); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + } +} + diff --git a/OneAndOne.Client/Endpoints/FirewallPolicies/FirewallPolicies.cs b/OneAndOne.Client/Endpoints/FirewallPolicies/FirewallPolicies.cs index 6b37e71..040ba22 100644 --- a/OneAndOne.Client/Endpoints/FirewallPolicies/FirewallPolicies.cs +++ b/OneAndOne.Client/Endpoints/FirewallPolicies/FirewallPolicies.cs @@ -1,4 +1,5 @@ -using OneAndOne.Client.RESTHelpers; +using Newtonsoft.Json; +using OneAndOne.Client.RESTHelpers; using OneAndOne.POCO.Requests.FirewallPolicies; using OneAndOne.POCO.Response; using RestSharp; @@ -51,12 +52,12 @@ public List Get(int? page = null, int? perPage = null, s } var request = new RestRequest(requestUrl, Method.GET); - var result = restclient.Execute>(request); + var result = restclient.Execute(request); if (result.StatusCode != HttpStatusCode.OK) { throw new Exception(result.Content); } - return result.Data; + return JsonConvert.DeserializeObject>(result.Content); } catch { diff --git a/OneAndOne.Client/Endpoints/Logs/Logs.cs b/OneAndOne.Client/Endpoints/Logs/Logs.cs index 017381c..c85347d 100644 --- a/OneAndOne.Client/Endpoints/Logs/Logs.cs +++ b/OneAndOne.Client/Endpoints/Logs/Logs.cs @@ -75,7 +75,7 @@ public List Get(PeriodType period, int? page = null, int? perPage /// /// Returns information about a log /// - /// Unique monitoring policy's identifier. + /// Unique log's identifier. /// public LogsResponse Show(string log_id) { diff --git a/OneAndOne.Client/Endpoints/Roles/Roles.cs b/OneAndOne.Client/Endpoints/Roles/Roles.cs new file mode 100644 index 0000000..275e0f1 --- /dev/null +++ b/OneAndOne.Client/Endpoints/Roles/Roles.cs @@ -0,0 +1,390 @@ +using OneAndOne.Client.RESTHelpers; +using OneAndOne.POCO.Requests.Users; +using OneAndOne.POCO.Response.Roles; +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.Client.Endpoints.Roles +{ + public class Roles : ResourceBase + { + public Roles(object _apiUrl = null, object _apiKey = null) + : base(_apiUrl, _apiKey) { } + #region Basic Operations + /// + /// Returns a list with all roles + /// + /// Allows to use pagination. Sets the number of servers that will be shown in each page. + /// Current page to show. + /// Allows to sort the result by priority:sort=name retrieves a list of elements ordered by their names.sort=-creation_date retrieves a list of elements ordered according to their creation date in descending order of priority. + /// Allows to search one string in the response and return the elements that contain it. In order to specify the string use parameter q: q=My server + /// Returns only the parameters requested: fields=id,name,description,hardware.ram + public List Get(int? page = null, int? perPage = null, string sort = null, string query = null, string fields = null) + { + try + { + string requestUrl = "/roles?"; + if (page != null) + { + requestUrl += string.Format("&page={0}", page); + } + if (perPage != null) + { + requestUrl += string.Format("&per_page={0}", perPage); + } + if (!string.IsNullOrEmpty(sort)) + { + requestUrl += string.Format("&sort={0}", sort); + } + if (!string.IsNullOrEmpty(query)) + { + requestUrl += string.Format("&q={0}", query); + } + if (!string.IsNullOrEmpty(fields)) + { + requestUrl += string.Format("&fields={0}", fields); + } + var request = new RestRequest(requestUrl, Method.GET); + + var result = restclient.Execute>(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + //Creates a new role. + // + public RoleResponse Create(string roleName) + { + try + { + var request = new RestRequest("/roles", Method.POST) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddBody(new + { + name = roleName + }); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Created) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Returns information about a role. + /// + /// Unique role's identifier. + /// + public RoleResponse Show(string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}", Method.GET); + request.AddUrlSegment("role_id", role_id); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Modifies role information. + /// + /// Unique role's identifier. + public RoleResponse Update(string name, string description, UserState state, string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}", Method.PUT) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("role_id", role_id); + request.AddBody(new + { + name = name, + description = description, + state = state + }); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Removes a role. + /// + /// Unique role's identifier. + /// + public RoleResponse Delete(string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}", Method.DELETE) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("role_id", role_id); + request.AddHeader("Content-Type", "application/json"); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Accepted) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + #endregion + + #region role permissions + /// + /// Lists role's permissions. + /// + /// Unique role's identifier. + /// + public Permissions GetPermissions(string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}/permissions", Method.GET); + request.AddUrlSegment("role_id", role_id); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Adds permissions to the role. + /// + /// Unique role's identifier. + public RoleResponse UpdatePermissions(Permissions permissions, string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}/permissions", Method.PUT) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("role_id", role_id); + request.AddBody(permissions); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + #endregion + + #region roles users + + /// + //Returns users assigned to role + /// Unique role's identifier. + // + public List GetRoleUsers(string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}/users", Method.GET); + request.AddUrlSegment("role_id", role_id); + + var result = restclient.Execute>(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + //Add users to role + /// Unique role's identifier. + // + public RoleResponse CreateRoleUsers(List users, string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}/users", Method.POST) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("role_id", role_id); + request.AddBody(new { users = users }); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Created) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Returns information about a user. + /// + /// Unique role's identifier. + /// Unique users's identifier. + /// + public OneAndOne.POCO.Response.Roles.User ShowRoleUser(string role_id, string user_id) + { + try + { + var request = new RestRequest("/roles/{role_id}/users/{user_id}", Method.GET); + request.AddUrlSegment("role_id", role_id); + request.AddUrlSegment("user_id", user_id); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Removes user from role. + /// + /// Unique role's identifier. + /// Unique users's identifier. + /// + public RoleResponse DeleteRoleUser(string role_id, string user_id) + { + try + { + var request = new RestRequest("/roles/{role_id}/users/{user_id}", Method.DELETE) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("role_id", role_id); + request.AddUrlSegment("user_id", user_id); + + request.AddHeader("Content-Type", "application/json"); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Accepted) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + //Clones a role + /// Unique role's identifier. + // + public RoleResponse CreateRoleClone(string name, string role_id) + { + try + { + var request = new RestRequest("/roles/{role_id}/clone", Method.POST) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("role_id", role_id); + request.AddBody(new { name = name }); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Created) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + #endregion + } +} + diff --git a/OneAndOne.Client/Endpoints/ServerAppliances/ServerAppliances.cs b/OneAndOne.Client/Endpoints/ServerAppliances/ServerAppliances.cs index 6c1eed4..c56e995 100644 --- a/OneAndOne.Client/Endpoints/ServerAppliances/ServerAppliances.cs +++ b/OneAndOne.Client/Endpoints/ServerAppliances/ServerAppliances.cs @@ -49,12 +49,12 @@ public List Get(int? page = null, int? perPage = null, } var request = new RestRequest(requestUrl, Method.GET); - var result = restclient.Execute>(request); + var result = restclient.Execute(request); if (result.StatusCode != HttpStatusCode.OK) { throw new Exception(result.Content); } - return result.Data; + return JsonConvert.DeserializeObject>(result.Content); } catch { diff --git a/OneAndOne.Client/Endpoints/Servers/Servers.cs b/OneAndOne.Client/Endpoints/Servers/Servers.cs index 259ad6f..f3b2247 100644 --- a/OneAndOne.Client/Endpoints/Servers/Servers.cs +++ b/OneAndOne.Client/Endpoints/Servers/Servers.cs @@ -96,6 +96,34 @@ public CreateServerResponse Create(CreateServerRequest server) } + + /// + /// Adds a new server. + /// + public CreateServerResponse CreateServerFromFlavor(CreateServerWithFlavorRequest server) + { + try + { + var request = new RestRequest("/servers", Method.POST) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddBody(server); + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Accepted) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + + } + /// /// Adds a new server. /// @@ -160,11 +188,11 @@ public DeleteServerResponse Delete(string serverId, bool keepsIps) { try { - var request = new RestRequest("/servers/{serverId}?keep_ips={keep_ips}", Method.DELETE) - { - RequestFormat = DataFormat.Json, - JsonSerializer = new CustomSerializer() - }; + var request = new RestRequest("/servers/{serverId}?keep_ips={keep_ips}", Method.DELETE) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; request.AddUrlSegment("serverId", serverId); request.AddUrlSegment("keep_ips", keepsIps.ToString().ToLower()); request.AddHeader("Content-Type", "application/json"); diff --git a/OneAndOne.Client/Endpoints/SharedStorages/SharedStorages.cs b/OneAndOne.Client/Endpoints/SharedStorages/SharedStorages.cs index 9ac81b0..c31087b 100644 --- a/OneAndOne.Client/Endpoints/SharedStorages/SharedStorages.cs +++ b/OneAndOne.Client/Endpoints/SharedStorages/SharedStorages.cs @@ -182,13 +182,13 @@ public SharedStoragesResponse Delete(string shared_storage_id) /// /// Returns the credentials for accessing the shared storages. /// - public List ShowSharedStorageAccess() + public List ShowSharedStorageAccess() { try { var request = new RestRequest("/shared_storages/access", Method.GET); - var result = restclient.Execute>(request); + var result = restclient.Execute>(request); if (result.StatusCode != HttpStatusCode.OK) { throw new Exception(result.Content); @@ -205,7 +205,7 @@ public List ShowSharedStorageAccess() /// Changes the password for accessing the shared storages. /// /// password - public List UpdateSharedStorageAccess(string password) + public List UpdateSharedStorageAccess(string password) { try { @@ -216,7 +216,7 @@ public List UpdateSharedStorageAccess(string passwor }; request.AddBody(new { password }); - var result = restclient.Execute>(request); + var result = restclient.Execute>(request); if (result.StatusCode != HttpStatusCode.Accepted) { throw new Exception(result.Content); diff --git a/OneAndOne.Client/Endpoints/Vpn/Vpn.cs b/OneAndOne.Client/Endpoints/Vpn/Vpn.cs new file mode 100644 index 0000000..d402080 --- /dev/null +++ b/OneAndOne.Client/Endpoints/Vpn/Vpn.cs @@ -0,0 +1,208 @@ +using OneAndOne.Client.RESTHelpers; +using OneAndOne.POCO.Requests.Vpn; +using OneAndOne.POCO.Response.Vpn; +using RestSharp; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Mail; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.Client.Endpoints.Vpn +{ + public class Vpn : ResourceBase + { + public Vpn(object _apiUrl = null, object _apiKey = null) + : base(_apiUrl, _apiKey) { } + #region Basic Operations + /// + /// Returns a list of your VPN. + /// + /// Allows to use pagination. Sets the number of servers that will be shown in each page. + /// Current page to show. + /// Allows to sort the result by priority:sort=name retrieves a list of elements ordered by their names.sort=-creation_date retrieves a list of elements ordered according to their creation date in descending order of priority. + /// Allows to search one string in the response and return the elements that contain it. In order to specify the string use parameter q: q=My server + /// Returns only the parameters requested: fields=id,name,description,hardware.ram + public List Get(int? page = null, int? perPage = null, string sort = null, string query = null, string fields = null) + { + try + { + string requestUrl = "/vpns?"; + if (page != null) + { + requestUrl += string.Format("&page={0}", page); + } + if (perPage != null) + { + requestUrl += string.Format("&per_page={0}", perPage); + } + if (!string.IsNullOrEmpty(sort)) + { + requestUrl += string.Format("&sort={0}", sort); + } + if (!string.IsNullOrEmpty(query)) + { + requestUrl += string.Format("&q={0}", query); + } + if (!string.IsNullOrEmpty(fields)) + { + requestUrl += string.Format("&fields={0}", fields); + } + var request = new RestRequest(requestUrl, Method.GET); + + var result = restclient.Execute>(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + //Adds a new VPN. + // + public VpnResponse Create(CreateVpnRequest vpn) + { + try + { + var request = new RestRequest("/vpns", Method.POST) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddBody(vpn); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Accepted) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Download your VPN configuration file. + /// + /// Unique server's identifier. + /// + public Config ShowConfiguration(string vpnId) + { + try + { + var request = new RestRequest("/vpns/{vpn_id}/configuration_file", Method.GET); + request.AddUrlSegment("vpn_id", vpnId); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + + return result.Data; + } + catch + { + throw; + } + } + + + /// + /// Returns information about one vpn. + /// + /// Unique server's identifier. + /// + public VpnResponse Show(string vpnId) + { + try + { + var request = new RestRequest("/vpns/{vpn_id}", Method.GET); + request.AddUrlSegment("vpn_id", vpnId); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + + /// + /// Modify VPN configuration file. + /// + public VpnResponse Update(UpdateVpnRequest vpn, string vpnId) + { + try + { + var request = new RestRequest("/vpns/{vpn_id}", Method.PUT) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("vpn_id", vpnId); + request.AddBody(vpn); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.OK) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + + /// + /// Removes a VPN. + /// + /// required (string ), Unique vpn's identifier. + /// + public VpnResponse Delete(string vpn_id) + { + try + { + var request = new RestRequest("/vpns/{vpn_id}", Method.DELETE) + { + RequestFormat = DataFormat.Json, + JsonSerializer = new CustomSerializer() + }; + request.AddUrlSegment("vpn_id", vpn_id); + request.AddHeader("Content-Type", "application/json"); + + var result = restclient.Execute(request); + if (result.StatusCode != HttpStatusCode.Accepted) + { + throw new Exception(result.Content); + } + return result.Data; + } + catch + { + throw; + } + } + #endregion + } +} diff --git a/OneAndOne.Client/OneAndOne.Client.csproj b/OneAndOne.Client/OneAndOne.Client.csproj index 0d67c7d..73bb629 100644 --- a/OneAndOne.Client/OneAndOne.Client.csproj +++ b/OneAndOne.Client/OneAndOne.Client.csproj @@ -1,106 +1,111 @@ - - - - - Debug - AnyCPU - {52B9C25D-DDE8-4178-B1F2-C0F1CEA0B8B3} - Library - Properties - OneAndOne.Client - OneAndOne.Client - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll - True - - - - - - - - - - - - - - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {4463871b-92d2-4070-9dc8-138aff00f2b1} - OneAndOne.POCO - - - - + + + + + Debug + AnyCPU + {52B9C25D-DDE8-4178-B1F2-C0F1CEA0B8B3} + Library + Properties + OneAndOne.Client + OneAndOne.Client + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll + True + + + + + + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {4463871b-92d2-4070-9dc8-138aff00f2b1} + OneAndOne.POCO + + + + + --> \ No newline at end of file diff --git a/OneAndOne.Client/OneAndOneClient.cs b/OneAndOne.Client/OneAndOneClient.cs index b8aa2ef..b23898c 100644 --- a/OneAndOne.Client/OneAndOneClient.cs +++ b/OneAndOne.Client/OneAndOneClient.cs @@ -1,4 +1,6 @@ using OneAndOne.Client.Endpoints; +using OneAndOne.Client.Endpoints.Common; +using OneAndOne.Client.Endpoints.DataCenter; using OneAndOne.Client.Endpoints.DVDs; using OneAndOne.Client.Endpoints.FirewallPolicies; using OneAndOne.Client.Endpoints.Images; @@ -8,11 +10,14 @@ using OneAndOne.Client.Endpoints.MonitoringPolicies; using OneAndOne.Client.Endpoints.PrivateNetworks; using OneAndOne.Client.Endpoints.PublicIPs; +using OneAndOne.Client.Endpoints.Roles; using OneAndOne.Client.Endpoints.ServerAppliances; using OneAndOne.Client.Endpoints.Servers; using OneAndOne.Client.Endpoints.SharedStorages; using OneAndOne.Client.Endpoints.Usages; using OneAndOne.Client.Endpoints.Users; +using OneAndOne.Client.Endpoints.Vpn; +using OneAndOne.Client.RESTHelpers; using System; using System.Collections.Generic; using System.Linq; @@ -25,32 +30,34 @@ namespace OneAndOne.Client public class OneAndOneClient { - object[] args = new object[2]; - string AssemblyName; - private OneAndOneClient(string apiUrl = null, string apiKey = null) + static String Endpoint = "https://cloudpanel-api.1and1.com/v1"; + static Configuration configuration; + private OneAndOneClient(Configuration config) { - args[0] = apiUrl; - args[1] = apiKey; - AssemblyName = typeof(OneAndOneClient).Assembly.GetName().Name; + configuration = config; + if (config.ApiUrl == null) + { + config.ApiUrl = Endpoint; + } } /// /// Singleton instance. /// - public static OneAndOneClient Instance(string apiUrl = null, string apiKey = null) + public static OneAndOneClient Instance(Configuration config) { if (instance == null) { lock (syncRoot) { if (instance == null) - instance = new OneAndOneClient(apiUrl, apiKey); + instance = new OneAndOneClient(config); } } return instance; } - + /// /// singleton instance. @@ -69,7 +76,7 @@ public Servers Servers { get { - return new Servers(args[0], args[1]); + return new Servers(configuration.ApiUrl, configuration.ApiKey); } } @@ -80,7 +87,7 @@ public ServersHardware ServersHardware { get { - return new ServersHardware(args[0], args[1]); + return new ServersHardware(configuration.ApiUrl, configuration.ApiKey); } } @@ -91,7 +98,7 @@ public ServerHdds ServerHdds { get { - return new ServerHdds(args[0], args[1]); + return new ServerHdds(configuration.ApiUrl, configuration.ApiKey); } } @@ -102,7 +109,7 @@ public ServerImage ServerImage { get { - return new ServerImage(args[0], args[1]); + return new ServerImage(configuration.ApiUrl, configuration.ApiKey); } } @@ -113,7 +120,7 @@ public ServerIps ServerIps { get { - return new ServerIps(args[0], args[1]); + return new ServerIps(configuration.ApiUrl, configuration.ApiKey); } } @@ -124,7 +131,7 @@ public LoadBalancer LoadBalancer { get { - return new LoadBalancer(args[0], args[1]); + return new LoadBalancer(configuration.ApiUrl, configuration.ApiKey); } } @@ -135,7 +142,7 @@ public DVDs DVDs { get { - return new DVDs(args[0], args[1]); + return new DVDs(configuration.ApiUrl, configuration.ApiKey); } } @@ -146,7 +153,7 @@ public PrivateNetworks PrivateNetworks { get { - return new PrivateNetworks(args[0], args[1]); + return new PrivateNetworks(configuration.ApiUrl, configuration.ApiKey); } } @@ -157,7 +164,7 @@ public Images Images { get { - return new Images(args[0], args[1]); + return new Images(configuration.ApiUrl, configuration.ApiKey); } } @@ -168,7 +175,7 @@ public SharedStorages SharedStorages { get { - return new SharedStorages(args[0], args[1]); + return new SharedStorages(configuration.ApiUrl, configuration.ApiKey); } } @@ -179,7 +186,7 @@ public FirewallPolicies FirewallPolicies { get { - return new FirewallPolicies(args[0], args[1]); + return new FirewallPolicies(configuration.ApiUrl, configuration.ApiKey); } } @@ -190,7 +197,7 @@ public PublicIPs PublicIPs { get { - return new PublicIPs(args[0], args[1]); + return new PublicIPs(configuration.ApiUrl, configuration.ApiKey); } } @@ -201,7 +208,7 @@ public MonitoringCenter MonitoringCenter { get { - return new MonitoringCenter(args[0], args[1]); + return new MonitoringCenter(configuration.ApiUrl, configuration.ApiKey); } } @@ -212,7 +219,7 @@ public MonitoringPolicies MonitoringPolicies { get { - return new MonitoringPolicies(args[0], args[1]); + return new MonitoringPolicies(configuration.ApiUrl, configuration.ApiKey); } } @@ -223,7 +230,7 @@ public MonitoringPoliciesPorts MonitoringPoliciesPorts { get { - return new MonitoringPoliciesPorts(args[0], args[1]); + return new MonitoringPoliciesPorts(configuration.ApiUrl, configuration.ApiKey); } } @@ -234,7 +241,7 @@ public MonitoringPoliciesProcesses MonitoringPoliciesProcesses { get { - return new MonitoringPoliciesProcesses(args[0], args[1]); + return new MonitoringPoliciesProcesses(configuration.ApiUrl, configuration.ApiKey); } } @@ -245,7 +252,7 @@ public MonitoringPoliciesServers MonitoringPoliciesServers { get { - return new MonitoringPoliciesServers(args[0], args[1]); + return new MonitoringPoliciesServers(configuration.ApiUrl, configuration.ApiKey); } } @@ -256,7 +263,7 @@ public Logs Logs { get { - return new Logs(args[0], args[1]); + return new Logs(configuration.ApiUrl, configuration.ApiKey); } } @@ -267,7 +274,7 @@ public Users Users { get { - return new Users(args[0], args[1]); + return new Users(configuration.ApiUrl, configuration.ApiKey); } } @@ -278,7 +285,7 @@ public UserAPI UserAPI { get { - return new UserAPI(args[0], args[1]); + return new UserAPI(configuration.ApiUrl, configuration.ApiKey); } } @@ -289,7 +296,7 @@ public Usages Usages { get { - return new Usages(args[0], args[1]); + return new Usages(configuration.ApiUrl, configuration.ApiKey); } } @@ -300,7 +307,51 @@ public ServerAppliances ServerAppliances { get { - return new ServerAppliances(args[0], args[1]); + return new ServerAppliances(configuration.ApiUrl, configuration.ApiKey); + } + } + + /// + /// DataCenters client + /// + public DataCenters DataCenters + { + get + { + return new DataCenters(configuration.ApiUrl, configuration.ApiKey); + } + } + + /// + /// Vpn client + /// + public Vpn Vpn + { + get + { + return new Vpn(configuration.ApiUrl, configuration.ApiKey); + } + } + + /// + /// Role client + /// + public Roles Roles + { + get + { + return new Roles(configuration.ApiUrl, configuration.ApiKey); + } + } + + /// + /// Common operations like ping and pricing client + /// + public Common Common + { + get + { + return new Common(configuration.ApiUrl, configuration.ApiKey); } } } diff --git a/OneAndOne.Client/Properties/AssemblyInfo.cs b/OneAndOne.Client/Properties/AssemblyInfo.cs index ef1b0d4..39173c8 100644 --- a/OneAndOne.Client/Properties/AssemblyInfo.cs +++ b/OneAndOne.Client/Properties/AssemblyInfo.cs @@ -5,6 +5,7 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. + [assembly: AssemblyTitle("OneAndOne.Client")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -32,5 +33,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/OneAndOne.Client/RESTHelpers/Configuration.cs b/OneAndOne.Client/RESTHelpers/Configuration.cs new file mode 100644 index 0000000..f6080cb --- /dev/null +++ b/OneAndOne.Client/RESTHelpers/Configuration.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.Client.RESTHelpers +{ + /// + /// Represents a set of configuration settings + /// + public class Configuration + { + /// + /// Initializes a new instance of the Configuration class with different settings + /// + /// accessToken + /// /// ApiUrl + public Configuration(string apiKey = null, string apiUrl = null) + { + ApiKey = apiKey; + ApiUrl = apiUrl; + } + + /// + /// Gets or sets the default Configuration. + /// + /// Configuration. + public static Configuration Default = new Configuration(); + + /// + /// Gets or sets the access token for OAuth2 authentication. + /// + /// The access token. + public String ApiKey { get; set; } + + + /// + /// Gets or sets the api URL + /// + /// The ApiUrl + public String ApiUrl { get; set; } + + } +} \ No newline at end of file diff --git a/OneAndOne.Client/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/OneAndOne.Client/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 765e94a..971e198 100644 Binary files a/OneAndOne.Client/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/OneAndOne.Client/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/OneAndOne.Client/packages.config b/OneAndOne.Client/packages.config index e09901c..210d60b 100644 --- a/OneAndOne.Client/packages.config +++ b/OneAndOne.Client/packages.config @@ -1,5 +1,6 @@ - - - - + + + + + \ No newline at end of file diff --git a/OneAndOne.Example/OneAndOne.Example.csproj b/OneAndOne.Example/OneAndOne.Example.csproj index 76d589a..34a219a 100644 --- a/OneAndOne.Example/OneAndOne.Example.csproj +++ b/OneAndOne.Example/OneAndOne.Example.csproj @@ -1,68 +1,69 @@ - - - - - Debug - AnyCPU - {9FB41C74-06B0-4B98-BFB3-42DE222D559B} - Exe - Properties - OneAndOne.Example - OneAndOne.Example - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - {52b9c25d-dde8-4178-b1f2-c0f1cea0b8b3} - OneAndOne.Client - - - {4463871b-92d2-4070-9dc8-138aff00f2b1} - OneAndOne.POCO - - - + + + + + Debug + AnyCPU + {9FB41C74-06B0-4B98-BFB3-42DE222D559B} + Exe + Properties + OneAndOne.Example + OneAndOne.Example + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {52b9c25d-dde8-4178-b1f2-c0f1cea0b8b3} + OneAndOne.Client + + + {4463871b-92d2-4070-9dc8-138aff00f2b1} + OneAndOne.POCO + + + + --> \ No newline at end of file diff --git a/OneAndOne.Example/Program.cs b/OneAndOne.Example/Program.cs index 94e8528..869f575 100644 --- a/OneAndOne.Example/Program.cs +++ b/OneAndOne.Example/Program.cs @@ -7,6 +7,7 @@ using OneAndOne.POCO.Response.Servers; using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Text; using System.Threading; @@ -16,7 +17,7 @@ namespace OneAndOne.Example { public class Program { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(new Client.RESTHelpers.Configuration { ApiKey= ConfigurationManager.AppSettings["APIToken"] }); static void Main(string[] args) { GetServers(); diff --git a/OneAndOne.POCO/APISharedEnums.cs b/OneAndOne.POCO/APISharedEnums.cs index 47b6535..ea9ca1a 100644 --- a/OneAndOne.POCO/APISharedEnums.cs +++ b/OneAndOne.POCO/APISharedEnums.cs @@ -40,7 +40,7 @@ public enum OSType public enum OSFamliyType { - Windows, Linux, Others + Windows, Linux, Others,NULL } public enum ImageType diff --git a/OneAndOne.POCO/OneAndOne.POCO.csproj b/OneAndOne.POCO/OneAndOne.POCO.csproj index 34dae11..e12d5e5 100644 --- a/OneAndOne.POCO/OneAndOne.POCO.csproj +++ b/OneAndOne.POCO/OneAndOne.POCO.csproj @@ -1,129 +1,136 @@ - - - - - Debug - AnyCPU - {4463871B-92D2-4070-9DC8-138AFF00F2B1} - Library - Properties - OneAndOne.POCO - OneAndOne.POCO - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + AnyCPU + {4463871B-92D2-4070-9DC8-138AFF00F2B1} + Library + Properties + OneAndOne.POCO + OneAndOne.POCO + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> \ No newline at end of file diff --git a/OneAndOne.POCO/Requests/Images/CreateImageRequest.cs b/OneAndOne.POCO/Requests/Images/CreateImageRequest.cs index 41395b0..3bbb07a 100644 --- a/OneAndOne.POCO/Requests/Images/CreateImageRequest.cs +++ b/OneAndOne.POCO/Requests/Images/CreateImageRequest.cs @@ -67,7 +67,63 @@ public int NumIimages { get { return num_images; } set { num_images = value; } - } + } + + /// + ///ID of the datacenter where the shared storage will be created + /// + private string datacetner_id; + + public string DatacetnerId + { + get { return datacetner_id; } + + set { datacetner_id = value; } + } + + /// + ///Source of the new image: server (from an existing server), image (from an imported image) or iso (from an imported iso) + /// + private string source; + + [JsonConverter(typeof(StringEnumConverter))] + public ImageSource Source + { + get { return (ImageSource)Enum.Parse(typeof(ImageSource), source); } + set { source = ((ImageSource)value).ToString(); } + } + + /// + ///URL where the image can be downloaded. It is required when the source is image or iso. + /// + private String url; + public string Url + { + get { return url; } + set { url = value; } + } + + /// + ///ID of the Operative System you want to import. You can get a list of the available ones with the method /iamges/os. + /// + private String os_id; + + public string OsId + { + get { return os_id; } + set { os_id = value; } + } + + /// + ///Type of the ISO you want to import: os (Operative System) or app (Application). It is required when the source is iso. + /// + private string type; + [JsonConverter(typeof(StringEnumConverter))] + public ImageType Type + { + get { return (ImageType)Enum.Parse(typeof(ImageType), type); } + set { type = ((ImageType)value).ToString(); } + } } public enum ImageFrequency @@ -77,4 +133,19 @@ public enum ImageFrequency WEEKLY, Null } + + public enum ImageType + { + os, + app, + Null + } + + public enum ImageSource + { + server, + image, + iso, + Null + } } diff --git a/OneAndOne.POCO/Requests/LoadBalancer/CreateLoadBalancerRequest.cs b/OneAndOne.POCO/Requests/LoadBalancer/CreateLoadBalancerRequest.cs index 2f437e4..94c4168 100644 --- a/OneAndOne.POCO/Requests/LoadBalancer/CreateLoadBalancerRequest.cs +++ b/OneAndOne.POCO/Requests/LoadBalancer/CreateLoadBalancerRequest.cs @@ -25,7 +25,23 @@ public string Description { get { return description; } set { description = value; } + } + + /// + //datacenter_id + // + private string datacenter_id; + [JsonProperty(PropertyName = "datacenter_id")] + + public string DatacenterId + { + get + { return datacenter_id; } + + set + { datacenter_id = value; } } + /// /// Required: Type of the health check. At the moment, HTTP is not allowed. /// diff --git a/OneAndOne.POCO/Requests/PrivateNetworks/CreatePrivateNetworkRequest.cs b/OneAndOne.POCO/Requests/PrivateNetworks/CreatePrivateNetworkRequest.cs index 0a5fb7a..39f68ac 100644 --- a/OneAndOne.POCO/Requests/PrivateNetworks/CreatePrivateNetworkRequest.cs +++ b/OneAndOne.POCO/Requests/PrivateNetworks/CreatePrivateNetworkRequest.cs @@ -49,5 +49,20 @@ public string SubnetMask get { return subnet_mask; } set { subnet_mask = value; } } + + /// + //datacenter_id + // + private string datacenter_id; + [JsonProperty(PropertyName = "datacenter_id")] + + public string DatacenterId + { + get + { return datacenter_id; } + + set + { datacenter_id = value; } + } } } diff --git a/OneAndOne.POCO/Requests/PublicIPs/CreatePublicIPRequest.cs b/OneAndOne.POCO/Requests/PublicIPs/CreatePublicIPRequest.cs index beaae39..c1f5f0c 100644 --- a/OneAndOne.POCO/Requests/PublicIPs/CreatePublicIPRequest.cs +++ b/OneAndOne.POCO/Requests/PublicIPs/CreatePublicIPRequest.cs @@ -28,6 +28,21 @@ public IPType Type { type = ((IPType)value).ToString(); } + } + + /// + //datacenter_id + // + private string datacenter_id; + [JsonProperty(PropertyName = "datacenter_id")] + + public string DatacenterId + { + get + { return datacenter_id; } + + set + { datacenter_id = value; } } } } diff --git a/OneAndOne.POCO/Requests/Servers/CreateServerRequest.cs b/OneAndOne.POCO/Requests/Servers/CreateServerRequest.cs index a15dad8..5e54247 100644 --- a/OneAndOne.POCO/Requests/Servers/CreateServerRequest.cs +++ b/OneAndOne.POCO/Requests/Servers/CreateServerRequest.cs @@ -29,7 +29,7 @@ public string Name set { name = value; } } - //public string name { get; set; } + //public string name; /// /// Required: description of your servers. /// @@ -149,8 +149,5 @@ public string MonitoringPolicyId get { return monitoring_policy_id; } set { monitoring_policy_id = value; } } - - - } } diff --git a/OneAndOne.POCO/Requests/Servers/CreateServerWithFlavorRequest.cs b/OneAndOne.POCO/Requests/Servers/CreateServerWithFlavorRequest.cs new file mode 100644 index 0000000..d8c086d --- /dev/null +++ b/OneAndOne.POCO/Requests/Servers/CreateServerWithFlavorRequest.cs @@ -0,0 +1,162 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.POCO.Requests.Servers +{ + public class CreateServerWithFlavorRequest + { + + /// + /// Required: Name of the server. + /// + /// + + private string name; + [JsonProperty(PropertyName = "name")] + public string Name + { + get { return name; } + set { name = value; } + } + + //public string name; + /// + /// Required: description of your servers. + /// + /// + private string description; + [JsonProperty(PropertyName = "description")] + public string Description + { + get { return description; } + set { description = value; } + } + + /// + /// Required: Hardware features of the server. Choose your resources using fixed_instance_size_id + /// + /// + private HardwareFlavorRequest hardware; + [JsonProperty(PropertyName = "hardware")] + public HardwareFlavorRequest Hardware + { + get { return hardware; } + set { hardware = value; } + } + + /// + /// Required: Image will be installed on server + /// + /// + private string appliance_id; + [JsonProperty(PropertyName = "appliance_id")] + public string ApplianceId + { + get { return appliance_id; } + set { appliance_id = value; } + } + + /// + /// Password of the server. Password must contain more than 8 characters using uppercase letters, numbers and other special symbols. minLength: 8,maxLength: 64. + /// + /// + private string password; + [JsonProperty(PropertyName = "password")] + public string Password + { + get { return password; } + set { password = value; } + } + + /// + ///NOT REQUIRED: ID of the region where the server will be created + /// + /// + private string region_id; + [JsonProperty(PropertyName = "region_id")] + public string RegionId + { + get { return region_id; } + set { region_id = value; } + } + + /// + /// Power on server after creation + /// + /// + private bool power_on; + [JsonProperty(PropertyName = "power_on")] + public bool PowerOn + { + get { return power_on; } + set { power_on = value; } + } + + /// + /// Firewall policy's ID + /// + /// + private string firewall_policy_id; + [JsonProperty(PropertyName = "firewall_policy_id")] + public string FirewallPolicyId + { + get { return firewall_policy_id; } + set { firewall_policy_id = value; } + } + + /// + /// IP's ID + /// + /// + private string ip_id; + [JsonProperty(PropertyName = "ip_id")] + public string IpId + { + get { return ip_id; } + set { ip_id = value; } + } + + /// + /// Load balancer's ID + /// + /// + private string loadr_balancer_id; + [JsonProperty(PropertyName = "loadr_balancer_id")] + public string LoadrBalancerId + { + get { return loadr_balancer_id; } + set { loadr_balancer_id = value; } + } + + /// + /// Monitoring policy's ID + /// + /// + private string monitoring_policy_id; + [JsonProperty(PropertyName = "monitoring_policy_id")] + public string MonitoringPolicyId + { + get { return monitoring_policy_id; } + set { monitoring_policy_id = value; } + } + } + + public class HardwareFlavorRequest + { + /// + /// Required: Size of the ID desired for the server + /// + /// + private string fixed_instance_size_id; + [JsonProperty(PropertyName = "fixed_instance_size_id")] + public string FixedInstanceSizeId + { + get { return fixed_instance_size_id; } + set { fixed_instance_size_id = value; } + } + } +} diff --git a/OneAndOne.POCO/Requests/Servers/UpdateHardwareRequest.cs b/OneAndOne.POCO/Requests/Servers/UpdateHardwareRequest.cs index 78b463d..12617f8 100644 --- a/OneAndOne.POCO/Requests/Servers/UpdateHardwareRequest.cs +++ b/OneAndOne.POCO/Requests/Servers/UpdateHardwareRequest.cs @@ -10,38 +10,38 @@ namespace OneAndOne.POCO.Requests.Servers public class UpdateHardwareRequest { - private int vcore; + private int? vcore; [JsonProperty(PropertyName = "vcore")] /// /// Required: Total amount of processors minimum: "1",maximum: "16",multipleOf: "1",. /// /// - public int Vcore + public int? Vcore { get { return vcore; } set { vcore = value; } } - private int cores_per_processor; + private int? cores_per_processor; [JsonProperty(PropertyName = "cores_per_processor")] /// /// Required: Number of cores per processor minimum: "1",maximum: "16",multipleOf: "1", /// /// - public int CoresPerProcessor + public int? CoresPerProcessor { get { return cores_per_processor; } set { cores_per_processor = value; } } - private int ram; + private int? ram; [JsonProperty(PropertyName = "ram")] /// /// Required: RAM memory size minimum: "1",maximum: "128",multipleOf: "0.5",. /// - public int Ram + public int? Ram { get { return ram; } set { ram = value; } diff --git a/OneAndOne.POCO/Requests/Servers/UpdateServerImageRequest.cs b/OneAndOne.POCO/Requests/Servers/UpdateServerImageRequest.cs index b39f2fd..7070f5e 100644 --- a/OneAndOne.POCO/Requests/Servers/UpdateServerImageRequest.cs +++ b/OneAndOne.POCO/Requests/Servers/UpdateServerImageRequest.cs @@ -22,25 +22,7 @@ public string Password { get { return password; } set { password = value; } - } - private UpdateFirewallPolicy firewall_policy; - [JsonProperty(PropertyName = "firewall_policy")] - public UpdateFirewallPolicy Firewall_policy - { - get { return firewall_policy; } - set { firewall_policy = value; } - } - } - - public class UpdateFirewallPolicy - { - private string id; - [JsonProperty(PropertyName = "id")] - public string Id - { - get { return id; } - set { id = value; } - } - + } + } } diff --git a/OneAndOne.POCO/Requests/Servers/UpdateServerRequest.cs b/OneAndOne.POCO/Requests/Servers/UpdateServerRequest.cs index e5b6419..f62ab07 100644 --- a/OneAndOne.POCO/Requests/Servers/UpdateServerRequest.cs +++ b/OneAndOne.POCO/Requests/Servers/UpdateServerRequest.cs @@ -21,7 +21,7 @@ public string Name set { name = value; } } - //public string name { get; set; } + //public string name; /// /// Required: description of your servers. /// diff --git a/OneAndOne.POCO/Requests/SharedStorages/CreateSharedStorage.cs b/OneAndOne.POCO/Requests/SharedStorages/CreateSharedStorage.cs index 3dde7a5..e1ecf13 100644 --- a/OneAndOne.POCO/Requests/SharedStorages/CreateSharedStorage.cs +++ b/OneAndOne.POCO/Requests/SharedStorages/CreateSharedStorage.cs @@ -39,5 +39,24 @@ public int Size get { return size; } set { size = value; } } + + /// + //datacenter_id of the shared storage + // + private string datacenter_id; + [JsonProperty(PropertyName = "datacenter_id")] + + public string DatacenterId + { + get + { + return datacenter_id; + } + + set + { + datacenter_id = value; + } + } } } diff --git a/OneAndOne.POCO/Requests/Vpn/CreateVpnRequest.cs b/OneAndOne.POCO/Requests/Vpn/CreateVpnRequest.cs new file mode 100644 index 0000000..4ffcd84 --- /dev/null +++ b/OneAndOne.POCO/Requests/Vpn/CreateVpnRequest.cs @@ -0,0 +1,39 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.POCO.Requests.Vpn +{ + public class CreateVpnRequest + { + private string name; + [JsonProperty(PropertyName = "name")] + public string Name + { + get { return name; } + + set { name = value; } + } + + private string description; + [JsonProperty(PropertyName = "description")] + public string Description + { + get { return description; } + + set { description = value; } + } + + private string datacenter_id; + [JsonProperty(PropertyName = "datacenter_id")] + public string Datacenterid + { + get { return datacenter_id; } + + set { datacenter_id = value; } + } + } +} diff --git a/OneAndOne.POCO/Requests/Vpn/UpdateVpnRequest.cs b/OneAndOne.POCO/Requests/Vpn/UpdateVpnRequest.cs new file mode 100644 index 0000000..85c292a --- /dev/null +++ b/OneAndOne.POCO/Requests/Vpn/UpdateVpnRequest.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.POCO.Requests.Vpn +{ + public class UpdateVpnRequest + { + private string name; + [JsonProperty(PropertyName = "name")] + + public string Name + { + get { return name; } + + set { name = value; } + } + + private string description; + [JsonProperty(PropertyName = "description")] + + public string Description + { + get { return description; } + + set { description = value; } + } + + + } +} diff --git a/OneAndOne.POCO/Response/Common/PricingResponse.cs b/OneAndOne.POCO/Response/Common/PricingResponse.cs new file mode 100644 index 0000000..adbd0fe --- /dev/null +++ b/OneAndOne.POCO/Response/Common/PricingResponse.cs @@ -0,0 +1,192 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.POCO.Response.Common +{ + public class Hdd + { + + [JsonProperty("size")] + public int Size { get; set; } + } + + public class Hardware + { + + [JsonProperty("vcore")] + public int Vcore { get; set; } + + [JsonProperty("ram")] + public int Ram { get; set; } + + [JsonProperty("hdds")] + public List Hdds { get; set; } + } + + public class FixedServer + { + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("price_net")] + public double PriceNet { get; set; } + + [JsonProperty("price_gross")] + public double PriceGross { get; set; } + + [JsonProperty("unit")] + public string Unit { get; set; } + + [JsonProperty("hardware")] + public Hardware Hardware { get; set; } + } + + public class FlexibleSever + { + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("price_net")] + public double PriceNet { get; set; } + + [JsonProperty("price_gross")] + public double PriceGross { get; set; } + + [JsonProperty("unit")] + public string Unit { get; set; } + } + + public class Server + { + + [JsonProperty("fixed_servers")] + public List FixedServers { get; set; } + + [JsonProperty("flexible_sever")] + public List FlexibleSever { get; set; } + } + + public class PublicIp + { + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("price_net")] + public int PriceNet { get; set; } + + [JsonProperty("price_gross")] + public double PriceGross { get; set; } + + [JsonProperty("unit")] + public string Unit { get; set; } + } + + public class Image + { + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("price_net")] + public double PriceNet { get; set; } + + [JsonProperty("price_gross")] + public double PriceGross { get; set; } + + [JsonProperty("unit")] + public string Unit { get; set; } + } + + public class SharedStorage + { + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("price_net")] + public double PriceNet { get; set; } + + [JsonProperty("price_gross")] + public double PriceGross { get; set; } + + [JsonProperty("unit")] + public string Unit { get; set; } + } + + public class SoftwareLicens + { + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("price_net")] + public double PriceNet { get; set; } + + [JsonProperty("price_gross")] + public double PriceGross { get; set; } + + [JsonProperty("unit")] + public string Unit { get; set; } + + [JsonProperty("pice_gross")] + public double? PiceGross { get; set; } + } + + public class Backups + { + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("price_net")] + public double PriceNet { get; set; } + + [JsonProperty("price_gross")] + public double PriceGross { get; set; } + + [JsonProperty("unit")] + public string Unit { get; set; } + } + + public class PricingPlans + { + + [JsonProperty("server")] + public Server Server { get; set; } + + [JsonProperty("public_ip")] + public List PublicIp { get; set; } + + [JsonProperty("image")] + public Image Image { get; set; } + + [JsonProperty("shared_storage")] + public SharedStorage SharedStorage { get; set; } + + [JsonProperty("software_licenses")] + public List SoftwareLicenses { get; set; } + + [JsonProperty("backups")] + public Backups Backups { get; set; } + } + + public class PricingResponse + { + + [JsonProperty("currency")] + public string Currency { get; set; } + + [JsonProperty("vat")] + public int Vat { get; set; } + + [JsonProperty("pricing_plans")] + public PricingPlans PricingPlans { get; set; } + } +} diff --git a/OneAndOne.POCO/Response/DataCenters/DataCenterResponse.cs b/OneAndOne.POCO/Response/DataCenters/DataCenterResponse.cs new file mode 100644 index 0000000..b16d8ef --- /dev/null +++ b/OneAndOne.POCO/Response/DataCenters/DataCenterResponse.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.POCO.Response.DataCenters +{ + public class DataCenterResponse + { + private string id; + + public string Id + { + get + { + return id; + } + + set + { + id = value; + } + } + private string location; + + public string Location + { + get + { + return location; + } + + set + { + location = value; + } + } + private string country_code; + + public string CountryCode + { + get + { + return country_code; + } + + set + { + country_code = value; + } + } + } +} diff --git a/OneAndOne.POCO/Response/FirewallPolicies/FirewallPolicyResponse.cs b/OneAndOne.POCO/Response/FirewallPolicies/FirewallPolicyResponse.cs index 66cd8c1..8d40381 100644 --- a/OneAndOne.POCO/Response/FirewallPolicies/FirewallPolicyResponse.cs +++ b/OneAndOne.POCO/Response/FirewallPolicies/FirewallPolicyResponse.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; @@ -102,7 +103,9 @@ public string ServerName public enum RuleProtocol { - TCP, UDP, ICMP, AH, ESP, GRE + TCP, UDP, ICMP, AH, ESP, GRE, + [EnumMember(Value = "TCP/UDP")] + TCPUDP, NULL } public class FirewallRule { @@ -117,7 +120,13 @@ public string Id [JsonConverter(typeof(StringEnumConverter))] public RuleProtocol Protocol { - get { return (RuleProtocol)Enum.Parse(typeof(RuleProtocol), protocol); } + get + { + if (protocol != null) + return (RuleProtocol)Enum.Parse(typeof(RuleProtocol), protocol); + else + return RuleProtocol.NULL; + } set { protocol = ((RuleProtocol)value).ToString(); diff --git a/OneAndOne.POCO/Response/Images/ImagesResponse.cs b/OneAndOne.POCO/Response/Images/ImagesResponse.cs index 0c8d437..35c8f03 100644 --- a/OneAndOne.POCO/Response/Images/ImagesResponse.cs +++ b/OneAndOne.POCO/Response/Images/ImagesResponse.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using OneAndOne.POCO.Requests.Images; +using OneAndOne.POCO.Response.DataCenters; using System; using System.Collections.Generic; using System.Linq; @@ -144,6 +145,15 @@ public string ServerId get { return server_id; } set { server_id = value; } } + + private DataCenterResponse datacenter; + public DataCenterResponse Datacenter + { + get { return datacenter; } + + set { datacenter = value; } + } + private string frequency; [JsonConverter(typeof(StringEnumConverter))] public ImageFrequency Frequency @@ -175,6 +185,8 @@ public string CreationDate get { return creation_date; } set { creation_date = value; } } + + } public class Hdd diff --git a/OneAndOne.POCO/Response/LoadBalancers/LoadBalancerResponse.cs b/OneAndOne.POCO/Response/LoadBalancers/LoadBalancerResponse.cs index a8255da..055738b 100644 --- a/OneAndOne.POCO/Response/LoadBalancers/LoadBalancerResponse.cs +++ b/OneAndOne.POCO/Response/LoadBalancers/LoadBalancerResponse.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; +using OneAndOne.POCO.Response.DataCenters; using System; using System.Collections.Generic; using System.Linq; @@ -128,6 +129,14 @@ public string CloudpanelId get { return cloudpanel_id; } set { cloudpanel_id = value; } } + + private DataCenterResponse datacenter; + public DataCenterResponse Datacenter + { + get { return datacenter; } + + set { datacenter = value; } + } } public class LoadBalancerRule { diff --git a/OneAndOne.POCO/Response/MonitoringPolicies/MonitoringPoliciesResponse.cs b/OneAndOne.POCO/Response/MonitoringPolicies/MonitoringPoliciesResponse.cs index 3141587..c93150c 100644 --- a/OneAndOne.POCO/Response/MonitoringPolicies/MonitoringPoliciesResponse.cs +++ b/OneAndOne.POCO/Response/MonitoringPolicies/MonitoringPoliciesResponse.cs @@ -101,10 +101,10 @@ public string CloudpanelId get { return cloudpanel_id; } set { cloudpanel_id = value; } } - } - - - + } + + + public class Processes { private string id; @@ -282,6 +282,24 @@ public Critical Critical set { critical = value; } } } + + public class Disk + { + private Warning warning; + + public Warning Warning + { + get { return warning; } + set { warning = value; } + } + private Critical critical; + + public Critical Critical + { + get { return critical; } + set { critical = value; } + } + } public class Transfer { private Warning warning; @@ -326,6 +344,7 @@ public Cpu Cpu get { return cpu; } set { cpu = value; } } + private Ram ram; public Ram Ram @@ -346,7 +365,16 @@ public InternalPing InternalPing { get { return internal_ping; } set { internal_ping = value; } - } + } + + private Disk disk; + + public Disk Disk + { + get { return disk; } + + set { disk = value; } + } } } diff --git a/OneAndOne.POCO/Response/PrivateNetworks/PrivateNetworksResponse.cs b/OneAndOne.POCO/Response/PrivateNetworks/PrivateNetworksResponse.cs index 8197d68..19ed2e5 100644 --- a/OneAndOne.POCO/Response/PrivateNetworks/PrivateNetworksResponse.cs +++ b/OneAndOne.POCO/Response/PrivateNetworks/PrivateNetworksResponse.cs @@ -1,4 +1,5 @@ -using System; +using OneAndOne.POCO.Response.DataCenters; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -70,6 +71,14 @@ public string CloudpanelId { get { return cloudpanel_id; } set { cloudpanel_id = value; } + } + + private DataCenterResponse datacenter; + public DataCenterResponse Datacenter + { + get { return datacenter; } + + set { datacenter = value; } } } diff --git a/OneAndOne.POCO/Response/PublicIPs/PublicIPsResponse.cs b/OneAndOne.POCO/Response/PublicIPs/PublicIPsResponse.cs index 3c59a76..a5ed3e0 100644 --- a/OneAndOne.POCO/Response/PublicIPs/PublicIPsResponse.cs +++ b/OneAndOne.POCO/Response/PublicIPs/PublicIPsResponse.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using OneAndOne.POCO.Requests.Servers; +using OneAndOne.POCO.Response.DataCenters; using System; using System.Collections.Generic; using System.Linq; @@ -69,6 +70,14 @@ public string CreationDate { get { return creation_date; } set { creation_date = value; } + } + + private DataCenterResponse datacenter; + public DataCenterResponse Datacenter + { + get { return datacenter; } + + set { datacenter = value; } } } diff --git a/OneAndOne.POCO/Response/Roles/RoleResponse.cs b/OneAndOne.POCO/Response/Roles/RoleResponse.cs new file mode 100644 index 0000000..0d1b5a0 --- /dev/null +++ b/OneAndOne.POCO/Response/Roles/RoleResponse.cs @@ -0,0 +1,461 @@ +using Newtonsoft.Json; +using OneAndOne.POCO.Requests.Users; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.POCO.Response.Roles +{ + public class User + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + } + + public class Servers + { + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("start")] + public bool Start { get; set; } + + [JsonProperty("restart")] + public bool Restart { get; set; } + + [JsonProperty("shutdown")] + public bool Shutdown { get; set; } + + [JsonProperty("resize")] + public bool Resize { get; set; } + + [JsonProperty("reinstall")] + public bool Reinstall { get; set; } + + [JsonProperty("clone")] + public bool Clone { get; set; } + + [JsonProperty("manage_snapshot")] + public bool ManageSnapshot { get; set; } + + [JsonProperty("assign_ip")] + public bool AssignIp { get; set; } + + [JsonProperty("manage_dvd")] + public bool ManageDvd { get; set; } + + [JsonProperty("access_kvm_console")] + public bool AccessKvmConsole { get; set; } + } + + public class Images + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("disable_automatic_creation")] + public bool DisableAutomaticCreation { get; set; } + } + + public class SharedStorages + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("manage_attached_servers")] + public bool ManageAttachedServers { get; set; } + + [JsonProperty("access")] + public bool Access { get; set; } + + [JsonProperty("resize")] + public bool Resize { get; set; } + } + + public class FirewallPolicies + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("manage_rules")] + public bool ManageRules { get; set; } + + [JsonProperty("manage_attached_server_ips")] + public bool ManageAttachedServerIps { get; set; } + + [JsonProperty("clone")] + public bool Clone { get; set; } + } + + public class LoadBalancers + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("manage_rules")] + public bool ManageRules { get; set; } + + [JsonProperty("manage_attached_server_ips")] + public bool ManageAttachedServerIps { get; set; } + + [JsonProperty("modify")] + public bool Modify { get; set; } + } + + public class PublicIps + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("release")] + public bool Release { get; set; } + + [JsonProperty("set_reverse_dns")] + public bool SetReverseDns { get; set; } + } + + public class PrivateNetwork + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("set_network_info")] + public bool SetNetworkInfo { get; set; } + + [JsonProperty("manage_attached_servers")] + public bool ManageAttachedServers { get; set; } + } + + public class Vpn + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("download_file")] + public bool DownloadFile { get; set; } + } + + public class MonitoringCenter + { + + [JsonProperty("show")] + public bool Show { get; set; } + } + + public class MonitoringPolicies + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("set_email")] + public bool SetEmail { get; set; } + + [JsonProperty("modify_resources")] + public bool ModifyResources { get; set; } + + [JsonProperty("manage_ports")] + public bool ManagePorts { get; set; } + + [JsonProperty("manage_processes")] + public bool ManageProcesses { get; set; } + + [JsonProperty("manage_attached_servers")] + public bool ManageAttachedServers { get; set; } + + [JsonProperty("clone")] + public bool Clone { get; set; } + } + + public class Backups + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + } + + public class Logs + { + + [JsonProperty("show")] + public bool Show { get; set; } + } + + public class Users + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("set_email")] + public bool SetEmail { get; set; } + + [JsonProperty("set_password")] + public bool SetPassword { get; set; } + + [JsonProperty("manage_api")] + public bool ManageApi { get; set; } + + [JsonProperty("enable")] + public bool Enable { get; set; } + + [JsonProperty("disable")] + public bool Disable { get; set; } + + [JsonProperty("change_role")] + public bool ChangeRole { get; set; } + } + + public class Roles + { + + [JsonProperty("show")] + public bool Show { get; set; } + + [JsonProperty("create")] + public bool Create { get; set; } + + [JsonProperty("delete")] + public bool Delete { get; set; } + + [JsonProperty("set_name")] + public bool SetName { get; set; } + + [JsonProperty("set_description")] + public bool SetDescription { get; set; } + + [JsonProperty("manage_users")] + public bool ManageUsers { get; set; } + + [JsonProperty("modify")] + public bool Modify { get; set; } + + [JsonProperty("clone")] + public bool Clone { get; set; } + } + + public class Usages + { + + [JsonProperty("show")] + public bool Show { get; set; } + } + + public class InteractiveInvoices + { + + [JsonProperty("show")] + public bool Show { get; set; } + } + + public class Permissions + { + + [JsonProperty("servers")] + public Servers Servers { get; set; } + + [JsonProperty("images")] + public Images Images { get; set; } + + [JsonProperty("shared_storages")] + public SharedStorages SharedStorages { get; set; } + + [JsonProperty("firewall_policies")] + public FirewallPolicies FirewallPolicies { get; set; } + + [JsonProperty("load_balancers")] + public LoadBalancers LoadBalancers { get; set; } + + [JsonProperty("public_ips")] + public PublicIps PublicIps { get; set; } + + [JsonProperty("private_network")] + public PrivateNetwork PrivateNetwork { get; set; } + + [JsonProperty("vpn")] + public Vpn Vpn { get; set; } + + [JsonProperty("monitoring_center")] + public MonitoringCenter MonitoringCenter { get; set; } + + [JsonProperty("monitoring_policies")] + public MonitoringPolicies MonitoringPolicies { get; set; } + + [JsonProperty("backups")] + public Backups Backups { get; set; } + + [JsonProperty("logs")] + public Logs Logs { get; set; } + + [JsonProperty("users")] + public Users Users { get; set; } + + [JsonProperty("roles")] + public Roles Roles { get; set; } + + [JsonProperty("usages")] + public Usages Usages { get; set; } + + [JsonProperty("interactive_invoices")] + public InteractiveInvoices InteractiveInvoices { get; set; } + } + + public class RoleResponse + { + + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("state")] + public UserState State { get; set; } + + [JsonProperty("default")] + public int Default { get; set; } + + [JsonProperty("creation_date")] + public DateTime CreationDate { get; set; } + + [JsonProperty("users")] + public List Users { get; set; } + + [JsonProperty("permissions")] + public Permissions Permissions { get; set; } + } + + +} diff --git a/OneAndOne.POCO/Response/ServerAppliances/ServerAppliancesResponse.cs b/OneAndOne.POCO/Response/ServerAppliances/ServerAppliancesResponse.cs index 236777a..8e068f0 100644 --- a/OneAndOne.POCO/Response/ServerAppliances/ServerAppliancesResponse.cs +++ b/OneAndOne.POCO/Response/ServerAppliances/ServerAppliancesResponse.cs @@ -25,12 +25,12 @@ public string Name set { name = value; } } - private List available_sites; + private List available_datacenters; - public List AvailableSites + public List AvailableDatacenters { - get { return available_sites; } - set { available_sites = value; } + get { return available_datacenters; } + set { available_datacenters = value; } } @@ -90,13 +90,13 @@ public int MinHddSize get { return min_hdd_size; } set { min_hdd_size = value; } } - private List licenses; + //private List licenses; - public List Licenses - { - get { return licenses; } - set { licenses = value; } - } + //public List Licenses + //{ + // get { return licenses; } + // set { licenses = value; } + //} private bool automatic_installation; public bool AutomaticInstallation diff --git a/OneAndOne.POCO/Response/Servers/ServerIPS.cs b/OneAndOne.POCO/Response/Servers/ServerIPS.cs index 35c56af..5cb9c3e 100644 --- a/OneAndOne.POCO/Response/Servers/ServerIPS.cs +++ b/OneAndOne.POCO/Response/Servers/ServerIPS.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using OneAndOne.POCO.Converters; using System; using System.Collections.Generic; using System.Linq; @@ -37,6 +38,8 @@ public List LoadBalancers } private List firewall_policy; [JsonProperty(PropertyName = "firewall_policy")] + [JsonConverter(typeof(SingleValueArrayConverter))] + public List FirewallPolicy { diff --git a/OneAndOne.POCO/Response/Servers/ServerResponse.cs b/OneAndOne.POCO/Response/Servers/ServerResponse.cs index 6005595..5f3726a 100644 --- a/OneAndOne.POCO/Response/Servers/ServerResponse.cs +++ b/OneAndOne.POCO/Response/Servers/ServerResponse.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using OneAndOne.POCO.Converters; using OneAndOne.POCO.Requests.Servers; +using OneAndOne.POCO.Response.DataCenters; using System; using System.Collections.Generic; using System.ComponentModel; @@ -151,6 +152,14 @@ public List PrivateNetworks { get { return private_networks; } set { private_networks = value; } + } + + private DataCenterResponse datacenter; + public DataCenterResponse Datacenter + { + get { return datacenter; } + + set { datacenter = value; } } } @@ -179,6 +188,7 @@ public enum ServerState POWERING_ON, POWERED_ON, POWERED_OFF, + POWERING_OFF, DEPLOYING, REBOOTING, REMOVING, diff --git a/OneAndOne.POCO/Response/SharedStorages/ShareStorageAccessResponse.cs b/OneAndOne.POCO/Response/SharedStorages/ShareStorageAccessResponse.cs index cbf4fc1..befca47 100644 --- a/OneAndOne.POCO/Response/SharedStorages/ShareStorageAccessResponse.cs +++ b/OneAndOne.POCO/Response/SharedStorages/ShareStorageAccessResponse.cs @@ -6,7 +6,7 @@ namespace OneAndOne.POCO.Response.SharedStorages { - public class ShareStorageAccessResponse + public class SharedStorageAccessResponse { private string site_id; diff --git a/OneAndOne.POCO/Response/SharedStorages/SharedStoragesResponse.cs b/OneAndOne.POCO/Response/SharedStorages/SharedStoragesResponse.cs index d11976e..790f27f 100644 --- a/OneAndOne.POCO/Response/SharedStorages/SharedStoragesResponse.cs +++ b/OneAndOne.POCO/Response/SharedStorages/SharedStoragesResponse.cs @@ -1,4 +1,5 @@ -using System; +using OneAndOne.POCO.Response.DataCenters; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -74,6 +75,14 @@ public List Servers get { return servers; } set { servers = value; } } + + private DataCenterResponse datacenter; + public DataCenterResponse Datacenter + { + get { return datacenter; } + + set { datacenter = value; } + } } public class Server diff --git a/OneAndOne.POCO/Response/Users/UserResponse.cs b/OneAndOne.POCO/Response/Users/UserResponse.cs index 42dd85f..c017932 100644 --- a/OneAndOne.POCO/Response/Users/UserResponse.cs +++ b/OneAndOne.POCO/Response/Users/UserResponse.cs @@ -1,4 +1,5 @@ -using System; +using OneAndOne.POCO.Requests.Users; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -36,9 +37,9 @@ public string Email get { return email; } set { email = value; } } - private string state; + private UserState state; - public string State + public UserState State { get { return state; } set { state = value; } diff --git a/OneAndOne.POCO/Response/Vpn/VpnResponse.cs b/OneAndOne.POCO/Response/Vpn/VpnResponse.cs new file mode 100644 index 0000000..0585a7a --- /dev/null +++ b/OneAndOne.POCO/Response/Vpn/VpnResponse.cs @@ -0,0 +1,114 @@ +using OneAndOne.POCO.Response.DataCenters; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OneAndOne.POCO.Response.Vpn +{ + public class VpnResponse + { + + private string id; + + public string Id + { + get { return id; } + + set { id = value; } + } + + private string name; + + public string Name + { + get { return name; } + set { name = value; } + } + + private object description; + + public object Description + { + get { return description; } + + set { description = value; } + } + + private string state; + + public string State + { + get + { return state; } + set { state = value; } + } + + private DataCenterResponse datacenter; + + public DataCenterResponse Datacenter + { + get { return datacenter; } + + set { datacenter = value; } + } + + private string type; + + public string Type + { + get { return type; } + + set { type = value; } + } + + private List ips; + + public List Ips + { + get { return ips; } + set { ips = value; } + } + + private string cloudpanel_id; + + public string CloudpanelId + { + get { return cloudpanel_id; } + + set { cloudpanel_id = value; } + } + + private string creation_date; + + public string CreationDate + { + get { return creation_date; } + + set { creation_date = value; } + } + } + + public class Config + { + private string config_zip_file; + + /// + /// A string with base64 format with the configuration for OpenVPN. It is a zip file. + /// + /// + public string ConfigZipFile + { + get + { + return config_zip_file; + } + + set + { + config_zip_file = value; + } + } + } +} diff --git a/OneAndOne.UnitTests/App.config b/OneAndOne.UnitTests/App.config index 6003b4f..847c983 100644 --- a/OneAndOne.UnitTests/App.config +++ b/OneAndOne.UnitTests/App.config @@ -6,7 +6,7 @@ - + \ No newline at end of file diff --git a/OneAndOne.UnitTests/Common/CommonTest.cs b/OneAndOne.UnitTests/Common/CommonTest.cs new file mode 100644 index 0000000..7a8beb0 --- /dev/null +++ b/OneAndOne.UnitTests/Common/CommonTest.cs @@ -0,0 +1,52 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; + +namespace OneAndOne.UnitTests.Common +{ + [TestClass] + public class CommonTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + + [TestMethod] + public void GetPricing() + { + var result = client.Common.GetPricing(); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void GetDataCenters() + { + var result = client.DataCenters.Get(); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowDataCenter() + { + var dcList = client.DataCenters.Get(); + + var result = client.DataCenters.Show(dcList[0].Id); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void PingApi() + { + var result = client.Common.Ping(); + Assert.IsTrue(result); + } + + [TestMethod] + public void PingApiAuthentication() + { + var result = client.Common.PingAuthentication(); + Assert.IsTrue(result); + } + } +} diff --git a/OneAndOne.UnitTests/Config.cs b/OneAndOne.UnitTests/Config.cs new file mode 100644 index 0000000..a3ddcb5 --- /dev/null +++ b/OneAndOne.UnitTests/Config.cs @@ -0,0 +1,170 @@ +using OneAndOne.Client; +using OneAndOne.Client.RESTHelpers; +using OneAndOne.POCO.Response.Servers; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace OneAndOne.UnitTests +{ + public class Config + { + public static Client.RESTHelpers.Configuration Configuration + { + get + { + return new Client.RESTHelpers.Configuration + { + ApiKey = ConfigurationManager.AppSettings["APIToken"] + + }; + } + } + + public static void waitServerReady(string ServerId) + { + Thread.Sleep(5000); + var client = OneAndOneClient.Instance(Configuration); + var server = client.Servers.Show(ServerId); + while (server != null && ((server.Status.State != POCO.Response.Servers.ServerState.POWERED_ON && server.Status.State != POCO.Response.Servers.ServerState.POWERED_OFF) || (server.Status.Percent != 0 && server.Status.Percent != 99))) + { + Thread.Sleep(10000); + server = client.Servers.Show(ServerId); + } + } + + public static void waitServerTurnedOff(string ServerId) + { + Thread.Sleep(5000); + var client = OneAndOneClient.Instance(Configuration); + var server = client.Servers.Show(ServerId); + while (server != null && (server.Status.State != POCO.Response.Servers.ServerState.POWERED_OFF || (server.Status.Percent != 0 && server.Status.Percent != 99))) + { + Thread.Sleep(10000); + server = client.Servers.Show(ServerId); + } + } + + public static void waitPrivateNetworkReady(string pnId) + { + var client = OneAndOneClient.Instance(Configuration); + var pn = client.PrivateNetworks.Show(pnId); + while (pn.State != "ACTIVE") + { + Thread.Sleep(10000); + pn = client.PrivateNetworks.Show(pnId); + } + } + + public static void waitSharedStorageReady(string shareStorageId) + { + var client = OneAndOneClient.Instance(Configuration); + var sharedStorage = client.SharedStorages.Show(shareStorageId); + while (sharedStorage.State == "CONFIGURING") + { + Thread.Sleep(2000); + sharedStorage = client.SharedStorages.Show(sharedStorage.Id); + } + } + + public static void waitFirewallPolicyReady(string fwId) + { + var client = OneAndOneClient.Instance(Configuration); + var fw = client.FirewallPolicies.Show(fwId); + while (fw.State == "CONFIGURING") + { + Thread.Sleep(2000); + fw = client.FirewallPolicies.Show(fw.Id); + } + } + + public static void waitLoadBalancerReady(string lbId) + { + var client = OneAndOneClient.Instance(Configuration); + var lb = client.LoadBalancer.Show(lbId); + while (lb.State == "CONFIGURING") + { + Thread.Sleep(2000); + lb = client.LoadBalancer.Show(lb.Id); + } + } + + public static void waitMonitoringPolicyReady(string mpId) + { + var client = OneAndOneClient.Instance(Configuration); + var mp = client.MonitoringPolicies.Show(mpId); + while (mp.State != "ACTIVE") + { + Thread.Sleep(2000); + mp = client.MonitoringPolicies.Show(mp.Id); + } + } + + public static void waitIpRemoved(string ipId) + { + + try + { + var client = OneAndOneClient.Instance(Configuration); + var publicIP = client.PublicIPs.Show(ipId); + while (publicIP != null && publicIP.State == "REMOVING") + { + Thread.Sleep(2000); + publicIP = client.PublicIPs.Show(publicIP.Id); + } + } + catch (Exception ex) + { + if (ex.Message != "{\"type\":\"ELEMENT_NOT_FOUND\",\"message\":\"\",\"errors\":null}") + { + throw ex; + } + } + } + + public static ServerResponse CreateTestServer(string serverName, bool powerON=true) + { + var client = OneAndOneClient.Instance(Configuration); + int vcore = 4; + int CoresPerProcessor = 2; + var appliances = client.ServerAppliances.Get(null, null, null, "ubuntu", null); + POCO.Response.ServerAppliances.ServerAppliancesResponse appliance = null; + if (appliances == null || appliances.Count() == 0) + { + appliance = client.ServerAppliances.Get().FirstOrDefault(); + } + else + { + appliance = appliances.FirstOrDefault(); + } + var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() + { + ApplianceId = appliance != null ? appliance.Id : null, + Name = serverName, + Description = "desc", + Hardware = new POCO.Requests.Servers.HardwareRequest() + { + CoresPerProcessor = CoresPerProcessor, + Hdds = new List() + { + {new POCO.Requests.Servers.HddRequest() + { + IsMain=true, + Size=20, + }} + }, + Ram = 4, + Vcore = vcore + }, + PowerOn = powerON, + }); + return client.Servers.Show(result.Id); + } + } + + +} diff --git a/OneAndOne.UnitTests/DVDISO/DVDIsosTest.cs b/OneAndOne.UnitTests/DVDISO/DVDIsosTest.cs index 27244e1..9d49041 100644 --- a/OneAndOne.UnitTests/DVDISO/DVDIsosTest.cs +++ b/OneAndOne.UnitTests/DVDISO/DVDIsosTest.cs @@ -7,7 +7,7 @@ namespace OneAndOne.UnitTests.DVDISO [TestClass] public class DVDIsosTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); [TestMethod] public void GetDVDISOs() { diff --git a/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicies.orderedtest b/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicies.orderedtest index 0436af6..b674a3e 100644 --- a/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicies.orderedtest +++ b/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicies.orderedtest @@ -1,18 +1,10 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicyRulesTest.cs b/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicyRulesTest.cs index 2115534..0d1f637 100644 --- a/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicyRulesTest.cs +++ b/OneAndOne.UnitTests/FirewallPolicies/FirewallPolicyRulesTest.cs @@ -9,61 +9,39 @@ namespace OneAndOne.UnitTests.FirewallPolicies [TestClass] public class FirewallPolicyRulesTest { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetFirewallPolicyRules() - { - Random random = new Random(); - var firewallpolicies = client.FirewallPolicies.Get(); - var firewallpolicy = firewallpolicies[random.Next(firewallpolicies.Count - 1)]; - var result = client.FirewallPolicies.GetFirewallPolicyRules(firewallpolicy.Id); - - Assert.IsNotNull(result); - } + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static public FirewallPolicyResponse firewall = null; - [TestMethod] - public void ShowFirewallPolicyRule() + [ClassInitialize] + static public void TestInit(TestContext context) { - var firewallpolicies = client.FirewallPolicies.Get(); - var firewallpolicy = firewallpolicies[0]; - foreach (var item in firewallpolicies) + Random random = new Random(); + var newRules = new System.Collections.Generic.List(); + newRules.Add(new POCO.Requests.FirewallPolicies.CreateFirewallPocliyRule() { - if (item.Rules != null && item.Rules.Count > 0) - { - firewallpolicy = item; - break; - } - } - if (firewallpolicy.Rules != null && firewallpolicy.Rules.Count > 0) + PortTo = 80, + PortFrom = 80, + Protocol = RuleProtocol.TCP, + Source = "0.0.0.0" + + }); + var result = client.FirewallPolicies.Create(new POCO.Requests.FirewallPolicies.CreateFirewallPolicyRequest() { - var result = client.FirewallPolicies.ShowFirewallPolicyRule(firewallpolicy.Id, firewallpolicy.Rules[0].Id); + Description = ".netTestFirewall" + random.Next(10, 30), + Name = ".netFW" + random.Next(10, 30), + Rules = newRules + }); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - [TestMethod] - public void AddFirewallPolicyRule() - { - Random random = new Random(); - var firewallpolicies = client.FirewallPolicies.Get(); - var firewallpolicy = firewallpolicies[0]; + Config.waitFirewallPolicyReady(result.Id); + firewall = result; + + //add rule to the policy var ruleSource = "0.0.0.0"; - foreach (var firewall in firewallpolicies) - { - if (firewall.Default < 1) - { - firewallpolicy = firewall; - break; - } - } - if (firewallpolicy.Default < 1) + var randomPort = random.Next(1111, 9999); + var request = new POCO.Requests.FirewallPolicies.AddFirewallPolicyRuleRequest() { - var randomPort = random.Next(1111, 9999); - var request = new POCO.Requests.FirewallPolicies.AddFirewallPolicyRuleRequest() - { - Rules = new System.Collections.Generic.List() + Rules = new System.Collections.Generic.List() { {new OneAndOne.POCO.Requests.FirewallPolicies.RuleRequest() { @@ -73,43 +51,50 @@ public void AddFirewallPolicyRule() Source = "0.0.0.0" }} } - }; + }; + firewall = client.FirewallPolicies.CreateFirewallPolicyRule(request, firewall.Id); - var result = client.FirewallPolicies.CreateFirewallPolicyRule(request, firewallpolicy.Id); + Assert.IsNotNull(firewall); + Assert.IsNotNull(firewall.Id); + //check the policy rule is Added + var updatedpolicy = client.FirewallPolicies.Show(firewall.Id); + Assert.IsTrue(updatedpolicy.Rules.Any(ru => ru.PortFrom == randomPort && ru.PortTo == randomPort && ru.Source == ruleSource)); + Config.waitFirewallPolicyReady(result.Id); + } - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check the policy rule is Added - var updatedpolicy = client.FirewallPolicies.Show(firewallpolicy.Id); - Assert.IsTrue(updatedpolicy.Rules.Any(ru => ru.PortFrom == randomPort && ru.PortTo == randomPort && ru.Source == ruleSource)); + [ClassCleanup] + static public void TestClean() + { + if (firewall != null) + { + RemoveFirewallPolicyRule(); + Config.waitFirewallPolicyReady(firewall.Id); + client.FirewallPolicies.Delete(firewall.Id); } } [TestMethod] - public void RemoveFirewallPolicyRule() + public void GetShowFirewallPolicyRules() { - Random random = new Random(); - var firewallpolicies = client.FirewallPolicies.Get(); - OneAndOne.POCO.Response.FirewallPolicyResponse firewallpolicy = null; - foreach (var item in firewallpolicies) - { + var result = client.FirewallPolicies.GetFirewallPolicyRules(firewall.Id); + Assert.IsNotNull(result); - if (item.Rules != null && item.Rules.Count > 0 && item.Default < 1) - { - firewallpolicy = item; - break; - } - } - if (firewallpolicy != null && firewallpolicy.Rules != null && firewallpolicy.Rules.Count > 0 && firewallpolicy.Default < 1) - { - var result = client.FirewallPolicies.DeleteFirewallPolicyRules(firewallpolicy.Id, firewallpolicy.Rules[0].Id); + var show = client.FirewallPolicies.ShowFirewallPolicyRule(firewall.Id, firewall.Rules[0].Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check the policy rule is removed - var updatedpolicy = client.FirewallPolicies.Show(firewallpolicy.Id); - Assert.IsTrue(!updatedpolicy.Rules.Any(ru => ru.Id == firewallpolicy.Rules[0].Id)); - } + Assert.IsNotNull(show); + Assert.IsNotNull(show.Id); + } + + + static public void RemoveFirewallPolicyRule() + { + var result = client.FirewallPolicies.DeleteFirewallPolicyRules(firewall.Id, firewall.Rules[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check the policy rule is removed + var updatedpolicy = client.FirewallPolicies.Show(firewall.Id); + Assert.IsTrue(!updatedpolicy.Rules.Any(ru => ru.Id == firewall.Rules[0].Id)); } } } diff --git a/OneAndOne.UnitTests/FirewallPolicies/FirewallpoliciesTest.cs b/OneAndOne.UnitTests/FirewallPolicies/FirewallpoliciesTest.cs index 599a571..00b38e5 100644 --- a/OneAndOne.UnitTests/FirewallPolicies/FirewallpoliciesTest.cs +++ b/OneAndOne.UnitTests/FirewallPolicies/FirewallpoliciesTest.cs @@ -9,43 +9,22 @@ namespace OneAndOne.UnitTests.FirewallPolicies [TestClass] public class FirewallpoliciesTest { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetFirewallpolicies() - { - var result = client.FirewallPolicies.Get(); - - Assert.IsNotNull(result); - Assert.IsTrue(result.Count > 0); - } - - [TestMethod] - public void ShowFirewallPolicy() - { - Random random = new Random(); - - var firewalls = client.FirewallPolicies.Get(); - var firewall = firewalls[random.Next(firewalls.Count - 1)]; - - var result = client.FirewallPolicies.Show(firewall.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static public FirewallPolicyResponse firewall = null; - [TestMethod] - public void CreateFirewallPolicy() + [ClassInitialize] + static public void TestInit(TestContext context) { Random random = new Random(); var newRules = new System.Collections.Generic.List(); newRules.Add(new POCO.Requests.FirewallPolicies.CreateFirewallPocliyRule() - { - PortTo = 80, - PortFrom = 80, - Protocol = RuleProtocol.TCP, - Source = "0.0.0.0" + { + PortTo = 80, + PortFrom = 80, + Protocol = RuleProtocol.TCP, + Source = "0.0.0.0" - }); + }); var result = client.FirewallPolicies.Create(new POCO.Requests.FirewallPolicies.CreateFirewallPolicyRequest() { Description = ".netTestFirewall" + random.Next(10, 30), @@ -59,14 +38,41 @@ public void CreateFirewallPolicy() var policyresult = client.FirewallPolicies.Show(result.Id); Assert.IsNotNull(policyresult); Assert.IsNotNull(result.Id); + Config.waitFirewallPolicyReady(result.Id); + firewall = result; + } + + [ClassCleanup] + static public void TestClean() + { + if (firewall != null) + { + Config.waitFirewallPolicyReady(firewall.Id); + DeleteFirewallPolicy(); + } + } + + [TestMethod] + public void GetFirewallpolicies() + { + var result = client.FirewallPolicies.Get(); + + Assert.IsNotNull(result); + Assert.IsTrue(result.Count > 0); + } + + [TestMethod] + public void ShowFirewallPolicy() + { + var result = client.FirewallPolicies.Show(firewall.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); } [TestMethod] public void UpdateFirewallPolicy() { - Random random = new Random(); - var firewalls = client.FirewallPolicies.Get().Where(str => str.Name.Contains(".netFW")).ToList(); - var firewall = firewalls[random.Next(firewalls.Count - 1)]; var result = client.FirewallPolicies.Update(new POCO.Requests.FirewallPolicies.UpdateFirewallPolicyRequest() { Name = "Updated" + firewall.Name, @@ -83,12 +89,8 @@ public void UpdateFirewallPolicy() Assert.AreEqual(result.Description, policyresult.Description); } - [TestMethod] - public void DeleteFirewallPolicy() + static public void DeleteFirewallPolicy() { - Random random = new Random(); - var firewalls = client.FirewallPolicies.Get().Where(str => str.Name.Contains(".netFW")).ToList(); - var firewall = firewalls[random.Next(firewalls.Count - 1)]; var result = client.FirewallPolicies.Delete(firewall.Id); Assert.IsNotNull(result); diff --git a/OneAndOne.UnitTests/FirewallPolicies/FirewallpolicyServerIpsTest.cs b/OneAndOne.UnitTests/FirewallPolicies/FirewallpolicyServerIpsTest.cs index 96901a8..3ec4051 100644 --- a/OneAndOne.UnitTests/FirewallPolicies/FirewallpolicyServerIpsTest.cs +++ b/OneAndOne.UnitTests/FirewallPolicies/FirewallpolicyServerIpsTest.cs @@ -3,99 +3,94 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OneAndOne.Client; using System.Collections.Generic; +using OneAndOne.POCO.Response; +using OneAndOne.POCO.Response.Servers; namespace OneAndOne.UnitTests.FirewallPolicies { [TestClass] public class FirewallpolicyServerIpsTest { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetFirewallPolicyServerIps() + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static public POCO.Response.FirewallPolicyResponse firewall = null; + static ServerResponse server = null; + + [ClassInitialize] + static public void TestInit(TestContext context) { Random random = new Random(); - var firewallpolicies = client.FirewallPolicies.Get(); - var firewallpolicy = firewallpolicies[random.Next(firewallpolicies.Count - 1)]; - var result = client.FirewallPolicies.GetFirewallPolicyServerIps(firewallpolicy.Id); + server = Config.CreateTestServer("firewall servers test"); - Assert.IsNotNull(result); + Config.waitServerReady(server.Id); + server = client.Servers.Show(server.Id); + //create fw policy + var newRules = new System.Collections.Generic.List(); + newRules.Add(new POCO.Requests.FirewallPolicies.CreateFirewallPocliyRule() + { + PortTo = 80, + PortFrom = 80, + Protocol = RuleProtocol.TCP, + Source = "0.0.0.0" + + }); + var result = client.FirewallPolicies.Create(new POCO.Requests.FirewallPolicies.CreateFirewallPolicyRequest() + { + Description = ".netTestFirewall" + random.Next(10, 30), + Name = ".netFW" + random.Next(10, 30), + Rules = newRules + }); + + Config.waitFirewallPolicyReady(result.Id); + firewall = result; + //add server ip to a firewall policy + var iptoAdd = new List(); + iptoAdd.Add(server.Ips[0].Id); + var serverIp = client.FirewallPolicies.CreateFirewallPolicyServerIPs(new POCO.Requests.FirewallPolicies.AssignFirewallServerIPRequest() { ServerIps = iptoAdd }, firewall.Id); + Assert.IsNotNull(serverIp); + Assert.IsNotNull(serverIp.Id); + var updatedpolicy = client.FirewallPolicies.Show(serverIp.Id); + Assert.IsTrue(updatedpolicy.ServerIps.Any(ip => ip.Id == server.Ips[0].Id)); } - [TestMethod] - public void ShowFirewallPolicyServerIp() + [ClassCleanup] + static public void TestClean() { - var firewallpolicies = client.FirewallPolicies.Get(); - var firewallpolicy = firewallpolicies[0]; - foreach (var item in firewallpolicies) + if (firewall != null) { - if (item.ServerIps != null && item.ServerIps.Count > 0) - { - firewallpolicy = item; - break; - } + UnassignFirewallPolicyServerIp(); + Config.waitFirewallPolicyReady(firewall.Id); + client.FirewallPolicies.Delete(firewall.Id); } - if (firewallpolicy.ServerIps != null && firewallpolicy.ServerIps.Count > 0) - { - var result = client.FirewallPolicies.ShowFirewallPolicyServerIp(firewallpolicy.Id, firewallpolicy.ServerIps[0].Id); + Config.waitServerReady(server.Id); + client.Servers.Delete(server.Id, false); + } + [TestMethod] + public void GetFirewallPolicyServerIps() + { + var result = client.FirewallPolicies.GetFirewallPolicyServerIps(firewall.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } + Assert.IsNotNull(result); } [TestMethod] - public void AssignFirewallPolicyServerIp() + public void ShowFirewallPolicyServerIp() { - Random random = new Random(); - var servers = client.Servers.Get(); - var firewallpolicies = client.FirewallPolicies.Get(); - var firewallpolicy = firewallpolicies[random.Next(0, firewallpolicies.Count - 1)]; - OneAndOne.POCO.Response.Servers.IpAddress ipAddress = null; - if (servers.Count > 0) - { - foreach (var server in servers) - { - if (server.Ips != null && server.Ips.Count > 0) - { - ipAddress = server.Ips[0]; - } - } - if (ipAddress != null) - { - var iptoAdd = new List(); - iptoAdd.Add(ipAddress.Id); - var result = client.FirewallPolicies.CreateFirewallPolicyServerIPs(new POCO.Requests.FirewallPolicies.AssignFirewallServerIPRequest() { ServerIps = iptoAdd }, firewallpolicy.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - var updatedpolicy = client.FirewallPolicies.Show(firewallpolicy.Id); - Assert.IsTrue(updatedpolicy.ServerIps.Any(ip => ip.Id == ipAddress.Id)); - } - } + var fw = client.FirewallPolicies.Show(firewall.Id); + var result = client.FirewallPolicies.ShowFirewallPolicyServerIp(firewall.Id, fw.ServerIps[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); } - [TestMethod] - public void UnassignFirewallPolicyServerIp() + static public void UnassignFirewallPolicyServerIp() { - Random random = new Random(); - var firewallpolicies = client.FirewallPolicies.Get(); - OneAndOne.POCO.Response.FirewallPolicyResponse firewallpolicy = null; - foreach (var item in firewallpolicies) - { - if (item.ServerIps != null && item.ServerIps.Count > 0) - { - firewallpolicy = item; - break; - } - } - if (firewallpolicy != null && firewallpolicy.ServerIps != null && firewallpolicy.ServerIps.Count > 0) - { - var result = client.FirewallPolicies.DeleteFirewallPolicyServerIP(firewallpolicy.Id, firewallpolicy.ServerIps[0].Id); + var result = client.FirewallPolicies.DeleteFirewallPolicyServerIP(firewall.Id, server.Ips[0].Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - var updatedpolicy = client.FirewallPolicies.Show(firewallpolicy.Id); - Assert.IsTrue(!updatedpolicy.ServerIps.Any(ip => ip.Id == firewallpolicy.ServerIps[0].Id)); - } + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + Config.waitFirewallPolicyReady(firewall.Id); + var updatedpolicy = client.FirewallPolicies.Show(firewall.Id); + Assert.IsTrue(!updatedpolicy.ServerIps.Any(ip => ip.Id == firewall.ServerIps[0].Id)); } } } diff --git a/OneAndOne.UnitTests/Images/Image.orderedtest b/OneAndOne.UnitTests/Images/Image.orderedtest index 50f5cfd..34cd9bb 100644 --- a/OneAndOne.UnitTests/Images/Image.orderedtest +++ b/OneAndOne.UnitTests/Images/Image.orderedtest @@ -1,10 +1,9 @@ - - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/Images/ImagesTest.cs b/OneAndOne.UnitTests/Images/ImagesTest.cs index b600fae..b9ff387 100644 --- a/OneAndOne.UnitTests/Images/ImagesTest.cs +++ b/OneAndOne.UnitTests/Images/ImagesTest.cs @@ -6,14 +6,41 @@ using OneAndOne.POCO.Response.Images; using System.Threading; using OneAndOne.POCO.Response.Servers; +using System.Collections.Generic; +using OneAndOne.POCO.Response.DataCenters; namespace OneAndOne.UnitTests.Images { [TestClass] public class ImagesTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); public ImagesResponse response = null; + static ServerResponse server = null; + static ImagesResponse image = null; + static DataCenterResponse dc = null; + + [ClassInitialize] + static public void ServerInit(TestContext context) + { + dc = client.DataCenters.Get().FirstOrDefault(); + server = Config.CreateTestServer("image test .net"); + Config.waitServerReady(server.Id); + server = client.Servers.Show(server.Id); + } + + [ClassCleanup] + static public void ServerClean() + { + if (image != null) + { + DeleteImage(); + } + Config.waitServerReady(server.Id); + client.Servers.Delete(server.Id, false); + } + + [TestMethod] public void GetImages() @@ -38,51 +65,37 @@ public void ShowImage() public void CreateImage() { var random = new Random(); - var servers = client.Servers.Get(); - var server = servers[0]; - while (server.Status.State != ServerState.POWERED_OFF) + image = client.Images.Create(new POCO.Requests.Images.CreateImageRequest() { - server = servers[random.Next(0, servers.Count - 1)]; - break; - } - var image = client.Images.Create(new POCO.Requests.Images.CreateImageRequest() - { - - ServerId = server.Id, - Description = "describe image", - Frequency = ImageFrequency.DAILY, - Name = random.Next(100, 999) + "testImage", - NumIimages = random.Next(1, 50) + ServerId = server.Id, + Description = "describe image", + Frequency = ImageFrequency.DAILY, + Name = random.Next(100, 999) + "testImage", + NumIimages = random.Next(1, 50), + DatacetnerId = dc.Id, + Source = ImageSource.server + }); - }); response = image; - Assert.IsNotNull(image); Assert.IsNotNull(image.Id); //check if the image is added - var resultImage = client.Images.Show(image.Id); - Assert.IsNotNull(resultImage); - Assert.IsNotNull(resultImage.Id); + image = client.Images.Show(image.Id); + Assert.IsNotNull(image); + Assert.IsNotNull(image.Id); } [TestMethod] public void UpdateImage() { var random = new Random(); - var images = client.Images.Get().Where(img => img.Name.Contains("testImage")).ToList(); - var image = images[random.Next(images.Count - 1)]; - while (image.State != "POWERED_ON" && image.State != "ACTIVE") - { - Thread.Sleep(1000); - image = client.Images.Show(image.Id); - } var result = client.Images.Update(new UpdateImageRequest() - { - Description = "updated", - Frequency = ImageFrequency.ONCE, - Name = "updaeted API" - }, image.Id); + { + Description = "updated", + Frequency = ImageFrequency.ONCE, + Name = "updaeted API" + }, image.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); @@ -94,36 +107,13 @@ public void UpdateImage() Assert.AreEqual(resultImage.Frequency, ImageFrequency.ONCE); } - [TestMethod] - public void DeleteImage() + static public void DeleteImage() { - var images = client.Images.Get().Where(img => img.Name.Contains("testImage") || img.Name.Contains("updaeted API")).ToList(); - var image = images[0]; - foreach (var item in images) - { - if (item.State == "POWERED_ON") - image = item; - } var result = client.Images.Delete(image.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); } - [TestMethod] - public void DeleteAllTestImages() - { - var random = new Random(); - var images = client.Images.Get().Where(img => img.Name.Contains("testImage") || img.Name.Contains("updaeted API")).ToList(); - foreach (var item in images) - { - if (item.State == "POWERED_ON" || item.State == "ACTIVE") - { - var result = client.Images.Delete(item.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - } } } diff --git a/OneAndOne.UnitTests/LoadBalancer/LoadBalancerRulesTest.cs b/OneAndOne.UnitTests/LoadBalancer/LoadBalancerRulesTest.cs index 5c27611..7723ac9 100644 --- a/OneAndOne.UnitTests/LoadBalancer/LoadBalancerRulesTest.cs +++ b/OneAndOne.UnitTests/LoadBalancer/LoadBalancerRulesTest.cs @@ -1,106 +1,116 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Response; -using OneAndOne.POCO.Response.LoadBalancers; - -namespace OneAndOne.UnitTests.LoadBalancer -{ - [TestClass] - public class LoadBalancerRulesTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetLoadBalancersRules() - { - Random random = new Random(); - var loadBalancers = client.LoadBalancer.Get(); - var loadBalancer = loadBalancers[random.Next(loadBalancers.Count - 1)]; - var result = client.LoadBalancer.GetLoadBalancerRules(loadBalancer.Id); - - Assert.IsNotNull(result); - } - - [TestMethod] - public void ShowLoadBalancerRule() - { - var loadBalancers = client.LoadBalancer.Get(); - var loadBalancer = loadBalancers[0]; - foreach (var item in loadBalancers) - { - if (item.Rules != null && item.Rules.Count > 0) - { - loadBalancer = item; - break; - } - } - if (loadBalancer.Rules != null && loadBalancer.Rules.Count > 0) - { - var result = client.LoadBalancer.ShowLoadBalancerRule(loadBalancer.Id, loadBalancer.Rules[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - - } - } - - [TestMethod] - public void AddFLoadBalancerRule() - { - Random random = new Random(); - string ruleSource = "0.0.0.0"; - var loadBalancers = client.LoadBalancer.Get(); - var loadBalancer = loadBalancers[random.Next(0, loadBalancers.Count - 1)]; - var randomPort = random.Next(1111, 9999); - var request = new POCO.Requests.LoadBalancer.AddLoadBalancerRuleRequest() - { - Rules = new System.Collections.Generic.List() - { - {new OneAndOne.POCO.Requests.LoadBalancer.RuleRequest() - { - PortBalancer =randomPort, - PortServer = randomPort, - Protocol = LBRuleProtocol.TCP, - Source = ruleSource - }} - } - }; - - var result = client.LoadBalancer.CreateLoadBalancerRule(request, loadBalancer.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check the rule is Added - var updatedLoadBalancer = client.LoadBalancer.Show(loadBalancer.Id); - Assert.IsTrue(updatedLoadBalancer.Rules.Any(ru => ru.PortServer == randomPort && ru.PortBalancer == randomPort && ru.Source == ruleSource)); - } - - [TestMethod] - public void RemoveLoadBalancerRule() - { - Random random = new Random(); - var loadBalancers = client.LoadBalancer.Get(); - OneAndOne.POCO.Response.LoadBalancers.LoadBalancerResponse loadBalancer = null; - foreach (var item in loadBalancers) - { - - if (item.Rules != null && item.Rules.Count > 0) - { - loadBalancer = item; - break; - } - } - if (loadBalancer != null && loadBalancer.Rules != null && loadBalancer.Rules.Count > 1) - { - var result = client.LoadBalancer.DeleteLoadBalancerRules(loadBalancer.Id, loadBalancer.Rules[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check the policy is Added - var updatedpolicy = client.LoadBalancer.Show(loadBalancer.Id); - Assert.IsFalse(updatedpolicy.Rules.Any(ru => ru.Id == loadBalancer.Rules[0].Id)); - } - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Response; +using OneAndOne.POCO.Response.LoadBalancers; + +namespace OneAndOne.UnitTests.LoadBalancer +{ + [TestClass] + public class LoadBalancerRulesTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static LoadBalancerResponse loadBalancer = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + Random random = new Random(); + var result = client.LoadBalancer.Create(new POCO.Requests.LoadBalancer.CreateLoadBalancerRequest() + { + Name = "LBTest" + random.Next(100, 999), + Description = "LBdesc", + HealthCheckInterval = 1, + Persistence = true, + PersistenceTime = 30, + HealthCheckTest = HealthCheckTestTypes.NONE, + Method = LoadBalancerMethod.ROUND_ROBIN, + Rules = new System.Collections.Generic.List() + { + {new POCO.Requests.LoadBalancer.LoadBalancerRuleRequest() + { + PortBalancer=80, + Protocol=LBRuleProtocol.TCP, + Source="0.0.0.0", + PortServer=80 + } + } + } + }); + + Config.waitLoadBalancerReady(result.Id); + loadBalancer = result; + + string ruleSource = "0.0.0.0"; + //add new rule + var randomPort = random.Next(1111, 9999); + var request = new POCO.Requests.LoadBalancer.AddLoadBalancerRuleRequest() + { + Rules = new System.Collections.Generic.List() + { + {new OneAndOne.POCO.Requests.LoadBalancer.RuleRequest() + { + PortBalancer =randomPort, + PortServer = randomPort, + Protocol = LBRuleProtocol.TCP, + Source = ruleSource + }} + } + }; + + var newRule = client.LoadBalancer.CreateLoadBalancerRule(request, loadBalancer.Id); + + Assert.IsNotNull(newRule); + Assert.IsNotNull(newRule.Id); + Config.waitLoadBalancerReady(loadBalancer.Id); + //check the rule is Added + var updatedLoadBalancer = client.LoadBalancer.Show(loadBalancer.Id); + Assert.IsTrue(updatedLoadBalancer.Rules.Any(ru => ru.PortServer == randomPort && ru.PortBalancer == randomPort && ru.Source == ruleSource)); + + } + + [ClassCleanup] + static public void TestClean() + { + if (loadBalancer != null) + { + RemoveLoadBalancerRule(); + Config.waitLoadBalancerReady(loadBalancer.Id); + client.LoadBalancer.Delete(loadBalancer.Id); + } + } + [TestMethod] + public void GetLoadBalancersRules() + { + Random random = new Random(); + var loadBalancers = client.LoadBalancer.Get(); + var loadBalancer = loadBalancers[random.Next(loadBalancers.Count - 1)]; + var result = client.LoadBalancer.GetLoadBalancerRules(loadBalancer.Id); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowLoadBalancerRule() + { + var lb = client.LoadBalancer.Show(loadBalancer.Id); + var result = client.LoadBalancer.ShowLoadBalancerRule(lb.Id, lb.Rules[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + static public void RemoveLoadBalancerRule() + { + var lb = client.LoadBalancer.Show(loadBalancer.Id); + var result = client.LoadBalancer.DeleteLoadBalancerRules(lb.Id, lb.Rules[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check the policy is removed + var updatedpolicy = client.LoadBalancer.Show(lb.Id); + Assert.IsFalse(updatedpolicy.Rules.Any(ru => ru.Id == lb.Rules[0].Id)); + } + } +} diff --git a/OneAndOne.UnitTests/LoadBalancer/LoadBalancerServerIpsTest.cs b/OneAndOne.UnitTests/LoadBalancer/LoadBalancerServerIpsTest.cs index c9b7019..29a6722 100644 --- a/OneAndOne.UnitTests/LoadBalancer/LoadBalancerServerIpsTest.cs +++ b/OneAndOne.UnitTests/LoadBalancer/LoadBalancerServerIpsTest.cs @@ -1,110 +1,111 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using System.Collections.Generic; - -namespace OneAndOne.UnitTests.LoadBalancer -{ - [TestClass] - public class LoadBalancerServerIpsTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetLoadBalancerServerIps() - { - Random random = new Random(); - var loadBalancers = client.LoadBalancer.Get(); - var loadBalancer = loadBalancers[random.Next(loadBalancers.Count - 1)]; - var result = client.LoadBalancer.GetLoadBalancerServerIps(loadBalancer.Id); - - Assert.IsNotNull(result); - } - - [TestMethod] - public void ShowLoadBalancerServerIp() - { - var loadBalancers = client.LoadBalancer.Get(); - var loadBalancer = loadBalancers[0]; - foreach (var item in loadBalancers) - { - if (item.ServerIps != null && item.ServerIps.Count > 0) - { - loadBalancer = item; - break; - } - } - if (loadBalancer.ServerIps != null && loadBalancer.ServerIps.Count > 0) - { - var result = client.LoadBalancer.ShowLoadBalancerServerIp(loadBalancer.Id, loadBalancer.ServerIps[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - - [TestMethod] - public void AssignLoadBalancerServerIp() - { - Random random = new Random(); - var servers = client.Servers.Get(); - var loadBalancers = client.LoadBalancer.Get(); - var loadBalancer = loadBalancers[random.Next(0, loadBalancers.Count - 1)]; - OneAndOne.POCO.Response.Servers.IpAddress ipAddress = null; - if (servers.Count > 0) - { - foreach (var server in servers) - { - if (server.Ips != null && server.Ips.Count > 0) - { - ipAddress = server.Ips[0]; - break; - } - } - if (ipAddress != null) - { - var iptoAdd = new List(); - iptoAdd.Add(ipAddress.Id); - var result = client.LoadBalancer.CreateLoadBalancerServerIPs(new POCO.Requests.LoadBalancer.AssignLoadBalancerServerIpsRequest() - { - ServerIps = iptoAdd - }, loadBalancer.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - var updatedLoadBalancer = client.LoadBalancer.Show(loadBalancer.Id); - //check the ip is added - Assert.IsNotNull(updatedLoadBalancer); - Assert.IsTrue(updatedLoadBalancer.ServerIps.Any(ip => ip.Id == ipAddress.Id)); - } - } - } - - [TestMethod] - public void UnassignLoadBalancerServerIp() - { - Random random = new Random(); - var loadBalancers = client.LoadBalancer.Get(); - OneAndOne.POCO.Response.LoadBalancers.LoadBalancerResponse loadBalancer = null; - foreach (var item in loadBalancers) - { - if (item.ServerIps != null && item.ServerIps.Count > 0) - { - loadBalancer = item; - break; - } - } - if (loadBalancer != null && loadBalancer.ServerIps != null && loadBalancer.ServerIps.Count > 0) - { - var result = client.LoadBalancer.DeleteLoadBalancerServerIP(loadBalancer.Id, loadBalancer.ServerIps[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - var updatedLoadBalancer = client.LoadBalancer.Show(loadBalancer.Id); - //check the ip is removed - Assert.IsNotNull(updatedLoadBalancer); - Assert.IsFalse(updatedLoadBalancer.ServerIps.Any(ip => ip.Id == loadBalancer.ServerIps[0].Id)); - } - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using System.Collections.Generic; +using OneAndOne.POCO.Response.Servers; +using OneAndOne.POCO.Response.LoadBalancers; + +namespace OneAndOne.UnitTests.LoadBalancer +{ + [TestClass] + public class LoadBalancerServerIpsTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static ServerResponse server = null; + static LoadBalancerResponse loadBalancer = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + Random random = new Random(); + server = Config.CreateTestServer("loadbalancer servers test"); + + Config.waitServerReady(server.Id); + server = client.Servers.Show(server.Id); + //create loadbalancer + var result = client.LoadBalancer.Create(new POCO.Requests.LoadBalancer.CreateLoadBalancerRequest() + { + Name = "LBTest" + random.Next(100, 999), + Description = "LBdesc", + HealthCheckInterval = 1, + Persistence = true, + PersistenceTime = 30, + HealthCheckTest = HealthCheckTestTypes.NONE, + Method = LoadBalancerMethod.ROUND_ROBIN, + Rules = new System.Collections.Generic.List() + { + {new POCO.Requests.LoadBalancer.LoadBalancerRuleRequest() + { + PortBalancer=80, + Protocol=LBRuleProtocol.TCP, + Source="0.0.0.0", + PortServer=80 + } + } + } + }); + + loadBalancer = result; + //add server ip to load balancer + var iptoAdd = new List(); + iptoAdd.Add(server.Ips[0].Id); + var lbIps = client.LoadBalancer.CreateLoadBalancerServerIPs(new POCO.Requests.LoadBalancer.AssignLoadBalancerServerIpsRequest() + { + ServerIps = iptoAdd + }, loadBalancer.Id); + + Assert.IsNotNull(lbIps); + Assert.IsNotNull(lbIps.Id); + Config.waitLoadBalancerReady(loadBalancer.Id); + var updatedLoadBalancer = client.LoadBalancer.Show(loadBalancer.Id); + //check the ip is added + Assert.IsNotNull(updatedLoadBalancer); + Assert.IsTrue(updatedLoadBalancer.ServerIps.Any(ip => ip.Id == server.Ips[0].Id)); + } + + [ClassCleanup] + static public void TestClean() + { + if (loadBalancer != null) + { + UnassignLoadBalancerServerIp(); + Config.waitLoadBalancerReady(loadBalancer.Id); + client.LoadBalancer.Delete(loadBalancer.Id); + } + Config.waitServerReady(server.Id); + client.Servers.Delete(server.Id, false); + } + + [TestMethod] + public void GetLoadBalancerServerIps() + { + var result = client.LoadBalancer.GetLoadBalancerServerIps(loadBalancer.Id); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowLoadBalancerServerIp() + { + var lb = client.LoadBalancer.Show(loadBalancer.Id); + var result = client.LoadBalancer.ShowLoadBalancerServerIp(lb.Id, lb.ServerIps[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + static public void UnassignLoadBalancerServerIp() + { + var lb = client.LoadBalancer.Show(loadBalancer.Id); + var result = client.LoadBalancer.DeleteLoadBalancerServerIP(lb.Id, lb.ServerIps[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + var updatedLoadBalancer = client.LoadBalancer.Show(lb.Id); + //check the ip is removed + Assert.IsNotNull(updatedLoadBalancer); + Assert.IsFalse(updatedLoadBalancer.ServerIps.Any(ip => ip.Id == lb.ServerIps[0].Id)); + } + } +} diff --git a/OneAndOne.UnitTests/LoadBalancer/LoadBalancerTest.cs b/OneAndOne.UnitTests/LoadBalancer/LoadBalancerTest.cs index 335b2fc..b23c519 100644 --- a/OneAndOne.UnitTests/LoadBalancer/LoadBalancerTest.cs +++ b/OneAndOne.UnitTests/LoadBalancer/LoadBalancerTest.cs @@ -9,44 +9,24 @@ namespace OneAndOne.UnitTests.LoadBalancer [TestClass] public class LoadBalancerTest { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetLoadBalancers() - { - var result = client.LoadBalancer.Get(); - - Assert.IsNotNull(result); - Assert.IsTrue(result.Count > 0); - } - - [TestMethod] - public void ShowLoadBalancer() - { - Random random = new Random(); - - var loadBalancers = client.LoadBalancer.Get(); - var loadBalancer = loadBalancers[random.Next(loadBalancers.Count - 1)]; + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static LoadBalancerResponse loadBalancer = null; - var result = client.LoadBalancer.Show(loadBalancer.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void CreateLoadBalancer() + [ClassInitialize] + static public void TestInit(TestContext context) { Random random = new Random(); var result = client.LoadBalancer.Create(new POCO.Requests.LoadBalancer.CreateLoadBalancerRequest() - { - Name = "LBTest" + random.Next(100, 999), - Description = "LBdesc", - HealthCheckInterval = 1, - Persistence = true, - PersistenceTime = 30, - HealthCheckTest = HealthCheckTestTypes.NONE, - Method = LoadBalancerMethod.ROUND_ROBIN, - Rules = new System.Collections.Generic.List() + { + Name = "LBTest" + random.Next(100, 999), + Description = "LBdesc", + HealthCheckInterval = 1, + Persistence = true, + PersistenceTime = 30, + HealthCheckTest = HealthCheckTestTypes.NONE, + Method = LoadBalancerMethod.ROUND_ROBIN, + Rules = new System.Collections.Generic.List() { {new POCO.Requests.LoadBalancer.LoadBalancerRuleRequest() { @@ -57,20 +37,47 @@ public void CreateLoadBalancer() } } } - }); + }); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); var createdLoadBalancer = client.LoadBalancer.Show(result.Id); Assert.IsNotNull(createdLoadBalancer.Id); + loadBalancer = createdLoadBalancer; + } + + [ClassCleanup] + static public void TestClean() + { + if (loadBalancer != null) + { + Config.waitLoadBalancerReady(loadBalancer.Id); + DeleteLoadBalancer(); + } + } + + + [TestMethod] + public void GetLoadBalancers() + { + var result = client.LoadBalancer.Get(); + + Assert.IsNotNull(result); + Assert.IsTrue(result.Count > 0); + } + + [TestMethod] + public void ShowLoadBalancer() + { + var result = client.LoadBalancer.Show(loadBalancer.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); } [TestMethod] public void UpdateLoadBalancer() { - Random random = new Random(); - var loadBalancers = client.LoadBalancer.Get().Where(str => str.Name.Contains("LBTest")).ToList(); - var loadBalancer = loadBalancers[random.Next(loadBalancers.Count - 1)]; var result = client.LoadBalancer.Update(new POCO.Requests.LoadBalancer.UpdateLoadBalancerRequest() { HealthCheckInterval = 100, @@ -86,6 +93,7 @@ public void UpdateLoadBalancer() Assert.IsNotNull(result); Assert.IsNotNull(result.Id); + Config.waitLoadBalancerReady(loadBalancer.Id); var updatedLoadBalancer = client.LoadBalancer.Show(result.Id); Assert.IsNotNull(updatedLoadBalancer.Id); Assert.AreEqual(updatedLoadBalancer.Name, result.Name); @@ -95,12 +103,9 @@ public void UpdateLoadBalancer() Assert.AreEqual(updatedLoadBalancer.Method, LoadBalancerMethod.ROUND_ROBIN); } - [TestMethod] - public void DeleteLoadBalancer() + static public void DeleteLoadBalancer() { Random random = new Random(); - var loadBalancers = client.LoadBalancer.Get().Where(str => str.Name.Contains("LBTest")).ToList(); - var loadBalancer = loadBalancers[random.Next(loadBalancers.Count - 1)]; var result = client.LoadBalancer.Delete(loadBalancer.Id); Assert.IsNotNull(result); @@ -109,18 +114,5 @@ public void DeleteLoadBalancer() var removedLoadBalancer = client.LoadBalancer.Show(result.Id); Assert.IsTrue(removedLoadBalancer.State == "REMOVING"); } - - [TestMethod] - public void DeleteAllTestLoadBalancer() - { - Random random = new Random(); - var loadBalancers = client.LoadBalancer.Get().Where(str => str.Name.Contains("LBTest")).ToList(); - foreach (var item in loadBalancers) - { - var result = client.LoadBalancer.Delete(item.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } } } diff --git a/OneAndOne.UnitTests/LoadBalancer/LoadBalancersTest.orderedtest b/OneAndOne.UnitTests/LoadBalancer/LoadBalancersTest.orderedtest index af23438..f06b37c 100644 --- a/OneAndOne.UnitTests/LoadBalancer/LoadBalancersTest.orderedtest +++ b/OneAndOne.UnitTests/LoadBalancer/LoadBalancersTest.orderedtest @@ -1,18 +1,12 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/Logs/LogsTest.cs b/OneAndOne.UnitTests/Logs/LogsTest.cs index d2712f3..5c2f570 100644 --- a/OneAndOne.UnitTests/Logs/LogsTest.cs +++ b/OneAndOne.UnitTests/Logs/LogsTest.cs @@ -9,7 +9,7 @@ namespace OneAndOne.UnitTests.Logs [TestClass] public class LogsTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); [TestMethod] public void GetLogs() { diff --git a/OneAndOne.UnitTests/MonitoringCenter/MonitoringCenterTest.cs b/OneAndOne.UnitTests/MonitoringCenter/MonitoringCenterTest.cs index 7c21e54..3a49f1a 100644 --- a/OneAndOne.UnitTests/MonitoringCenter/MonitoringCenterTest.cs +++ b/OneAndOne.UnitTests/MonitoringCenter/MonitoringCenterTest.cs @@ -1,45 +1,158 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Response.MonitoringCenter; -using System.Threading; -using OneAndOne.POCO; - -namespace OneAndOne.UnitTests.MonitoringCenter -{ - [TestClass] - public class MonitoringCenterTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - - [TestMethod] - public void GetMonitoringCenter() - { - var mCenters = client.MonitoringCenter.Get(); - - Assert.IsNotNull(mCenters); - Assert.IsTrue(mCenters.Count > 0); - } - - [TestMethod] - public void GetServerMonitoringCenter() - { - Random random = new Random(); - var servers = client.Servers.Get(); - var server = client.Servers.Show(servers[random.Next(0, servers.Count - 1)].Id); - foreach (var item in servers) - { - Thread.Sleep(500); - server = client.Servers.Show(item.Id); - if (server.MonitoringPolicy != null) - { - server = item; - break; - } - } - var mCenters = client.MonitoringCenter.Show(server.Id, PeriodType.CUSTOM, DateTime.Today.AddMonths(-2), DateTime.Today); - Assert.IsNotNull(mCenters); - Assert.IsNotNull(mCenters.Id); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Response.MonitoringCenter; +using System.Threading; +using OneAndOne.POCO; +using OneAndOne.POCO.Response.MonitoringPolicies; +using OneAndOne.POCO.Response.Servers; +using System.Collections.Generic; + +namespace OneAndOne.UnitTests.MonitoringCenter +{ + [TestClass] + public class MonitoringCenterTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static MonitoringPoliciesResponse mp = null; + static ServerResponse server = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var ports = new List(); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 22, + Protocol = ProtocolType.TCP + }); + var processes = new List(); + processes.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.NOT_RUNNING, + Process = "test", + }); + var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolicyRequest() + { + Name = ".net Monitoring center test", + Description = ".net decription", + Agent = true, + Ports = ports, + Processes = processes, + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + }; + var result = client.MonitoringPolicies.Create(request); + mp = result; + + Config.waitMonitoringPolicyReady(mp.Id); + + server = Config.CreateTestServer("Monitoring center servers test"); + + Config.waitServerReady(server.Id); + server = client.Servers.Show(server.Id); + + var servers = new List(); + servers.Add(server.Id); + + var addedServer = client.MonitoringPoliciesServers.Create(servers, mp.Id); + } + + [ClassCleanup] + static public void TestClean() + { + if (mp != null) + { + Config.waitMonitoringPolicyReady(mp.Id); + client.MonitoringPolicies.Delete(mp.Id); + client.Servers.Delete(server.Id, false); + } + } + + [TestMethod] + public void GetMonitoringCenter() + { + var mCenters = client.MonitoringCenter.Get(); + + Assert.IsNotNull(mCenters); + Assert.IsTrue(mCenters.Count > 0); + } + + [TestMethod] + public void GetServerMonitoringCenter() + { + var mCenters = client.MonitoringCenter.Show(server.Id, PeriodType.LAST_24H); + Assert.IsNotNull(mCenters); + Assert.IsNotNull(mCenters.Id); + } + } +} diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPolicies.orderedtest b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPolicies.orderedtest index 922c1fb..3a41361 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPolicies.orderedtest +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPolicies.orderedtest @@ -1,10 +1,8 @@ - - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPort.orderedtest b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPort.orderedtest index f1d1ee8..642cf1e 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPort.orderedtest +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPort.orderedtest @@ -1,9 +1,8 @@ - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPortsTest.cs b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPortsTest.cs index 7d650a7..272eaad 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPortsTest.cs +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesPortsTest.cs @@ -1,168 +1,212 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Requests.MonitoringPolicies; -using System.Collections.Generic; -using OneAndOne.POCO; - -namespace OneAndOne.UnitTests.MonitoringPolicies -{ - [TestClass] - public class MonitoringPoliciesPortsTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetMonitoringPolicyPorts() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(0, monitoringPolicies.Count - 1)]; - var result = client.MonitoringPoliciesPorts.Get(monitoringPolicy.Id); - - Assert.IsNotNull(result); - } - - [TestMethod] - public void ShowMonitoringPolicyPort() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Ports != null && item.Ports.Count > 0) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Ports != null && monitoringPolicy.Ports.Count > 0) - { - var ports = client.MonitoringPoliciesPorts.Get(monitoringPolicy.Id); - var port = ports[random.Next(ports.Count - 1)]; - - var result = client.MonitoringPoliciesPorts.Show(monitoringPolicy.Id, port.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - - [TestMethod] - public void AddMonitoringPolicyPort() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Default < 1) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Default == 1) - return; - var ports = new List(); - ports.Add(new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 97, - Protocol = ProtocolType.TCP - - }); - - ports.Add(new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 98, - Protocol = ProtocolType.TCP - - }); - - var result = client.MonitoringPoliciesPorts.Create(ports, monitoringPolicy.Id); - - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if ports created do really exist - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); - Assert.AreEqual(ports.Count, checkResult.Ports.Count); - foreach (var item in ports) - { - var matchingPort = checkResult.Ports.FirstOrDefault(po => po.Protocol == item.Protocol && po.Port == item.Port); - Assert.AreEqual(item.AlertIf, matchingPort.AlertIf); - Assert.AreEqual(item.EmailNotification, matchingPort.EmailNotification); - } - } - - [TestMethod] - public void UpdateMonitoringPolicyport() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Ports != null && item.Ports.Count > 0) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Ports != null && monitoringPolicy.Ports.Count > 0) - { - var request = new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 23, - Protocol = ProtocolType.TCP - - }; - var result = client.MonitoringPoliciesPorts.Update(request, monitoringPolicy.Id, monitoringPolicy.Ports[0].Id); - - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if ports updated do really exist - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); - Assert.AreEqual(result.Ports.Count, checkResult.Ports.Count); - foreach (var item in result.Ports) - { - var matchingPort = checkResult.Ports.FirstOrDefault(po => po.Id == item.Id); - Assert.AreEqual(item.AlertIf, matchingPort.AlertIf); - Assert.AreEqual(item.EmailNotification, matchingPort.EmailNotification); - } - - } - } - - [TestMethod] - public void DeleteMonitoringPolicyPort() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Ports != null && item.Ports.Count > 0) - { - monitoringPolicy = item; - break; - } - } - var result = client.MonitoringPoliciesPorts.Delete(monitoringPolicy.Id, monitoringPolicy.Ports[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if ports is removed - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); - Assert.IsFalse(checkResult.Ports.Any(prt => prt.Id == monitoringPolicy.Ports[0].Id)); - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Requests.MonitoringPolicies; +using System.Collections.Generic; +using OneAndOne.POCO; +using OneAndOne.POCO.Response.MonitoringPolicies; + +namespace OneAndOne.UnitTests.MonitoringPolicies +{ + [TestClass] + public class MonitoringPoliciesPortsTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static MonitoringPoliciesResponse mp = null; + static MonitoringPoliciesResponse updatedMp = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var ports = new List(); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 22, + Protocol = ProtocolType.TCP + }); + var processes = new List(); + processes.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.NOT_RUNNING, + Process = "test", + }); + var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolicyRequest() + { + Name = ".net MP ports test", + Description = ".net decription", + Agent = true, + Ports = ports, + Processes = processes, + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + }; + var result = client.MonitoringPolicies.Create(request); + mp = result; + + Config.waitMonitoringPolicyReady(mp.Id); + + var addedPorts = new List(); + addedPorts.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 97, + Protocol = ProtocolType.TCP + + }); + + addedPorts.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 98, + Protocol = ProtocolType.TCP + + }); + + updatedMp = client.MonitoringPoliciesPorts.Create(addedPorts, mp.Id); + + + Assert.IsNotNull(updatedMp); + Assert.IsNotNull(updatedMp.Id); + Config.waitMonitoringPolicyReady(mp.Id); + + } + + [ClassCleanup] + static public void TestClean() + { + if (mp != null) + { + Config.waitMonitoringPolicyReady(mp.Id); + DeleteMonitoringPolicyPort(); + Config.waitMonitoringPolicyReady(mp.Id); + client.MonitoringPolicies.Delete(mp.Id); + } + } + [TestMethod] + public void GetMonitoringPolicyPorts() + { + var result = client.MonitoringPoliciesPorts.Get(mp.Id); + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowMonitoringPolicyPort() + { + var result = client.MonitoringPoliciesPorts.Show(mp.Id, updatedMp.Ports[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void UpdateMonitoringPolicyport() + { + var request = new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 23, + Protocol = ProtocolType.TCP + + }; + var result = client.MonitoringPoliciesPorts.Update(request, mp.Id, updatedMp.Ports[0].Id); + + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if ports updated do really exist + var checkResult = client.MonitoringPolicies.Show(mp.Id); + Assert.AreEqual(result.Ports.Count, checkResult.Ports.Count); + foreach (var item in result.Ports) + { + var matchingPort = checkResult.Ports.FirstOrDefault(po => po.Id == item.Id); + Assert.AreEqual(item.AlertIf, matchingPort.AlertIf); + Assert.AreEqual(item.EmailNotification, matchingPort.EmailNotification); + } + + } + + static public void DeleteMonitoringPolicyPort() + { + var result = client.MonitoringPoliciesPorts.Delete(mp.Id, updatedMp.Ports[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if ports is removed + var checkResult = client.MonitoringPolicies.Show(updatedMp.Id); + Assert.IsFalse(checkResult.Ports.Any(prt => prt.Id == updatedMp.Ports[0].Id)); + } + } +} diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcesses.orderedtest b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcesses.orderedtest index ab81186..6c1ea34 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcesses.orderedtest +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcesses.orderedtest @@ -1,10 +1,8 @@ - - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcessesTest.cs b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcessesTest.cs index afacd01..1e1cae0 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcessesTest.cs +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesProcessesTest.cs @@ -1,163 +1,213 @@ -using System.Linq; -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Requests.MonitoringPolicies; -using System.Collections.Generic; -using OneAndOne.POCO; - -namespace OneAndOne.UnitTests.MonitoringPolicies -{ - [TestClass] - public class MonitoringPoliciesProcessesTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetMonitoringPolicyProcesss() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - var result = client.MonitoringPoliciesProcesses.Get(monitoringPolicy.Id); - - Assert.IsNotNull(result); - } - - [TestMethod] - public void ShowMonitoringPolicyProcess() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Processes != null && item.Processes.Count > 0) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Processes != null && monitoringPolicy.Processes.Count > 0) - { - var processes = client.MonitoringPoliciesProcesses.Get(monitoringPolicy.Id); - var process = processes[random.Next(processes.Count - 1)]; - - var result = client.MonitoringPoliciesProcesses.Show(monitoringPolicy.Id, process.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - - [TestMethod] - public void AddMonitoringPolicyProcess() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Default < 1) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Default == 1) - return; - var processes = new List(); - processes.Add(new POCO.Requests.MonitoringPolicies.Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.RUNNING, - Process = "iexplorer" - - }); - - processes.Add(new POCO.Requests.MonitoringPolicies.Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.RUNNING, - Process = "test" - - }); - - var result = client.MonitoringPoliciesProcesses.Create(processes, monitoringPolicy.Id); - - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - - //check if Processes created do really exist - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); - Assert.AreEqual(processes.Count, checkResult.Processes.Count); - foreach (var item in processes) - { - var matchingProcess = checkResult.Processes.FirstOrDefault(po => po.Process == item.Process && po.AlertIf == item.AlertIf); - Assert.AreEqual(item.AlertIf, matchingProcess.AlertIf); - Assert.AreEqual(item.EmailNotification, matchingProcess.EmailNotification); - } - } - - [TestMethod] - public void UpdateMonitoringPolicyProcess() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Processes != null && item.Processes.Count > 0) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Processes != null && monitoringPolicy.Processes.Count > 0) - { - var result = client.MonitoringPoliciesProcesses.Update(new POCO.Requests.MonitoringPolicies.Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.RUNNING, - Process = "test" - - }, monitoringPolicy.Id, monitoringPolicy.Processes[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if Processes updated do really exist - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); - Assert.AreEqual(result.Processes.Count, checkResult.Processes.Count); - foreach (var item in result.Processes) - { - var matchingProcess = checkResult.Processes.FirstOrDefault(po => po.Id == item.Id); - Assert.AreEqual(item.AlertIf, matchingProcess.AlertIf); - Assert.AreEqual(item.EmailNotification, matchingProcess.EmailNotification); - } - } - } - - [TestMethod] - public void DeleteMonitoringPolicyProcess() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Processes != null && item.Processes.Count > 0) - { - monitoringPolicy = item; - break; - } - } - var result = client.MonitoringPoliciesProcesses.Delete(monitoringPolicy.Id, monitoringPolicy.Processes[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if Process is removed - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); - Assert.IsFalse(checkResult.Processes.Any(prt => prt.Id == monitoringPolicy.Processes[0].Id)); - } - } -} +using System.Linq; +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Requests.MonitoringPolicies; +using System.Collections.Generic; +using OneAndOne.POCO; +using OneAndOne.POCO.Response.MonitoringPolicies; + +namespace OneAndOne.UnitTests.MonitoringPolicies +{ + [TestClass] + public class MonitoringPoliciesProcessesTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static MonitoringPoliciesResponse mp = null; + static MonitoringPoliciesResponse updatedMp = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var ports = new List(); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 22, + Protocol = ProtocolType.TCP + }); + var processes = new List(); + processes.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.NOT_RUNNING, + Process = "test", + }); + var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolicyRequest() + { + Name = ".net MP Process test", + Description = ".net decription", + Agent = true, + Ports = ports, + Processes = processes, + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + }; + var result = client.MonitoringPolicies.Create(request); + mp = result; + + Config.waitMonitoringPolicyReady(mp.Id); + + var newProcesses = new List(); + newProcesses.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.RUNNING, + Process = "iexplorer" + + }); + + newProcesses.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.RUNNING, + Process = "test" + + }); + + updatedMp = client.MonitoringPoliciesProcesses.Create(newProcesses, mp.Id); + + + Assert.IsNotNull(updatedMp); + Assert.IsNotNull(updatedMp.Id); + + Config.waitMonitoringPolicyReady(mp.Id); + + } + + [ClassCleanup] + static public void TestClean() + { + if (mp != null) + { + Config.waitMonitoringPolicyReady(mp.Id); + DeleteMonitoringPolicyProcess(); + Config.waitMonitoringPolicyReady(mp.Id); + client.MonitoringPolicies.Delete(mp.Id); + } + } + + [TestMethod] + public void GetMonitoringPolicyProcesss() + { + var result = client.MonitoringPoliciesProcesses.Get(mp.Id); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowMonitoringPolicyProcess() + { + var processes = client.MonitoringPoliciesProcesses.Get(mp.Id); + var result = client.MonitoringPoliciesProcesses.Show(mp.Id, processes[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void UpdateMonitoringPolicyProcess() + { + Config.waitMonitoringPolicyReady(mp.Id); + + var result = client.MonitoringPoliciesProcesses.Update(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = false, + AlertIf = ProcessAlertType.RUNNING, + Process = "iexplorer" + + }, mp.Id, updatedMp.Processes[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if Processes updated do really exist + var checkResult = client.MonitoringPolicies.Show(mp.Id); + Assert.AreEqual(result.Processes.Count, checkResult.Processes.Count); + foreach (var item in result.Processes) + { + var matchingProcess = checkResult.Processes.FirstOrDefault(po => po.Id == item.Id); + Assert.AreEqual(item.AlertIf, matchingProcess.AlertIf); + Assert.AreEqual(item.EmailNotification, matchingProcess.EmailNotification); + } + } + + static public void DeleteMonitoringPolicyProcess() + { + + var result = client.MonitoringPoliciesProcesses.Delete(updatedMp.Id, updatedMp.Processes[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if Process is removed + var checkResult = client.MonitoringPolicies.Show(updatedMp.Id); + Assert.IsFalse(checkResult.Processes.Any(prt => prt.Id == updatedMp.Processes[0].Id)); + } + } +} diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServerTest.cs b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServerTest.cs index e66ee32..f214806 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServerTest.cs +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServerTest.cs @@ -3,108 +3,180 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OneAndOne.Client; using System.Collections.Generic; - +using OneAndOne.POCO.Response.MonitoringPolicies; +using OneAndOne.POCO; +using OneAndOne.POCO.Response.Servers; + namespace OneAndOne.UnitTests.MonitoringPolicies { [TestClass] public class MonitoringPoliciesServerTest { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetMonitoringPolicyServers() + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static MonitoringPoliciesResponse mp = null; + static List serversList = new List(); + static ServerResponse server = null; + + [ClassInitialize] + static public void TestInit(TestContext context) { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - var result = client.MonitoringPoliciesServers.Get(monitoringPolicy.Id); + var ports = new List(); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 22, + Protocol = ProtocolType.TCP + }); + var processes = new List(); + processes.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.NOT_RUNNING, + Process = "test", + }); + var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolicyRequest() + { + Name = ".net MP test", + Description = ".net decription", + Agent = true, + Ports = ports, + Processes = processes, + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + }; + var result = client.MonitoringPolicies.Create(request); + mp = result; - Assert.IsNotNull(result); - } + Config.waitMonitoringPolicyReady(mp.Id); - [TestMethod] - public void ShowMonitoringPolicyServer() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Servers != null && item.Servers.Count > 0) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Servers != null && monitoringPolicy.Servers.Count > 0) - { - var servers = client.MonitoringPoliciesServers.Get(monitoringPolicy.Id); - var server = servers[random.Next(servers.Count - 1)]; + server = Config.CreateTestServer("mp servers test"); - var result = client.MonitoringPoliciesServers.Show(monitoringPolicy.Id, server.Id); + Config.waitServerReady(server.Id); + server = client.Servers.Show(server.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - - [TestMethod] - public void AddMonitoringPolicyServer() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Default < 1) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Default == 1) - return; - var serversList = client.Servers.Get(); - var servers = new List(); - servers.Add(serversList[0].Id); - if (servers.Count > 1) - { - servers.Add(serversList[1].Id); - } + var servers = new List(); + servers.Add(server.Id); - var result = client.MonitoringPoliciesServers.Create(servers, monitoringPolicy.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); + var addedServer = client.MonitoringPoliciesServers.Create(servers, mp.Id); + Assert.IsNotNull(addedServer); + Assert.IsNotNull(addedServer.Id); //check if servers created do really exist - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); + var checkResult = client.MonitoringPolicies.Show(mp.Id); Assert.AreEqual(servers.Count, checkResult.Servers.Count); foreach (var item in servers) { var matchingServer = checkResult.Servers.FirstOrDefault(po => po.Id == item); Assert.AreEqual(item, matchingServer.Id); - } + } + } - [TestMethod] - public void DeleteMonitoringPolicyServer() + [ClassCleanup] + static public void TestClean() { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) + if (mp != null) { - if (item.Servers != null && item.Servers.Count > 0) - { - monitoringPolicy = item; - break; - } + Config.waitMonitoringPolicyReady(mp.Id); + DeleteMonitoringPolicyServer(); + Config.waitMonitoringPolicyReady(mp.Id); + client.MonitoringPolicies.Delete(mp.Id); + client.Servers.Delete(server.Id, false); } - var result = client.MonitoringPoliciesServers.Delete(monitoringPolicy.Id, monitoringPolicy.Servers[0].Id); + } + [TestMethod] + public void GetMonitoringPolicyServers() + { + var result = client.MonitoringPoliciesServers.Get(mp.Id); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowMonitoringPolicyServer() + { + var result = client.MonitoringPoliciesServers.Show(mp.Id, server.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + static public void DeleteMonitoringPolicyServer() + { + var result = client.MonitoringPoliciesServers.Delete(mp.Id, server.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); //check if server is removed - var checkResult = client.MonitoringPolicies.Show(monitoringPolicy.Id); - Assert.IsFalse(checkResult.Servers.Any(ser => ser.Id == monitoringPolicy.Servers[0].Id)); + Config.waitMonitoringPolicyReady(mp.Id); + var checkResult = client.MonitoringPolicies.Show(mp.Id); + Assert.IsFalse(checkResult.Servers.Any(ser => ser.Id == server.Id)); } } } diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServers.orderedtest b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServers.orderedtest index 22b43a2..0fe37fb 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServers.orderedtest +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesServers.orderedtest @@ -1,9 +1,7 @@ - - - - - - - - + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesTest.cs b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesTest.cs index 0f9f1f9..a7f2db1 100644 --- a/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesTest.cs +++ b/OneAndOne.UnitTests/MonitoringPolicies/MonitoringPoliciesTest.cs @@ -1,312 +1,288 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using System.Collections.Generic; -using OneAndOne.POCO.Requests.MonitoringPolicies; -using OneAndOne.POCO; -using System.Threading; - -namespace OneAndOne.UnitTests.MonitoringPolicies -{ - [TestClass] - public class MonitoringPoliciesTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetMonitoringPolicies() - { - var result = client.MonitoringPolicies.Get(); - - Assert.IsNotNull(result); - } - - [TestMethod] - public void ShowMonitoringPolicy() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - - var result = client.MonitoringPolicies.Show(monitoringPolicy.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void CreateMonitoringPolicy() - { - Random random = new Random(); - var ports = new List(); - ports.Add(new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 22, - Protocol = ProtocolType.TCP - }); - var processes = new List(); - processes.Add(new Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.NOT_RUNNING, - Process = "test", - }); - var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolicyRequest() - { - Name = ".netMP" + random.Next(100, 990), - Description = ".net decription", - Agent = true, - Ports = ports, - Processes = processes, - Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() - { - Cpu = new POCO.Requests.MonitoringPolicies.Cpu() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Ram = new POCO.Requests.MonitoringPolicies.Ram() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Disk = new POCO.Requests.MonitoringPolicies.Disk() - { - Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() - { - Alert = false, - Value = 90 - }, - Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() - { - Alert = false, - Value = 80 - } - }, - InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() - { - Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() - { - Alert = false, - Value = 100 - }, - Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() - { - Alert = false, - Value = 50 - } - }, - Transfer = new POCO.Requests.MonitoringPolicies.Transfer() - { - Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() - { - Alert = false, - Value = 2000 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 1000 - } - } - } - }; - var result = client.MonitoringPolicies.Create(request); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - var monitoringPolicyResult = client.MonitoringPolicies.Show(result.Id); - Assert.AreEqual(monitoringPolicyResult.Agent, request.Agent); - Assert.AreEqual(monitoringPolicyResult.Ports.Count, request.Ports.Count); - Assert.AreEqual(monitoringPolicyResult.Processes.Count, request.Processes.Count); - //check CPU values - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Alert, request.Thresholds.Cpu.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Value, request.Thresholds.Cpu.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Alert, request.Thresholds.Cpu.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Value, request.Thresholds.Cpu.Warning.Value); - //check RAM values - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Alert, request.Thresholds.Ram.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Value, request.Thresholds.Ram.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Alert, request.Thresholds.Ram.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Value, request.Thresholds.Ram.Warning.Value); - //check InternalPing values - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Alert, request.Thresholds.InternalPing.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Value, request.Thresholds.InternalPing.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Alert, request.Thresholds.InternalPing.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Value, request.Thresholds.InternalPing.Warning.Value); - //check Transfer values - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Alert, request.Thresholds.Transfer.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Value, request.Thresholds.Transfer.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Alert, request.Thresholds.Transfer.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Value, request.Thresholds.Transfer.Warning.Value); - - } - - [TestMethod] - public void UpdateMonitoringPolicy() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - foreach (var item in monitoringPolicies) - { - if (item.Default < 1) - { - monitoringPolicy = item; - break; - } - } - if (monitoringPolicy.Default == 1) - return; - var request = new UpdateMonitoringPolicyRequest() - { - Name = "updated" + monitoringPolicy.Name, - Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() - { - Cpu = new POCO.Requests.MonitoringPolicies.Cpu() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Ram = new POCO.Requests.MonitoringPolicies.Ram() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Disk = new POCO.Requests.MonitoringPolicies.Disk() - { - Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() - { - Alert = false, - Value = 90 - }, - Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() - { - Alert = false, - Value = 80 - } - }, - InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() - { - Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() - { - Alert = false, - Value = 100 - }, - Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() - { - Alert = false, - Value = 50 - } - }, - Transfer = new POCO.Requests.MonitoringPolicies.Transfer() - { - Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() - { - Alert = false, - Value = 2000 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 1000 - } - } - } - - }; - var result = client.MonitoringPolicies.Update(request, monitoringPolicy.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - var monitoringPolicyResult = client.MonitoringPolicies.Show(result.Id); - //check CPU values - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Alert, request.Thresholds.Cpu.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Value, request.Thresholds.Cpu.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Alert, request.Thresholds.Cpu.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Value, request.Thresholds.Cpu.Warning.Value); - //check RAM values - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Alert, request.Thresholds.Ram.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Value, request.Thresholds.Ram.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Alert, request.Thresholds.Ram.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Value, request.Thresholds.Ram.Warning.Value); - //check InternalPing values - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Alert, request.Thresholds.InternalPing.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Value, request.Thresholds.InternalPing.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Alert, request.Thresholds.InternalPing.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Value, request.Thresholds.InternalPing.Warning.Value); - //check Transfer values - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Alert, request.Thresholds.Transfer.Critical.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Value, request.Thresholds.Transfer.Critical.Value); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Alert, request.Thresholds.Transfer.Warning.Alert); - Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Value, request.Thresholds.Transfer.Warning.Value); - } - - [TestMethod] - public void DeleteMonitoringPolicy() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get().Where(pn => pn.Name.Contains("netMP")).ToList(); - var monitoringPolicy = monitoringPolicies[random.Next(monitoringPolicies.Count - 1)]; - var result = client.MonitoringPolicies.Delete(monitoringPolicy.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the monitoring policy is removed - var monitoringPoliciesResult = client.MonitoringPolicies.Get().Where(pn => pn.Name.Contains("netMP")).ToList(); - while (monitoringPoliciesResult.Count >= monitoringPolicies.Count) - { - Thread.Sleep(1000); - monitoringPoliciesResult = client.MonitoringPolicies.Get().Where(pn => pn.Name.Contains("netMP")).ToList(); - } - Assert.IsFalse(monitoringPoliciesResult.Any(mp => mp.Id == result.Id)); - } - - [TestMethod] - public void DeleteAllTestMonitoringPolicies() - { - Random random = new Random(); - var monitoringPolicies = client.MonitoringPolicies.Get().Where(pn => pn.Name.Contains("netMP")).ToList(); - foreach (var item in monitoringPolicies) - { - var result = client.MonitoringPolicies.Delete(item.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using System.Collections.Generic; +using OneAndOne.POCO.Requests.MonitoringPolicies; +using OneAndOne.POCO; +using System.Threading; +using OneAndOne.POCO.Response.MonitoringPolicies; + +namespace OneAndOne.UnitTests.MonitoringPolicies +{ + [TestClass] + public class MonitoringPoliciesTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static MonitoringPoliciesResponse mp = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var ports = new List(); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 22, + Protocol = ProtocolType.TCP + }); + var processes = new List(); + processes.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.NOT_RUNNING, + Process = "test", + }); + var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolicyRequest() + { + Name = ".net MP test" , + Description = ".net decription", + Agent = true, + Ports = ports, + Processes = processes, + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + }; + var result = client.MonitoringPolicies.Create(request); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + var monitoringPolicyResult = client.MonitoringPolicies.Show(result.Id); + mp = monitoringPolicyResult; + Assert.AreEqual(monitoringPolicyResult.Agent, request.Agent); + Assert.AreEqual(monitoringPolicyResult.Ports.Count, request.Ports.Count); + Assert.AreEqual(monitoringPolicyResult.Processes.Count, request.Processes.Count); + //check CPU values + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Alert, request.Thresholds.Cpu.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Value, request.Thresholds.Cpu.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Alert, request.Thresholds.Cpu.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Value, request.Thresholds.Cpu.Warning.Value); + //check RAM values + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Alert, request.Thresholds.Ram.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Value, request.Thresholds.Ram.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Alert, request.Thresholds.Ram.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Value, request.Thresholds.Ram.Warning.Value); + //check InternalPing values + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Alert, request.Thresholds.InternalPing.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Value, request.Thresholds.InternalPing.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Alert, request.Thresholds.InternalPing.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Value, request.Thresholds.InternalPing.Warning.Value); + //check Transfer values + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Alert, request.Thresholds.Transfer.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Value, request.Thresholds.Transfer.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Alert, request.Thresholds.Transfer.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Value, request.Thresholds.Transfer.Warning.Value); + Config.waitMonitoringPolicyReady(mp.Id); + } + + [ClassCleanup] + static public void TestClean() + { + if (mp != null) + { + Config.waitMonitoringPolicyReady(mp.Id); + DeleteMonitoringPolicy(); + } + } + + + [TestMethod] + public void GetMonitoringPolicies() + { + var result = client.MonitoringPolicies.Get(); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowMonitoringPolicy() + { + var result = client.MonitoringPolicies.Show(mp.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void UpdateMonitoringPolicy() + { + var request = new UpdateMonitoringPolicyRequest() + { + Name = "updated name", + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + + }; + var result = client.MonitoringPolicies.Update(request, mp.Id); + Config.waitMonitoringPolicyReady(mp.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + var monitoringPolicyResult = client.MonitoringPolicies.Show(result.Id); + //check CPU values + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Alert, request.Thresholds.Cpu.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Critical.Value, request.Thresholds.Cpu.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Alert, request.Thresholds.Cpu.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Cpu.Warning.Value, request.Thresholds.Cpu.Warning.Value); + //check RAM values + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Alert, request.Thresholds.Ram.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Critical.Value, request.Thresholds.Ram.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Alert, request.Thresholds.Ram.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Ram.Warning.Value, request.Thresholds.Ram.Warning.Value); + //check InternalPing values + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Alert, request.Thresholds.InternalPing.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Critical.Value, request.Thresholds.InternalPing.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Alert, request.Thresholds.InternalPing.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.InternalPing.Warning.Value, request.Thresholds.InternalPing.Warning.Value); + //check Transfer values + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Alert, request.Thresholds.Transfer.Critical.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Critical.Value, request.Thresholds.Transfer.Critical.Value); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Alert, request.Thresholds.Transfer.Warning.Alert); + Assert.AreEqual(monitoringPolicyResult.Thresholds.Transfer.Warning.Value, request.Thresholds.Transfer.Warning.Value); + } + + static public void DeleteMonitoringPolicy() + { + var result = client.MonitoringPolicies.Delete(mp.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if the monitoring policy is removed + var monitoringPoliciesResult = client.MonitoringPolicies.Get().Where(pn => pn.Name.Contains("netMP")).ToList(); + Assert.IsFalse(monitoringPoliciesResult.Any(mp => mp.Id == result.Id)); + } + } +} diff --git a/OneAndOne.UnitTests/OneAndOne.UnitTests.csproj b/OneAndOne.UnitTests/OneAndOne.UnitTests.csproj index b6a64cc..ec12e69 100644 --- a/OneAndOne.UnitTests/OneAndOne.UnitTests.csproj +++ b/OneAndOne.UnitTests/OneAndOne.UnitTests.csproj @@ -1,196 +1,202 @@ - - - - Debug - AnyCPU - {7901DF8A-16CA-4190-8B48-9FF898D81CA2} - Library - Properties - OneAndOne.UnitTests - OneAndOne.UnitTests - v4.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - {52b9c25d-dde8-4178-b1f2-c0f1cea0b8b3} - OneAndOne.Client - - - {4463871b-92d2-4070-9dc8-138aff00f2b1} - OneAndOne.POCO - - - - - - - - False - - - False - - - False - - - False - - - - - - + + + + Debug + AnyCPU + {7901DF8A-16CA-4190-8B48-9FF898D81CA2} + Library + Properties + OneAndOne.UnitTests + OneAndOne.UnitTests + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + {52b9c25d-dde8-4178-b1f2-c0f1cea0b8b3} + OneAndOne.Client + + + {4463871b-92d2-4070-9dc8-138aff00f2b1} + OneAndOne.POCO + + + + + + + + False + + + False + + + False + + + False + + + + + + + --> \ No newline at end of file diff --git a/OneAndOne.UnitTests/PrivateNetworks/PrivateNetwork.orderedtest b/OneAndOne.UnitTests/PrivateNetworks/PrivateNetwork.orderedtest index e50a797..da5a1d3 100644 --- a/OneAndOne.UnitTests/PrivateNetworks/PrivateNetwork.orderedtest +++ b/OneAndOne.UnitTests/PrivateNetworks/PrivateNetwork.orderedtest @@ -1,14 +1,8 @@ - - - - - - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/PrivateNetworks/PrivateNetworkServerstest.cs b/OneAndOne.UnitTests/PrivateNetworks/PrivateNetworkServerstest.cs deleted file mode 100644 index 1614f72..0000000 --- a/OneAndOne.UnitTests/PrivateNetworks/PrivateNetworkServerstest.cs +++ /dev/null @@ -1,136 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Response.Servers; -using OneAndOne.POCO.Response.SharedStorages; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace OneAndOne.UnitTests.PrivateNetworks -{ - [TestClass] - public class PrivateNetworkServerstest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetPrivateNetworksServers() - { - Random random = new Random(); - var privateNetworks = client.PrivateNetworks.Get(); - var privateNetwork = privateNetworks[random.Next(privateNetworks.Count - 1)]; - var result = client.PrivateNetworks.GetPrivateNetworkServers(privateNetwork.Id); - - Assert.IsNotNull(result); - } - - [TestMethod] - public void ShowPrivateNetworkServer() - { - Random random = new Random(); - var privateNetworks = client.PrivateNetworks.Get(); - var privateNetwork = privateNetworks[random.Next(privateNetworks.Count - 1)]; - foreach (var item in privateNetworks) - { - if (item.Servers != null && item.Servers.Count > 0) - { - privateNetwork = item; - break; - } - } - if (privateNetwork.Servers != null && privateNetwork.Servers.Count > 0) - { - var result = client.PrivateNetworks.ShowPrivateNetworkServer(privateNetwork.Id, privateNetwork.Servers[0].Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } - - [TestMethod] - public void AssignPrivateNetworkServer() - { - Random random = new Random(); - var privateNetworks = client.PrivateNetworks.Get(); - var privateNetwork = privateNetworks[0]; - var servers = client.Servers.Get(); - var randomServer = servers[0]; - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Snapshot == null) - { - randomServer = server; - break; - } - } - foreach (var item in privateNetworks) - { - if (!item.Servers.Any(itm => itm.Id == randomServer.Id)) - { - privateNetwork = item; - break; - } - } - if (servers.Count > 0) - { - var serverstoAdd = new System.Collections.Generic.List(); - serverstoAdd.Add(randomServer.Id); - if (privateNetwork.Servers.Any(itm => itm.Id == randomServer.Id)) - { - return; - } - var result = client.PrivateNetworks.CreatePrivateNetworkServers( - new POCO.Requests.PrivateNetworks.AttachPrivateNetworkServersRequest() - { - Servers = serverstoAdd - }, privateNetwork.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the private network is assigned to the server - var serverResult = client.Servers.Show(randomServer.Id); - Assert.IsTrue(serverResult.PrivateNetworks.Any(pn => pn.Id == result.Id)); - } - } - - [TestMethod] - public void DeletePrivateNetworksServer() - { - Random random = new Random(); - var privateNetworks = client.PrivateNetworks.Get().Where(pn => pn.Name.Contains("testPrivateNetwork")).ToList(); - var privateNetwork = privateNetworks[random.Next(privateNetworks.Count - 1)]; - int indexOfserver = 0; - foreach (var item in privateNetworks) - { - if (item.Servers != null && item.Servers.Count > 0) - { - foreach (var server in item.Servers) - { - Thread.Sleep(1000); - var fromApi = client.Servers.Show(server.Id); - if (fromApi.Status.State == ServerState.POWERED_OFF || (!fromApi.Image.Name.Contains("ub") && !fromApi.Image.Name.Contains("centos"))) - { - privateNetwork = item; - indexOfserver = item.Servers.IndexOf(server); - break; - } - } - } - return; - } - if (privateNetwork != null && privateNetwork.Servers != null && privateNetwork.Servers.Count > 0) - { - var result = client.PrivateNetworks.DeletePrivateNetworksServer(privateNetwork.Id, privateNetwork.Servers[indexOfserver].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the private network is unassigned from the server - var serverResult = client.Servers.Show(privateNetwork.Servers[0].Id); - Assert.IsFalse(serverResult.PrivateNetworks.Any(pn => pn.Id == result.Id)); - } - } - } -} diff --git a/OneAndOne.UnitTests/PrivateNetworks/PrivateNetworkTest.cs b/OneAndOne.UnitTests/PrivateNetworks/PrivateNetworkTest.cs index 114b848..85f98c5 100644 --- a/OneAndOne.UnitTests/PrivateNetworks/PrivateNetworkTest.cs +++ b/OneAndOne.UnitTests/PrivateNetworks/PrivateNetworkTest.cs @@ -1,169 +1,176 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Response.Servers; -using OneAndOne.POCO; -using System.Threading; - -namespace OneAndOne.UnitTests.PrivateNetworks -{ - [TestClass] - public class PrivateNetworkTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetPrivateNetworks() - { - var result = client.PrivateNetworks.Get(); - - Assert.IsNotNull(result); - } - - [TestMethod] - public void ShowPrivateNetwork() - { - Random random = new Random(); - var privateNetworks = client.PrivateNetworks.Get(); - var privateNetwork = privateNetworks[random.Next(privateNetworks.Count - 1)]; - - var result = client.PrivateNetworks.Show(privateNetwork.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void CreatePrivateNetwork() - { - var privateNetworks = client.PrivateNetworks.Get(); - //we are not allowed to create more than two by the account - if (privateNetworks.Count == 2) - return; - Random random = new Random(); - string networkAddress = "192.168.1.0"; - string subnetMask = "255.255.255.0"; - var result = client.PrivateNetworks.Create(new POCO.Requests.PrivateNetworks.CreatePrivateNetworkRequest() - { - Name = random.Next(1000, 9999) + "testPrivateNetwork", - Description = "test description", - NetworkAddress = networkAddress, - SubnetMask = subnetMask - }); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the network was created with correct values - var privateNetworkResult = client.PrivateNetworks.Show(result.Id); - Assert.IsNotNull(privateNetworkResult.Id); - Assert.AreEqual(result.Name, privateNetworkResult.Name); - Assert.AreEqual(result.NetworkAddress, privateNetworkResult.NetworkAddress); - Assert.AreEqual(result.SubnetMask, privateNetworkResult.SubnetMask); - - } - - [TestMethod] - public void UpdatePrivateNetwork() - { - Random random = new Random(); - string networkAddress = "192.168.1.0"; - string subnetMask = "255.255.255.0"; - var privateNetworks = client.PrivateNetworks.Get().Where(pn => pn.Name.Contains("testPrivateNetwork")).ToList(); - var privateNetwork = privateNetworks[random.Next(privateNetworks.Count - 1)]; - var result = client.PrivateNetworks.Update(new POCO.Requests.PrivateNetworks.UpdatePrivateNetworkRequest() - { - Name = "updated" + privateNetwork.Name, - NetworkAddress = networkAddress, - SubnetMask = subnetMask, - }, privateNetwork.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the network was updated with correct values - var privateNetworkResult = client.PrivateNetworks.Show(result.Id); - Assert.IsNotNull(privateNetworkResult.Id); - Assert.AreEqual(result.Name, privateNetworkResult.Name); - Assert.AreEqual(result.NetworkAddress, privateNetworkResult.NetworkAddress); - Assert.AreEqual(result.SubnetMask, privateNetworkResult.SubnetMask); - } - - [TestMethod] - public void DeletePrivateNetwork() - { - Random random = new Random(); - var privateNetworks = client.PrivateNetworks.Get().Where(pn => pn.Name.Contains("testPrivateNetwork")).ToList(); - var privateNetwork = privateNetworks[0]; - foreach (var item in privateNetworks) - { - if (item.State != "ACTIVE") - { return; } - privateNetwork = item; - foreach (var server in item.Servers) - { - var fromApi = client.Servers.Show(server.Id); - if (fromApi.Status.State != ServerState.POWERED_OFF) - { - client.Servers.UpdateStatus(new POCO.Requests.Servers.UpdateStatusRequest() - { - Action = ServerAction.POWER_OFF, - Method = ServerActionMethod.SOFTWARE - }, fromApi.Id); - - var status = client.Servers.GetStatus(fromApi.Id); - while (status.State != ServerState.POWERED_OFF || status.Percent < 50) - { - Thread.Sleep(1000); - status = client.Servers.GetStatus(fromApi.Id); - } - break; - } - else - { - break; - - } - } - } - var result = client.PrivateNetworks.Delete(privateNetwork.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the network was removed - var privateNetworkResult = client.PrivateNetworks.Get(); - var exists = privateNetworkResult.FirstOrDefault(pn => pn.Id == privateNetwork.Id); - if (exists != null && exists.State == "REMOVING") - return; - Assert.IsFalse(privateNetworkResult.Any(pn => pn.Id == privateNetwork.Id)); - } - - [TestMethod] - public void DeleteAllTestPrivateNetworks() - { - Random random = new Random(); - var privateNetworks = client.PrivateNetworks.Get().Where(pn => pn.Name.Contains("testPrivateNetwork")).ToList(); - foreach (var item in privateNetworks) - { - foreach (var server in item.Servers) - { - var fromApi = client.Servers.Show(server.Id); - if (fromApi.Status.State != ServerState.POWERED_OFF) - { - client.Servers.UpdateStatus(new POCO.Requests.Servers.UpdateStatusRequest() - { - Action = ServerAction.POWER_OFF, - Method = ServerActionMethod.SOFTWARE - }, fromApi.Id); - - var status = client.Servers.GetStatus(fromApi.Id); - while (status == null || status.State != ServerState.POWERED_OFF) - { - Thread.Sleep(1000); - status = client.Servers.GetStatus(fromApi.Id); - } - } - } - var result = client.PrivateNetworks.Delete(item.Id); - } - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Response.Servers; +using OneAndOne.POCO; +using System.Threading; +using OneAndOne.POCO.Response.PrivateNetworks; +using System.Collections.Generic; + +namespace OneAndOne.UnitTests.PrivateNetworks +{ + [TestClass] + public class PrivateNetworkTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static PrivateNetworksResponse privateNetwork = null; + static List serverIds = new List(); + + [ClassInitialize] + static public void TestInit(TestContext context) + { + string networkAddress = "192.168.1.0"; + string subnetMask = "255.255.255.0"; + var datacenters = client.DataCenters.Get(); + var dc = datacenters.FirstOrDefault(); + var privateNetworks = client.PrivateNetworks.Get(); + + //creating three servers, Private networks requires 3 servers to be created + for (int i = 0; i < 3; i++) + { + Thread.Sleep(5000); + var server = Config.CreateTestServer("Private Network test .net111 " + i, false); + Config.waitServerReady(server.Id); + serverIds.Add(server.Id); + } + + var result = client.PrivateNetworks.Create(new POCO.Requests.PrivateNetworks.CreatePrivateNetworkRequest() + { + Name = "testPrivateNetwork .net", + Description = "test description", + NetworkAddress = networkAddress, + SubnetMask = subnetMask, + DatacenterId = dc.Id + }); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + Config.waitPrivateNetworkReady(result.Id); + //check if the network was created with correct values + var privateNetworkResult = client.PrivateNetworks.Show(result.Id); + privateNetwork = privateNetworkResult; + Assert.IsNotNull(privateNetworkResult.Id); + Assert.AreEqual(result.Name, privateNetworkResult.Name); + Assert.AreEqual(result.NetworkAddress, privateNetworkResult.NetworkAddress); + Assert.AreEqual(result.SubnetMask, privateNetworkResult.SubnetMask); + + //add a server to the private network + var serverstoAdd = new System.Collections.Generic.List(); + serverstoAdd.Add(serverIds[0]); + var addedServer = client.PrivateNetworks.CreatePrivateNetworkServers( + new POCO.Requests.PrivateNetworks.AttachPrivateNetworkServersRequest() + { + Servers = serverstoAdd + }, privateNetwork.Id); + + Assert.IsNotNull(addedServer); + Assert.IsNotNull(addedServer.Id); + Config.waitPrivateNetworkReady(privateNetwork.Id); + //check if the private network is assigned to the server + var serverResult = client.Servers.Show(serverIds[0]); + Assert.IsTrue(serverResult.PrivateNetworks.Any(pn => pn.Id == addedServer.Id)); + } + + [ClassCleanup] + static public void TestClean() + { + if (privateNetwork != null) + { + Config.waitPrivateNetworkReady(privateNetwork.Id); + Config.waitServerReady(serverIds[0]); + var result = client.PrivateNetworks.DeletePrivateNetworksServer(privateNetwork.Id, serverIds[0]); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + Config.waitPrivateNetworkReady(privateNetwork.Id); + //check if the private network is unassigned from the server + var serverResult = client.Servers.Show(serverIds[0]); + Assert.IsTrue(serverResult.PrivateNetworks == null); + + Config.waitPrivateNetworkReady(privateNetwork.Id); + + foreach (string id in serverIds) + { + Config.waitServerReady(id); + client.Servers.Delete(id, false); + } + + Config.waitPrivateNetworkReady(privateNetwork.Id); + //remove the private network + var removed = client.PrivateNetworks.Delete(privateNetwork.Id); + + Assert.IsNotNull(removed); + Assert.IsNotNull(removed.Id); + //check if the network was removed + var privateNetworkResult = client.PrivateNetworks.Get(); + var exists = privateNetworkResult.FirstOrDefault(pn => pn.Id == privateNetwork.Id); + if (exists != null && exists.State == "REMOVING") + return; + Assert.IsFalse(privateNetworkResult.Any(pn => pn.Id == privateNetwork.Id)); + } + + } + + + [TestMethod] + public void GetPrivateNetworks() + { + var result = client.PrivateNetworks.Get(); + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowPrivateNetwork() + { + var result = client.PrivateNetworks.Show(privateNetwork.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void UpdatePrivateNetwork() + { + Random random = new Random(); + string networkAddress = "192.168.1.0"; + string subnetMask = "255.255.255.0"; + var result = client.PrivateNetworks.Update(new POCO.Requests.PrivateNetworks.UpdatePrivateNetworkRequest() + { + Name = "updated" + privateNetwork.Name, + NetworkAddress = networkAddress, + SubnetMask = subnetMask, + }, privateNetwork.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + Config.waitPrivateNetworkReady(privateNetwork.Id); + //check if the network was updated with correct values + var privateNetworkResult = client.PrivateNetworks.Show(result.Id); + Assert.IsNotNull(privateNetworkResult.Id); + Assert.AreEqual(result.Name, privateNetworkResult.Name); + Assert.AreEqual(result.NetworkAddress, privateNetworkResult.NetworkAddress); + Assert.AreEqual(result.SubnetMask, privateNetworkResult.SubnetMask); + } + + #region private networks servers + [TestMethod] + public void GetPrivateNetworksServers() + { + var result = client.PrivateNetworks.GetPrivateNetworkServers(privateNetwork.Id); + Assert.IsNotNull(result); + } + + [TestMethod] + public void ShowPrivateNetworkServer() + { + var updatedPN = client.PrivateNetworks.Show(privateNetwork.Id); + var result = client.PrivateNetworks.ShowPrivateNetworkServer(privateNetwork.Id, updatedPN.Servers[0].Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + #endregion + + } +} diff --git a/OneAndOne.UnitTests/PublicIPs/PublicIPs.orderedtest b/OneAndOne.UnitTests/PublicIPs/PublicIPs.orderedtest index 59ae71a..e138f2f 100644 --- a/OneAndOne.UnitTests/PublicIPs/PublicIPs.orderedtest +++ b/OneAndOne.UnitTests/PublicIPs/PublicIPs.orderedtest @@ -1,10 +1,8 @@ - - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/PublicIPs/PublicIPsTest.cs b/OneAndOne.UnitTests/PublicIPs/PublicIPsTest.cs index 2532f4d..e5f6f03 100644 --- a/OneAndOne.UnitTests/PublicIPs/PublicIPsTest.cs +++ b/OneAndOne.UnitTests/PublicIPs/PublicIPsTest.cs @@ -3,54 +3,64 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OneAndOne.Client; using OneAndOne.POCO.Requests.Servers; +using OneAndOne.POCO.Response.PublicIPs; namespace OneAndOne.UnitTests.PublicIPs { [TestClass] public class PublicIPsTest { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetPublicIPs() + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static PublicIPsResponse ip = null; + + + [ClassInitialize] + static public void TestInit(TestContext context) { - var result = client.PublicIPs.Get(); + var datacenters = client.DataCenters.Get(); + var dc = datacenters.FirstOrDefault(); + Random random = new Random(); + var randomValue = random.Next(10, 99) + "netTest.net"; + var result = client.PublicIPs.Create(new POCO.Requests.PublicIPs.CreatePublicIPRequest() + { + ReverseDns = randomValue, + Type = IPType.IPV4 + }); + ip = result; Assert.IsNotNull(result); - Assert.IsTrue(result.Count > 0); + Assert.IsNotNull(result.Id); + //check if the public ip was created + var ipResult = client.PublicIPs.Show(result.Id); + Assert.IsNotNull(ipResult.Id); + Assert.AreEqual(ipResult.ReverseDns, randomValue); } - [TestMethod] - public void ShowPublicIP() + [ClassCleanup] + static public void TestClean() { - Random random = new Random(); - - var publicIps = client.PublicIPs.Get(); - var publicIp = publicIps[random.Next(publicIps.Count - 1)]; + if (ip != null) + { + DeletePublicIP(); + } + } - var result = client.PublicIPs.Show(publicIp.Id); + [TestMethod] + public void GetPublicIPs() + { + var result = client.PublicIPs.Get(); Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); + Assert.IsTrue(result.Count > 0); } [TestMethod] - public void CreatePublicIP() + public void ShowPublicIP() { - Random random = new Random(); - var randomValue = random.Next(10, 99) + "netTest.net"; - var result = client.PublicIPs.Create(new POCO.Requests.PublicIPs.CreatePublicIPRequest() - { - ReverseDns = randomValue, - Type = IPType.IPV4 - }); + var result = client.PublicIPs.Show(ip.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); - //check if the public ip was created - var ipResult = client.PublicIPs.Show(result.Id); - Assert.IsNotNull(ipResult.Id); - Assert.AreEqual(ipResult.ReverseDns, randomValue); - } [TestMethod] @@ -58,9 +68,7 @@ public void UpdatePublicIP() { Random random = new Random(); var randomValue = random.Next(10, 99) + "updateTest.net"; - var publicIps = client.PublicIPs.Get().Where(str => str.ReverseDns != null && str.ReverseDns.Contains("netTest")).ToList(); - var publicIp = publicIps[random.Next(publicIps.Count - 1)]; - var result = client.PublicIPs.Update(randomValue, publicIp.Id); + var result = client.PublicIPs.Update(randomValue, ip.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); @@ -70,29 +78,12 @@ public void UpdatePublicIP() Assert.AreEqual(ipResult.ReverseDns, randomValue); } - [TestMethod] - public void DeletePublicIP() + static public void DeletePublicIP() { - Random random = new Random(); - var publicIps = client.PublicIPs.Get().Where(str => str.ReverseDns != null && (str.ReverseDns.Contains("netTest") || str.ReverseDns.Contains("updateTest"))).ToList(); - var publicIp = publicIps[random.Next(publicIps.Count - 1)]; - var result = client.PublicIPs.Delete(publicIp.Id); + var result = client.PublicIPs.Delete(ip.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); } - - [TestMethod] - public void DeleteAllTESTPublicIP() - { - Random random = new Random(); - var publicIps = client.PublicIPs.Get().Where(str => str.ReverseDns != null && (str.ReverseDns.Contains("netTest") || str.ReverseDns.Contains("updateTest"))).ToList(); - foreach (var item in publicIps) - { - var result = client.PublicIPs.Delete(item.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - } } } diff --git a/OneAndOne.UnitTests/Roles/RolesTests.cs b/OneAndOne.UnitTests/Roles/RolesTests.cs new file mode 100644 index 0000000..da314f1 --- /dev/null +++ b/OneAndOne.UnitTests/Roles/RolesTests.cs @@ -0,0 +1,136 @@ +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Response.Roles; +using OneAndOne.POCO.Response.Users; + +namespace OneAndOne.UnitTests.Roles +{ + [TestClass] + public class RolesTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static RoleResponse role = null; + static RoleResponse clone = null; + static UserResponse user = null; + + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var result = client.Roles.Create(".net role test"); + role = result; + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + + user = client.Users.Create(new POCO.Requests.Users.CreateUserRequest() + { + Name = "roletestuser", + Password = "Random123!", + Description = "description", + }); + + //add user to role + client.Roles.CreateRoleUsers(new System.Collections.Generic.List { { user.Id } }, role.Id); + } + + [ClassCleanup] + static public void TestClean() + { + var result = client.Roles.Delete(role.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + + if (user != null) + { + client.Users.Delete(user.Id); + } + + if (clone != null) + { + client.Roles.Delete(clone.Id); + } + } + + [TestMethod] + public void GetRoles() + { + var result = client.Roles.Get(); + + Assert.IsNotNull(result); + Assert.IsTrue(result.Count > 0); + } + + [TestMethod] + public void ShowRoles() + { + var result = client.Roles.Show(role.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void GetRolesPermissions() + { + var result = client.Roles.GetPermissions(role.Id); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void GetRolesUsers() + { + var result = client.Roles.GetRoleUsers(role.Id); + + Assert.IsTrue(result.Count > 0); + + //get single user info + var userInfo = client.Roles.ShowRoleUser(role.Id, user.Id); + + Assert.AreEqual(userInfo.Id, user.Id); + + //remove user role + var removed = client.Roles.DeleteRoleUser(role.Id, user.Id); + } + + [TestMethod] + public void CloneRoleUser() + { + var cloneName = "i am a clone of " + role.Name; + clone = client.Roles.CreateRoleClone(cloneName, role.Id); + Assert.AreEqual(clone.Name, cloneName); + } + + [TestMethod] + public void UpdateRoles() + { + var result = client.Roles.Update("updated name", "delete me", POCO.Requests.Users.UserState.ACTIVE, role.Id); + + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void UpdateRolesPermissions() + { + var result = client.Roles.UpdatePermissions(new Permissions + { + Servers = new POCO.Response.Roles.Servers + { + Show = true, + SetName = false, + Shutdown = true + } + }, role.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + Assert.IsTrue(result.Permissions.Servers.Show); + Assert.IsFalse(result.Permissions.Servers.SetName); + Assert.IsTrue(result.Permissions.Servers.Shutdown); + } + } +} diff --git a/OneAndOne.UnitTests/ServerAppliances/ServerAppliancesTest.cs b/OneAndOne.UnitTests/ServerAppliances/ServerAppliancesTest.cs index 720b3df..f2650b6 100644 --- a/OneAndOne.UnitTests/ServerAppliances/ServerAppliancesTest.cs +++ b/OneAndOne.UnitTests/ServerAppliances/ServerAppliancesTest.cs @@ -7,10 +7,10 @@ namespace OneAndOne.UnitTests.ServerAppliances [TestClass] public class ServerAppliancesTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); [TestMethod] public void GetServerAppliances() - { + { var result = client.ServerAppliances.Get(); Assert.IsNotNull(result); diff --git a/OneAndOne.UnitTests/Servers/ServerHardware.orderedtest b/OneAndOne.UnitTests/Servers/ServerHardware.orderedtest index 5cae04a..f6dc7b3 100644 --- a/OneAndOne.UnitTests/Servers/ServerHardware.orderedtest +++ b/OneAndOne.UnitTests/Servers/ServerHardware.orderedtest @@ -1,12 +1,10 @@ - - - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/Servers/ServerHardwareTest.cs b/OneAndOne.UnitTests/Servers/ServerHardwareTest.cs index cb357f9..a71da5d 100644 --- a/OneAndOne.UnitTests/Servers/ServerHardwareTest.cs +++ b/OneAndOne.UnitTests/Servers/ServerHardwareTest.cs @@ -1,305 +1,195 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using System.Threading; -using OneAndOne.POCO.Response.Servers; - -namespace OneAndOne.UnitTests -{ - [TestClass] - public class ServerHardwareTest - { - - static OneAndOneClient client = OneAndOneClient.Instance(); - - [TestMethod] - public void GetServerHardWare() - { - var servers = client.Servers.Get().FirstOrDefault(); - var result = client.ServersHardware.Show(servers.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.CoresPerProcessor); - } - - [TestMethod] - public void UpdateServerHardWare() - { - var random = new Random(); - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest")).ToList(); - var server = servers[random.Next(servers.Count - 1)]; - //setup initial values for update - int CoresPerProcessor = 4; - float Ram = 4; - int Vcore = 4; - //search for an appropriate server for udpating - foreach (var item in servers) - { - server = client.Servers.Show(item.Id); - //cannot update servers with snapshots - //cannot hot update servers with linux system installed - if (server.Status.State == ServerState.DEPLOYING || server.Snapshot != null || server.Image.Name.Contains("ub") || server.Image.Name.Contains("centos")) - { - continue; - } - //check if server current values are less than the updated values for hot update - if (server.Hardware.CoresPerProcessor < CoresPerProcessor && server.Hardware.Ram < Ram && server.Hardware.Vcore < Vcore) - { - server = item; - break; - } - //else increase the already existing values - else - { - CoresPerProcessor = server.Hardware.CoresPerProcessor + 1; - Ram = server.Hardware.Ram + (float)2.0; - Vcore = server.Hardware.Vcore + 2; - break; - } - } - //if the updated values exceed any of the limits stop the update - CoresPerProcessor = server.Hardware.CoresPerProcessor + 1; - Ram = server.Hardware.Ram + (float)2.0; - Vcore = server.Hardware.Vcore + 2; - if (CoresPerProcessor > 16 || Ram > 128 || Vcore > 16 || CoresPerProcessor > Vcore) - { - return; - } - if (server.Status.State != ServerState.DEPLOYING && server.Snapshot == null && !server.Image.Name.Contains("ub") && !server.Image.Name.Contains("centos")) - { - - var request = new POCO.Requests.Servers.UpdateHardwareRequest() - { - CoresPerProcessor = server.Hardware.Vcore > 1 ? server.Hardware.Vcore / 2 : 1, - Ram = (int)Ram, - Vcore = server.Hardware.Vcore - }; - - CoresPerProcessor = request.CoresPerProcessor; - Vcore = request.Vcore; - Ram = request.Ram; - var result = client.ServersHardware.Update(request, server.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Hardware.CoresPerProcessor); - //give the server time to update - var resultserver = client.Servers.Show(result.Id); - while (resultserver.Status.Percent > 0) - { - Thread.Sleep(5000); - resultserver = client.Servers.Show(result.Id); - } - //check if the values are updated as expected - Assert.AreEqual(resultserver.Hardware.CoresPerProcessor, CoresPerProcessor); - Assert.AreEqual(resultserver.Hardware.Ram, Ram); - Assert.AreEqual(resultserver.Hardware.Vcore, Vcore); - } - } - - [TestMethod] - public void GetServerHardDrives() - { - var server = client.Servers.Get().FirstOrDefault(); - var result = client.ServerHdds.Get(server.Id); - - Assert.IsNotNull(result); - Assert.IsTrue(result.Count > 0); - } - - [TestMethod] - public void ShowHardDrives() - { - var random = new Random(); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - - var result = client.ServerHdds.Show(server.Id, server.Hardware.Hdds[random.Next(server.Hardware.Hdds.Count - 1)].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void AddServerHardDrives() - { - var random = new Random(); - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest") || ser.Name.Contains("Updated")).ToList(); - var server = servers[random.Next(servers.Count - 1)]; - int prevoiousHDDCounts = 0; - foreach (var item in servers) - { - Thread.Sleep(1000); - server = client.Servers.Show(item.Id); - if (server.Snapshot == null) - { - break; - } - } - if (server.Hardware.Hdds.Count < 8 && server.Snapshot == null && server.Status.State != ServerState.DEPLOYING) - { - prevoiousHDDCounts = server.Hardware.Hdds.Count; - var result = client.ServerHdds.Create(new POCO.Requests.Servers.AddHddRequest() - { - Hdds = new System.Collections.Generic.List() - { - { new POCO.Requests.Servers.HddRequest() - {Size=20,IsMain=false}}, - {new POCO.Requests.Servers.HddRequest() - {Size=30,IsMain=false} - }} - }, server.Id); - Thread.Sleep(8000); - var resultserver = client.Servers.Show(result.Id); - while (resultserver.Hardware.Hdds.Count == prevoiousHDDCounts) - { - Thread.Sleep(1000); - resultserver = client.Servers.Show(result.Id); - } - Assert.IsNotNull(result); - Assert.IsTrue(result.Hardware.Hdds.Count > 0); - //check if the number of HDD has increased - Assert.IsTrue(resultserver.Hardware.Hdds.Count > prevoiousHDDCounts); - } - } - - [TestMethod] - public void UpdateHardDrives() - { - var random = new Random(); - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest") || ser.Name.Contains("Updated")).ToList(); ; - var server = servers[random.Next(servers.Count - 1)]; - var randomHdd = server.Hardware.Hdds[random.Next(server.Hardware.Hdds.Count - 1)]; - int previousSize = randomHdd.Size; - if (server.Status.State == ServerState.REMOVING || server.Status.State == ServerState.DEPLOYING - || server.Status.State == ServerState.CONFIGURING || server.Status.State == ServerState.CONFIGURING) - { - return; - } - int updatedSize = 20; - if (randomHdd.Size < 100) - updatedSize = 120; - else - { - updatedSize = randomHdd.Size + 20; - } - if (randomHdd.Size == 2000 || randomHdd.Size > updatedSize) - { - return; - } - var result = client.ServerHdds.Update(new POCO.Requests.Servers.UpdateHddRequest() - { - Size = updatedSize - }, server.Id, randomHdd.Id); - - Assert.IsNotNull(result); - //check if the number of HDD size increased - Assert.IsTrue(updatedSize > previousSize); - } - - [TestMethod] - public void DeleteHardDrive() - { - var random = new Random(); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - var randomHdd = server.Hardware.Hdds[random.Next(server.Hardware.Hdds.Count - 1)]; - foreach (var item in servers) - { - Thread.Sleep(1000); - server = client.Servers.Show(item.Id); - if (server.Hardware.Hdds.Count > 1 && server.Status.State != ServerState.REMOVING && server.Snapshot == null) - { - server = item; - break; - } - } - foreach (var item in server.Hardware.Hdds) - { - if (!item.IsMain) - { - randomHdd = item; - break; - } - } - - if (server.Hardware.Hdds.Count > 1 && !randomHdd.IsMain) - { - string previousHddId = randomHdd.Id; - var result = client.ServerHdds.Delete(server.Id, randomHdd.Id); - Assert.IsNotNull(result); - //check if the number of HDD number decreased - var resultserver = client.Servers.Show(result.Id); - while (resultserver.Hardware.Hdds.Any(Hdd => Hdd.Id == previousHddId)) - { - Thread.Sleep(1000); - resultserver = client.Servers.Show(result.Id); - } - Thread.Sleep(1000); - resultserver = client.Servers.Show(result.Id); - Assert.IsFalse(resultserver.Hardware.Hdds.Any(Hdd => Hdd.Id == previousHddId)); - } - - } - - [TestMethod] - public void GetDVD() - { - var random = new Random(); - var servers = client.Servers.Get(); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.DVD != null) - { - var result = client.ServersHardware.ShowDVD(server.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - break; - } - } - } - - [TestMethod] - public void UpdateDVD() - { - var random = new Random(); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - var dvd = client.DVDs.Get(); - while (server.Status.State == ServerState.REMOVING || server.Status.State == ServerState.DEPLOYING - || server.Status.State == ServerState.CONFIGURING || server.Status.State == ServerState.CONFIGURING) - { - server = servers[random.Next(servers.Count - 1)]; - } - var result = client.ServersHardware.UpdateDVD(server.Id, dvd[0].Id); - Assert.IsNotNull(result); - } - - [TestMethod] - public void DeleteDVD() - { - var random = new Random(); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - while (server.Status.State == ServerState.REMOVING || server.Status.State == ServerState.DEPLOYING - || server.Status.State == ServerState.CONFIGURING || server.Status.State == ServerState.CONFIGURING) - { - server = servers[random.Next(servers.Count - 1)]; - } - var result = client.ServersHardware.DeleteDVD(server.Id); - //give the server time to update - var resultserver = client.ServersHardware.ShowDVD(result.Id); - while (resultserver != null) - { - Thread.Sleep(5000); - resultserver = client.ServersHardware.ShowDVD(result.Id); - } - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - Assert.IsNull(resultserver); - - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using System.Threading; +using OneAndOne.POCO.Response.Servers; +using System.Collections.Generic; +using OneAndOne.POCO; + +namespace OneAndOne.UnitTests +{ + [TestClass] + public class ServerHardwareTest + { + + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static ServerResponse server = null; + static Hdd hddToUpdate = null; + + [ClassInitialize] + static public void ServerHardwareInit(TestContext context) + { + int vcore = 4; + int CoresPerProcessor = 2; + var appliances = client.ServerAppliances.Get(null, null, null, "ubuntu", null); + POCO.Response.ServerAppliances.ServerAppliancesResponse appliance = null; + if (appliances == null || appliances.Count() == 0) + { + appliance = client.ServerAppliances.Get().FirstOrDefault(); + } + else + { + appliance = appliances.FirstOrDefault(); + } + var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() + { + ApplianceId = appliance != null ? appliance.Id : null, + Name = "server hardware test .net", + Description = "desc", + Hardware = new POCO.Requests.Servers.HardwareRequest() + { + CoresPerProcessor = CoresPerProcessor, + Hdds = new List() + { + {new POCO.Requests.Servers.HddRequest() + { + IsMain=true, + Size=20, + }}, + {new POCO.Requests.Servers.HddRequest() + { + IsMain=false, + Size=20, + }} + }, + Ram = 4, + Vcore = vcore + }, + PowerOn = true, + }); + + Config.waitServerReady(result.Id); + server = client.Servers.Show(result.Id); + } + + [ClassCleanup] + static public void ServerHardwareClean() + { + Config.waitServerReady(server.Id); + client.Servers.Delete(server.Id, false); + } + + [TestMethod] + public void GetServerHardWare() + { + var result = client.ServersHardware.Show(server.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.CoresPerProcessor); + } + + [TestMethod] + public void UpdateServerHardWare() + { + Config.waitServerReady(server.Id); + //setup initial values for update + float Ram = 8; + var request = new POCO.Requests.Servers.UpdateHardwareRequest() + { + Ram = (int)Ram, + }; + + Ram = request.Ram.Value; + var result = client.ServersHardware.Update(request, server.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Hardware.CoresPerProcessor); + Config.waitServerReady(server.Id); + var resultserver = client.Servers.Show(result.Id); + //check if the values are updated as expected + Assert.AreEqual(resultserver.Hardware.Ram, Ram); + } + + [TestMethod] + public void GetServerHardDrives() + { + var result = client.ServerHdds.Get(server.Id); + + Assert.IsNotNull(result); + Assert.IsTrue(result.Count > 0); + } + + [TestMethod] + public void ShowHardDrives() + { + var result = client.ServerHdds.Show(server.Id, server.Hardware.Hdds[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void AddServerHardDrives() + { + Config.waitServerReady(server.Id); + + int prevoiousHDDCounts = 0; + prevoiousHDDCounts = server.Hardware.Hdds.Count; + var result = client.ServerHdds.Create(new POCO.Requests.Servers.AddHddRequest() + { + Hdds = new System.Collections.Generic.List() + { + { new POCO.Requests.Servers.HddRequest() + {Size=20,IsMain=false}}, + } + }, server.Id); + Config.waitServerReady(server.Id); + var resultserver = client.Servers.Show(result.Id); + hddToUpdate = resultserver.Hardware.Hdds.Where(hdd => !hdd.IsMain).FirstOrDefault(); + Assert.IsNotNull(result); + Assert.IsTrue(result.Hardware.Hdds.Count > 0); + + var updateResult = client.ServerHdds.Update(new POCO.Requests.Servers.UpdateHddRequest() + { + Size = hddToUpdate.Size + 10 + }, server.Id, hddToUpdate.Id); + + Config.waitServerReady(server.Id); + + Assert.IsNotNull(updateResult); + + //delete HDD + DeleteHardDrive(); + } + + public void DeleteHardDrive() + { + var hdds = client.ServerHdds.Get(server.Id); + if (hdds.Count > 1) + { + var result = client.ServerHdds.Delete(server.Id, hdds.Where(hdd => !hdd.IsMain).FirstOrDefault().Id); + Assert.IsNotNull(result); + } + } + + [TestMethod] + public void GetDVD() + { + var serverDvd = client.Servers.Show(server.Id); + if (serverDvd.DVD != null) + { + var result = client.ServersHardware.ShowDVD(serverDvd.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + } + + [TestMethod] + public void UpdateDVD() + { + var dvd = client.DVDs.Get(null, null, null, "ubuntu", null); + Config.waitServerReady(server.Id); + var result = client.ServersHardware.UpdateDVD(server.Id, dvd[0].Id); + Assert.IsNotNull(result); + } + + [TestMethod] + public void DeleteDVD() + { + var result = client.ServersHardware.DeleteDVD(server.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + } +} diff --git a/OneAndOne.UnitTests/Servers/ServerIPs.orderedtest b/OneAndOne.UnitTests/Servers/ServerIPs.orderedtest index e3c4b21..cacb77a 100644 --- a/OneAndOne.UnitTests/Servers/ServerIPs.orderedtest +++ b/OneAndOne.UnitTests/Servers/ServerIPs.orderedtest @@ -1,15 +1,12 @@ - - - - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/Servers/ServerImagesTest.cs b/OneAndOne.UnitTests/Servers/ServerImagesTest.cs index d98cb80..e207f1d 100644 --- a/OneAndOne.UnitTests/Servers/ServerImagesTest.cs +++ b/OneAndOne.UnitTests/Servers/ServerImagesTest.cs @@ -2,20 +2,38 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OneAndOne.Client; using OneAndOne.POCO.Response.Servers; +using System.Linq; +using System.Collections.Generic; namespace OneAndOne.UnitTests { [TestClass] public class ServerImagesTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static ServerResponse server = null; Random random = new Random(); + + [ClassInitialize] + static public void ServerInit(TestContext context) + { + server = Config.CreateTestServer("Server image test .net"); + Config.waitServerReady(server.Id); + server = client.Servers.Show(server.Id); + } + + [ClassCleanup] + static public void ServerClean() + { + Config.waitServerReady(server.Id); + client.Servers.Delete(server.Id, false); + } + + [TestMethod] public void GetImage() { - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; var image = client.ServerImage.Show(server.Id); Assert.IsNotNull(image); @@ -24,23 +42,16 @@ public void GetImage() [TestMethod] public void UpdateImage() { + Config.waitServerReady(server.Id); string randomName = "Pass!" + random.Next(1000, 3000); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - if (server.Status.State != ServerState.DEPLOYING || server.Status.State != ServerState.REMOVING) + var result = client.ServerImage.Update(new POCO.Requests.Servers.UpdateServerImageRequest() { - var result = client.ServerImage.Update(new POCO.Requests.Servers.UpdateServerImageRequest() - { - Id = server.Image.Id, - Password = randomName - - }, server.Id); - - Assert.IsNotNull(result); - //check if the image is deploying - Assert.IsTrue(result.Status.Percent > 0); - Assert.IsTrue(result.Status.State == ServerState.DEPLOYING); - } + Id = server.Image.Id, + Password = randomName + + }, server.Id); + + Assert.IsNotNull(result); } } } diff --git a/OneAndOne.UnitTests/Servers/ServerIpsTest.cs b/OneAndOne.UnitTests/Servers/ServerIpsTest.cs index 12f8b58..65a6d82 100644 --- a/OneAndOne.UnitTests/Servers/ServerIpsTest.cs +++ b/OneAndOne.UnitTests/Servers/ServerIpsTest.cs @@ -1,272 +1,294 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Requests.Servers; -using OneAndOne.POCO.Response; -using OneAndOne.POCO.Response.Servers; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace OneAndOne.UnitTests -{ - [TestClass] - public class ServerIpsTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - Random random = new Random(); - - [TestMethod] - public void GetServerIPList() - { - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - if (server.Status.State == ServerState.DEPLOYING || server.Status.State == ServerState.REMOVING) - { - return; - } - var result = client.ServerIps.Get(server.Id); - - Assert.IsNotNull(result); - Assert.IsTrue(result.Count > 0); - } - - [TestMethod] - public void AddServerIP() - { - var servers = client.Servers.Get(null, null, null, "ServerTest"); - var server = servers[random.Next(servers.Count - 1)]; - int previousIpCount = 0; - foreach (var item in servers) - { - if (item.Status.State == ServerState.DEPLOYING || item.Status.State == ServerState.REMOVING || item.Ips.Count >= 5) - { - return; - } - else - { - server = item; - previousIpCount = item.Ips.Count; - break; - } - } - - var result = client.ServerIps.Create(new POCO.Requests.Servers.CreateServerIPRequest() - { - Type = IPType.IPV4 - }, server.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //give the server time to update - var resultserver = client.Servers.Show(result.Id); - while (resultserver.Ips.Count == previousIpCount) - { - Thread.Sleep(2000); - resultserver = client.Servers.Show(result.Id); - } - Assert.IsNotNull(resultserver.Ips.Count > previousIpCount); - } - - [TestMethod] - public void ShowIP() - { - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - if (server.Status.State == ServerState.DEPLOYING || server.Status.State == ServerState.REMOVING) - { - return; - } - var result = client.ServerIps.Show(server.Id, server.Ips[0].Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void DeleteIP() - { - var servers = client.Servers.Get(null, null, null, "ServerTest"); - var server = servers[random.Next(servers.Count - 1)]; - int previousIpCount = 0; - - foreach (var item in servers) - { - if (item.Ips.Count > 1) - { - server = item; - previousIpCount = item.Ips.Count; - break; - } - } - if (server.Status.State == ServerState.DEPLOYING || server.Status.State == ServerState.REMOVING || server.Ips.Count == 1) - { - return; - } - var result = client.ServerIps.Delete(server.Id, server.Ips[new Random().Next(0, server.Ips.Count - 1)].Id, true); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //give the server time to update - var resultserver = client.Servers.Show(result.Id); - while (resultserver.Ips.Count == previousIpCount) - { - Thread.Sleep(2000); - resultserver = client.Servers.Show(result.Id); - } - Assert.IsNotNull(resultserver.Ips.Count < previousIpCount); - } - - #region Firewall policy - - [TestMethod] - public void GetFirewallPolicyTest() - { - - var servers = client.Servers.Get(); - List result = null; - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Ips.Any(ip => ip.FirewallPolicy != null && ip.FirewallPolicy.Count > 0)) - { - var curIP = server.Ips.FirstOrDefault(ip => ip.FirewallPolicy != null && ip.FirewallPolicy.Count > 0); - result = client.ServerIps.GetFirewallPolicies(item.Id, curIP.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Count > 0); - break; - - } - } - } - - [TestMethod] - public void DeleteFirewallPolicy() - { - var servers = client.Servers.Get(); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Ips.Any(ip => ip.FirewallPolicy != null && ip.FirewallPolicy.Count > 0)) - { - var curIP = server.Ips.FirstOrDefault(ip => ip.FirewallPolicy != null && ip.FirewallPolicy.Count > 0); - - var result = client.ServerIps.DeleteFirewallPolicy(item.Id, curIP.Id); - Assert.IsNotNull(result); - break; - } - } - } - - [TestMethod] - public void UpdateFirewallPolicy() - { - var random = new Random(); - int prevCount = 0; - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest") || ser.Name.Contains("Updated")).ToList(); ; - var firewallPolicies = client.FirewallPolicies.Get(); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - var policyToAdd = firewallPolicies[random.Next(0, firewallPolicies.Count - 1)].Id; - var curIP = server.Ips.FirstOrDefault(); - foreach (var ip in server.Ips) - { - //check the policy does not exist - if (ip.FirewallPolicy != null && ip.FirewallPolicy.Any(po => po.Id == policyToAdd)) - continue; - else - { - curIP = ip; - break; - } - } - //check the policy does not exist - if (curIP.FirewallPolicy != null && curIP.FirewallPolicy.Any(po => po.Id == policyToAdd)) - continue; - if (curIP.FirewallPolicy != null) - prevCount = curIP.FirewallPolicy.Count; - var result = client.ServerIps.UpdateFirewallPolicy(item.Id, curIP.Id, policyToAdd); - Assert.IsNotNull(result); - //give the server time to update - var resultserver = client.Servers.Show(result.Id); - var resultIP = result.Ips.FirstOrDefault(ip => ip.Id == curIP.Id); - Assert.IsTrue(resultIP.FirewallPolicy.Any(fp => fp.Id == policyToAdd)); - break; - } - } - - #endregion - - #region loadbalancers - [TestMethod] - public void CreateLoadBalancer() - { - Random random = new Random(); - var servers = client.Servers.Get(); - var loadBalancer = client.LoadBalancer.Get(); - foreach (var item in servers) - { - var currentIp = item.Ips[random.Next(0, item.Ips.Count - 1)]; - var currentloadBalancer = loadBalancer[random.Next(0, loadBalancer.Count - 1)]; - var result = client.ServerIps.CreateLoadBalancer(item.Id, currentIp.Id, currentloadBalancer.Id); - var updatedLoadBalancer = client.LoadBalancer.GetLoadBalancerServerIps(currentloadBalancer.Id); - Assert.IsNotNull(result); - //check if loadbalancer does have the server IP - Assert.IsTrue(updatedLoadBalancer.Any(ip => ip.Id == currentIp.Id)); - break; - } - } - - [TestMethod] - public void GetLoadBalancer() - { - var servers = client.Servers.Get(); - List loadbalancer = null; - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Ips.Any(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0)) - { - var curIP = server.Ips.FirstOrDefault(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0); - loadbalancer = client.ServerIps.GetLoadBalancer(item.Id, curIP.Id); - Assert.IsNotNull(loadbalancer); - Assert.IsNotNull(loadbalancer.Count > 0); - break; - } - } - - - } - - [TestMethod] - public void DeleteLoadBalancer() - { - var servers = client.Servers.Get(); - foreach (var item in servers) - { - var server = client.Servers.Show(item.Id); - Thread.Sleep(1000); - if (server.Ips.Any(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0)) - { - var curIP = server.Ips.FirstOrDefault(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0); - var result = client.ServerIps.DeleteLoadBalancer(item.Id, curIP.Id, curIP.LoadBalancers[0].Id); - Assert.IsNotNull(result); - var updatedLoadBalancer = client.LoadBalancer.GetLoadBalancerServerIps(curIP.LoadBalancers[0].Id); - Assert.IsNotNull(result); - //check if loadbalancer does notk have the server IP - Assert.IsTrue(!updatedLoadBalancer.Any(ip => ip.Id == curIP.Id)); - break; - } - } - - } - - #endregion - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Requests.Servers; +using OneAndOne.POCO.Response; +using OneAndOne.POCO.Response.LoadBalancers; +using OneAndOne.POCO.Response.Servers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace OneAndOne.UnitTests +{ + [TestClass] + public class ServerIpsTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + Random random = new Random(); + static ServerResponse server = null; + static LoadBalancerResponse loadBalancer = null; + static POCO.Response.FirewallPolicyResponse firewallPolicy = null; + + [ClassInitialize] + static public void ServerInit(TestContext context) + { + int vcore = 4; + int CoresPerProcessor = 2; + var appliances = client.ServerAppliances.Get(null, null, null, "ubuntu", null); + POCO.Response.ServerAppliances.ServerAppliancesResponse appliance = null; + if (appliances == null || appliances.Count() == 0) + { + appliance = client.ServerAppliances.Get().FirstOrDefault(); + } + else + { + appliance = appliances.FirstOrDefault(); + } + var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() + { + ApplianceId = appliance != null ? appliance.Id : null, + Name = "server ip test .net", + Description = "desc", + Hardware = new POCO.Requests.Servers.HardwareRequest() + { + CoresPerProcessor = CoresPerProcessor, + Hdds = new List() + { + {new POCO.Requests.Servers.HddRequest() + { + IsMain=true, + Size=20, + }}, + {new POCO.Requests.Servers.HddRequest() + { + IsMain=false, + Size=20, + }} + }, + Ram = 4, + Vcore = vcore + }, + PowerOn = true, + }); + + Config.waitServerReady(result.Id); + server = client.Servers.Show(result.Id); + } + + [ClassCleanup] + static public void ServerClean() + { + Config.waitServerReady(server.Id); + DeleteIP(); + Thread.Sleep(400000); + Config.waitServerReady(server.Id); + client.Servers.Delete(server.Id, false); + + if (loadBalancer != null) + { + Config.waitLoadBalancerReady(loadBalancer.Id); + client.LoadBalancer.Delete(loadBalancer.Id); + } + + if (firewallPolicy != null) + { + Config.waitFirewallPolicyReady(firewallPolicy.Id); + client.FirewallPolicies.Delete(firewallPolicy.Id); + + } + + } + [TestMethod] + public void GetServerIPList() + { + Config.waitServerReady(server.Id); + var result = client.ServerIps.Get(server.Id); + + Assert.IsNotNull(result); + Assert.IsTrue(result.Count > 0); + } + + [TestMethod] + public void AddServerIP() + { + int previousIpCount = 0; + Config.waitServerReady(server.Id); + + var result = client.ServerIps.Create(new POCO.Requests.Servers.CreateServerIPRequest() + { + Type = IPType.IPV4 + }, server.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + + Config.waitServerReady(server.Id); + //give the server time to update + var resultserver = client.Servers.Show(result.Id); + while (resultserver.Ips.Count == previousIpCount) + { + Thread.Sleep(2000); + resultserver = client.Servers.Show(result.Id); + } + Assert.IsNotNull(resultserver.Ips.Count > previousIpCount); + + Config.waitServerReady(server.Id); + } + + [TestMethod] + public void ShowIP() + { + Config.waitServerReady(server.Id); + var result = client.ServerIps.Show(server.Id, server.Ips[0].Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + static public void DeleteIP() + { + var serverWithips = client.Servers.Show(server.Id); + if (serverWithips.Ips != null && serverWithips.Ips.Count > 1) + { + Config.waitServerReady(server.Id); + var result = client.ServerIps.Delete(server.Id, server.Ips[1].Id, true); + Config.waitIpRemoved(server.Ips[1].Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + } + + #region Firewall policy + + public void GetFirewallPolicyTest() + { + + var curIP = server.Ips.FirstOrDefault(ip => ip.FirewallPolicy != null && ip.FirewallPolicy.Count > 0); + var result = client.ServerIps.GetFirewallPolicies(server.Id, curIP.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Count > 0); + } + + public void DeleteFirewallPolicy() + { + var curIP = server.Ips.FirstOrDefault(ip => ip.FirewallPolicy != null && ip.FirewallPolicy.Count > 0); + var result = client.ServerIps.DeleteFirewallPolicy(server.Id, curIP.Id); + Assert.IsNotNull(result); + } + + [TestMethod] + public void UpdateFirewallPolicy() + { + int prevCount = 0; + var newRules = new System.Collections.Generic.List(); + newRules.Add(new POCO.Requests.FirewallPolicies.CreateFirewallPocliyRule() + { + PortTo = 80, + PortFrom = 80, + Protocol = RuleProtocol.TCP, + Source = "0.0.0.0" + + }); + firewallPolicy = client.FirewallPolicies.Create(new POCO.Requests.FirewallPolicies.CreateFirewallPolicyRequest + { + Description = ".netTestFirewall" + random.Next(10, 30), + Name = ".netFW" + random.Next(10, 30), + Rules = newRules + }); + Config.waitFirewallPolicyReady(firewallPolicy.Id); + var curIP = server.Ips.FirstOrDefault(); + foreach (var ip in server.Ips) + { + //check the policy does not exist + if (ip.FirewallPolicy != null && ip.FirewallPolicy.Any(po => po.Id == firewallPolicy.Id)) + continue; + else + { + curIP = ip; + break; + } + } + if (curIP.FirewallPolicy != null) + prevCount = curIP.FirewallPolicy.Count; + var result = client.ServerIps.UpdateFirewallPolicy(server.Id, curIP.Id, firewallPolicy.Id); + Assert.IsNotNull(result); + Config.waitServerReady(server.Id); + //give the server time to update + var resultserver = client.Servers.Show(result.Id); + var resultIP = result.Ips.FirstOrDefault(ip => ip.Id == curIP.Id); + Assert.IsTrue(resultIP.FirewallPolicy.Any(fp => fp.Id == firewallPolicy.Id)); + + Config.waitServerReady(server.Id); + + GetFirewallPolicyTest(); + DeleteFirewallPolicy(); + } + + #endregion + + #region loadbalancers + [TestMethod] + public void CreateLoadBalancer() + { + Random random = new Random(); + loadBalancer = client.LoadBalancer.Create(new POCO.Requests.LoadBalancer.CreateLoadBalancerRequest + { + Name = "LBTest", + Description = "LBdesc", + HealthCheckInterval = 1, + Persistence = true, + PersistenceTime = 30, + HealthCheckTest = HealthCheckTestTypes.NONE, + Method = LoadBalancerMethod.ROUND_ROBIN, + Rules = new System.Collections.Generic.List() + { + {new POCO.Requests.LoadBalancer.LoadBalancerRuleRequest() + { + PortBalancer=80, + Protocol=LBRuleProtocol.TCP, + Source="0.0.0.0", + PortServer=80 + } + } + } + }); + Config.waitLoadBalancerReady(loadBalancer.Id); + var serverWithIps = client.Servers.Show(server.Id); + var currentIp = serverWithIps.Ips[random.Next(0, serverWithIps.Ips.Count - 1)]; + + var result = client.ServerIps.CreateLoadBalancer(serverWithIps.Id, currentIp.Id, loadBalancer.Id); + Config.waitServerReady(server.Id); + var updatedLoadBalancer = client.LoadBalancer.GetLoadBalancerServerIps(loadBalancer.Id); + + Assert.IsNotNull(result); + //check if loadbalancer does have the server IP + Assert.IsTrue(updatedLoadBalancer.Any(ip => ip.Id == currentIp.Id)); + } + + [TestMethod] + public void GetLoadBalancer() + { + List loadbalancer = null; + var serverWithIps = client.Servers.Show(server.Id); + if (serverWithIps.Ips.Any(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0)) + { + var curIP = serverWithIps.Ips.FirstOrDefault(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0); + loadbalancer = client.ServerIps.GetLoadBalancer(server.Id, curIP.Id); + Assert.IsNotNull(loadbalancer); + Assert.IsNotNull(loadbalancer.Count > 0); + } + } + + [TestMethod] + public void DeleteLoadBalancer() + { + var serverWithIps = client.Servers.Show(server.Id); + Thread.Sleep(1000); + if (server.Ips.Any(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0)) + { + var curIP = server.Ips.FirstOrDefault(ip => ip.LoadBalancers != null && ip.LoadBalancers.Count > 0); + var result = client.ServerIps.DeleteLoadBalancer(server.Id, curIP.Id, curIP.LoadBalancers[0].Id); + Assert.IsNotNull(result); + var updatedLoadBalancer = client.LoadBalancer.GetLoadBalancerServerIps(curIP.LoadBalancers[0].Id); + Assert.IsNotNull(result); + //check if loadbalancer does notk have the server IP + Assert.IsTrue(!updatedLoadBalancer.Any(ip => ip.Id == curIP.Id)); + } + } + + #endregion + } +} diff --git a/OneAndOne.UnitTests/Servers/Servers.orderedtest b/OneAndOne.UnitTests/Servers/Servers.orderedtest index b47e895..420f4ae 100644 --- a/OneAndOne.UnitTests/Servers/Servers.orderedtest +++ b/OneAndOne.UnitTests/Servers/Servers.orderedtest @@ -1,16 +1,13 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/Servers/ServersTest.cs b/OneAndOne.UnitTests/Servers/ServersTest.cs index 3d5e505..23de7e6 100644 --- a/OneAndOne.UnitTests/Servers/ServersTest.cs +++ b/OneAndOne.UnitTests/Servers/ServersTest.cs @@ -1,485 +1,344 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using System.Collections.Generic; -using OneAndOne.POCO.Requests.Servers; -using OneAndOne.POCO.Response.Servers; -using System.Threading; -using OneAndOne.POCO; -using OneAndOne.POCO.Response.ServerAppliances; - -namespace OneAndOne.UnitTests -{ - [TestClass] - public class ServersTest - { - //Add the API Token and the API URL here to test - static OneAndOneClient client = OneAndOneClient.Instance(); - string randomName; - - public ServersTest() - { - Random random = new Random(); - randomName = "ServerTest" + random.Next(1000, 9999); - } - - #region SERVER MAIN OPERTAIONS - - [TestMethod] - public void CreateServer() - { - int vcore = 4; - int CoresPerProcessor = 2; - var servers = client.Servers.Get(); - if (servers.Any(ser => ser.Name == randomName)) - { - return; - } - var appliances = client.ServerAppliances.Get().Where(app => app.OsFamily == OSFamliyType.Windows && app.AutomaticInstallation == true); - ServerAppliancesResponse appliance = null; - if (appliances == null || appliances.Count() == 0) - { - appliance = client.ServerAppliances.Get().FirstOrDefault(); - } - else - { - appliance = appliances.FirstOrDefault(); - } - var publicIP = client.PublicIPs.Get().FirstOrDefault(ip => ip.State == "ACTIVE" && ip.AssignedTo == null); - var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() - { - ApplianceId = appliance != null ? appliance.Id : null, - Name = randomName, - Description = "Example" + randomName, - Hardware = new POCO.Requests.Servers.HardwareRequest() - { - CoresPerProcessor = CoresPerProcessor, - Hdds = new List() - { - {new POCO.Requests.Servers.HddRequest() - { - IsMain=true, - Size=appliance.MinHddSize, - }} - }, - Ram = 4, - Vcore = vcore - }, - PowerOn = true, - Password = "Test123!", - IpId = publicIP != null ? publicIP.Id : null - }); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Name); - Assert.IsNotNull(result.Hardware); - Assert.IsNotNull(result.Status.Percent); - } - - [TestMethod] - public void UpdateServer() - { - Random random = new Random(); - var servers = client.Servers.Get(); - var server = client.Servers.Show(servers[random.Next(0, servers.Count - 1)].Id); - foreach (var item in client.Servers.Get()) - { - if (item.Name.Contains("ServerTest") && ( - item.Status.State != ServerState.POWERING_ON && item.Status.State != ServerState.DEPLOYING - && item.Status.State != ServerState.CONFIGURING && item.Status.State != ServerState.REBOOTING)) - { - server = item; - break; - } - } - var ranValue = new Random().Next(1, 1000); - string udpatedName = "Updated" + ranValue; - string updatedDesc = "Updated desc" + ranValue; - if (server != null) - { - if (!server.Name.Contains("Updated")) - { - var result = client.Servers.Update(new UpdateServerRequest() - { - Description = updatedDesc, - Name = udpatedName - }, server.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Name); - Assert.IsNotNull(result.Hardware); - //check if the values are udpated - Assert.AreEqual(result.Name, udpatedName); - Assert.AreEqual(result.Description, updatedDesc); - } - } - } - [TestMethod] - public void GetServers() - { - var servers = client.Servers.Get(); - - Assert.IsNotNull(servers); - Assert.IsTrue(servers.Count > 0); - } - [TestMethod] - public void GetServersWithPaging() - { - var servers = client.Servers.Get(1, 3, "name"); - - Assert.IsNotNull(servers); - Assert.IsTrue(servers.Count > 0); - } - - [TestMethod] - public void GetAvailableServerFalvours() - { - var servers = client.Servers.GetAvailableFixedServers(); - - Assert.IsNotNull(servers); - Assert.IsTrue(servers.Count > 0); - } - - [TestMethod] - public void GetSingleFixedServerFalvours() - { - var all = client.Servers.GetAvailableFixedServers().FirstOrDefault(); - var result = client.Servers.GetFlavorInformation(all.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void GetSingleServerData() - { - var servers = client.Servers.Get().FirstOrDefault(); - var result = client.Servers.Show(servers.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void CreateServerWithFixedHardwareImage() - { - //TODO: Add functional test to check the availablity of server - Random random = new Random(); - string randomName = "ServerTest" + random.Next(9999); - var availabeFixedImage = client.Servers.GetAvailableFixedServers().FirstOrDefault(); - - var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() - { - ApplianceId = "B5F778B85C041347BCDCFC3172AB3F3C", - Name = randomName, - Description = "Example" + randomName, - Hardware = new POCO.Requests.Servers.HardwareRequest() - { - CoresPerProcessor = availabeFixedImage.Hardware.CoresPerProcessor, - Hdds = availabeFixedImage.Hardware.Hdds.Select(itm => new HddRequest() - { - IsMain = itm.IsMain, - Size = itm.Size - - }).ToList(), - Ram = availabeFixedImage.Hardware.Ram, - Vcore = availabeFixedImage.Hardware.Vcore, - }, - PowerOn = true - }); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Name); - Assert.IsNotNull(result.Hardware); - Assert.IsNotNull(result.FirstPassword); - } - - [TestMethod] - public void DeleteServer() - { - ServerResponse serverToDelete = null; - foreach (var item in client.Servers.Get()) - { - if ((item.Name.Contains("ServerTest") || item.Name.Contains("Updated")) && (item.Status.State != ServerState.POWERED_OFF - && item.Status.State == ServerState.POWERED_ON)) - { - serverToDelete = item; - break; - } - } - if (serverToDelete != null) - { - var result = client.Servers.Delete(serverToDelete.Id, false); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Name); - Assert.IsNotNull(result.Hardware); - //check server state is removing - Assert.AreEqual(result.Status.State, ServerState.REMOVING); - } - } - - [TestMethod] - public void DeleteAllTestServers() - { - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest") || ser.Name.Contains("Updated")); - foreach (var item in servers) - { - if (item.Status.State == ServerState.POWERED_ON || item.Status.State == ServerState.POWERED_OFF) - { - var result = client.Servers.Delete(item.Id, false); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Name); - Assert.IsNotNull(result.Hardware); - } - } - } - - #endregion - - #region Secondary Operations - - [TestMethod] - public void GetServerStatus() - { - Random random = new Random(); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - - var result = client.Servers.GetStatus(server.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.State); - } - - [TestMethod] - public void UpdateServerStatus() - { - Random random = new Random(); - var servers = client.Servers.Get(); - ServerAction newState = ServerAction.REBOOT; - var server = servers[random.Next(servers.Count - 1)]; - foreach (var item in servers) - { - if (item.Status.State == ServerState.POWERED_ON || item.Status.State == ServerState.POWERED_OFF) - { - server = item; - break; - } - } - if (server.Status.State == ServerState.POWERED_OFF) - { - newState = ServerAction.POWER_ON; - - } - var result = client.Servers.UpdateStatus(new UpdateStatusRequest() - { - Action = newState, - Method = ServerActionMethod.SOFTWARE - }, server.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Status); - //check server state is either rebooting or powering on - Assert.AreEqual(result.Status.State, newState == ServerAction.REBOOT ? ServerState.REBOOTING : ServerState.POWERING_ON); - - } - #endregion - - #region Private Networks - [TestMethod] - public void GetPrivateNetworks() - { - Random random = new Random(); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - - var result = client.Servers.GetPrivateNetworks(server.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Count > 0); - } - - [TestMethod] - public void ShowPrivateNetworks() - { - var servers = client.Servers.Get(); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.PrivateNetworks != null && server.PrivateNetworks.Count > 0) - { - - var result = client.Servers.ShowPrivateNetworks(server.Id, server.PrivateNetworks[0].Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - break; - } - } - } - - [TestMethod] - public void CreatePrivateNetwork() - { - Random random = new Random(); - var servers = client.Servers.Get(); - foreach (var server in servers.Where(p => p.Name.Contains("ServerTest"))) - { - var privateNetworks = client.PrivateNetworks.Get(); - if (privateNetworks == null || privateNetworks.Count == 0) - { - return; - } - - var privateNetwork = privateNetworks[0]; - var curServer = client.Servers.Show(server.Id); - if (curServer.Status.State == ServerState.POWERING_ON || curServer.Snapshot != null) - continue; - if (server.PrivateNetworks == null || !server.PrivateNetworks.Any(pn => pn.Id == privateNetwork.Id)) - { - privateNetwork = privateNetworks[0]; - } - var result = client.Servers.CreatePrivateNetwork(curServer.Id, privateNetwork.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the private network is added to the servers list - Assert.IsTrue(result.PrivateNetworks.Any(pn => pn.Id == privateNetwork.Id)); - break; - } - } - - [TestMethod] - public void DeletePrivateNetwork() - { - var servers = client.Servers.Get(); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - //this check is here becuase i get the following error when trying to delete netwotk on ubuntu os - //Network interface cannot be hot removed in Ubuntu virtual machines - if (server.Image.Name.Contains("ub") || server.Snapshot != null || server.Status.Percent > 0) - continue; - if (server.PrivateNetworks != null && server.PrivateNetworks.Count > 0) - { - var currentPrivateNetwork = client.Servers.ShowPrivateNetworks(server.Id, server.PrivateNetworks[0].Id); - while (currentPrivateNetwork.State == "CONFIGURING") - { - Thread.Sleep(1500); - currentPrivateNetwork = client.Servers.ShowPrivateNetworks(server.Id, server.PrivateNetworks[0].Id); - } - var result = client.Servers.DeletePrivateNetwork(server.Id, server.PrivateNetworks[0].Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //give the server time to update - var resultserver = client.Servers.Show(result.Id); - while (resultserver.PrivateNetworks != null && resultserver.PrivateNetworks.Any(pn => pn.Id == server.PrivateNetworks[0].Id)) - { - Thread.Sleep(5000); - resultserver = client.Servers.Show(result.Id); - } - //check if the private network is gone from the servers list - Assert.IsTrue(resultserver.PrivateNetworks == null || !resultserver.PrivateNetworks.Any(pn => pn.Id == server.PrivateNetworks[0].Id)); - break; - - } - } - } - #endregion - - #region Snapshots - - [TestMethod] - public void GetSnapshots() - { - Random random = new Random(); - var servers = client.Servers.Get(); - var server = servers[random.Next(servers.Count - 1)]; - - var result = client.Servers.GetSnapshots(server.Id); - Assert.IsNotNull(result); - } - - [TestMethod] - public void UpdateSnapshots() - { - var servers = client.Servers.Get(); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Snapshot != null) - { - if (server.Status.Percent == 0 && server.Status.State == ServerState.POWERED_OFF) - { - var result = client.Servers.UpdateSnapshot(server.Id, server.Snapshot.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - break; - } - } - } - } - - [TestMethod] - public void CreateSnapshots() - { - Random random = new Random(); - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest") || ser.Name.Contains("Updated")); ; - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Snapshot == null) - { - var result = client.Servers.CreateSnapshot(server.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - Assert.IsNotNull(result.Snapshot); - //check if the snapshot is newly added - Assert.IsTrue(result.Snapshot.CreationDate <= DateTime.Now && result.Snapshot.CreationDate > DateTime.Now.AddHours(-2)); - break; - } - } - } - - [TestMethod] - public void DeleteSnapshot() - { - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest") || ser.Name.Contains("Updated")); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Snapshot != null) - { - var result = client.Servers.DeleteSnapshot(server.Id, server.Snapshot.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the snapshot has deletion date - Assert.IsNotNull(result.Snapshot.DeletionDate); - break; - } - } - } - - [TestMethod] - public void CreateClone() - { - Random random = new Random(); - var servers = client.Servers.Get(); - foreach (var item in servers) - { - Thread.Sleep(1000); - var server = client.Servers.Show(item.Id); - if (server.Snapshot == null && server.Status.Percent == 0) - { - var result = client.Servers.CreateClone(server.Id, server.Name + "Clone" + random.Next(1000, 9999)); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - break; - } - } - } - - #endregion - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using System.Collections.Generic; +using OneAndOne.POCO.Requests.Servers; +using OneAndOne.POCO.Response.Servers; +using System.Threading; +using OneAndOne.POCO; +using OneAndOne.POCO.Response.ServerAppliances; +using OneAndOne.POCO.Response.PrivateNetworks; + +namespace OneAndOne.UnitTests +{ + [TestClass] + public class ServersTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static ServerResponse server = null; + static ServerResponse clone = null; + static ServerResponse flavoredServer = null; + static POCO.Response.ServerAppliances.ServerAppliancesResponse appliance = null; + static PrivateNetworksResponse pn; + static List serverIds = new List(); + + [ClassInitialize] + static public void ServerHardwareInit(TestContext context) + { + int vcore = 4; + int CoresPerProcessor = 2; + var appliances = client.ServerAppliances.Get(null, null, null, "centos", null); + if (appliances == null || appliances.Count() == 0) + { + appliance = client.ServerAppliances.Get().FirstOrDefault(); + } + else + { + appliance = appliances.FirstOrDefault(); + } + var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() + { + ApplianceId = appliance != null ? appliance.Id : null, + Name = "main server test .net", + Description = "desc", + Hardware = new POCO.Requests.Servers.HardwareRequest() + { + CoresPerProcessor = CoresPerProcessor, + Hdds = new List() + { + {new POCO.Requests.Servers.HddRequest() + { + IsMain=true, + Size=20, + }}, + {new POCO.Requests.Servers.HddRequest() + { + IsMain=false, + Size=20, + }} + }, + Ram = 4, + Vcore = vcore + }, + PowerOn = false, + }); + + Config.waitServerReady(result.Id); + server = client.Servers.Show(result.Id); + serverIds.Add(server.Id); + + //creating three servers, Private networks requires 3 servers to be created + for (int i = 0; i < 2; i++) + { + Thread.Sleep(5000); + var additional = Config.CreateTestServer("PN test .net" + i, false); + Config.waitServerReady(additional.Id); + serverIds.Add(additional.Id); + } + } + + [ClassCleanup] + static public void ServerHardwareClean() + { + foreach (var id in serverIds) + { + if (id != null) + { + Config.waitServerReady(id); + client.Servers.Delete(id, false); + } + } + + if (flavoredServer != null) + { + Config.waitServerReady(flavoredServer.Id); + client.Servers.Delete(flavoredServer.Id, false); + } + if (clone != null) + { + Config.waitServerReady(clone.Id); + client.Servers.Delete(clone.Id, false); + } + + if (pn != null) + { + Config.waitPrivateNetworkReady(pn.Id); + client.PrivateNetworks.Delete(pn.Id); + } + } + + #region SERVER MAIN OPERTAIONS + + [TestMethod] + public void UpdateServer() + { + var ranValue = new Random().Next(1, 1000); + string udpatedName = "Updated" + ranValue; + string updatedDesc = "Updated desc" + ranValue; + var result = client.Servers.Update(new UpdateServerRequest() + { + Description = updatedDesc, + Name = udpatedName + }, server.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Name); + Assert.IsNotNull(result.Hardware); + //check if the values are udpated + Assert.AreEqual(result.Name, udpatedName); + Assert.AreEqual(result.Description, updatedDesc); + } + [TestMethod] + public void GetServers() + { + var servers = client.Servers.Get(); + + Assert.IsNotNull(servers); + Assert.IsTrue(servers.Count > 0); + } + [TestMethod] + public void GetServersWithPaging() + { + var servers = client.Servers.Get(1, 3, null); + + Assert.IsNotNull(servers); + Assert.IsTrue(servers.Count > 0); + } + + [TestMethod] + public void GetAvailableServerFalvours() + { + var servers = client.Servers.GetAvailableFixedServers(); + + Assert.IsNotNull(servers); + Assert.IsTrue(servers.Count > 0); + } + + [TestMethod] + public void GetSingleFixedServerFalvours() + { + var all = client.Servers.GetAvailableFixedServers().FirstOrDefault(); + var result = client.Servers.GetFlavorInformation(all.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void GetSingleServerData() + { + var servers = client.Servers.Get().FirstOrDefault(); + var result = client.Servers.Show(servers.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void CreateServerWithFixedHardwareImage() + { + Random random = new Random(); + string randomName = "ServerTestFlavor" + random.Next(9999); + var availabeFixedImage = client.Servers.GetAvailableFixedServers()[1]; + + var result = client.Servers.CreateServerFromFlavor(new POCO.Requests.Servers.CreateServerWithFlavorRequest() + { + ApplianceId = appliance.Id, + Name = randomName, + Description = "Example" + randomName, + Hardware = new POCO.Requests.Servers.HardwareFlavorRequest() + { + FixedInstanceSizeId = availabeFixedImage.Id + }, + PowerOn = true + }); + + flavoredServer = client.Servers.Show(result.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Name); + Assert.IsNotNull(result.Hardware); + Config.waitServerReady(result.Id); + + UpdateServerStatus(); + } + + #endregion + + #region Secondary Operations + + [TestMethod] + public void GetServerStatus() + { + var result = client.Servers.GetStatus(server.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.State); + } + + public void UpdateServerStatus() + { + var result = client.Servers.UpdateStatus(new UpdateStatusRequest() + { + Action = ServerAction.POWER_OFF, + Method = ServerActionMethod.SOFTWARE + }, flavoredServer.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Status); + } + #endregion + + #region Private Networks + + [TestMethod] + public void CreatePrivateNetwork() + { + string networkAddress = "192.168.1.0"; + string subnetMask = "255.255.255.0"; + var datacenters = client.DataCenters.Get(); + var dc = datacenters.FirstOrDefault(); + pn = client.PrivateNetworks.Create(new POCO.Requests.PrivateNetworks.CreatePrivateNetworkRequest + { + Name = "testPrivateNetwork .net", + Description = "test description", + NetworkAddress = networkAddress, + SubnetMask = subnetMask, + DatacenterId = dc.Id + }); + Config.waitPrivateNetworkReady(pn.Id); + var result = client.Servers.CreatePrivateNetwork(server.Id, pn.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + Config.waitPrivateNetworkReady(pn.Id); + var withPn = client.Servers.Show(result.Id); + //check if the private network is added to the servers list + Assert.IsTrue(withPn.PrivateNetworks.Any(pn => pn.Id == pn.Id)); + + //test list private networks + var pns = client.Servers.GetPrivateNetworks(server.Id); + Assert.IsNotNull(pns); + Assert.IsNotNull(pns.Count > 0); + + // test get private networks + var spn = client.Servers.ShowPrivateNetworks(server.Id, withPn.PrivateNetworks[0].Id); + Assert.IsNotNull(spn); + Assert.IsNotNull(spn.Id); + } + + [TestMethod] + public void DeletePrivateNetwork() + { + var pnserver = client.Servers.Show(server.Id); + Config.waitPrivateNetworkReady(pn.Id); + Config.waitServerReady(pnserver.Id); + if (pnserver.Status.State == ServerState.POWERED_ON) + { + //turn off server to remove PN + var turnOff = client.Servers.UpdateStatus(new UpdateStatusRequest { Action = ServerAction.POWER_OFF, Method = ServerActionMethod.SOFTWARE }, pnserver.Id); + Config.waitServerTurnedOff(pnserver.Id); + } + var result = client.Servers.DeletePrivateNetwork(pnserver.Id, pn.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + #endregion + + #region Snapshots + + public void GetSnapshots() + { + var result = client.Servers.GetSnapshots(serverIds.Last()); + Assert.IsNotNull(result); + } + + public void UpdateSnapshots() + { + Config.waitServerReady(serverIds.Last()); + var snapshotServer = client.Servers.Show(serverIds.Last()); + var result = client.Servers.UpdateSnapshot(snapshotServer.Id, snapshotServer.Snapshot.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void CreateSnapshots() + { + Config.waitServerReady(serverIds.Last()); + var result = client.Servers.CreateSnapshot(serverIds.Last()); + Config.waitServerReady(result.Id); + result = client.Servers.Show(result.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + Assert.IsNotNull(result.Snapshot); + + UpdateSnapshots(); + GetSnapshots(); + DeleteSnapshot(); + } + + public void DeleteSnapshot() + { + Config.waitServerReady(serverIds.Last()); + var snapshotServer = client.Servers.Show(serverIds.Last()); + var result = client.Servers.DeleteSnapshot(snapshotServer.Id, snapshotServer.Snapshot.Id); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if the snapshot has deletion date + Assert.IsNotNull(result.Snapshot.DeletionDate); + } + + [TestMethod] + public void CreateClone() + { + Config.waitServerReady(serverIds.Last()); + Random random = new Random(); + var result = client.Servers.CreateClone(serverIds.Last(), server.Name + "Clone" + random.Next(1000, 9999)); + clone = result; + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + #endregion + } +} diff --git a/OneAndOne.UnitTests/SharedStorages/ServersSharedStorageTest.cs b/OneAndOne.UnitTests/SharedStorages/ServersSharedStorageTest.cs index de9b544..25d4d43 100644 --- a/OneAndOne.UnitTests/SharedStorages/ServersSharedStorageTest.cs +++ b/OneAndOne.UnitTests/SharedStorages/ServersSharedStorageTest.cs @@ -3,13 +3,68 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OneAndOne.Client; using OneAndOne.POCO.Response.SharedStorages; +using OneAndOne.POCO.Response.Servers; +using System.Collections.Generic; namespace OneAndOne.UnitTests.SharedStorages { [TestClass] public class ServersSharedStorageTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static public SharedStoragesResponse sharedStorage = null; + static ServerResponse server = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var datacenters = client.DataCenters.Get(); + var dc = datacenters.FirstOrDefault(); + sharedStorage = client.SharedStorages.Create(new POCO.Requests.SharedStorages.CreateSharedStorage() + { + Description = "description", + Name = "Test server shared storage .net", + Size = 50, + DatacenterId = dc.Id + }); + + Config.waitSharedStorageReady(sharedStorage.Id); + + server = Config.CreateTestServer("share storage test .net"); + Config.waitServerReady(server.Id); + server = client.Servers.Show(server.Id); + + //add server to a shared storage + var serverstoAdd = new System.Collections.Generic.List(); + serverstoAdd.Add(new POCO.Requests.SharedStorages.Server() + { + Id = server.Id, + Rights = StorageServerRights.RW + }); + var addServer = client.SharedStorages.CreateServerSharedStorages(new POCO.Requests.SharedStorages.AttachSharedStorageServerRequest() + { + Servers = serverstoAdd + }, sharedStorage.Id); + + Assert.IsNotNull(addServer); + Assert.IsNotNull(addServer.Id); + //check the server has the shared storage access + var serverResult = client.SharedStorages.ShowSharedStoragesServer(sharedStorage.Id, server.Id); + Assert.IsNotNull(serverResult); + } + + [ClassCleanup] + static public void TestClean() + { + if (sharedStorage != null) + { + Config.waitSharedStorageReady(sharedStorage.Id); + client.SharedStorages.Delete(sharedStorage.Id); + } + + client.Servers.Delete(server.Id, false); + } + [TestMethod] public void GetSharedStoragesServers() { @@ -44,61 +99,15 @@ public void ShowSharedStoragesServers() } [TestMethod] - public void CreateSharedStoragesServers() - { - Random random = new Random(); - var servers = client.Servers.Get().Where(ser => ser.Name.Contains("ServerTest")).ToList(); - var sharedStorages = client.SharedStorages.Get().Where(str => str.Name.Contains("TestStorage")).ToList(); - if (sharedStorages.Count == 0) - return; - var sharedStorage = sharedStorages[random.Next(sharedStorages.Count - 1)]; - - if (servers.Count > 0) - { - var currentServer = servers[random.Next(0, servers.Count - 1)]; - var serverstoAdd = new System.Collections.Generic.List(); - serverstoAdd.Add(new POCO.Requests.SharedStorages.Server() - { - Id = currentServer.Id, - Rights = StorageServerRights.RW - }); - var result = client.SharedStorages.CreateServerSharedStorages(new POCO.Requests.SharedStorages.AttachSharedStorageServerRequest() - { - Servers = serverstoAdd - }, sharedStorage.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check the server has the shared storage access - var serverResult = client.SharedStorages.ShowSharedStoragesServer(sharedStorage.Id, currentServer.Id); - Assert.IsNotNull(serverResult); - } - } - - [TestMethod] - public void DeleteSharedStoragesServers() + public void RemoveSharedStoragesServers() { - Random random = new Random(); - var sharedStorages = client.SharedStorages.Get().Where(str => str.Name.Contains("TestStorage")).ToList(); - SharedStoragesResponse sharedStorage = null; - foreach (var item in sharedStorages) - { - if (item.Servers != null && item.Servers.Count > 0) - { - sharedStorage = item; - break; - } - } - if (sharedStorage != null && sharedStorage.Servers != null && sharedStorage.Servers.Count > 0) - { - var result = client.SharedStorages.DeleteSharedStoragesServer(sharedStorage.Id, sharedStorage.Servers[0].Id); + var result = client.SharedStorages.DeleteSharedStoragesServer(sharedStorage.Id, server.Id); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check the server has no shared storage access - var serverResult = client.SharedStorages.ShowSharedStoragesServer(sharedStorage.Id, sharedStorage.Servers[0].Id); - Assert.IsNull(serverResult); - } + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check the server has no shared storage access + var serverResult = client.SharedStorages.ShowSharedStoragesServer(sharedStorage.Id, server.Id); + Assert.IsNull(serverResult); } } } diff --git a/OneAndOne.UnitTests/SharedStorages/SharedStorageBasic.orderedtest b/OneAndOne.UnitTests/SharedStorages/SharedStorageBasic.orderedtest index b1dba50..5072e1d 100644 --- a/OneAndOne.UnitTests/SharedStorages/SharedStorageBasic.orderedtest +++ b/OneAndOne.UnitTests/SharedStorages/SharedStorageBasic.orderedtest @@ -1,11 +1,9 @@ - - - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/SharedStorages/SharedStorageServer.orderedtest b/OneAndOne.UnitTests/SharedStorages/SharedStorageServer.orderedtest index 8bb1d78..5154794 100644 --- a/OneAndOne.UnitTests/SharedStorages/SharedStorageServer.orderedtest +++ b/OneAndOne.UnitTests/SharedStorages/SharedStorageServer.orderedtest @@ -1,10 +1,7 @@ - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/OneAndOne.UnitTests/SharedStorages/SharedStoragesTest.cs b/OneAndOne.UnitTests/SharedStorages/SharedStoragesTest.cs index ff01ca8..d55db77 100644 --- a/OneAndOne.UnitTests/SharedStorages/SharedStoragesTest.cs +++ b/OneAndOne.UnitTests/SharedStorages/SharedStoragesTest.cs @@ -3,13 +3,47 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OneAndOne.Client; using System.Threading; +using OneAndOne.POCO.Response.SharedStorages; namespace OneAndOne.UnitTests.SharedStorages { [TestClass] public class SharedStoragesTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static public SharedStoragesResponse sharedStorage = null; + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var datacenters = client.DataCenters.Get(); + var dc = datacenters.FirstOrDefault(); + sharedStorage = client.SharedStorages.Create(new POCO.Requests.SharedStorages.CreateSharedStorage() + { + Description = "description", + Name = "TestStorage .net", + Size = 50, + DatacenterId = dc.Id + }); + + Assert.IsNotNull(sharedStorage); + Assert.IsNotNull(sharedStorage.Id); + //check the storage is created + var storageresult = client.SharedStorages.Show(sharedStorage.Id); + Assert.IsNotNull(sharedStorage.Id); + } + + [ClassCleanup] + static public void TestClean() + { + if (sharedStorage != null) + { + Config.waitSharedStorageReady(sharedStorage.Id); + DeleteSharedStorages(); + } + } + + [TestMethod] public void GetSharedStorages() { @@ -33,41 +67,11 @@ public void ShowSharedStorages() Assert.IsNotNull(result.Id); } - [TestMethod] - public void CreateSharedStorages() - { - Random random = new Random(); - var result = client.SharedStorages.Create(new POCO.Requests.SharedStorages.CreateSharedStorage() - { - Description = "description", - Name = "TestStorage" + random.Next(100, 999), - Size = 50 - }); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check the storage is created - var storageresult = client.SharedStorages.Show(result.Id); - Assert.IsNotNull(result.Id); - - } - [TestMethod] public void UpdateSharedStorages() { Random random = new Random(); - var sharedStorages = client.SharedStorages.Get().Where(str => str.Name.Contains("TestStorage")).ToList(); - var sharedStorage = sharedStorages[0]; - foreach (var item in sharedStorages) - { - if (item.State == "CONFIGURING") - continue; - } - while (sharedStorage.State == "CONFIGURING") - { - Thread.Sleep(2000); - sharedStorage = client.SharedStorages.Show(sharedStorage.Id); - } + Config.waitSharedStorageReady(sharedStorage.Id); var result = client.SharedStorages.Update(new POCO.Requests.SharedStorages.UpdateSharedStorageRequest() { Description = "description", @@ -83,17 +87,13 @@ public void UpdateSharedStorages() Assert.AreEqual(result.Description, storageresult.Description); Assert.AreEqual(result.Size, storageresult.Size); Assert.AreEqual(result.Name, storageresult.Name); + Config.waitSharedStorageReady(result.Id); } - [TestMethod] - public void DeleteSharedStorages() + static public void DeleteSharedStorages() { - Random random = new Random(); - var sharedStorages = client.SharedStorages.Get().Where(str => str.Name.Contains("TestStorage")).ToList(); - var sharedStorage = sharedStorages[random.Next(sharedStorages.Count - 1)]; var result = client.SharedStorages.Delete(sharedStorage.Id); - Assert.IsNotNull(result); Assert.IsNotNull(result.Id); //check the storage is being removed @@ -101,21 +101,6 @@ public void DeleteSharedStorages() Assert.IsTrue(storageresult.State == "REMOVING"); } - [TestMethod] - public void DeleteAllTestSharedStorages() - { - Random random = new Random(); - var sharedStorages = client.SharedStorages.Get().Where(str => str.Name.Contains("TestStorage")).ToList(); - foreach (var item in sharedStorages) - { - var result = client.SharedStorages.Delete(item.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - } - [TestMethod] public void ShowSharedStorageAccess() { @@ -124,10 +109,12 @@ public void ShowSharedStorageAccess() Assert.IsNotNull(result); } + [Ignore()] [TestMethod] public void UpdateSharedStorageAccess() { - var result = client.SharedStorages.UpdateSharedStorageAccess("test123!"); + Config.waitSharedStorageReady(sharedStorage.Id); + var result = client.SharedStorages.UpdateSharedStorageAccess("Asdasdfgagsw32!!"); Assert.IsNotNull(result); } } diff --git a/OneAndOne.UnitTests/Usages/UsagesTest.cs b/OneAndOne.UnitTests/Usages/UsagesTest.cs index 2147c66..4a3ff99 100644 --- a/OneAndOne.UnitTests/Usages/UsagesTest.cs +++ b/OneAndOne.UnitTests/Usages/UsagesTest.cs @@ -8,7 +8,7 @@ namespace OneAndOne.UnitTests.Usages [TestClass] public class UsagesTest { - static OneAndOneClient client = OneAndOneClient.Instance(); + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); [TestMethod] public void GetUsages() { diff --git a/OneAndOne.UnitTests/Users/UserAPITest.cs b/OneAndOne.UnitTests/Users/UserAPITest.cs index c043062..3f50e89 100644 --- a/OneAndOne.UnitTests/Users/UserAPITest.cs +++ b/OneAndOne.UnitTests/Users/UserAPITest.cs @@ -3,51 +3,61 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OneAndOne.Client; using System.Collections.Generic; - +using OneAndOne.POCO.Response.Users; + namespace OneAndOne.UnitTests.Users { [TestClass] public class UserAPITest { - static OneAndOneClient client = OneAndOneClient.Instance(); - - [TestMethod] - public void ShowUsersAPIInfo() - { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static UserResponse user = null; + [ClassInitialize] + static public void TestInit(TestContext context) + { Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; - - var result = client.UserAPI.ShowUserAPI(User.Id); + var ranName = "dotnetTest"; + var ranPass = "Test" + random.Next(100, 999) + "!"; + var result = client.Users.Create(new POCO.Requests.Users.CreateUserRequest() + { + Name = ranName, + Password = ranPass, + Description = "description", + }); Assert.IsNotNull(result); - Assert.IsNotNull(result.Key); + Assert.IsNotNull(result.Id); + //check if the user is created + var userRes = client.Users.Get(null, null, null, ranName); + Assert.IsNotNull(userRes[0].Id); + Assert.AreEqual(userRes[0].Name.Split('.')[1], ranName); + user = userRes[0]; + + var enabled = client.UserAPI.UpdateUserAPI(user.Id, true); + + Assert.IsNotNull(enabled); } - - /// - /// Warning running this test might stop the api from working - /// + [ClassCleanup] + static public void TestClean() + { + DeleteUsersAPIIPs(); + client.Users.Delete(user.Id); + } [TestMethod] - public void UpdateUsersAPI() + public void ShowUsersAPIInfo() { - Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; - var result = client.UserAPI.UpdateUserAPI(User.Id, true); + var result = client.UserAPI.ShowUserAPI(user.Id); Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); + Assert.IsNotNull(result.Key); } + [TestMethod] public void ShowUsersAPIKey() { - Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; - - var result = client.UserAPI.ShowUserAPIKey(User.Id); + var result = client.UserAPI.ShowUserAPIKey(user.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Key); @@ -58,58 +68,44 @@ public void ShowUsersAPIKey() [TestMethod] public void UpdateUsersAPIKey() { - Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; - var result = client.UserAPI.UpdateAPIKey(User.Id); + var result = client.UserAPI.UpdateAPIKey(user.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); //test the new API KEY - var test = OneAndOneClient.Instance("https://cloudpanel-api.1and1.com/v1", result.Api.Key).Users.Get(null, null, null, "aliba"); + var test = OneAndOneClient.Instance(new Client.RESTHelpers.Configuration { ApiUrl = "https://cloudpanel-api.1and1.com/v1", ApiKey = result.Api.Key }).Users.Get(null, null, null, "dotnetTest"); Assert.IsNotNull(test); } [TestMethod] public void ShowUsersAPIIPs() { - Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; - - var result = client.UserAPI.GetUserIps(User.Id); + var result = client.UserAPI.GetUserIps(user.Id); Assert.IsNotNull(result); } [TestMethod] public void UpdateUsersAPIIPs() { - Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; var listOfIps = new List(); listOfIps.Add("185.13.243.86"); - var result = client.UserAPI.UpdateAPIIps(listOfIps, User.Id); + var result = client.UserAPI.UpdateAPIIps(listOfIps, user.Id); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); //check if ip is added - var testResult = client.Users.Get(null, null, null, "aliba")[0]; + var testResult = client.Users.Show(user.Id); Assert.IsTrue(testResult.Api.AllowedIps.Any(ip => ip == "185.13.243.86")); } - [TestMethod] - public void DeleteUsersAPIIPs() + static public void DeleteUsersAPIIPs() { - Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; - var result = client.UserAPI.DeleteUserIp(User.Id, User.Api.AllowedIps[0]); + var result = client.UserAPI.DeleteUserIp(user.Id, user.Api.AllowedIps[0]); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); //check if ip is removed - var testResult = client.Users.Get(null, null, null, "aliba")[0]; + var testResult = client.Users.Show(user.Id); Assert.IsFalse(testResult.Api.AllowedIps.Any(ip => ip == "185.13.243.86")); } } diff --git a/OneAndOne.UnitTests/Users/UsersTest.cs b/OneAndOne.UnitTests/Users/UsersTest.cs index ecfe882..0154a16 100644 --- a/OneAndOne.UnitTests/Users/UsersTest.cs +++ b/OneAndOne.UnitTests/Users/UsersTest.cs @@ -1,105 +1,91 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OneAndOne.Client; -using OneAndOne.POCO.Requests.Users; - -namespace OneAndOne.UnitTests.Users -{ - [TestClass] - public class UsersTest - { - static OneAndOneClient client = OneAndOneClient.Instance(); - [TestMethod] - public void GetUsers() - { - var result = client.Users.Get(); - - Assert.IsNotNull(result); - Assert.IsTrue(result.Count > 0); - } - - [TestMethod] - public void ShowUsers() - { - Random random = new Random(); - - var Users = client.Users.Get(null, null, null, "03d60140.aliba"); - var User = Users[0]; - - var result = client.Users.Show(User.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void CreateUsers() - { - Random random = new Random(); - var ranName = "dotnetTest" + random.Next(100, 999); - var ranPass = "Test" + random.Next(100, 999) + "!"; - var result = client.Users.Create(new POCO.Requests.Users.CreateUserRequest() - { - Name = ranName, - Password = ranPass, - Description = "description", - }); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the user is created - var user = client.Users.Get(null, null, null, ranName); - Assert.IsNotNull(user[0].Id); - Assert.AreEqual(user[0].Name.Split('.')[1], ranName); - } - - [TestMethod] - public void UpdateUsers() - { - Random random = new Random(); - var Users = client.Users.Get(null, null, null, "aliba"); - var User = Users[0]; - var result = client.Users.Update(new POCO.Requests.Users.UpdateUserRequest() - { - Description = "description", - State = UserState.ACTIVE - - }, User.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - //check if the user is created - var user = client.Users.Get(null, null, null, "aliba"); - Assert.IsNotNull(user[0].Id); - Assert.AreEqual(user[0].Description, "description"); - } - - [TestMethod] - public void DeleteUser() - { - Random random = new Random(); - var Users = client.Users.Get().Where(str => str.Name.Contains("dotnetTest")).ToList(); - var User = Users[random.Next(Users.Count - 1)]; - var result = client.Users.Delete(User.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - [TestMethod] - public void DeleteAllTestUsers() - { - Random random = new Random(); - var Users = client.Users.Get().Where(str => str.Name.Contains("dotnetTest")).ToList(); - foreach (var item in Users) - { - var result = client.Users.Delete(item.Id); - - Assert.IsNotNull(result); - Assert.IsNotNull(result.Id); - } - - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using OneAndOne.POCO.Requests.Users; +using OneAndOne.POCO.Response.Users; + +namespace OneAndOne.UnitTests.Users +{ + [TestClass] + public class UsersTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static UserResponse user = null; + static String testToken; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + Random random = new Random(); + var ranName = "dotnetTest"; + var ranPass = "Test" + random.Next(100, 999) + "!"; + var result = client.Users.Create(new POCO.Requests.Users.CreateUserRequest() + { + Name = ranName, + Password = ranPass, + Description = "description", + }); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if the user is created + var userRes = client.Users.Get(null, null, null, ranName); + Assert.IsNotNull(userRes[0].Id); + Assert.AreEqual(userRes[0].Name.Split('.')[1], ranName); + user = userRes[0]; + + //enable API for the user + testToken = client.UserAPI.UpdateAPIKey(user.Id).Api.Key; + } + + [ClassCleanup] + static public void TestClean() + { + var testclient = OneAndOneClient.Instance(new Client.RESTHelpers.Configuration(testToken)); + var result = testclient.Users.Delete(user.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void GetUsers() + { + var result = client.Users.Get(); + + Assert.IsNotNull(result); + Assert.IsTrue(result.Count > 0); + } + + [TestMethod] + public void ShowUsers() + { + Random random = new Random(); + + var result = client.Users.Show(user.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void UpdateUsers() + { + var testclient = OneAndOneClient.Instance(new Client.RESTHelpers.Configuration(testToken)); + var result = testclient.Users.Update(new POCO.Requests.Users.UpdateUserRequest() + { + Description = "description", + State = UserState.ACTIVE + + }, user.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if the user is modified + var updatedUser = client.Users.Get(null, null, null, "dotnetTest"); + Assert.IsNotNull(updatedUser[0].Id); + Assert.AreEqual(updatedUser[0].Description, "description"); + } + } +} diff --git a/OneAndOne.UnitTests/Vpn/VpnTest.cs b/OneAndOne.UnitTests/Vpn/VpnTest.cs new file mode 100644 index 0000000..2a88bea --- /dev/null +++ b/OneAndOne.UnitTests/Vpn/VpnTest.cs @@ -0,0 +1,97 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OneAndOne.Client; +using System.Linq; +using OneAndOne.POCO.Response.Vpn; +using System.Threading; + +namespace OneAndOne.UnitTests.Vpn +{ + [TestClass] + public class VpnTest + { + static OneAndOneClient client = OneAndOneClient.Instance(Config.Configuration); + static VpnResponse vpn = null; + + [ClassInitialize] + static public void TestInit(TestContext context) + { + var datacenters = client.DataCenters.Get(); + var dc = datacenters.FirstOrDefault(); + Random random = new Random(); + var result = client.Vpn.Create(new POCO.Requests.Vpn.CreateVpnRequest + { + Name = "vpn test", + Description = "desc", + Datacenterid = dc.Id + }); + + vpn = result; + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [ClassCleanup] + static public void TestClean() + { + if (vpn != null) + { + DeleteVpn(); + } + } + + [TestMethod] + public void GetVpns() + { + var result = client.Vpn.Get(); + + Assert.IsNotNull(result); + Assert.IsTrue(result.Count > 0); + } + + [TestMethod] + public void ShowVpn() + { + var result = client.Vpn.Show(vpn.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + + [TestMethod] + public void Configuration() + { + Thread.Sleep(5000); + var result = client.Vpn.ShowConfiguration(vpn.Id); + + Assert.IsNotNull(result); + } + + [TestMethod] + public void UpdateVpn() + { + Random random = new Random(); + var randomValue = random.Next(10, 99) + "updateTest.net"; + var result = client.Vpn.Update(new POCO.Requests.Vpn.UpdateVpnRequest + { + Name = "updated name", + Description = "desc update" + }, vpn.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + //check if the vpn updated + var updated = client.Vpn.Show(result.Id); + Assert.IsNotNull(updated.Id); + Assert.AreEqual(updated.Name, "updated name"); + } + + static public void DeleteVpn() + { + var result = client.Vpn.Delete(vpn.Id); + + Assert.IsNotNull(result); + Assert.IsNotNull(result.Id); + } + } +} diff --git a/README.md b/README.md index 45542ee..ac4fb42 100644 --- a/README.md +++ b/README.md @@ -1,1058 +1,1210 @@ -# .NET SDK -This guide will show you how to programmatically perform common management tasks using the .NET SDK for the 1&1 REST API. - -## Table of Contents - -* [Overview](#overview) -* [Getting Started](#getting-started) - * [Installation](#installation) - * [Configuration](#configuration) - * [Using the Driver](#using-the-driver) - * [Additional Documentation and Support](#additional-documentation-and-support) -* [Operations](#operations) - * [Servers](#servers) - * [Images](#images) - * [Shared Storages](#shared-storages) - * [Firewall Policies](#firewall-policies) - * [Load Balancers](#load-balancers) - * [Public IPs](#public-ips) - * [Private Networks](#private-networks) - * [Monitoring Center](#monitoring-center) - * [Monitoring Policies](#monitoring-policies) - * [Logs](#logs) - * [Users](#users) - * [Usages](#usages) - * [Server Appliances](#server-appliances) - * [DVD ISO](#dvd-iso) - - -## Overview -*** -This .NET library is a wrapper for the 1&1 REST API. All API operations are performed over SSL and authenticated using your 1&1 token key. The API can be accessed within an instance running in 1&1 or directly over the Internet from any application that can send an HTTPS request and receive an HTTPS response. - -## Getting Started -*** -Before you begin you will need to have signed up for a 1&1 account. The credentials you create during sign-up will be used to authenticate against the API. - -To create a user and generate an API token that will be used to authenticate against the REST API, log into your 1&1 control panel. Go to the Server section -> Management -> Users. - -#####Installation - -The official .NET library is available from the 1&1 GitHub account found [here](https://github.com/StackPointCloud/oneandone-cloudserver-sdk-dotnet). To install the latest stable version, clone the repository, then add the binaries to your project. - -#####Configuration - -Depending on the type of project, you have the option to either create an App.config or Web.config file to interact with the service before you begin, or to pass the required values when initializing the client through your code. This file should contain the following values: - -``` - - - -``` - -#####Using the Driver -Here is a simple example on how to use the library. - -List all Servers: - -`var servers=OneAndOneClient.Instance().Servers.Get();` - - -This will list all servers under your 1&1 account. -#####Additional Documentation and Support - -You can engage with us in the community and we'll be more than happy to answer any questions you might have. - -## Operations - -- [Servers](#servers) -- [Images](#images) -- [Shared Storages](#shared-storages) -- [Firewall Policies](#firewall-policies) -- [Load Balancers](#load-balancers) -- [Public IPs](#public-ips) -- [Private Networks](#private-networks) -- [Monitoring Center](#monitoring-center) -- [Monitoring Policies](#monitoring-policies) -- [Logs](#logs) -- [Users](#users) -- [Usages](#usages) -- [Server Appliances](#server-appliances) -- [DVD ISO](#dvd-iso) - -There are two ways to initialize the 1&1 client. You can either have the API URL and token key in your app/web config, or you can pass the values in the constructor of the 1&1 client. - -`OneAndOneClient client = OneAndOneClient.Instance("https://xxxxxx.1and1.com/v1", apiToken); //API values passed through code` - -`OneAndOneClient client = OneAndOneClient.Instance(); // API values in the config file` - -## Servers - -**List all servers:** - -`var servers = client.Servers.Get();` - -**Show a single server:** - -`var server = client.Servers.Show(serverId);` - -**List available server flavors:** - -`var serverFlavours = client.Servers.GetAvailableFixedServers();` - -**Show a single server flavor:** - -`var serverFlavour=client.Servers.GetFlavorInformation(serverFlavourId);` - -**Create a server:** - -`//get a server appliance for example here it's windows and it automatically installs, -var appliance = client.ServerAppliances.Get().Where(app => app.OsFamily == OSFamliyType.Windows && app.AutomaticInstallation == true).FirstOrDefault();` - -`//get a public IP that is not assigned to any server yet -var publicIP = client.PublicIPs.Get().FirstOrDefault(ip => ip.AssignedTo == null);` - - - - var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() - { - ApplianceId = appliance.Id, - Name = "My server", - Description = "Example description", - Hardware = new POCO.Requests.Servers.HardwareReqeust() - { - CoresPerProcessor = 1, - Hdds = new List() - { - {new POCO.Requests.Servers.HddRequest() - { - IsMain=true, - //make sure that the hard drive meets the appliance minimum requirements - Size=appliance.MinHddSize, - }} - }, - Ram = 4, - Vcore = 2 - }, - PowerOn = true, - Password = "Test123!", - IpId = publicIP.Id - });` - -**Update a server:** - - var result = client.Servers.Update(new UpdateServerRequest() - { - Description = "my server updated", - Name = "my server updated" - }, serverId); - -**Delete a server:** - -`// the bool parameter is for Set true for keeping server IPs after deleting a server (false by default). -var result = client.Servers.Delete(serverToDelete.Id, false);` - -**Show a server's hardware:** - -`var result = client.ServersHardware.Show(serverId);` - -**Update a server's hardware:** - - var result = client.ServersHardware.Update(new POCO.Requests.Servers.UpdateHardwareRequest() - { - CoresPerProcessor = 2, - Ram = 8, - Vcore = 4 - }, serverId);` - -**Get server's hard drives:** - -`var result = client.ServerHdds.Get(serverId);` - -**Show a server's hard drive:** - -`var result = client.ServerHdds.Show(serverId, hardDriveId);` - -**Add a hard drive to a server:** - - var result = client.ServerHdds.Create(new POCO.Requests.Servers.AddHddRequest() - { - Hdds = new System.Collections.Generic.List() - { - { new POCO.Requests.Servers.HddRequest() - {Size=20,IsMain=false}}, - {new POCO.Requests.Servers.HddRequest() - {Size=30,IsMain=false} - }} - }, serverId); - -**Update a server’s hard drive size:** - - var result = client.ServerHdds.Update(new POCO.Requests.Servers.UpdateHddRequest() - { - Size = updatedSize - }, serverId, harddriveId); - -**Remove a hard drive from server:** - -`var result = client.ServerHdds.Delete(serverId, harddriveId);` - -**Show the server's loaded DVD:** - -`var result = client.ServersHardware.ShowDVD(serverId);` - -**Load a DVD into the server's unit:** - -`var result = client.ServersHardware.UpdateDVD(serverId, dvdId);` - -**Unload the server's loaded DVD:** - -`var result = client.ServersHardware.DeleteDVD(serverId);` - -**Show the server's image:** - -`var image = client.ServerImage.Show(serverId);` - -**Reinstall a new image into a server:** - - var result = client.ServerImage.Update(new POCO.Requests.Servers.UpdateServerImageRequest() - { - Id = imageId, - Password = "Test123!" - }, serverId); - -**List the server's IP addresses:** - -`var result = client.ServerIps.Get(serverId);` - -**Show a server's IP address:** - -`var result = client.ServerIps.Show(serverId, ipId);` - -**Assign an IP to the server:** - - var result = client.ServerIps.Create(new POCO.Requests.Servers.CreateServerIPRequest() - { - Type = IPType.IPV4 - }, serverId); - -**Un-Assign an IP from the server:** - -`//the bool parameter Set true for releasing the IP without removing it -var result = client.ServerIps.Delete(serverId, ipId, true);` - -**List server's firewall policies:** - -`var result = client.ServerIps.GetFirewallPolicies(serverId, ipId);` - -**Adds a new firewall policy to the server's IP:** - -`var policyresult = client.FirewallPolicies.Show(firewallPolicyId); -var result = client.ServerIps.UpdateFirewallPolicy(serverId, ipId, policyresult.Id);` - -**Remove a firewall policy from server's IP:** - -`var result = client.ServerIps.DeleteFirewallPolicy(serverId, ipId);` - -**List all server's IP address load balancers:** - -`var result = client.ServerIps.GetLoadBalancer(serverId, ipId);` - -**Add a new load balancer to the IP:** - -`var result = client.ServerIps.CreateLoadBalancer(serverId, ipId, loadBalancerId);` - -**Remove load balancer from the IP:** - -`var result = client.ServerIps.DeleteLoadBalancer(serverId, ipId, loadBalancerId);` - -**Get server status:** - -`var result = client.Servers.GetStatus(serverId);` - -**Change server status:** - - var result = client.Servers.UpdateStatus(new UpdateStatusRequest() - { - Action = ServerAction.REBOOT, - Method = ServerActionMethod.SOFTWARE - }, serverId); - -**List server's private networks:** - -`var result = client.Servers.GetPrivateNetworks(serverId);` - -**Show a server's private network:** - -`var result = client.Servers.ShowPrivateNetworks(serverId, privateNetworkId);` - -**Add a server's private network:** - -`var result = client.Servers.CreatePrivateNetwork(serverId, privateNetworkId);` - -**Remove a server's private network:** - -`var result = client.Servers.DeletePrivateNetwork(serverId, privateNetworkId);` - -**List server's snapshots:** - -`var result = client.Servers.GetSnapshots(serverId);` - -**Creates a new snapshot of the server:** - -`var result = client.Servers.CreateSnapshot(serverId);` - -**Restore a snapshot into server:** - -`var result = client.Servers.UpdateSnapshot(serverId, snapshotId);` - -**Remove a snapshot from server:** - -`var result = client.Servers.DeleteSnapshot(serverId, snapshotId);` - -**Create a server clone:** - -`var result = client.Servers.CreateClone(serverId, "Clone Name");` - - -## Images - -**List all images:** - -`var images = client.Images.Get();` - -**Get a single image:** - -`var image = client.Images.Show(imageId);` - -**Create an image:** - - var image = client.Images.Create(new POCO.Requests.Images.CreateImageRequest() - { - ServerId = serverId, - Description = "describe image", - Frequency = ImageFrequency.DAILY, - Name = "testImage", - NumIimages = 44// Max number of images - }); - -**Update an image:** - - - var result = client.Images.Update(new UpdateImageRequest() - { - Description = "updated", - Frequency = ImageFrequency.ONCE, - Name = "updaeted API Image" - }, image.Id); - -**Delete an image:** - -`var result = client.Images.Delete(imageId);` - - -## Shared Storages - -**List shared storages:** - -`var result = client.SharedStorages.Get();` - -**Get a single shared storage:** - -`var result = client.SharedStorages.Show(sharedStorageId);` - -**Create a shared storage:** - - var result = client.SharedStorages.Create(new POCO.Requests.SharedStorages.CreateSharedStorage() - { - Description = "description", - Name = "TestStorage", - Size = 50 - }); - -**Update a shared storage:** - - var result = client.SharedStorages.Update(new POCO.Requests.SharedStorages.UpdateSharedStorageRequest() - { - Description = "description", - Name = "TestStorageupdated", - Size = 70 - }, sharedStorageId); - -**Remove a shared storage:** - -`var result = client.SharedStorages.Delete(sharedStorageId);` - -**List a shared storage servers:** - -`var result = client.SharedStorages.GetSharedStorageServers(sharedStorageId);` - -**Get a shared storage single server:** - -`var result = client.SharedStorages.ShowSharedStoragesServer(sharedStorageId, serverId);` - -**Attaches servers to a shared storage:** - -`//serverstoAdd is a list of string that represents the server id -var result = client.SharedStorages.CreateServerSharedStorages(new POCO.Requests.SharedStorages.AttachSharedStorageServerRequest() - { - Servers = serverstoAdd - }, sharedStorageId);` - -**Unattaches a server from a shared storage:** - -`var result = client.SharedStorages.DeleteSharedStoragesServer(sharedStorageId, serverId);` - -**Return the credentials for accessing the shared storages:** - -`var result = client.SharedStorages.ShowSharedStorageAccess();` - -**Change the password for accessing the shared storages:** - -`var result = client.SharedStorages.UpdateSharedStorageAccess("test123!");` - - - -## Firewall Policies - -**List firewall policies:** - -`var result = client.FirewallPolicies.Get();` - -**Get a single firewall policy:** - -`var result = client.FirewallPolicies.Show(firewallId);` - -**Create a firewall policy:** - - var newRules = new System.Collections.Generic.List(); - newRules.Add(new POCO.Requests.FirewallPolicies.CreateFirewallPocliyRule() - { - PortTo = 80, - PortFrom = 80, - Protocol = RuleProtocol.TCP, - Source = "0.0.0.0" - }); - var result = client.FirewallPolicies.Create(new POCO.Requests.FirewallPolicies.CreateFirewallPolicyRequest() - { - Description = "TestFirewall", - Name = "TestFW", - Rules = newRules - }); - -**Update a firewall policy:** - - var result = client.FirewallPolicies.Update(new POCO.Requests.FirewallPolicies.UpdateFirewallPolicyRequest() - { - Name = "Updated", - Description = "UpdDesc", - }, firewallId); - -**Delete a firewall policy:** - -`var result = client.FirewallPolicies.Delete(firewallId);` - -**Return a list of the servers/IPs attached to a firewall policy:** - -`var result = client.FirewallPolicies.GetFirewallPolicyServerIps(firewallpolicyId);` - -**Return information about a server/IP assigned to a firewall policy:** - -`var result = client.FirewallPolicies.ShowFirewallPolicyServerIp(firewallpolicyId, serverIpId);` - -**Assign servers/IPs to a firewall policy:** - -`// ServerIps is a string list of server id -var result = client.FirewallPolicies.CreateFirewallPolicyServerIPs(new POCO.Requests.FirewallPolicies.AssignFirewallServerIPRequest() { ServerIps = iptoAdd }, firewallpolicyId);` - -**Unassign a server/IP from a firewall policy:** - -`var result = client.FirewallPolicies.DeleteFirewallPolicyServerIP(firewallpolicyId, serverIpId);` - -**Return a list of the rules of a firewall policy:** - -`var result = client.FirewallPolicies.GetFirewallPolicyRules(firewallpolicyId);` - -**Return information about a rule of a firewall policy:** - -`var result = client.FirewallPolicies.ShowFirewallPolicyRule(firewallpolicyId, firewallpolicyRuleId);` - -**Adds new rules to a firewall policy:** - - var result = client.FirewallPolicies.CreateFirewallPolicyRule(new POCO.Requests.FirewallPolicies.AddFirewallPolicyRuleRequest() - { - Rules = new System.Collections.Generic.List() - { - {new OneAndOne.POCO.Requests.FirewallPolicies.RuleRequest() - { - PortFrom =8080, - PortTo = 8070, - Protocol = RuleProtocol.TCP, - Source = "0.0.0.0" - }} - } - }, firewallpolicyId); - -**Remove a rule from a firewall policy:** - -`var result = client.FirewallPolicies.DeleteFirewallPolicyRules(firewallpolicyId, firewallpolicyRulesId);` - - -## Load Balancers - -**Return a list of your load balancers:** - -`var result = client.LoadBalancer.Get();` - -**Return information about a load balancer:** - -`var result = client.LoadBalancer.Show(loadBalancerId);` - -**Create a new load balancer:** - - var result = client.LoadBalancer.Create(new POCO.Requests.LoadBalancer.CreateLoadBalancerRequest() - { - Name = "LBTest", - Description = "LBdesc", - HealthCheckInterval = 1, - Persistence = true, - PersistenceTime = 30, - HealthCheckTest = HealthCheckTestTypes.NONE, - Method = LoadBalancerMethod.ROUND_ROBIN, - Rules = new System.Collections.Generic.List() - { - {new POCO.Requests.LoadBalancer.LoadBalancerRuleRequest() - { - PortBalancer=80, - Protocol=LBRuleProtocol.TCP, - Source="0.0.0.0", - PortServer=80 - } - } - } - }); - -**Modify a load balancer:** - - var result = client.LoadBalancer.Update(new POCO.Requests.LoadBalancer.UpdateLoadBalancerRequest() - { - HealthCheckInterval = 100, - HealthCheckTest = HealthCheckTestTypes.TCP, - Method = LoadBalancerMethod.ROUND_ROBIN, - Persistence = false, - Name = "UpdatedLB" + loadBalancer.Name, - HealthCheckPathParse = "regex", - HealthCheckPath = "google.com" - }, loadBalancerId); - -**Removes a load balancer:** - -`var result = client.LoadBalancer.Delete(loadBalancer.Id);` - -**Return a list of the servers/IPs attached to a load balancer:** - -`var result = client.LoadBalancer.GetLoadBalancerServerIps(loadBalancerId);` - -**Return information about a server/IP assigned to a load balancer:** - -`var result = client.LoadBalancer.ShowLoadBalancerServerIp(loadBalancerId, serverIpId);` - -**Assign servers/IPs to a load balancer:** - - // iptoAdd is a list of string contains IDs of server Ips - var result = client.LoadBalancer.CreateLoadBalancerServerIPs(new POCO.Requests.LoadBalancer.AssignLoadBalancerServerIpsRequest() - { - ServerIps = iptoAdd - }, loadBalancerId); - -**Unassign a server/IP from a load balancer:** - -`var result = client.LoadBalancer.DeleteLoadBalancerServerIP(loadBalancerId, serverIpId);` - -**Return a list of the rules of a load balancer:** - -`var result = client.LoadBalancer.GetLoadBalancerRules(loadBalancerId);` - -**Returns information about a rule of a load balancer:** - -`var result = client.LoadBalancer.ShowLoadBalancerRule(loadBalancerId, ruleId);` - -**Add new rules to a load balancer:** - - var result = client.LoadBalancer.CreateLoadBalancerRule(new POCO.Requests.LoadBalancer.AddLoadBalancerRuleRequest() - { - Rules = new System.Collections.Generic.List() - { - {new OneAndOne.POCO.Requests.LoadBalancer.RuleRequest() - { - PortBalancer =8080, - PortServer = 8080, - Protocol = LBRuleProtocol.TCP, - Source = "0.0.0.0" - }} - } - }, loadBalancerId); - -**Removes a rule from a load balancer:** - -`var result = client.LoadBalancer.DeleteLoadBalancerRules(loadBalancerId, ruleId);` - -## Public IPs - -**Return a list of your public IPs:** - -`var result = client.PublicIPs.Get();` - -**Return information about a public IP:** - -`var result = client.PublicIPs.Show(publicIpId);` - -**Creates a new public IP:** - - var result = client.PublicIPs.Create(new POCO.Requests.PublicIPs.CreatePublicIPRequest() - { - ReverseDns = "dnsNameTest", - Type = IPType.IPV4 - }); - -**Modify the reverse DNS of a public IP:** - -`var result = client.PublicIPs.Update("dnsNameTest", publicIpId);` - -**Remove a public IP:** - -`var result = client.PublicIPs.Delete(publicIpId);` - - -## Private Networks - -**Return a list of your private networks:** - -`var result = client.PrivateNetworks.Get();` - -**Return information about a private network:** - -`var result = client.PrivateNetworks.Show(privateNetworkId);` - -**Create a new private network:** - - var result = client.PrivateNetworks.Create(new POCO.Requests.PrivateNetworks.CreatePrivateNetworkRequest() - { - Name ="testPrivateNetwork", - Description = "test description", - NetworkAddress = "192.168.1.0", - SubnetMask = "255.255.255.0" - }); - -**Modify a private network:** - - var result = client.PrivateNetworks.Update(new POCO.Requests.PrivateNetworks.UpdatePrivateNetworkRequest() - { - Name = "updated testPrivateNetwork", - NetworkAddress = "192.168.1.0", - SubnetMask = "255.255.255.0", - }, privateNetworkId); - -**Remove a private network:** - -`var result = client.PrivateNetworks.Delete(privateNetworkId);` - - -## Monitoring Center - -**List usages and alerts of monitoring servers:** - -`var mCenters = client.MonitoringCenter.Get();` - - -**Return the usage of the resources for the specified time range:** - -`var mCenters = client.MonitoringCenter.Show(serverId, PeriodType.CUSTOM, DateTime.Today.AddMonths(-2), DateTime.Today);` - - - -## Monitoring Policies - -**Return a list of your monitoring policies:** - -`var result = client.MonitoringPolicies.Get();` - -**Return information about a monitoring policy:** - -`var result = client.MonitoringPolicies.Show(monitoringPolicyId);` - -**Create a new monitoring policy:** - - var ports = new List(); - ports.Add(new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 22, - Protocol = ProtocolType.TCP - }); - var processes = new List(); - processes.Add(new Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.NOT_RUNNING, - Process = "test", - }); - var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolictRequest() - { - Name = ".netMP", - Description = ".net decription", - Agent = true, - Ports = ports, - Processes = processes, - Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() - { - Cpu = new POCO.Requests.MonitoringPolicies.Cpu() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Ram = new POCO.Requests.MonitoringPolicies.Ram() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Disk = new POCO.Requests.MonitoringPolicies.Disk() - { - Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() - { - Alert = false, - Value = 90 - }, - Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() - { - Alert = false, - Value = 80 - } - }, - InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() - { - Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() - { - Alert = false, - Value = 100 - }, - Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() - { - Alert = false, - Value = 50 - } - }, - Transfer = new POCO.Requests.MonitoringPolicies.Transfer() - { - Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() - { - Alert = false, - Value = 2000 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 1000 - } - } - } - }; - var result = client.MonitoringPolicies.Create(request); - -**Modifiy a monitoring policy:** - - var request = new UpdateMonitoringPolicyRequest() - { - Name = "updated" + monitoringPolicy.Name, - Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() - { - Cpu = new POCO.Requests.MonitoringPolicies.Cpu() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Ram = new POCO.Requests.MonitoringPolicies.Ram() - { - Critical = new POCO.Requests.MonitoringPolicies.Critical() - { - Alert = false, - Value = 95 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 90 - } - }, - Disk = new POCO.Requests.MonitoringPolicies.Disk() - { - Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() - { - Alert = false, - Value = 90 - }, - Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() - { - Alert = false, - Value = 80 - } - }, - InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() - { - Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() - { - Alert = false, - Value = 100 - }, - Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() - { - Alert = false, - Value = 50 - } - }, - Transfer = new POCO.Requests.MonitoringPolicies.Transfer() - { - Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() - { - Alert = false, - Value = 2000 - }, - Warning = new POCO.Requests.MonitoringPolicies.Warning() - { - Alert = false, - Value = 1000 - } - } - } - }; - var result = client.MonitoringPolicies.Update(request, monitoringPolicy.Id); - -**Remove a monitoring policy:** - -`var result = client.MonitoringPolicies.Delete(monitoringPolicyId);` - -**Return a list of the ports of a monitoring policy:** - -`var result = client.MonitoringPoliciesPorts.Get(monitoringPolicyId);` - -**Returns information about a port of a monitoring policy:** - -`var result = client.MonitoringPoliciesPorts.Show(monitoringPolicy.Id, port.Id);` - -**Add new ports to a monitoring policy:** - - var ports = new List(); - ports.Add(new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 97, - Protocol = ProtocolType.TCP - }); - ports.Add(new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 98, - Protocol = ProtocolType.TCP - }); - var result = client.MonitoringPoliciesPorts.Create(ports, monitoringPolicyId); - -**Modify a port from a monitoring policy:** - - var request = new POCO.Requests.MonitoringPolicies.Ports() - { - EmailNotification = true, - AlertIf = AlertIfType.RESPONDING, - Port = 23, - Protocol = ProtocolType.TCP - }; - var result = client.MonitoringPoliciesPorts.Update(request, monitoringPolicyId, portId);` - -**Remove a port from a monitoring policy:** - -`var result = client.MonitoringPoliciesPorts.Delete(monitoringPolicyId, portId);` - -**Return a list of the processes of a monitoring policy:** - -`var result = client.MonitoringPoliciesProcesses.Get(monitoringPolicyId);` - -**Return information about a process of a monitoring policy:** - -`var result = client.MonitoringPoliciesProcesses.Show(monitoringPolicyId, processId);` - -**Add new processes to a monitoring policy:** - - var processes = new List(); - processes.Add(new POCO.Requests.MonitoringPolicies.Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.RUNNING, - Process = "iexplorer" - }); - processes.Add(new POCO.Requests.MonitoringPolicies.Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.RUNNING, - Process = "test" - }); - var result = client.MonitoringPoliciesProcesses.Create(processes, monitoringPolicyId); - -**Modify a process from a monitoring policy:** - - var result = client.MonitoringPoliciesProcesses.Update(new POCO.Requests.MonitoringPolicies.Processes() - { - EmailNotification = true, - AlertIf = ProcessAlertType.RUNNING, - Process = "test" - }, monitoringPolicyId, processId); - -**Remove a process from a monitoring policy:** - -`var result = client.MonitoringPoliciesProcesses.Delete(monitoringPolicyId, processId);` - -**Return a list of the servers attached to a monitoring policy:** - -` var result = client.MonitoringPoliciesServers.Get(monitoringPolicyId);` - -**Return information about a server attached to a monitoring policy:** - -`var result = client.MonitoringPoliciesServers.Show(monitoringPolicyId, serverId);` - -**Attach servers to a monitoring policy:** - -`//servers are a list of string of the servers IDs -var result = client.MonitoringPoliciesServers.Create(servers, monitoringPolicyId);` - -**Unattach a server from a monitoring policy:** - -`var result = client.MonitoringPoliciesServers.Delete(monitoringPolicyId, serverId);` - - -## Logs - -**Return a list with logs:** - -`var result = client.Logs.Get(PeriodType.LAST_24H);` - -**Return information about a log:** - -`var result = client.Logs.Show(logId);` - - -## Users - -**Return a list with all users:** - -`var result = client.Users.Get();` - -**Return information about a user:** - -`var result = client.Users.Show(UserId);` - -**Creates a new user:** - - var result = client.Users.Create(new POCO.Requests.Users.CreateUserRequest() - { - Name = "test user", - Password = "Test123!", - Description = "description", - }); - -**Modify user information:** - - var result = client.Users.Update(new POCO.Requests.Users.UpdateUserRequest() - { - Description = "description", - State = UserState.ACTIVE - }, UserId); - -**Remove a user:** - -`var result = client.Users.Delete(UserId);` - -**Information about API:** - -`var result = client.UserAPI.ShowUserAPI(UserId);` - -**Allow to enable or disable the API:** - -` var result = client.UserAPI.UpdateUserAPI(UserId, true);` - -**Show the API key:** - -`var result = client.UserAPI.ShowUserAPIKey(UserId);` - -**Change the API key:** - -` var result = client.UserAPI.UpdateAPIKey(UserId);` - -**Return IPs from which access to API is allowed:** - -`var result = client.UserAPI.GetUserIps(UserId);` - -**Allow a new IP:** - - var listOfIps = new List(); - listOfIps.Add("185.13.243.86"); - var result = client.UserAPI.UpdateAPIIps(listOfIps, UserId);` - -**Delete an IP and forbid API access for it:** - -`var result = client.UserAPI.DeleteUserIp(UserId, allowedIp);` - -## Usages - -**Return a list of your usages:** - -`var result = client.Usages.Get(PeriodType.LAST_24H);` - - -## Server Appliances - -**Return a list of all the appliances that you can use for creating a server:** - -`var result = client.ServerAppliances.Get();` - -**Return Information about specific appliance:** - -`var result = client.ServerAppliances.Show(appliancesId);` - - -## DVD ISO - -**Return a list of all the operative systems and tools that you can load into your virtual DVD unit:** - -`var result = client.DVDs.Get();` - -**Information about specific ISO image:** - -`var result = client.DVDs.Show(dvdId);` - -Copyright (c) 2016 1&1 Internet SE - +# .NET SDK +This guide will show you how to programmatically perform common management tasks using the .NET SDK for the 1&1 REST API. + +## Table of Contents + +* [Overview](#overview) +* [Getting Started](#getting-started) + * [Installation](#installation) + * [Configuration](#configuration) + * [Using the Driver](#using-the-driver) + * [Additional Documentation and Support](#additional-documentation-and-support) +* [Operations](#operations) + * [Servers](#servers) + * [Images](#images) + * [Shared Storages](#shared-storages) + * [Firewall Policies](#firewall-policies) + * [Load Balancers](#load-balancers) + * [Public IPs](#public-ips) + * [Private Networks](#private-networks) + * [VPN](#vpn) + * [Monitoring Center](#monitoring-center) + * [Monitoring Policies](#monitoring-policies) + * [Logs](#logs) + * [Users](#users) + * [Roles](#roles) + * [Usages](#usages) + * [Server Appliances](#server-appliances) + * [DVD ISO](#dvd-iso) + * [Ping](#ping) + * [Pricing](#pricing) + * [Datacenters](#datacenters) + + +## Overview +*** +This .NET library is a wrapper for the 1&1 REST API. All API operations are performed over SSL and authenticated using your 1&1 token key. The API can be accessed within an instance running in 1&1 or directly over the Internet from any application that can send an HTTPS request and receive an HTTPS response. + +## Getting Started +*** +Before you begin you will need to have signed up for a 1&1 account. The credentials you create during sign-up will be used to authenticate against the API. + +To create a user and generate an API token that will be used to authenticate against the REST API, log into your 1&1 control panel. Go to the Server section -> Management -> Users. + +##### Installation + +The official .NET library is available from the 1&1 GitHub account found [here](https://github.com/StackPointCloud/oneandone-cloudserver-sdk-dotnet). To install the latest stable version, clone the repository, then add the binaries to your project. + +##### Configuration + +Depending on the type of project, you have the option to either create an App.config or Web.config file to interact with the service before you begin, This file should contain the following values: + +``` + + + +``` + +Or you can pass the required values when initializing the client through your code. +``` +OneAndOneClient client = OneAndOneClient.Instance(new Client.RESTHelpers.Configuration() + { + ApiKey="token", + ApiUrl="url" + }); +``` + +##### Using the Driver +Here is a simple example on how to use the library. + +List all Servers: + +`var servers=OneAndOneClient.Instance().Servers.Get();` + + +This will list all servers under your 1&1 account. +##### Additional Documentation and Support + +You can engage with us in the community and we'll be more than happy to answer any questions you might have. + +## Operations + +- [Servers](#servers) +- [Images](#images) +- [Shared Storages](#shared-storages) +- [Firewall Policies](#firewall-policies) +- [Load Balancers](#load-balancers) +- [Public IPs](#public-ips) +- [Private Networks](#private-networks) +- [VPN](#vpn) +- [Monitoring Center](#monitoring-center) +- [Monitoring Policies](#monitoring-policies) +- [Logs](#logs) +- [Users](#users) +- [Roles](#roles) +- [Usages](#usages) +- [Server Appliances](#server-appliances) +- [DVD ISO](#dvd-iso) +- [Ping](#ping) +- [Pricing](#pricing) +- [Datacenters](#datacenters) + + +There are two ways to initialize the 1&1 client. You can either have the API URL and token key in your app/web config, or you can pass the values in the constructor of the 1&1 client. + +`OneAndOneClient client = OneAndOneClient.Instance("https://xxxxxx.1and1.com/v1", apiToken); //API values passed through code` + +`OneAndOneClient client = OneAndOneClient.Instance(); // API values in the config file` + +## Servers + +**List all servers:** + +`var servers = client.Servers.Get();` + +**Show a single server:** + +`var server = client.Servers.Show(serverId);` + +**List available server flavors:** + +`var serverFlavours = client.Servers.GetAvailableFixedServers();` + +**Show a single server flavor:** + +`var serverFlavour=client.Servers.GetFlavorInformation(serverFlavourId);` + +**Create a server:** + +`//get a server appliance for example here it's windows and it automatically installs, +var appliance = client.ServerAppliances.Get().Where(app => app.OsFamily == OSFamliyType.Windows && app.AutomaticInstallation == true).FirstOrDefault();` + +`//get a public IP that is not assigned to any server yet +var publicIP = client.PublicIPs.Get().FirstOrDefault(ip => ip.AssignedTo == null);` + + + + var result = client.Servers.Create(new POCO.Requests.Servers.CreateServerRequest() + { + ApplianceId = appliance.Id, + Name = "My server", + Description = "Example description", + Hardware = new POCO.Requests.Servers.HardwareReqeust() + { + CoresPerProcessor = 1, + Hdds = new List() + { + {new POCO.Requests.Servers.HddRequest() + { + IsMain=true, + //make sure that the hard drive meets the appliance minimum requirements + Size=appliance.MinHddSize, + }} + }, + Ram = 4, + Vcore = 2 + }, + PowerOn = true, + Password = "Test123!", + IpId = publicIP.Id + });` + +**Update a server:** + + var result = client.Servers.Update(new UpdateServerRequest() + { + Description = "my server updated", + Name = "my server updated" + }, serverId); + +**Delete a server:** + +`// the bool parameter is for Set true for keeping server IPs after deleting a server (false by default). +var result = client.Servers.Delete(serverToDelete.Id, false);` + +**Show a server's hardware:** + +`var result = client.ServersHardware.Show(serverId);` + +**Update a server's hardware:** + + var result = client.ServersHardware.Update(new POCO.Requests.Servers.UpdateHardwareRequest() + { + CoresPerProcessor = 2, + Ram = 8, + Vcore = 4 + }, serverId);` + +**Get server's hard drives:** + +`var result = client.ServerHdds.Get(serverId);` + +**Show a server's hard drive:** + +`var result = client.ServerHdds.Show(serverId, hardDriveId);` + +**Add a hard drive to a server:** + + var result = client.ServerHdds.Create(new POCO.Requests.Servers.AddHddRequest() + { + Hdds = new System.Collections.Generic.List() + { + { new POCO.Requests.Servers.HddRequest() + {Size=20,IsMain=false}}, + {new POCO.Requests.Servers.HddRequest() + {Size=30,IsMain=false} + }} + }, serverId); + +**Update a server’s hard drive size:** + + var result = client.ServerHdds.Update(new POCO.Requests.Servers.UpdateHddRequest() + { + Size = updatedSize + }, serverId, harddriveId); + +**Remove a hard drive from server:** + +`var result = client.ServerHdds.Delete(serverId, harddriveId);` + +**Show the server's loaded DVD:** + +`var result = client.ServersHardware.ShowDVD(serverId);` + +**Load a DVD into the server's unit:** + +`var result = client.ServersHardware.UpdateDVD(serverId, dvdId);` + +**Unload the server's loaded DVD:** + +`var result = client.ServersHardware.DeleteDVD(serverId);` + +**Show the server's image:** + +`var image = client.ServerImage.Show(serverId);` + +**Reinstall a new image into a server:** + + var result = client.ServerImage.Update(new POCO.Requests.Servers.UpdateServerImageRequest() + { + Id = imageId, + Password = "Test123!" + }, serverId); + +**List the server's IP addresses:** + +`var result = client.ServerIps.Get(serverId);` + +**Show a server's IP address:** + +`var result = client.ServerIps.Show(serverId, ipId);` + +**Assign an IP to the server:** + + var result = client.ServerIps.Create(new POCO.Requests.Servers.CreateServerIPRequest() + { + Type = IPType.IPV4 + }, serverId); + +**Un-Assign an IP from the server:** + +`//the bool parameter Set true for releasing the IP without removing it +var result = client.ServerIps.Delete(serverId, ipId, true);` + +**List server's firewall policies:** + +`var result = client.ServerIps.GetFirewallPolicies(serverId, ipId);` + +**Adds a new firewall policy to the server's IP:** + +`var policyresult = client.FirewallPolicies.Show(firewallPolicyId); +var result = client.ServerIps.UpdateFirewallPolicy(serverId, ipId, policyresult.Id);` + +**Remove a firewall policy from server's IP:** + +`var result = client.ServerIps.DeleteFirewallPolicy(serverId, ipId);` + +**List all server's IP address load balancers:** + +`var result = client.ServerIps.GetLoadBalancer(serverId, ipId);` + +**Add a new load balancer to the IP:** + +`var result = client.ServerIps.CreateLoadBalancer(serverId, ipId, loadBalancerId);` + +**Remove load balancer from the IP:** + +`var result = client.ServerIps.DeleteLoadBalancer(serverId, ipId, loadBalancerId);` + +**Get server status:** + +`var result = client.Servers.GetStatus(serverId);` + +**Change server status:** + + var result = client.Servers.UpdateStatus(new UpdateStatusRequest() + { + Action = ServerAction.REBOOT, + Method = ServerActionMethod.SOFTWARE + }, serverId); + +**List server's private networks:** + +`var result = client.Servers.GetPrivateNetworks(serverId);` + +**Show a server's private network:** + +`var result = client.Servers.ShowPrivateNetworks(serverId, privateNetworkId);` + +**Add a server's private network:** + +`var result = client.Servers.CreatePrivateNetwork(serverId, privateNetworkId);` + +**Remove a server's private network:** + +`var result = client.Servers.DeletePrivateNetwork(serverId, privateNetworkId);` + +**List server's snapshots:** + +`var result = client.Servers.GetSnapshots(serverId);` + +**Creates a new snapshot of the server:** + +`var result = client.Servers.CreateSnapshot(serverId);` + +**Restore a snapshot into server:** + +`var result = client.Servers.UpdateSnapshot(serverId, snapshotId);` + +**Remove a snapshot from server:** + +`var result = client.Servers.DeleteSnapshot(serverId, snapshotId);` + +**Create a server clone:** + +`var result = client.Servers.CreateClone(serverId, "Clone Name");` + + +## Images + +**List all images:** + +`var images = client.Images.Get();` + +**Get a single image:** + +`var image = client.Images.Show(imageId);` + +**Create an image:** + + var image = client.Images.Create(new POCO.Requests.Images.CreateImageRequest() + { + ServerId = serverId, + Description = "describe image", + Frequency = ImageFrequency.DAILY, + Name = "testImage", + NumIimages = 44// Max number of images + }); + +**Update an image:** + + + var result = client.Images.Update(new UpdateImageRequest() + { + Description = "updated", + Frequency = ImageFrequency.ONCE, + Name = "updaeted API Image" + }, image.Id); + +**Delete an image:** + +`var result = client.Images.Delete(imageId);` + + +## Shared Storages + +**List shared storages:** + +`var result = client.SharedStorages.Get();` + +**Get a single shared storage:** + +`var result = client.SharedStorages.Show(sharedStorageId);` + +**Create a shared storage:** + + var result = client.SharedStorages.Create(new POCO.Requests.SharedStorages.CreateSharedStorage() + { + Description = "description", + Name = "TestStorage", + Size = 50 + }); + +**Update a shared storage:** + + var result = client.SharedStorages.Update(new POCO.Requests.SharedStorages.UpdateSharedStorageRequest() + { + Description = "description", + Name = "TestStorageupdated", + Size = 70 + }, sharedStorageId); + +**Remove a shared storage:** + +`var result = client.SharedStorages.Delete(sharedStorageId);` + +**List a shared storage servers:** + +`var result = client.SharedStorages.GetSharedStorageServers(sharedStorageId);` + +**Get a shared storage single server:** + +`var result = client.SharedStorages.ShowSharedStoragesServer(sharedStorageId, serverId);` + +**Attaches servers to a shared storage:** + +`//serverstoAdd is a list of string that represents the server id +var result = client.SharedStorages.CreateServerSharedStorages(new POCO.Requests.SharedStorages.AttachSharedStorageServerRequest() + { + Servers = serverstoAdd + }, sharedStorageId);` + +**Unattaches a server from a shared storage:** + +`var result = client.SharedStorages.DeleteSharedStoragesServer(sharedStorageId, serverId);` + +**Return the credentials for accessing the shared storages:** + +`var result = client.SharedStorages.ShowSharedStorageAccess();` + +**Change the password for accessing the shared storages:** + +`var result = client.SharedStorages.UpdateSharedStorageAccess("test123!");` + + + +## Firewall Policies + +**List firewall policies:** + +`var result = client.FirewallPolicies.Get();` + +**Get a single firewall policy:** + +`var result = client.FirewallPolicies.Show(firewallId);` + +**Create a firewall policy:** + + var newRules = new System.Collections.Generic.List(); + newRules.Add(new POCO.Requests.FirewallPolicies.CreateFirewallPocliyRule() + { + PortTo = 80, + PortFrom = 80, + Protocol = RuleProtocol.TCP, + Source = "0.0.0.0" + }); + var result = client.FirewallPolicies.Create(new POCO.Requests.FirewallPolicies.CreateFirewallPolicyRequest() + { + Description = "TestFirewall", + Name = "TestFW", + Rules = newRules + }); + +**Update a firewall policy:** + + var result = client.FirewallPolicies.Update(new POCO.Requests.FirewallPolicies.UpdateFirewallPolicyRequest() + { + Name = "Updated", + Description = "UpdDesc", + }, firewallId); + +**Delete a firewall policy:** + +`var result = client.FirewallPolicies.Delete(firewallId);` + +**Return a list of the servers/IPs attached to a firewall policy:** + +`var result = client.FirewallPolicies.GetFirewallPolicyServerIps(firewallpolicyId);` + +**Return information about a server/IP assigned to a firewall policy:** + +`var result = client.FirewallPolicies.ShowFirewallPolicyServerIp(firewallpolicyId, serverIpId);` + +**Assign servers/IPs to a firewall policy:** + +`// ServerIps is a string list of server id +var result = client.FirewallPolicies.CreateFirewallPolicyServerIPs(new POCO.Requests.FirewallPolicies.AssignFirewallServerIPRequest() { ServerIps = iptoAdd }, firewallpolicyId);` + +**Unassign a server/IP from a firewall policy:** + +`var result = client.FirewallPolicies.DeleteFirewallPolicyServerIP(firewallpolicyId, serverIpId);` + +**Return a list of the rules of a firewall policy:** + +`var result = client.FirewallPolicies.GetFirewallPolicyRules(firewallpolicyId);` + +**Return information about a rule of a firewall policy:** + +`var result = client.FirewallPolicies.ShowFirewallPolicyRule(firewallpolicyId, firewallpolicyRuleId);` + +**Adds new rules to a firewall policy:** + + var result = client.FirewallPolicies.CreateFirewallPolicyRule(new POCO.Requests.FirewallPolicies.AddFirewallPolicyRuleRequest() + { + Rules = new System.Collections.Generic.List() + { + {new OneAndOne.POCO.Requests.FirewallPolicies.RuleRequest() + { + PortFrom =8080, + PortTo = 8070, + Protocol = RuleProtocol.TCP, + Source = "0.0.0.0" + }} + } + }, firewallpolicyId); + +**Remove a rule from a firewall policy:** + +`var result = client.FirewallPolicies.DeleteFirewallPolicyRules(firewallpolicyId, firewallpolicyRulesId);` + + +## Load Balancers + +**Return a list of your load balancers:** + +`var result = client.LoadBalancer.Get();` + +**Return information about a load balancer:** + +`var result = client.LoadBalancer.Show(loadBalancerId);` + +**Create a new load balancer:** + + var result = client.LoadBalancer.Create(new POCO.Requests.LoadBalancer.CreateLoadBalancerRequest() + { + Name = "LBTest", + Description = "LBdesc", + HealthCheckInterval = 1, + Persistence = true, + PersistenceTime = 30, + HealthCheckTest = HealthCheckTestTypes.NONE, + Method = LoadBalancerMethod.ROUND_ROBIN, + Rules = new System.Collections.Generic.List() + { + {new POCO.Requests.LoadBalancer.LoadBalancerRuleRequest() + { + PortBalancer=80, + Protocol=LBRuleProtocol.TCP, + Source="0.0.0.0", + PortServer=80 + } + } + } + }); + +**Modify a load balancer:** + + var result = client.LoadBalancer.Update(new POCO.Requests.LoadBalancer.UpdateLoadBalancerRequest() + { + HealthCheckInterval = 100, + HealthCheckTest = HealthCheckTestTypes.TCP, + Method = LoadBalancerMethod.ROUND_ROBIN, + Persistence = false, + Name = "UpdatedLB" + loadBalancer.Name, + HealthCheckPathParse = "regex", + HealthCheckPath = "google.com" + }, loadBalancerId); + +**Removes a load balancer:** + +`var result = client.LoadBalancer.Delete(loadBalancer.Id);` + +**Return a list of the servers/IPs attached to a load balancer:** + +`var result = client.LoadBalancer.GetLoadBalancerServerIps(loadBalancerId);` + +**Return information about a server/IP assigned to a load balancer:** + +`var result = client.LoadBalancer.ShowLoadBalancerServerIp(loadBalancerId, serverIpId);` + +**Assign servers/IPs to a load balancer:** + + // iptoAdd is a list of string contains IDs of server Ips + var result = client.LoadBalancer.CreateLoadBalancerServerIPs(new POCO.Requests.LoadBalancer.AssignLoadBalancerServerIpsRequest() + { + ServerIps = iptoAdd + }, loadBalancerId); + +**Unassign a server/IP from a load balancer:** + +`var result = client.LoadBalancer.DeleteLoadBalancerServerIP(loadBalancerId, serverIpId);` + +**Return a list of the rules of a load balancer:** + +`var result = client.LoadBalancer.GetLoadBalancerRules(loadBalancerId);` + +**Returns information about a rule of a load balancer:** + +`var result = client.LoadBalancer.ShowLoadBalancerRule(loadBalancerId, ruleId);` + +**Add new rules to a load balancer:** + + var result = client.LoadBalancer.CreateLoadBalancerRule(new POCO.Requests.LoadBalancer.AddLoadBalancerRuleRequest() + { + Rules = new System.Collections.Generic.List() + { + {new OneAndOne.POCO.Requests.LoadBalancer.RuleRequest() + { + PortBalancer =8080, + PortServer = 8080, + Protocol = LBRuleProtocol.TCP, + Source = "0.0.0.0" + }} + } + }, loadBalancerId); + +**Removes a rule from a load balancer:** + +`var result = client.LoadBalancer.DeleteLoadBalancerRules(loadBalancerId, ruleId);` + +## Public IPs + +**Return a list of your public IPs:** + +`var result = client.PublicIPs.Get();` + +**Return information about a public IP:** + +`var result = client.PublicIPs.Show(publicIpId);` + +**Creates a new public IP:** + + var result = client.PublicIPs.Create(new POCO.Requests.PublicIPs.CreatePublicIPRequest() + { + ReverseDns = "dnsNameTest", + Type = IPType.IPV4 + }); + +**Modify the reverse DNS of a public IP:** + +`var result = client.PublicIPs.Update("dnsNameTest", publicIpId);` + +**Remove a public IP:** + +`var result = client.PublicIPs.Delete(publicIpId);` + + +## Private Networks + +**Return a list of your private networks:** + +`var result = client.PrivateNetworks.Get();` + +**Return information about a private network:** + +`var result = client.PrivateNetworks.Show(privateNetworkId);` + +**Create a new private network:** + + var result = client.PrivateNetworks.Create(new POCO.Requests.PrivateNetworks.CreatePrivateNetworkRequest() + { + Name ="testPrivateNetwork", + Description = "test description", + NetworkAddress = "192.168.1.0", + SubnetMask = "255.255.255.0" + }); + +**Modify a private network:** + + var result = client.PrivateNetworks.Update(new POCO.Requests.PrivateNetworks.UpdatePrivateNetworkRequest() + { + Name = "updated testPrivateNetwork", + NetworkAddress = "192.168.1.0", + SubnetMask = "255.255.255.0", + }, privateNetworkId); + +**Remove a private network:** + +`var result = client.PrivateNetworks.Delete(privateNetworkId);` + +## VPN + +**Return a list of your vpns:** + +`var result = client.Vpn.Get()` + +**Return information about a vpn:** + +`var result = client.Vpn.Show(vpn.Id);` + +**Download your VPN configuration file, a string with base64 format with the configuration for OpenVPN. It is a zip file:** + +`var result = client.Vpn.ShowConfiguration(vpnId);` + +**Create a new vpn:** + +``` +var result = client.Vpn.Create(new POCO.Requests.Vpn.CreateVpnRequest + { + Name = "vpn test", + Description = "desc", + Datacenterid = datacenterId + }); +``` + +**Modify a vpn:** + +``` +var result = client.Vpn.Update(new POCO.Requests.Vpn.UpdateVpnRequest + { + Name = "updated name", + Description = "desc update" + }, vpnId); +``` + +**Remove a vpn:** + +`var result = client.Vpn.Delete(vpnId);` + + +## Monitoring Center + +**List usages and alerts of monitoring servers:** + +`var mCenters = client.MonitoringCenter.Get();` + + +**Return the usage of the resources for the specified time range:** + +`var mCenters = client.MonitoringCenter.Show(serverId, PeriodType.CUSTOM, DateTime.Today.AddMonths(-2), DateTime.Today);` + + + +## Monitoring Policies + +**Return a list of your monitoring policies:** + +`var result = client.MonitoringPolicies.Get();` + +**Return information about a monitoring policy:** + +`var result = client.MonitoringPolicies.Show(monitoringPolicyId);` + +**Create a new monitoring policy:** + + var ports = new List(); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 22, + Protocol = ProtocolType.TCP + }); + var processes = new List(); + processes.Add(new Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.NOT_RUNNING, + Process = "test", + }); + var request = new POCO.Requests.MonitoringPolicies.CreateMonitoringPolictRequest() + { + Name = ".netMP", + Description = ".net decription", + Agent = true, + Ports = ports, + Processes = processes, + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + }; + var result = client.MonitoringPolicies.Create(request); + +**Modifiy a monitoring policy:** + + var request = new UpdateMonitoringPolicyRequest() + { + Name = "updated" + monitoringPolicy.Name, + Thresholds = new POCO.Requests.MonitoringPolicies.Thresholds() + { + Cpu = new POCO.Requests.MonitoringPolicies.Cpu() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Ram = new POCO.Requests.MonitoringPolicies.Ram() + { + Critical = new POCO.Requests.MonitoringPolicies.Critical() + { + Alert = false, + Value = 95 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 90 + } + }, + Disk = new POCO.Requests.MonitoringPolicies.Disk() + { + Critical = new POCO.Requests.MonitoringPolicies.DiskCritical() + { + Alert = false, + Value = 90 + }, + Warning = new POCO.Requests.MonitoringPolicies.DiskWarning() + { + Alert = false, + Value = 80 + } + }, + InternalPing = new POCO.Requests.MonitoringPolicies.InternalPing() + { + Critical = new POCO.Requests.MonitoringPolicies.InternalPingCritical() + { + Alert = false, + Value = 100 + }, + Warning = new POCO.Requests.MonitoringPolicies.InternalPingWarning() + { + Alert = false, + Value = 50 + } + }, + Transfer = new POCO.Requests.MonitoringPolicies.Transfer() + { + Critical = new POCO.Requests.MonitoringPolicies.TransferCritical() + { + Alert = false, + Value = 2000 + }, + Warning = new POCO.Requests.MonitoringPolicies.Warning() + { + Alert = false, + Value = 1000 + } + } + } + }; + var result = client.MonitoringPolicies.Update(request, monitoringPolicy.Id); + +**Remove a monitoring policy:** + +`var result = client.MonitoringPolicies.Delete(monitoringPolicyId);` + +**Return a list of the ports of a monitoring policy:** + +`var result = client.MonitoringPoliciesPorts.Get(monitoringPolicyId);` + +**Returns information about a port of a monitoring policy:** + +`var result = client.MonitoringPoliciesPorts.Show(monitoringPolicy.Id, port.Id);` + +**Add new ports to a monitoring policy:** + + var ports = new List(); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 97, + Protocol = ProtocolType.TCP + }); + ports.Add(new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 98, + Protocol = ProtocolType.TCP + }); + var result = client.MonitoringPoliciesPorts.Create(ports, monitoringPolicyId); + +**Modify a port from a monitoring policy:** + + var request = new POCO.Requests.MonitoringPolicies.Ports() + { + EmailNotification = true, + AlertIf = AlertIfType.RESPONDING, + Port = 23, + Protocol = ProtocolType.TCP + }; + var result = client.MonitoringPoliciesPorts.Update(request, monitoringPolicyId, portId);` + +**Remove a port from a monitoring policy:** + +`var result = client.MonitoringPoliciesPorts.Delete(monitoringPolicyId, portId);` + +**Return a list of the processes of a monitoring policy:** + +`var result = client.MonitoringPoliciesProcesses.Get(monitoringPolicyId);` + +**Return information about a process of a monitoring policy:** + +`var result = client.MonitoringPoliciesProcesses.Show(monitoringPolicyId, processId);` + +**Add new processes to a monitoring policy:** + + var processes = new List(); + processes.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.RUNNING, + Process = "iexplorer" + }); + processes.Add(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.RUNNING, + Process = "test" + }); + var result = client.MonitoringPoliciesProcesses.Create(processes, monitoringPolicyId); + +**Modify a process from a monitoring policy:** + + var result = client.MonitoringPoliciesProcesses.Update(new POCO.Requests.MonitoringPolicies.Processes() + { + EmailNotification = true, + AlertIf = ProcessAlertType.RUNNING, + Process = "test" + }, monitoringPolicyId, processId); + +**Remove a process from a monitoring policy:** + +`var result = client.MonitoringPoliciesProcesses.Delete(monitoringPolicyId, processId);` + +**Return a list of the servers attached to a monitoring policy:** + +` var result = client.MonitoringPoliciesServers.Get(monitoringPolicyId);` + +**Return information about a server attached to a monitoring policy:** + +`var result = client.MonitoringPoliciesServers.Show(monitoringPolicyId, serverId);` + +**Attach servers to a monitoring policy:** + +`//servers are a list of string of the servers IDs +var result = client.MonitoringPoliciesServers.Create(servers, monitoringPolicyId);` + +**Unattach a server from a monitoring policy:** + +`var result = client.MonitoringPoliciesServers.Delete(monitoringPolicyId, serverId);` + + +## Logs + +**Return a list with logs:** + +`var result = client.Logs.Get(PeriodType.LAST_24H);` + +**Return information about a log:** + +`var result = client.Logs.Show(logId);` + + +## Users + +**Return a list with all users:** + +`var result = client.Users.Get();` + +**Return information about a user:** + +`var result = client.Users.Show(UserId);` + +**Creates a new user:** + + var result = client.Users.Create(new POCO.Requests.Users.CreateUserRequest() + { + Name = "test user", + Password = "Test123!", + Description = "description", + }); + +**Modify user information:** + + var result = client.Users.Update(new POCO.Requests.Users.UpdateUserRequest() + { + Description = "description", + State = UserState.ACTIVE + }, UserId); + +**Remove a user:** + +`var result = client.Users.Delete(UserId);` + +**Information about API:** + +`var result = client.UserAPI.ShowUserAPI(UserId);` + +**Allow to enable or disable the API:** + +` var result = client.UserAPI.UpdateUserAPI(UserId, true);` + +**Show the API key:** + +`var result = client.UserAPI.ShowUserAPIKey(UserId);` + +**Change the API key:** + +` var result = client.UserAPI.UpdateAPIKey(UserId);` + +**Return IPs from which access to API is allowed:** + +`var result = client.UserAPI.GetUserIps(UserId);` + +**Allow a new IP:** + + var listOfIps = new List(); + listOfIps.Add("185.13.243.86"); + var result = client.UserAPI.UpdateAPIIps(listOfIps, UserId);` + +**Delete an IP and forbid API access for it:** + +`var result = client.UserAPI.DeleteUserIp(UserId, allowedIp);` + +## Roles + +**Return a list with all roles:** + +`var result = client.Roles.Get();` + +**Return information about a role:** + +`var result = client.Roles.Show(roleId);` + +**Creates a new role:** + +``` +var result = client.Roles.Create(roleName); +``` + +**Modify role information:** + +`var result = client.Roles.Update(roleName, description, POCO.Requests.Users.UserState.ACTIVE, role.Id);` + +**Remove a role:** + +`var result = client.Roles.Delete(roleId);` + +**Lists role's permissions:** + +`var result = client.Roles.GetPermissions(role.Id);` + +**Adds permissions to the role:** + +``` +var result = client.Roles.UpdatePermissions(new Permissions + { + Servers = new POCO.Response.Roles.Servers + { + Show = true, + SetName = false, + Shutdown = true + } + }, roleId); +``` + +**Returns users assigned to role:** + +`var result = client.Roles.GetRoleUsers(roleId);` + +**Add users to role:** + +`var result=client.Roles.CreateRoleUsers(new System.Collections.Generic.List { { userId } }, roleId);` + +**Returns information about a user:** + +`var userInfo = client.Roles.ShowRoleUser(roleId, userId);` + +**Removes user from role:** + +``` +var removed = client.Roles.DeleteRoleUser(roleId, userId); +``` + +**Clones a role:** + +`var clone = client.Roles.CreateRoleClone(cloneName, roleId);` + +## Usages + +**Return a list of your usages:** + +`var result = client.Usages.Get(PeriodType.LAST_24H);` + + +## Server Appliances + +**Return a list of all the appliances that you can use for creating a server:** + +`var result = client.ServerAppliances.Get();` + +**Return Information about specific appliance:** + +`var result = client.ServerAppliances.Show(appliancesId);` + + +## DVD ISO + +**Return a list of all the operative systems and tools that you can load into your virtual DVD unit:** + +`var result = client.DVDs.Get();` + +**Information about specific ISO image:** + +`var result = client.DVDs.Show(dvdId);` + + +## Ping + +**Ping the API, returns true if the API is running:** + +`var result = client.Common.Ping();` + +**Ping the API Authentication, returns true if the API token is valid** + +`var result = client.Common.PingAuthentication();` + +## Pricing + +**Returns prices for all available resources in Cloud Panel:** + +`var result = client.Common.GetPricing();` + +## Datacenters + +**Returns information about available datacenters to create your resources:** + +`var result = client.DataCenters.Get();` + +**Returns information about a datacenter:** + +`var result = client.DataCenters.Show(dcId);` + + + +Copyright (c) 2016 1&1 Internet SE +