<s> import six <EOL> from ... errors . httpexception import HttpException <EOL> from ... errors . saklientexception import SaklientException <EOL> from . . client import Client <EOL> from . resource import Resource <EOL> from . icon import Icon <EOL> from . ipv4net import Ipv4Net <EOL> from . ipv6net import Ipv6Net <EOL> from . routeractivity import RouterActivity <EOL> from ... util import Util <EOL> import saklient <EOL> str = six . text_type <EOL> class Router ( Resource ) : <EOL> def _api_path ( self ) : <EOL> return "<STR_LIT>" <EOL> def _root_key ( self ) : <EOL> return "<STR_LIT>" <EOL> def _root_key_m ( self ) : <EOL> return "<STR_LIT>" <EOL> def _class_name ( self ) : <EOL> return "<STR_LIT>" <EOL> def _id ( self ) : <EOL> return self . get_id ( ) <EOL> def save ( self ) : <EOL> return self . _save ( ) <EOL> def reload ( self ) : <EOL> return self . _reload ( ) <EOL> def get_activity ( self ) : <EOL> return self . _activity <EOL> activity = property ( get_activity , None , None ) <EOL> def __init__ ( self , client , obj , wrapped = False ) : <EOL> super ( Router , self ) . __init__ ( client ) <EOL> Util . validate_type ( client , "<STR_LIT>" ) <EOL> Util . validate_type ( wrapped , "<STR_LIT:bool>" ) <EOL> self . _activity = RouterActivity ( client ) <EOL> self . api_deserialize ( obj , wrapped ) <EOL> def _on_after_api_deserialize ( self , r , root ) : <EOL> if r is not None : <EOL> self . _activity . set_source_id ( self . _id ( ) ) <EOL> def after_create ( self , timeoutSec , callback ) : <EOL> Util . validate_type ( timeoutSec , "<STR_LIT:int>" ) <EOL> Util . validate_type ( callback , "<STR_LIT>" ) <EOL> ret = self . sleep_while_creating ( timeoutSec ) <EOL> callback ( self , ret ) <EOL> def sleep_while_creating ( self , timeoutSec = <NUM_LIT> ) : <EOL> Util . validate_type ( timeoutSec , "<STR_LIT:int>" ) <EOL> step = <NUM_LIT:3> <EOL> isOk = False <EOL> while ( <NUM_LIT:0> < timeoutSec ) : <EOL> try : <EOL> if self . exists ( ) : <EOL> self . reload ( ) <EOL> isOk = True <EOL> except saklient . errors . httpexception . HttpException : <EOL> pass <EOL> timeoutSec -= step <EOL> if isOk : <EOL> timeoutSec = <NUM_LIT:0> <EOL> if <NUM_LIT:0> < timeoutSec : <EOL> Util . sleep ( step ) <EOL> return isOk <EOL> def get_swytch ( self ) : <EOL> model = Util . create_class_instance ( "<STR_LIT>" , [ self . _client ] ) <EOL> id = self . get_swytch_id ( ) <EOL> return model . get_by_id ( id ) <EOL> def add_ipv6_net ( self ) : <EOL> result = self . _client . request ( "<STR_LIT:POST>" , self . _api_path ( ) + "<STR_LIT:/>" + Util . url_encode ( self . _id ( ) ) + "<STR_LIT>" ) <EOL> self . reload ( ) <EOL> return Ipv6Net ( self . _client , ( result [ "<STR_LIT>" ] if "<STR_LIT>" in result else None ) ) <EOL> def remove_ipv6_net ( self , ipv6Net ) : <EOL> Util . validate_type ( ipv6Net , "<STR_LIT>" ) <EOL> self . _client . request ( "<STR_LIT>" , self . _api_path ( ) + "<STR_LIT:/>" + Util . url_encode ( self . _id ( ) ) + "<STR_LIT>" + ipv6Net . _id ( ) ) <EOL> self . reload ( ) <EOL> return self <EOL> def add_static_route ( self , maskLen , nextHop ) : <EOL> Util . validate_type ( maskLen , "<STR_LIT:int>" ) <EOL> Util . validate_type ( nextHop , "<STR_LIT:str>" ) <EOL> q = { } <EOL> Util . set_by_path ( q , "<STR_LIT>" , maskLen ) <EOL> Util . set_by_path ( q , "<STR_LIT>" , nextHop ) <EOL> result = self . _client . request ( "<STR_LIT:POST>" , self . _api_path ( ) + "<STR_LIT:/>" + Util . url_encode ( self . _id ( ) ) + "<STR_LIT>" , q ) <EOL> self . reload ( ) <EOL> return Ipv4Net ( self . _client , ( result [ "<STR_LIT>" ] if "<STR_LIT>" in result else None ) ) <EOL> def remove_static_route ( self , ipv4Net ) : <EOL> Util . validate_type ( ipv4Net , "<STR_LIT>" ) <EOL> self . _client . request ( "<STR_LIT>" , self . _api_path ( ) + "<STR_LIT:/>" + Util . url_encode ( self . _id ( ) ) + "<STR_LIT>" + ipv4Net . _id ( ) ) <EOL> self . reload ( ) <EOL> return self <EOL> def change_plan ( self , bandWidthMbps ) : <EOL> Util . validate_type ( bandWidthMbps , "<STR_LIT:int>" ) <EOL> path = self . _api_path ( ) + "<STR_LIT:/>" + Util . url_encode ( self . _id ( ) ) + "<STR_LIT>" <EOL> q = { } <EOL> Util . set_by_path ( q , "<STR_LIT>" , bandWidthMbps ) <EOL> result = self . _client . request ( "<STR_LIT>" , path , q ) <EOL> self . api_deserialize ( result , True ) <EOL> return self <EOL> def get_id ( self ) : <EOL> return self . m_id <EOL> id = property ( get_id , None , None ) <EOL> def get_name ( self ) : <EOL> return self . m_name <EOL> def set_name ( self , v ) : <EOL> Util . validate_type ( v , "<STR_LIT:str>" ) <EOL> self . m_name = v <EOL> self . n_name = True <EOL> return self . m_name <EOL> name = property ( get_name , set_name , None ) <EOL> def get_description ( self ) : <EOL> return self . m_description <EOL> def set_description ( self , v ) : <EOL> Util . validate_type ( v , "<STR_LIT:str>" ) <EOL> self . m_description = v <EOL> self . n_description = True <EOL> return self . m_description <EOL> description = property ( get_description , set_description , None ) <EOL> def get_network_mask_len ( self ) : <EOL> return self . m_network_mask_len <EOL> def set_network_mask_len ( self , v ) : <EOL> Util . validate_type ( v , "<STR_LIT:int>" ) <EOL> if not self . is_new : <EOL> raise SaklientException ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" ) <EOL> self . m_network_mask_len = v <EOL> self . n_network_mask_len = True <EOL> return self . m_network_mask_len <EOL> network_mask_len = property ( get_network_mask_len , set_network_mask_len , None ) <EOL> def get_band_width_mbps ( self ) : <EOL> return self . m_band_width_mbps <EOL> def set_band_width_mbps ( self , v ) : <EOL> Util . validate_type ( v , "<STR_LIT:int>" ) <EOL> if not self . is_new : <EOL> raise SaklientException ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" ) <EOL> self . m_band_width_mbps = v <EOL> self . n_band_width_mbps = True <EOL> return self . m_band_width_mbps <EOL> band_width_mbps = property ( get_band_width_mbps , set_band_width_mbps , None ) <EOL> def get_swytch_id ( self ) : <EOL> return self . m_swytch_id <EOL> swytch_id = property ( get_swytch_id , None , None ) <EOL> def api_deserialize_impl ( self , r ) : <EOL> self . is_new = r is None <EOL> if self . is_new : <EOL> r = { <EOL> } <EOL> self . is_incomplete = False <EOL> if Util . exists_path ( r , "<STR_LIT>" ) : <EOL> self . m_id = None if Util . get_by_path ( r , "<STR_LIT>" ) is None else str ( Util . get_by_path ( r , "<STR_LIT>" ) ) <EOL> else : <EOL> self . m_id = None <EOL> self . is_incomplete = True <EOL> self . n_id = False <EOL> if Util . exists_path ( r , "<STR_LIT:Name>" ) : <EOL> self . m_name = None if Util . get_by_path ( r , "<STR_LIT:Name>" ) is None else str ( Util . get_by_path ( r , "<STR_LIT:Name>" ) ) <EOL> else : <EOL> self . m_name = None <EOL> self . is_incomplete = True <EOL> self . n_name = False <EOL> if Util . exists_path ( r , "<STR_LIT>" ) : <EOL> self . m_description = None if Util . get_by_path ( r , "<STR_LIT>" ) is None else str ( Util . get_by_path ( r , "<STR_LIT>" ) ) <EOL> else : <EOL> self . m_description = None <EOL> self . is_incomplete = True <EOL> self . n_description = False <EOL> if Util . exists_path ( r , "<STR_LIT>" ) : <EOL> self . m_network_mask_len = None if Util . get_by_path ( r , "<STR_LIT>" ) is None else int ( str ( Util . get_by_path ( r , "<STR_LIT>" ) ) ) <EOL> else : <EOL> self . m_network_mask_len = None <EOL> self . is_incomplete = True <EOL> self . n_network_mask_len = False <EOL> if Util . exists_path ( r , "<STR_LIT>" ) : <EOL> self . m_band_width_mbps = None if Util . get_by_path ( r , "<STR_LIT>" ) is None else int ( str ( Util . get_by_path ( r , "<STR_LIT>" ) ) ) <EOL> else : <EOL> self . m_band_width_mbps = None <EOL> self . is_incomplete = True <EOL> self . n_band_width_mbps = False <EOL> if Util . exists_path ( r , "<STR_LIT>" ) : <EOL> self . m_swytch_id = None if Util . get_by_path ( r , "<STR_LIT>" ) is None else str ( Util . get_by_path ( r , "<STR_LIT>" ) ) <EOL> else : <EOL> self . m_swytch_id = None <EOL> self . is_incomplete = True <EOL> self . n_swytch_id = False <EOL> def api_serialize_impl ( self , withClean = False ) : <EOL> Util . validate_type ( withClean , "<STR_LIT:bool>" ) <EOL> missing = [ ] <EOL> ret = { <EOL> } <EOL> if withClean or self . n_id : <EOL> Util . set_by_path ( ret , "<STR_LIT>" , self . m_id ) <EOL> if withClean or self . n_name : <EOL> Util . set_by_path ( ret , "<STR_LIT:Name>" , self . m_name ) <EOL> else : <EOL> if self . is_new : <EOL> missing . append ( "<STR_LIT:name>" ) <EOL> if withClean or self . n_description : <EOL> Util . set_by_path ( ret , "<STR_LIT>" , self . m_description ) <EOL> if withClean or self . n_network_mask_len : <EOL> Util . set_by_path ( ret , "<STR_LIT>" , self . m_network_mask_len ) <EOL> else : <EOL> if self . is_new : <EOL> missing . append ( "<STR_LIT>" ) <EOL> if withClean or self . n_band_width_mbps : <EOL> Util . set_by_path ( ret , "<STR_LIT>" , self . m_band_width_mbps ) <EOL> else : <EOL> if self . is_new : <EOL> missing . append ( "<STR_LIT>" ) <EOL> if withClean or self . n_swytch_id : <EOL> Util . set_by_path ( ret , "<STR_LIT>" , self . m_swytch_id ) <EOL> if len ( missing ) > <NUM_LIT:0> : <EOL> raise SaklientException ( "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( missing ) ) <EOL> return ret </s>
