public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options) { LinodeNodeOptions ops = options as LinodeNodeOptions; if (ops == null && options != null) throw new Exception ("Only LinodeNodeOptions can be used as NodeOptions for creating Linode Nodes."); else if (ops == null) ops = new LinodeNodeOptions (); return API.CreateNode (name, size, image, location, auth, ops); }
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); }
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"); }