Ejemplo n.º 1
0
        /// <summary>
        /// Gets the Operating System configuration for the Server.
        /// </summary>
        /// <param name="server">The Server to extract the Operating System
        /// configuration for.</param>
        /// <returns>The Operating System configuration for the Server.</returns>
        /// <exception cref="ArgumentException">If the Server Operating System is
        /// misconfigured.</exception>
        public VultrOperatingSystem GetOs(Server server)
        {
            if (!string.IsNullOrEmpty(server.Os.App))
            {
                if (!string.IsNullOrEmpty(server.Os.Name))
                {
                    throw new ArgumentException(
                              "OS.Name must be empty if OS.App is set", nameof(server));
                }

                if (!string.IsNullOrEmpty(server.Os.Iso))
                {
                    throw new ArgumentException(
                              "OS.ISO must be empty if OS.App is set", nameof(server));
                }

                if (!string.IsNullOrEmpty(server.StartupScript))
                {
                    throw new ArgumentException(
                              "OS.StartupScript must be empty if OS.App is set",
                              nameof(server));
                }

                return(VultrOperatingSystem.CreateApp(server.Os.App, Client));
            }

            if (!string.IsNullOrEmpty(server.Os.Iso))
            {
                if (!string.IsNullOrEmpty(server.Os.Name))
                {
                    throw new ArgumentException(
                              "OS.Name must be empty if OS.ISO is set", nameof(server));
                }

                if (!string.IsNullOrEmpty(server.StartupScript))
                {
                    throw new ArgumentException(
                              "OS.StartupScript must be empty if OS.ISO is set",
                              nameof(server));
                }

                return(VultrOperatingSystem.CreateIso(server.Os.Iso, Client));
            }

            if (string.IsNullOrEmpty(server.Os.Name))
            {
                throw new ArgumentException(
                          "OS.App, OS.ISO or OS.Name must be set", nameof(server));
            }

            return(!string.IsNullOrEmpty(server.StartupScript) ?
                   VultrOperatingSystem.CreateScript(server.Os.Name, server.StartupScript, Client)
                : VultrOperatingSystem.CreateOs(server.Os.Name, Client));
        }
Ejemplo n.º 2
0
        public void TestCreateSnapshot(string id)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/snapshot/list", Resources.VultrSnapshotList));

            var snapshot = VultrOperatingSystem.CreateSnapshot(id, requests.Client);

            Assert.Equal(164, snapshot.OsId);
            Assert.Equal(id, snapshot.SnapshotId);
            Assert.Null(snapshot.Appid);
            Assert.Null(snapshot.IsoId);
            Assert.Null(snapshot.ScriptId);
        }
Ejemplo n.º 3
0
        public void TestCreateOs(int id, string name)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/os/list", Resources.VultrOSList));

            var os = VultrOperatingSystem.CreateOs(name, requests.Client);

            Assert.Equal(id, os.OsId);
            Assert.Null(os.Appid);
            Assert.Null(os.IsoId);
            Assert.Null(os.ScriptId);
            Assert.Null(os.SnapshotId);
        }
Ejemplo n.º 4
0
        public void TestCreateIso(string name, int id)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/iso/list", Resources.VultrISOList));

            var iso = VultrOperatingSystem.CreateIso(name, requests.Client);

            Assert.Equal(159, iso.OsId);
            Assert.Equal(id, iso.IsoId);
            Assert.Null(iso.Appid);
            Assert.Null(iso.ScriptId);
            Assert.Null(iso.SnapshotId);
        }
Ejemplo n.º 5
0
        public void TestCreateApp(int id, string name)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/app/list", Resources.VultrAppList));

            var app = VultrOperatingSystem.CreateApp(name, requests.Client);

            Assert.Equal(186, app.OsId);
            Assert.Equal(id, app.Appid);
            Assert.Null(app.IsoId);
            Assert.Null(app.ScriptId);
            Assert.Null(app.SnapshotId);
        }
Ejemplo n.º 6
0
        public void TestCreateScript(string name, int id)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/os/list", Resources.VultrOSList),
                      new HttpHandler(
                          "/startupscript/list", Resources.VultrStartupScripts));

            var script = VultrOperatingSystem.CreateScript(
                "FreeBSD 11 x64", name, requests.Client);

            Assert.Equal(230, script.OsId);
            Assert.Equal(id, script.ScriptId);
            Assert.Null(script.Appid);
            Assert.Null(script.IsoId);
            Assert.Null(script.SnapshotId);
        }