An authorization mechanism for connecting to a node. These can be userid/password pairs, or userid and keyfile. The default user name is "root".
示例#1
0
        private void RunScript(string host, NodeAuth auth)
        {
            SshExec exec = new SshExec (host, auth.UserName);

            SetupSSH (exec, auth);

            exec.RunCommand (RemoteScriptPath);
        }
示例#2
0
        private void CopyScript(string host, NodeAuth auth)
        {
            Scp scp = new Scp (host, auth.UserName);

            SetupSSH (scp, auth);

            scp.Put (LocalScriptPath, RemoteScriptPath);
            scp.Close ();
        }
示例#3
0
        public static void Main(string[] args)
        {
            ///
            /// To run this sample you must have a
            /// LINODE-KEY.txt file with your Linode API
            /// key in it.  See the getting started guide for
            /// info on how to get a key.
            ///
            /// Note that this sample will create a new node
            /// on your account and you will be billed at least
            /// 1 day for that node.  You can manually destroy the
            /// node when you are done at linode.com or you can
            /// make a call to node.Destroy.
            ///

            if (!File.Exists ("LINODE-KEY.txt"))
                throw new Exception ("You must have a LINODE-KEY.txt file to run this sample.");

            var key = File.ReadAllText ("LINODE-KEY.txt").Trim ();
            if (key.Length < 40)
                throw new Exception ("Your LINODE-KEY.txt file must contain a Linode API key.");

            var driver = new LinodeDriver (key);

            // Find a location in the USA
            var location = driver.ListLocations ().FirstOrDefault (l => l.Country == "US");

            // Pick the cheapest plan possible
            var size = driver.ListSizes ().OrderBy (s => s.Price).FirstOrDefault ();

            // Grab any OpenSuse image.
            var image = driver.ListImages ().FirstOrDefault (i => i.Name.Contains ("OpenSUSE"));

            Console.WriteLine ("location: {0}  size:  {1}  image:  {2}", location, size, image);

            // Create the new with a random password
            string password = System.Web.Security.Membership.GeneratePassword (10, 3);
            NodeAuth auth = new NodeAuth (NodeAuthType.Password, password);
            Node n = driver.CreateNode ("my new node", size, image, location, auth);

            Console.WriteLine ("created new node located at {0} with password {1}", n.PublicIPs [0], password);

            var deployment = new MultiStepDeployment () {
                // Create a file on the node
                new RunCommand ("touch /root/test"),
                // Upload a file to the node
                new PutFile ("CreateLinode.exe"),
            };
            n.Deploy (deployment, auth);

            Console.WriteLine ("Your node has been deployed.");
        }
示例#4
0
        public override void Run(Node node, NodeAuth auth)
        {
            if (node == null)
                throw new ArgumentNullException ("node");
            if (auth == null)
                throw new ArgumentNullException ("auth");

            if (node.PublicIPs.Count < 1)
                throw new ArgumentException ("node", "No public IPs available on node.");

            string host = node.PublicIPs [0].ToString ();
            CopyScript (host, auth);

            SshExec exec = new SshExec (host, auth.UserName);
        }
示例#5
0
 private void SetupSSH(SshBase ssh, NodeAuth auth)
 {
     if (auth.Type == NodeAuthType.Password)
         ssh.Password = auth.Secret;
 }
示例#6
0
 public abstract void Run(Node node, NodeAuth auth);
示例#7
0
 public override void Run(Node node, NodeAuth auth)
 {
     foreach (Deployment d in Steps) {
         d.Run (node, auth);
     }
 }
示例#8
0
文件: Node.cs 项目: jacksonh/MCloud
 /// <summary>
 /// Run the supplied deployment on the node.  This is a syncrhonous operation and will block until
 /// the node deployment is completed.
 /// </summary>
 public void Deploy(Deployment d, NodeAuth auth)
 {
     d.Run (this, auth);
 }
示例#9
0
 public abstract Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options);
示例#10
0
 /// <summary>
 /// Create a new node using the default options for this node driver type.
 /// </summary>
 public Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth)
 {
     return CreateNode (name, size, image, location, auth, DefaultOptions);
 }