Пример #1
0
def poke_puppet_agent(hostname,
                      username,
                      password,
                      node_name,
                      master_certname='zstack'):
    with lock.FileLock(hostname):
        ssh.execute(
            '''ip=`env | grep SSH_CLIENT | cut -d '=' -f 2 | cut -d ' ' -f 1`; [ $ip == ::1 ] && ip=127.0.0.1; sed -i "/%s/d" /etc/hosts; echo "$ip %s" >> /etc/hosts'''
            % (master_certname, master_certname), hostname, username, password)
        (retcode, output, err) = ssh.execute(
            'puppet agent --certname %s --no-daemonize --onetime --waitforcert 60 --server %s --verbose --detailed-exitcodes'
            % (node_name, master_certname),
            hostname,
            username,
            password,
            exception_if_error=False)
        if retcode == 4 or retcode == 6 or retcode == 1:
            raise PuppetError(
                'failed to run puppet agent:\nstdout:%s\nstderr:%s\n' %
                (output, err))

        logger.debug(output)
Пример #2
0
def execute_salt_state(hostname,
                       username,
                       password,
                       state_name,
                       master_name,
                       machine_id=None):
    with lock.FileLock(hostname):
        ssh.execute(
            '''ip=`env | grep SSH_CLIENT | cut -d '=' -f 2 | cut -d ' ' -f 1`; [ $ip == ::1 ] && ip=127.0.0.1; sed -i "/%s/d" /etc/hosts; sed -i "/$ip/d" /etc/hosts; echo "$ip %s" >> /etc/hosts'''
            % (master_name, master_name), hostname, username, password)
        if not machine_id:
            (retcode, machine_id,
             err) = ssh.execute('cat /sys/class/dmi/id/product_uuid',
                                hostname,
                                username,
                                password,
                                exception_if_error=False)
            if not machine_id:
                raise SaltError("Can't find machine-id on %s" % hostname)

            machine_id = machine_id.strip()

        if not wait_for_salt_minion_daemon(machine_id, 1, False):
            ssh.execute(
                'which salt-minion; [ $? -ne 0 ] && curl -L http://bootstrap.saltstack.org | sudo sh ;sed -i "^id/d" /etc/salt/minion; sed -i "^master/d" /etc/salt/minion; echo "id: %s" >>/etc/salt/minion; echo "master: %s" >> /etc/salt/minion; rm -f /etc/salt/pki/minion/minion_master.pub ; service salt-minion restart'
                % (machine_id, master_name),
                hostname,
                username,
                password,
                exception_if_error=False)
            wait_for_salt_minion_daemon(machine_id)

        print 'salt %s %s' % (machine_id, state_name)
        output = shell.call('salt --out=json %s %s' % (machine_id, state_name))
        if not is_salt_failed(output):
            print '%s' % output
            print "salt has deployed %s" % state_name
        else:
            raise SaltError('salt execution failure: %s' % output)
Пример #3
0
    def run(self):
        '''
        Start translating the tweets.
        '''
        def still_waiting_cb():
            print('Waiting for the lock (is another instance running?).')

        self._lock = lock.FileLock(os.path.join(self._dir, 'lock'),
                                   timeout=2 * 60,
                                   still_waiting_cb=still_waiting_cb)
        self._lock.acquire()

        auth = self._get_auth()
        translator = self._get_translator()

        client = twitter.Client(
            translator,
            auth,
            self._my_user_name,
            self._target_user_name,
            self)
        client.process_tweets()