while status != 'available':
            if i%10 == 0:
                self.logger.log("\nPlease wait .")
            self.logger.log(".", append_to_last=True)
            status = self.conn.get_all_images(image_ids=[image_id])[0].state
            time.sleep(3)
            i=i+1

        self.logger.log("Done")

    def wait_terminate(self, instance_id):
        self.logger.log("Waiting for instance to terminate\nPlease wait ..")
        status = self.conn.get_all_instances([instance_id])[0].instances[0].state
        i=1
        while status != 'terminated':
            if i%10 == 0:
                self.logger.log("\nPlease wait .")
            self.logger.log(".", append_to_last=True)
            status = self.conn.get_all_instances([instance_id])[0].instances[0].state
            time.sleep(3)
            i=i+1

        self.logger.log("Instance is terminated!")

if __name__ == "__main__":
    check_args(2, "<output_dir> <config_path>")
    user_path, cfg, logger = get_cfg_logger(sys.argv[1], sys.argv[2])
    EC2CreateAMI(cfg, logger)


Exemple #2
0
                                   'Security group for MongoDB protocol',
                                   'tcp', ['27017', '27037', '27019'],
                                   '0.0.0.0/0')

    def create_security_group(self, name, description, protocol, ports, cidr):
        try:
            security_group = self.nc.security_groups.find(name=name)
        except NotFound:
            security_group = self.nc.security_groups.create(name, description)
        except Exception as e:
            raise e

        try:
            if not isinstance(ports, list):
                ports = [ports]
            for port in ports:
                self.nc.security_group_rules.create(security_group.id,
                                                    protocol, port, port, cidr)
        except BadRequest as e:
            if e.message != u'Security group %s already exists' % name and e.message != u'This rule already exists in group %s' % security_group.id:
                raise
        except Exception as e:
            pass


if __name__ == "__main__":
    check_args(2, "<output_dir> <config_path>")
    path, cfg, logger = get_cfg_logger(sys.argv[1], sys.argv[2])

    RemoveAll(cfg, logger)
from cloudscale.deployment_scripts.scripts import check_args, get_cfg_logger


class CreateKeyPair(AWSConfig):

    def __init__(self, user_path, config, logger):
        AWSConfig.__init__(self, config, logger)
        self.user_path = user_path

    def create(self):
        conn = ec2.connect_to_region(
            self.region,
            aws_access_key_id=self.access_key,
            aws_secret_access_key=self.secret_key
        )

        try:
            keypair = conn.create_key_pair(self.key_name)
        except EC2ResponseError as e:
            if e.error_code == 'InvalidKeyPair.Duplicate':
                conn.delete_key_pair(key_name=self.key_name)
                keypair = conn.create_key_pair(self.key_name)
            else:
                raise e

        keypair.save(self.user_path)

if __name__ == '__main__':
    check_args(2, "<config_path>")
    user_path, config, logger = get_cfg_logger(sys.argv[1], sys.argv[2])
    CreateKeyPair(user_path, config, logger)