コード例 #1
0
ファイル: PutSSHKeys.cs プロジェクト: jacksonh/MCloud
        protected override void RunImpl(Node node, NodeAuth auth)
        {
            string host = node.PublicIPs [0].ToString ();

            RunCommand ("mkdir " + RemoteDirectory, host, auth);
            PutFile (host, auth, FilePath, RemoteDirectory);
        }
コード例 #2
0
ファイル: LinodeDriver.cs プロジェクト: jacksonh/MCloud
 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);
 }
コード例 #3
0
ファイル: SSHDeployment.cs プロジェクト: jacksonh/MCloud
        protected void PutFile(string host, NodeAuth auth, string local, string remote)
        {
            Scp scp = new Scp (host, auth.UserName);

            SetupSSH (scp, auth);

            scp.Put (local, remote);
            scp.Close ();
        }
コード例 #4
0
ファイル: SSHDeployment.cs プロジェクト: jacksonh/MCloud
        protected void PutDirectory(string host, NodeAuth auth, string local, string remote)
        {
            Scp scp = new Scp (host, auth.UserName);

            SetupSSH (scp, auth);

            scp.To (local, remote, true);
            scp.Close ();
        }
コード例 #5
0
ファイル: RunScript.cs プロジェクト: jacksonh/MCloud
        protected override void RunImpl(Node node, NodeAuth auth)
        {
            string host = node.PublicIPs [0].ToString ();

            string remote = String.Concat (RemoteDirectory, FilePath);

            PutFile (host, auth, FilePath, remote);
            RunCommand ("chmod 775 " + remote, host, auth);
            RunCommand (remote, host, auth);
        }
コード例 #6
0
ファイル: Deployment.cs プロジェクト: jacksonh/MCloud
        /// <summary>
        /// Execute the deployment using the supplied NodeAuth to log into the node.
        /// </summary>
        public void Run(Node node, NodeAuth auth)
        {
            if (node == null)
                throw new ArgumentNullException ("node");
            if (auth == null)
                throw new ArgumentNullException ("auth");

            EnsureNodeRunning (node);
            RunImpl (node, auth);
        }
コード例 #7
0
ファイル: PushPgsqlDB.cs プロジェクト: jacksonh/MCloud
        protected override void RunImpl(Node node, NodeAuth auth)
        {
            string host = node.PublicIPs [0].ToString ();
            string file = GetDumpFile ();

            PutFile (host, auth, file, "/root/dump.sql.gz");
            RunCommand ("gunzip -d -f /root/dump.sql.gz", host, auth);
            RunCommand ("mv /root/dump.sql ~postgres/.", host, auth);
            RunCommand ("sudo -u postgres psql -f ~postgres/dump.sql", host, auth);
        }
コード例 #8
0
ファイル: SSHDeployment.cs プロジェクト: jacksonh/MCloud
        protected void RunCommand(string command, string host, NodeAuth auth)
        {
            SshExec exec = new SshExec (host, auth.UserName);

               SetupSSH (exec, auth);

               Console.WriteLine ("running command:  {0}   on host:  {1}", command, host);
               Console.WriteLine (exec.RunCommand (command));
               exec.Close ();
        }
コード例 #9
0
ファイル: LinodeAPI.cs プロジェクト: aggrata/MCloud
        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);
        }
コード例 #10
0
ファイル: EC2Driver.cs プロジェクト: jacksonh/MCloud
        public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options)
        {
            EC2NodeOptions ops = options as EC2NodeOptions;
            if (ops == null && options != null)
                throw new Exception ("Only EC2NodeOptions can be used as NodeOptions for creating EC2 Nodes.");
            else if (ops == null)
                ops = new EC2NodeOptions ();

            RunInstancesRequest request = new RunInstancesRequest () {
                InstanceType = size.Id,
                ImageId = image.Id,
                MinCount = 1,
                MaxCount = 1,
                KeyName = auth.UserName,
            };
            RunInstancesResponse response = Client.RunInstances (request);

            foreach (var i in response.RunInstancesResult.Reservation.RunningInstance) {
                return EC2Node.FromRunningInstance (i, this);
            }

            return null;
        }
コード例 #11
0
ファイル: SSHDeployment.cs プロジェクト: jacksonh/MCloud
        protected void SetupSSH(SshBase ssh, NodeAuth auth)
        {
            if (auth.Type == NodeAuthType.Password)
                ssh.Password = auth.Secret;
            if (auth.Type == NodeAuthType.SSHKey)
                ssh.AddIdentityFile (auth.Secret);

            Exception error = null;
            for (int i = 0; i < MaxConnectionAttempts; i++) {

                try{
                    ssh.Connect ();
                    return;
                } catch (Exception e) {
                    Console.WriteLine ("Connection error: {0}", e);
                    error = e;
                }

                Thread.Sleep (100);
            }

            if (error != null)
                throw error;
        }
コード例 #12
0
 protected override void RunImpl(Node node, NodeAuth auth)
 {
     foreach (Deployment d in Steps) {
         d.Run (node, auth);
     }
 }
コード例 #13
0
ファイル: Deployment.cs プロジェクト: jacksonh/MCloud
 protected abstract void RunImpl(Node node, NodeAuth auth);
コード例 #14
0
ファイル: PutDirectory.cs プロジェクト: jacksonh/MCloud
        protected override void RunImpl(Node node, NodeAuth auth)
        {
            string host = node.PublicIPs [0].ToString ();

            PutDirectory (host, auth, LocalDirectory, RemoteDirectory);
        }
コード例 #15
0
ファイル: PutFiles.cs プロジェクト: jacksonh/MCloud
        protected override void RunImpl(Node node, NodeAuth auth)
        {
            string host = node.PublicIPs [0].ToString ();

            foreach (string file in Files) {
                string remote = Path.Combine (RemoteDirectory, Path.GetFileName (file));

                PutFile (host, auth, file, remote);
            }
        }