我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用charmhelpers.core.hookenv.unit_private_ip()。
def get_database_setup(self): """Provide the default database credentials as a list of 3-tuples returns a structure of: [ {'database': <database>, 'username': <username>, 'hostname': <hostname of this unit> 'prefix': <the optional prefix for the database>, }, ] :returns [{'database': ...}, ...]: credentials for multiple databases """ return [ dict( database=self.config['database'], username=self.config['database-user'], hostname=hookenv.unit_private_ip(), ) ]
def server_removed(): """ Remove a server from the cluster """ private_address = unit_private_ip() log("Removing server: {}".format(private_address), INFO)
def configure_openvswitch(self, odl_ovsdb): hookenv.log("Configuring OpenvSwitch with ODL OVSDB controller: %s" % odl_ovsdb.connection_string()) local_ip = ch_ip.get_address_in_network( self.config.get('os-data-network'), hookenv.unit_private_ip()) ovs.set_config('local_ip', local_ip) ovs.set_config('controller-ips', odl_ovsdb.private_address(), table='external_ids') ovs.set_config('host-id', socket.gethostname(), table='external_ids') ovs.set_manager(odl_ovsdb.connection_string()) hookenv.status_set('active', 'Unit is ready')
def odl_node_registration(self, controller): """ Register node with ODL if not registered already """ odl_conn = odl.ODLConfig(**controller.connection()) device_name = socket.gethostname() if odl_conn.is_device_registered(device_name): hookenv.log('{} is already registered in odl'.format(device_name)) else: local_ip = ch_ip.get_address_in_network( self.config('os-data-network'), hookenv.unit_private_ip()) hookenv.log('Registering {} ({}) in odl'.format( device_name, local_ip)) odl_conn.odl_register_node(device_name, local_ip)
def get_database_setup(self): return [{ 'database': 'mistral', 'username': 'mistral', 'hostname': hookenv.unit_private_ip() },]
def set_sync_info(self, sync_time, sync_file): """Update leader DB with sync information :param sync_time: str Time sync was created in epoch seconds :param sync_file: str Local file containing zone information :returns: None """ sync_info = { LEADERDB_SYNC_SRC_KEY: 'http://{}:80/zone-syncs/{}'.format( hookenv.unit_private_ip(), sync_file), LEADERDB_SYNC_TIME_KEY: sync_time, } hookenv.leader_set(sync_info)
def prepare_tls_certificates(tls): status_set('maintenance', 'Requesting tls certificates.') common_name = hookenv.unit_public_ip() sans = [] sans.append(hookenv.unit_public_ip()) sans.append(hookenv.unit_private_ip()) sans.append(socket.gethostname()) certificate_name = hookenv.local_unit().replace('/', '_') tls.request_server_cert(common_name, sans, certificate_name)
def test_gets_unit_private_ip(self, _unitget): _unitget.return_value = sentinel.private_ip self.assertEqual(sentinel.private_ip, hookenv.unit_private_ip()) _unitget.assert_called_once_with('private-address')