<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os <EOL> import sys <EOL> import traceback <EOL> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> from oslo_serialization import jsonutils <EOL> from oslo_utils import importutils <EOL> from nova . conductor import rpcapi as conductor_rpcapi <EOL> import nova . conf <EOL> from nova import config <EOL> from nova import context <EOL> import nova . db . api <EOL> from nova import exception <EOL> from nova . i18n import _LE , _LW <EOL> from nova . network import rpcapi as network_rpcapi <EOL> from nova import objects <EOL> from nova . objects import base as objects_base <EOL> from nova import rpc <EOL> CONF = nova . conf . CONF <EOL> CONF . import_opt ( '<STR_LIT:host>' , '<STR_LIT>' ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def add_lease ( mac , ip_address ) : <EOL> """<STR_LIT>""" <EOL> api = network_rpcapi . NetworkAPI ( ) <EOL> api . lease_fixed_ip ( context . get_admin_context ( ) , ip_address , CONF . host ) <EOL> def old_lease ( mac , ip_address ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def del_lease ( mac , ip_address ) : <EOL> """<STR_LIT>""" <EOL> api = network_rpcapi . NetworkAPI ( ) <EOL> api . release_fixed_ip ( context . get_admin_context ( ) , ip_address , <EOL> CONF . host , mac ) <EOL> def init_leases ( network_id ) : <EOL> """<STR_LIT>""" <EOL> ctxt = context . get_admin_context ( ) <EOL> network = objects . Network . get_by_id ( ctxt , network_id ) <EOL> network_manager = importutils . import_object ( CONF . network_manager ) <EOL> return network_manager . get_dhcp_leases ( ctxt , network ) <EOL> def add_action_parsers ( subparsers ) : <EOL> subparsers . add_parser ( '<STR_LIT>' ) <EOL> for action in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> parser = subparsers . add_parser ( action ) <EOL> parser . add_argument ( '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:?>' , default = '<STR_LIT>' ) <EOL> parser . set_defaults ( func = globals ( ) [ action + '<STR_LIT>' ] ) <EOL> CONF . register_cli_opt ( <EOL> cfg . SubCommandOpt ( '<STR_LIT:action>' , <EOL> title = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> handler = add_action_parsers ) ) <EOL> def block_db_access ( ) : <EOL> class NoDB ( object ) : <EOL> def __getattr__ ( self , attr ) : <EOL> return self <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> stacktrace = "<STR_LIT>" . join ( traceback . format_stack ( ) ) <EOL> LOG . error ( _LE ( '<STR_LIT>' ) , <EOL> stacktrace ) <EOL> raise exception . DBNotAllowed ( '<STR_LIT>' ) <EOL> nova . db . api . IMPL = NoDB ( ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> config . parse_args ( sys . argv , <EOL> default_config_files = jsonutils . loads ( os . environ [ '<STR_LIT>' ] ) ) <EOL> logging . setup ( CONF , "<STR_LIT>" ) <EOL> global LOG <EOL> LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> if CONF . action . name == '<STR_LIT>' : <EOL> return <EOL> objects . register_all ( ) <EOL> if not CONF . conductor . use_local : <EOL> block_db_access ( ) <EOL> objects_base . NovaObject . indirection_api = conductor_rpcapi . ConductorAPI ( ) <EOL> else : <EOL> LOG . warning ( _LW ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> if CONF . action . name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> LOG . debug ( "<STR_LIT>" , <EOL> { "<STR_LIT:action>" : CONF . action . name , <EOL> "<STR_LIT>" : CONF . action . mac , <EOL> "<STR_LIT>" : CONF . action . ip } ) <EOL> CONF . action . func ( CONF . action . mac , CONF . action . ip ) <EOL> else : <EOL> try : <EOL> network_id = int ( os . environ . get ( '<STR_LIT>' ) ) <EOL> except TypeError : <EOL> LOG . error ( _LE ( "<STR_LIT>" ) ) <EOL> return ( <NUM_LIT:1> ) <EOL> print ( init_leases ( network_id ) ) <EOL> rpc . cleanup ( ) </s>
