我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用charmhelpers.core.hookenv.open_port()。
def __call__(self, manager, service_name, event_name): service = manager.get_service(service_name) new_ports = service.get('ports', []) port_file = os.path.join(hookenv.charm_dir(), '.{}.ports'.format(service_name)) if os.path.exists(port_file): with open(port_file) as fp: old_ports = fp.read().split(',') for old_port in old_ports: if bool(old_port): old_port = int(old_port) if old_port not in new_ports: hookenv.close_port(old_port) with open(port_file, 'w') as fp: fp.write(','.join(str(port) for port in new_ports)) for port in new_ports: if event_name == 'start': hookenv.open_port(port) elif event_name == 'stop': hookenv.close_port(port)