Ejemplo n.º 1
0
 def _configure_instance(self, instance, runtime, hostfile_lock):
     self._log.debug('Configuring instance %s', instance.instance_id)
     client = self.connect(instance)
     cpus = rcl.cpu_count(client)
     with hostfile_lock:
         self.hostfile += (instance.private_ip_address + '\n') * cpus
     if runtime:
         rcl.pmk_cmd(client, runtime.format(**self.__dict__))
Ejemplo n.º 2
0
    def create_ami(self, base=None, setup_fn=None, ver=None, update_image=True,
                   terminate=True, wait=True):
        """
        Create an AMI, returning the AMI ID.

        :param base: boto3.EC2.Instance object or nothing; optional to allow for
            snapshotting.
        :param setup_fn: The shell script used to configure the instance;
            optional to allow for snapshotting.
        :param ver: Name of AMI, defaults to self.ver.
        :param update_image: Flag; whether to change the RCluster's
            instance_conf AMI ID to that of the new image.
        :param terminate: Flag; whether to terminate the instance used to build
            the AMI (useful for debugging).
        """
        if not base:
            self._log.debug('Creating base instance for AMI generation.')
            base = self.create_instances(
                1,
                InstanceType='m4.large',
                Placement=None
            )[0]
            sleep(20)
        if setup_fn:
            client = self.connect(base)
            sftp_conn = client.open_sftp()
            sftp_conn.put(setup_fn, 'setup.sh')
            self._log.debug('Setup script %s, running configuration.', setup_fn)
            rcl.pmk_cmd(client, 'sudo bash setup.sh')
        if not ver:
            ver = self.ver
        self._log.debug('Creating AMI %s', self.ver)
        image = base.create_image(
            DryRun=False,
            Name=ver,
            Description="RCluster AMI",
            NoReboot=False
        )
        base.wait_until_running()
        if wait:
            while 'available' not in self.ec2.Image(image.id).state:
                self._log.debug('Waiting for AMI %s to be available', image.id)
                sleep(20)
        if terminate:
            base.terminate()
        if update_image:
            self.instance_conf['ImageId'] = image.id
        return image.id
Ejemplo n.º 3
0
    def issue_cmd(self, call, client=None, **kwargs):
        """

        :param call:
        :param client:
        :return:
        """
        if not client:
            client = self.connect()
        return rcl.pmk_cmd(client, call, **kwargs)