当前位置: 首页>>代码示例>>Python>>正文


Python hookenv.is_leader方法代码示例

本文整理汇总了Python中charmhelpers.core.hookenv.is_leader方法的典型用法代码示例。如果您正苦于以下问题:Python hookenv.is_leader方法的具体用法?Python hookenv.is_leader怎么用?Python hookenv.is_leader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在charmhelpers.core.hookenv的用法示例。


在下文中一共展示了hookenv.is_leader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_pools

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def update_pools(self):
        # designate-manage communicates with designate via message bus so no
        # need to set OS_ vars
        # NOTE(AJK) this runs with every hook (once most relations are up) and
        # so if it fails it will be picked up by the next relation change or
        # update-status.  i.e. it will heal eventually.
        if hookenv.is_leader():
            try:
                cmd = "designate-manage pool update"
                # Note(tinwood) that this command may fail if the pools.yaml
                # doesn't actually contain any pools.  This happens when the
                # relation is broken, which errors out the charm.  This stops
                # this happening and logs the error.
                subprocess.check_call(cmd.split(), timeout=60)
            except subprocess.CalledProcessError as e:
                hookenv.log("designate-manage pool update failed: {}"
                            .format(str(e)))
            except subprocess.TimeoutExpired as e:
                # the timeout is if the rabbitmq server has gone away; it just
                # retries continuously; this lets the hook complete.
                hookenv.log("designate-manage pool command timed out: {}".
                            format(str(e))) 
开发者ID:openstack,项目名称:charm-designate,代码行数:24,代码来源:designate.py

示例2: init_rndckey

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def init_rndckey(self):
        """Create a RNDC key if needed

        Return the rndc key from the leader DB or if one is not present
        generate a new one.

        :returns: str: rndc key
        """
        secret = DesignateBindCharm.get_rndc_secret()
        hookenv.log('Retrieving secret', level=hookenv.DEBUG)
        if not secret:
            hookenv.log('Secret not found in leader db', level=hookenv.DEBUG)
            if hookenv.is_leader():
                hookenv.log('Creating new secret as leader',
                            level=hookenv.DEBUG)
                secret = self.generate_rndc_key()
                hookenv.leader_set({LEADERDB_SECRET_KEY: secret})
        return secret 
开发者ID:openstack,项目名称:charm-designate-bind,代码行数:20,代码来源:designate_bind.py

示例3: check_zone_status

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def check_zone_status(hacluster):
    '''This unit has not been initialised yet so request a zones file or
    set an inital sync'''

    if hookenv.is_leader():
        if designate_bind.get_sync_time():
            # This unit is not the leader but a sync target has already been
            # set suggests this is a new unit which has been nominated as
            # leader early in its lifecycle. The leader responds to sync
            # requests and this unit is the leader so not worth sending out a
            # sync request.
            designate_bind.retrieve_zones()
        else:
            # This unit is the leader and no other unit has set up a sync
            # target then create one since this is a new deployment
            designate_bind.setup_sync()
            reactive.set_state('zones.initialised')
    else:
        # If this unit is not the leader as is not yet initialised then request
        # a zones file from a peer
        designate_bind.request_sync(hacluster) 
开发者ID:openstack,项目名称:charm-designate-bind,代码行数:23,代码来源:designate_bind_handlers.py

示例4: ceilometer_upgrade

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def ceilometer_upgrade():
    """Execute ceilometer-upgrade command, with retry on failure if gnocchi
    API is not ready for requests"""
    if is_leader():
        if (CompareOpenStackReleases(os_release('ceilometer-common')) >=
                'newton'):
            cmd = ['ceilometer-upgrade']
        else:
            cmd = ['ceilometer-dbsync']
        subprocess.check_call(cmd) 
开发者ID:openstack,项目名称:charm-ceilometer,代码行数:12,代码来源:ceilometer_utils.py

示例5: db_sync

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def db_sync(self):
        """Perform a database sync using the command defined in the
        self.sync_cmd attribute. The services defined in self.services are
        restarted after the database sync.
        """
        if not self.db_sync_done() and hookenv.is_leader():
            subprocess.check_call(self.sync_cmd)
            hookenv.leader_set({'db-sync-done': True})
            # Restart services immediately after db sync as
            # render_domain_config needs a working system
            self.restart_all() 
开发者ID:openstack,项目名称:charms.openstack,代码行数:13,代码来源:core.py

示例6: do_openstack_upgrade_db_migration

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def do_openstack_upgrade_db_migration(self):
        """Run database migration after upgrade

        :returns: None
        """
        if hookenv.is_leader():
            subprocess.check_call(self.sync_cmd)
        else:
            hookenv.log("Deferring DB sync to leader", level=hookenv.INFO)

    # NOTE(jamespage): Not currently used - switch from c-h function for perf? 
开发者ID:openstack,项目名称:charms.openstack,代码行数:13,代码来源:core.py

示例7: db_sync

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def db_sync(self):
        """Perform a database sync using the command defined in the
        self.sync_cmd attribute. The services defined in self.services are
        restarted after the database sync.
        """
        if not self.db_sync_done() and hookenv.is_leader():

            subprocess.check_call(['mistral-db-manage', '--config-file', '/etc/mistral/mistral.conf', 'upgrade', 'head'])
            subprocess.check_call(['mistral-db-manage', '--config-file', '/etc/mistral/mistral.conf', 'stamp', 'head'])
            subprocess.check_call(['mistral-db-manage', '--config-file', '/etc/mistral/mistral.conf', 'populate'])

            hookenv.leader_set({'db-sync-done': True})
            # Restart services immediately after db sync as
            # render_domain_config needs a working system
            self.restart_all() 
开发者ID:openstack,项目名称:charm-mistral,代码行数:17,代码来源:mistral.py

示例8: create_initial_servers_and_domains

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def create_initial_servers_and_domains(cls):
        """Create the nameserver entry and domains based on the charm user
        supplied config

        NOTE(AJK): This only wants to be done ONCE and by the leader, so we use
        leader settings to store that we've done it, after it's successfully
        completed.

        @returns None
        """
        KEY = 'create_initial_servers_and_domains'
        if hookenv.is_leader() and not hookenv.leader_get(KEY):
            nova_domain_name = hookenv.config('nova-domain')
            neutron_domain_name = hookenv.config('neutron-domain')
            with cls.check_zone_ids(nova_domain_name, neutron_domain_name):
                if hookenv.config('nameservers'):
                    for ns in hookenv.config('nameservers').split():
                        cls.create_server(ns)
                else:
                    hookenv.log('No nameserver specified, skipping creation of'
                                'nova and neutron domains',
                                level=hookenv.WARNING)
                    return
                if nova_domain_name:
                    cls.create_domain(
                        nova_domain_name,
                        hookenv.config('nova-domain-email'))
                if neutron_domain_name:
                    cls.create_domain(
                        neutron_domain_name,
                        hookenv.config('neutron-domain-email'))
            # if this fails, we weren't the leader any more; another unit may
            # attempt to do this too.
            hookenv.leader_set({KEY: 'done'}) 
开发者ID:openstack,项目名称:charm-designate,代码行数:36,代码来源:designate.py

示例9: setup_sync_target_alone

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def setup_sync_target_alone():
    '''If this is the only unit in the application then setup a sync target.
    This will likely by empty as zones.initialised is only unset when a unit
    frst comes up but the presence of the target allows subsequent units to
    bootstrap if leadership flips to them as they come up'''
    if hookenv.is_leader():
        designate_bind.setup_sync()
        reactive.set_state('zones.initialised') 
开发者ID:openstack,项目名称:charm-designate-bind,代码行数:10,代码来源:designate_bind_handlers.py

示例10: process_sync_requests

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def process_sync_requests(hacluster):
    '''If this unit is the leader process and new sync requests'''
    if hookenv.is_leader():
        designate_bind.process_requests(hacluster) 
开发者ID:openstack,项目名称:charm-designate-bind,代码行数:6,代码来源:designate_bind_handlers.py

示例11: cluster_token

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def cluster_token(self):
        ''' Getter to return the unique cluster token. '''
        if not is_leader():
            return leader_get('token')

        if not self.db.get('cluster-token'):
            token = self.id_generator()
            self.db.set('cluster-token', token)
            return token
        return self.db.get('cluster-token') 
开发者ID:juju-solutions,项目名称:layer-etcd,代码行数:12,代码来源:etcd_databag.py

示例12: test_is_leader_unsupported

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def test_is_leader_unsupported(self, check_output_):
        check_output_.side_effect = OSError(2, 'is-leader')
        self.assertRaises(NotImplementedError, hookenv.is_leader) 
开发者ID:juju,项目名称:charm-helpers,代码行数:5,代码来源:test_hookenv.py

示例13: test_is_leader

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def test_is_leader(self, check_output_):
        check_output_.return_value = b'false'
        self.assertFalse(hookenv.is_leader())
        check_output_.return_value = b'true'
        self.assertTrue(hookenv.is_leader()) 
开发者ID:juju,项目名称:charm-helpers,代码行数:7,代码来源:test_hookenv.py

示例14: acquire

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def acquire(self, lock):
        '''Acquire the named lock, non-blocking.

        The lock may be granted immediately, or in a future hook.

        Returns True if the lock has been granted. The lock will be
        automatically released at the end of the hook in which it is
        granted.

        Do not mindlessly call this method, as it triggers a cascade of
        hooks. For example, if you call acquire() every time in your
        peers relation-changed hook you will end up with an infinite loop
        of hooks. It should almost always be guarded by some condition.
        '''
        unit = hookenv.local_unit()
        ts = self.requests[unit].get(lock)
        if not ts:
            # If there is no outstanding request on the peers relation,
            # create one.
            self.requests.setdefault(lock, {})
            self.requests[unit][lock] = _timestamp()
            self.msg('Requested {}'.format(lock))

        # If the leader has granted the lock, yay.
        if self.granted(lock):
            self.msg('Acquired {}'.format(lock))
            return True

        # If the unit making the request also happens to be the
        # leader, it must handle the request now. Even though the
        # request has been stored on the peers relation, the peers
        # relation-changed hook will not be triggered.
        if hookenv.is_leader():
            return self.grant(lock, unit)

        return False  # Can't acquire lock, yet. Maybe next hook. 
开发者ID:juju,项目名称:charm-helpers,代码行数:38,代码来源:coordinator.py

示例15: handle

# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import is_leader [as 别名]
def handle(self):
        if not hookenv.is_leader():
            return  # Only the leader can grant requests.

        self.msg('Leader handling coordinator requests')

        # Clear our grants that have been released.
        for unit in self.grants.keys():
            for lock, grant_ts in list(self.grants[unit].items()):
                req_ts = self.requests.get(unit, {}).get(lock)
                if req_ts != grant_ts:
                    # The request timestamp does not match the granted
                    # timestamp. Several hooks on 'unit' may have run
                    # before the leader got a chance to make a decision,
                    # and 'unit' may have released its lock and attempted
                    # to reacquire it. This will change the timestamp,
                    # and we correctly revoke the old grant putting it
                    # to the end of the queue.
                    ts = datetime.strptime(self.grants[unit][lock],
                                           _timestamp_format)
                    del self.grants[unit][lock]
                    self.released(unit, lock, ts)

        # Grant locks
        for unit in self.requests.keys():
            for lock in self.requests[unit]:
                self.grant(lock, unit) 
开发者ID:juju,项目名称:charm-helpers,代码行数:29,代码来源:coordinator.py


注:本文中的charmhelpers.core.hookenv.is_leader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。