@@ -85,6 +85,39 @@ def _get_columns(item):
8585 )
8686
8787
88+ def _get_external_gateway_attrs (client_manager , parsed_args ):
89+ attrs = {}
90+
91+ if parsed_args .external_gateway :
92+ gateway_info = {}
93+ n_client = client_manager .network
94+ network = n_client .find_network (
95+ parsed_args .external_gateway , ignore_missing = False
96+ )
97+ gateway_info ['network_id' ] = network .id
98+ if parsed_args .disable_snat :
99+ gateway_info ['enable_snat' ] = False
100+ if parsed_args .enable_snat :
101+ gateway_info ['enable_snat' ] = True
102+ if parsed_args .fixed_ip :
103+ ips = []
104+ for ip_spec in parsed_args .fixed_ip :
105+ if ip_spec .get ('subnet' , False ):
106+ subnet_name_id = ip_spec .pop ('subnet' )
107+ if subnet_name_id :
108+ subnet = n_client .find_subnet (
109+ subnet_name_id , ignore_missing = False
110+ )
111+ ip_spec ['subnet_id' ] = subnet .id
112+ if ip_spec .get ('ip-address' , False ):
113+ ip_spec ['ip_address' ] = ip_spec .pop ('ip-address' )
114+ ips .append (ip_spec )
115+ gateway_info ['external_fixed_ips' ] = ips
116+ attrs ['external_gateway_info' ] = gateway_info
117+
118+ return attrs
119+
120+
88121def _get_attrs (client_manager , parsed_args ):
89122 attrs = {}
90123 if parsed_args .name is not None :
@@ -113,32 +146,9 @@ def _get_attrs(client_manager, parsed_args):
113146 parsed_args .project_domain ,
114147 ).id
115148 attrs ['project_id' ] = project_id
116- if parsed_args .external_gateway :
117- gateway_info = {}
118- n_client = client_manager .network
119- network = n_client .find_network (
120- parsed_args .external_gateway , ignore_missing = False
121- )
122- gateway_info ['network_id' ] = network .id
123- if parsed_args .disable_snat :
124- gateway_info ['enable_snat' ] = False
125- if parsed_args .enable_snat :
126- gateway_info ['enable_snat' ] = True
127- if parsed_args .fixed_ip :
128- ips = []
129- for ip_spec in parsed_args .fixed_ip :
130- if ip_spec .get ('subnet' , False ):
131- subnet_name_id = ip_spec .pop ('subnet' )
132- if subnet_name_id :
133- subnet = n_client .find_subnet (
134- subnet_name_id , ignore_missing = False
135- )
136- ip_spec ['subnet_id' ] = subnet .id
137- if ip_spec .get ('ip-address' , False ):
138- ip_spec ['ip_address' ] = ip_spec .pop ('ip-address' )
139- ips .append (ip_spec )
140- gateway_info ['external_fixed_ips' ] = ips
141- attrs ['external_gateway_info' ] = gateway_info
149+
150+ attrs .update (_get_external_gateway_attrs (client_manager , parsed_args ))
151+
142152 # "router set" command doesn't support setting flavor_id.
143153 if 'flavor_id' in parsed_args and parsed_args .flavor_id is not None :
144154 attrs ['flavor_id' ] = parsed_args .flavor_id
0 commit comments