Example #1
0
        public Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, LinodeNodeOptions options)
        {
            int rsize = size.Disk - options.SwapSize;

            string kernel = FindKernel (options);

            LinodeRequest request = new LinodeRequest ("linode.create", new Dictionary<string,object> {
                {"DatacenterID", location.Id}, {"PlanID", size.Id},
                {"PaymentTerm", (int) options.PaymentTerm}});
            LinodeResponse response = Execute (request);

            JObject node = response.Data [0];
            string id = node ["LinodeID"].ToString ();

            string root_pass;
            if (auth.Type == NodeAuthType.Password)
                root_pass = auth.Secret;
            else
                root_pass = GenerateRandomPassword ();

            request = new LinodeRequest ("linode.disk.createfromdistribution", new Dictionary<string,object> {
                {"LinodeID", id}, {"DistributionID", image.Id}, {"Label", name}, {"Size", rsize},
                {"rootPass", root_pass}});

            if (auth.Type == NodeAuthType.SSHKey)
                request.Parameters.Add ("rootSSHKey", auth.Secret);

            response = Execute (request);

            JObject distro = response.Data [0];
            string root_disk = distro ["DiskID"].ToString ();

            request = new LinodeRequest ("linode.disk.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"Label", "Swap"}, {"Type", "swap"}, {"Size", options.SwapSize}});
            response = Execute (request);

            string swap_disk = response.Data [0] ["DiskID"].ToString ();
            string disks = String.Format ("{0},{1},,,,,,,", root_disk, swap_disk);

            request = new LinodeRequest ("linode.config.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"KernelID", kernel}, {"Label", "mcloud config"}, {"DiskList", disks}});
            response = Execute (request);

            string config = response.Data [0]["ConfigID"].ToString ();

            request = new LinodeRequest ("linode.boot", new Dictionary<string,object> {
                {"LinodeID", id}, {"ConfigID", config}});
            response = Execute (request);

            request = new LinodeRequest ("linode.list", new Dictionary<string,object> {{"LinodeID", id}});
            response = Execute (request);

            return LinodeNode.FromData (response.Data [0], driver);
        }
Example #2
0
        public Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, int swap=128)
        {
            int rsize = size.Disk - swap;

            string kernel = FindKernel ();

            Console.WriteLine ("USING KERNEL:  {0}", kernel);

            LinodeRequest request = new LinodeRequest ("linode.create", new Dictionary<string,object> {
                {"DatacenterID", location.Id}, {"PlanID", size.Id},
                {"PaymentTerm", (int) driver.PaymentTerm}});
            LinodeResponse response = Execute (request);

            JObject node = response.Data [0];
            string id = node ["LinodeID"].ToString ();

            request = new LinodeRequest ("linode.disk.createfromdistribution", new Dictionary<string,object> {
                {"LinodeID", id}, {"DistributionID", image.Id}, {"Label", name}, {"Size", size.Disk},
                {"rootPass", "F23444sd"}});

            response = Execute (request);

            JObject distro = response.Data [0];
            string root_disk = distro ["DiskID"].ToString ();

            request = new LinodeRequest ("linode.disk.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"Label", "Swap"}, {"Type", "swap"}, {"Size", swap}});
            response = Execute (request);

            string swap_disk = response.Data [0] ["DiskID"].ToString ();
            string disks = String.Format ("{0},{1},,,,,,,", root_disk, swap_disk);

            request = new LinodeRequest ("linode.config.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"KernelID", kernel}, {"Label", "mcloud config"}, {"DiskList", disks}});
            response = Execute (request);

            string config = response.Data [0]["ConfigID"].ToString ();

            request = new LinodeRequest ("linode.boot", new Dictionary<string,object> {
                {"LinodeID", id}, {"ConfigID", config}});
            response = Execute (request);

            return null;
        }
Example #3
0
        private string FindKernel(LinodeNodeOptions options)
        {
            LinodeRequest request = new LinodeRequest ("avail.kernels");
            LinodeResponse response = Execute (request);

            foreach (JObject kernel in response.Data) {
                string label = (string) kernel ["LABEL"];
                if (options.Prefer64Bit && label == options.Kernel64Bit)
                    return kernel ["KERNELID"].ToString ();
                else if (!options.Prefer64Bit && label == options.Kernel32Bit)
                    return kernel ["KERNELID"].ToString ();
            }

            throw new Exception ("Unable to find a suitable Linode kernel");
        }
Example #4
0
        internal void IPsForNode(string id, List<IPAddress> public_ips, List<IPAddress> private_ips)
        {
            LinodeRequest request = new LinodeRequest ("linode.ip.list", new Dictionary<string,object> () {{"LINODEID", id}});
            LinodeResponse response = Execute (request);
            var ip_data = response.Data;

            foreach (var ip in ip_data) {
                if (ip ["ISPUBLIC"] != null)
                    public_ips.Add (IPAddress.Parse ((string) ip ["IPADDRESS"]));
                else
                    private_ips.Add (IPAddress.Parse ((string) ip ["IPADDRESS"]));
            }
        }
Example #5
0
        internal LinodeResponse Execute(LinodeRequest request)
        {
            string url = String.Concat (base_url, request.UrlParams ());

            string data = webclient.DownloadString (url);
            return LinodeResponse.FromJson (data);
        }
Example #6
0
        public bool RebootNode(Node node)
        {
            LinodeRequest request = new LinodeRequest ("linode.boot", new Dictionary<string,object> {{"LINODEID", node.Id}});
            LinodeResponse response = Execute (request);

            return true;
        }
Example #7
0
        public List<NodeSize> ListSizes(NodeLocation location)
        {
            LinodeRequest request = new LinodeRequest ("avail.linodeplans");
            LinodeResponse response = Execute (request);

            List<NodeSize> sizes = new List<NodeSize> ();
            foreach (JObject obj in response.Data) {
                string id = obj ["PLANID"].ToString ();
                string name = (string) obj ["LABEL"];
                int ram = (int) obj ["RAM"];
                int disk = (int) obj ["DISK"] * 1024;
                int bandwidth = (int) obj ["XFER"];
                float price = (float) obj ["PRICE"]; // price in dollars, we use cents

                NodeSize size = new NodeSize (id, name, ram, disk, bandwidth, (int) (price * 100), driver);
                sizes.Add (size);
            }

            return sizes;
        }
Example #8
0
        public List<Node> ListNodes()
        {
            LinodeRequest request = new LinodeRequest ("linode.list");
            LinodeResponse response = Execute (request);

            List<Node> nodes = new List<Node> ();
            foreach (var node in response.Data) {
                nodes.Add (LinodeNode.FromData (node, driver));
            }

            return nodes;
        }
Example #9
0
        public List<NodeLocation> ListLocations()
        {
            LinodeRequest request = new LinodeRequest ("avail.datacenters");
            LinodeResponse response = Execute (request);

            List<NodeLocation> locations = new List<NodeLocation> ();
            foreach (JObject obj in response.Data) {
                string id = obj ["DATACENTERID"].ToString ();
                string location = (string) obj ["LOCATION"];
                string country = null;

                if (location.Contains ("USA"))
                    country = "US";
                else if (location.Contains ("UK"))
                    country = "GB";
                else
                    throw new Exception (String.Format ("Can not determine location country: {0}", location));

                NodeLocation loc= new NodeLocation (id, location, country, driver);
                locations.Add (loc);
            }

            return locations;
        }
Example #10
0
        public List<NodeImage> ListImages(NodeLocation location)
        {
            LinodeRequest request = new LinodeRequest ("avail.distributions");
            LinodeResponse response = Execute (request);

            List<NodeImage> images = new List<NodeImage> ();
            foreach (JObject obj in response.Data) {
                string id = obj ["DISTRIBUTIONID"].ToString ();
                string name = (string) obj ["LABEL"];

                NodeImage image = new NodeImage (id, name, driver);
                images.Add (image);
            }

            return images;
        }
Example #11
0
 public void Echo()
 {
     LinodeRequest request = new LinodeRequest ("test.echo");
     LinodeResponse response = Execute (request);
 }
Example #12
0
        public bool DestroyNode(Node node)
        {
            LinodeRequest request = new LinodeRequest ("linode.delete", new Dictionary<string,object> {
                {"LinodeID", node.Id}, {"skipChecks", true}});
            LinodeResponse response = Execute (request);

            return true;
        }
Example #13
0
 public static LinodeResponse Execute(LinodeRequest request)
 {
 }
Example #14
0
        public List<Node> ListNodes(string id)
        {
            LinodeRequest request = new LinodeRequest ("linode.list");

            if (id != null)
                request.Parameters.Add ("LinodeID", id);

            LinodeResponse response = Execute (request);

            List<Node> nodes = new List<Node> ();
            foreach (var node in response.Data) {
                nodes.Add (LinodeNode.FromData (node, driver));
            }

            return nodes;
        }