Exemple #1
0
    def __init__(self):
        print "You are about to generate a puppet master server!"
        print "If one already exists, this method will fail. Please modify the code and rerun."
        print "If you want to learn puppet, use generic servers instead!"
        print "You can continue if you know the consequences of having multiple puppetmasters."
        sleep(3)
        
        # need to init the parent object to get connections
        BaseServer.__init__(self, "Puppetmaster")

        # Stop if puppetmaster exists
        if utils.get_puppetmaster_instance(self.ec2_conn) is not None:
            print "... and a puppetmaster exists. We're stopping now!"
            raise Exception("Puppetmaster exists!")

        # parameters are very specific.
        # use a string with comma separation between security groups!!
        # using lists will cause a creation to fail!
        self.params = [
                ("Hostname", self.hostname),
                ("PrivateIpAddress", self.private_ip),
                ("SubnetType",self.privacy_setting),
                ("SubnetRegion", self.subnet["az"]),
                ("InstanceType", self.instance_type),
                ("SecurityGroupIds", self.security_groups)]
Exemple #2
0
def deactivate_nodes(cf_conn, stackname):
    ec2_conn = AWS.get_ec2_connection()

    pm_instance = utils.get_puppetmaster_instance(ec2_conn)

    if pm_instance is None:
        return

    puppetmaster_ip = pm_instance.ip_address
    print "Deactivating nodes on puppetmaster (%s)" % puppetmaster_ip

    instance_ids = set()
    resources = cf_conn.list_stack_resources(stack_name_or_id=stackname)
    for r in resources:
        if r.resource_type == "AWS::EC2::Instance":
            instance_ids.add(r.physical_resource_id)

    password = fetch_secrets("secrets/hcs-root")

    ssh_conn = SSHable(puppetmaster_ip)
    ssh_conn.connect()

    for i in ec2_conn.get_only_instances():
        if i.id in instance_ids:
            hostname = i.tags["Name"]
            print "Deactivating node: " + hostname
            streams = ssh_conn.ssh(
                "echo {0} | sudo -S puppet node clean {1}; echo {0} | sudo -S puppet node deactivate {1}".format(
                    password, hostname
                )
            )
            print streams[1].read()

    ssh_conn.disconnect()
Exemple #3
0
    def _set_puppetmaster(self):
        ''' Sets the puppet master ip address.

            If it cannot find an ip address from our current instances, it uses
            the default address.
        '''

        pm_instance = utils.get_puppetmaster_instance(self.ec2_conn)

        if pm_instance is None:
            print "Could not find puppetmaster. Using default puppetmaster IP."
            self._puppetmaster_ip = self._default_puppetmaster_ip
            self._puppetmaster_hostname = "puppetmaster." + self._domain
        else:
            self._puppetmaster_ip = pm_instance.private_ip_address
            self._puppetmaster_hostname = pm_instance.tags['Name']
        print "Puppetmaster: " + self._puppetmaster_hostname + " (" + self._puppetmaster_ip + ")"