Beispiel #1
0
 def _ssh_output(self, cmd):
     return ssh_util.ssh_output(self.host, [cmd],
                                user=self.user,
                                private_key=remote_util.config_path(
                                    self.private_key),
                                connect_timeout=self.connect_timeout,
                                port=self.port)
Beispiel #2
0
 def _public_key(self):
     if not self.public_key:
         return None
     maybe_path = remote_util.config_path(self.public_key)
     if os.path.exists(maybe_path):
         return open(maybe_path, "r").read()
     else:
         return self.public_key
Beispiel #3
0
 def _copy_package_dist(self, package_dist_dir, remote_run_dir):
     src = package_dist_dir + "/"
     host_dest = "{}/.guild/job-packages/".format(remote_run_dir)
     log.info("Copying package")
     ssh_util.rsync_copy_to(
         src, self.host, host_dest,
         user=self.user,
         private_key=remote_util.config_path(self.private_key),
         port=self.port)
Beispiel #4
0
 def _ssh_cmd(self, cmd):
     ssh_util.ssh_cmd(
         self.host,
         [cmd],
         user=self.user,
         private_key=remote_util.config_path(self.private_key),
         connect_timeout=self.connect_timeout,
         port=self.port,
         proxy=self.proxy,
     )
Beispiel #5
0
 def _pull_run(self, run, delete):
     src_path = "{}/runs/{}/".format(self.guild_home, run.id)
     src = ssh_util.format_rsync_host_path(self.host, src_path, self.user)
     dest = os.path.join(var.runs_dir(), run.id + "/")
     cmd = ["rsync"] + self._pull_rsync_opts(delete) + [src, dest]
     cmd.extend(
         ssh_util.rsync_ssh_opts(remote_util.config_path(self.private_key),
                                 self.connect_timeout, self.port))
     log.info("Copying %s", run.id)
     log.debug("rsync cmd: %r", cmd)
     subprocess.check_call(cmd)
     remote_util.set_remote_lock(run, self.name)
Beispiel #6
0
 def _push_run(self, run, delete):
     src = run.path + "/"
     dest_path = "{}/runs/{}/".format(self.guild_home, run.id)
     dest = ssh_util.format_rsync_host_path(self.host, dest_path, self.user)
     cmd = ["rsync"] + self._push_rsync_opts(delete) + [src, dest]
     cmd.extend(
         ssh_util.rsync_ssh_opts(
             remote_util.config_path(self.private_key),
             self.connect_timeout,
             self.port,
             self.proxy,
         ))
     log.info("Copying %s", run.id)
     log.debug("rsync cmd: %r", cmd)
     subprocess.check_call(cmd)
Beispiel #7
0
 def _push_run(self, run, delete):
     cmd = ["rsync", "-al"]
     if delete:
         cmd.append("--delete")
     if log.getEffectiveLevel() <= logging.DEBUG:
         cmd.append("-vvv")
     else:
         cmd.append("-v")
     src = run.path + "/"
     dest_path = "{}/runs/{}/".format(self.guild_home, run.id)
     dest = ssh_util.format_rsync_host_path(self.host, dest_path, self.user)
     cmd.extend([src, dest])
     cmd.extend(
         ssh_util.rsync_ssh_opts(remote_util.config_path(self.private_key),
                                 self.connect_timeout, self.port))
     log.info("Copying %s", run.id)
     log.debug("rsync cmd: %r", cmd)
     subprocess.check_call(cmd)
Beispiel #8
0
 def _init_config(self):
     remote_name = self._safe_name()
     remote_key = "guild_%s" % remote_name
     vpc = {remote_key: {}}
     security_group = {
         remote_key: {
             "name":
             "guild-%s" % remote_name,
             "description":
             ("Security group for Guild remote %s" % remote_name),
             "vpc_id":
             "${aws_default_vpc.%s.id}" % remote_key,
             "ingress": [
                 {
                     "from_port": -1,
                     "to_port": -1,
                     "protocol": "icmp",
                     "cidr_blocks": ["0.0.0.0/0"],
                     "description": None,
                     "ipv6_cidr_blocks": None,
                     "prefix_list_ids": None,
                     "security_groups": None,
                     "self": None,
                 },
                 {
                     "from_port": 22,
                     "to_port": 22,
                     "protocol": "tcp",
                     "cidr_blocks": ["0.0.0.0/0"],
                     "description": None,
                     "ipv6_cidr_blocks": None,
                     "prefix_list_ids": None,
                     "security_groups": None,
                     "self": None,
                 },
             ],
             "egress": [{
                 "from_port": 0,
                 "to_port": 0,
                 "protocol": "-1",
                 "cidr_blocks": ["0.0.0.0/0"],
                 "description": None,
                 "ipv6_cidr_blocks": None,
                 "prefix_list_ids": None,
                 "security_groups": None,
                 "self": None,
             }],
         }
     }
     instance = {
         remote_key: {
             "instance_type":
             self.instance_type,
             "ami":
             self.ami,
             "vpc_security_group_ids":
             ["${aws_security_group.%s.id}" % remote_key],
         }
     }
     if self.root_device_size:
         instance[remote_key]["root_block_device"] = {
             "volume_size": self.root_device_size
         }
     output = {
         "host": {
             "value": "${aws_instance.%s.public_dns}" % remote_key
         }
     }
     config = {
         "provider": {
             "aws": {
                 "region": self.region
             },
             "null": {}
         },
         "resource": {
             "aws_default_vpc": vpc,
             "aws_security_group": security_group,
             "aws_instance": instance,
         },
         "output": output,
     }
     public_key = self._public_key()
     if public_key:
         config["resource"]["aws_key_pair"] = {
             remote_key: {
                 "key_name": remote_key,
                 "public_key": public_key
             }
         }
         instance[remote_key]["key_name"] = remote_key
     init_script = self._init_script()
     if init_script:
         init_script_path = self._write_init_script(init_script)
         connection = {
             "type": "ssh",
             "host": "${aws_instance.%s.public_ip}" % remote_key,
         }
         if self.init_timeout:
             if isinstance(self.init_timeout, int):
                 connection["timeout"] = "%im" % self.init_timeout
             else:
                 connection["timeout"] = self.init_timeout
         if self.private_key:
             connection[
                 "private_key"] = "${file(\"%s\")}" % remote_util.config_path(
                     self.private_key)
         if self.user:
             connection["user"] = self.user
         config["resource"]["null_resource"] = {
             "%s_init" % remote_key: {
                 "triggers": {
                     "cluster_instance_ids":
                     "${aws_instance.%s.id}" % remote_key
                 },
                 "connection": connection,
                 "provisioner": [{
                     "remote-exec": {
                         "script": init_script_path
                     }
                 }],
             }
         }
     return config
Beispiel #9
0
 def _ssh_output(self, cmd):
     return ssh_util.ssh_output(self.host, [cmd], self.user,
                                remote_util.config_path(self.private_key))
Beispiel #10
0
 def _ssh_cmd(self, cmd):
     ssh_util.ssh_cmd(self.host, [cmd], self.user, self.port,
                      remote_util.config_path(self.private_key))