Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | import logging |
Oleh Hryhorov | 4ce5d2c | 2018-11-08 18:41:20 +0200 | [diff] [blame] | 4 | import time |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 5 | from functools import wraps |
Oleh Hryhorov | 4ce5d2c | 2018-11-08 18:41:20 +0200 | [diff] [blame] | 6 | from salt.exceptions import CommandExecutionError |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 7 | LOG = logging.getLogger(__name__) |
Jiri Broulik | 5368cc5 | 2017-02-08 18:53:59 +0100 | [diff] [blame] | 8 | |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 9 | # Import third party libs |
| 10 | HAS_NEUTRON = False |
| 11 | try: |
| 12 | from neutronclient.v2_0 import client |
| 13 | HAS_NEUTRON = True |
| 14 | except ImportError: |
| 15 | pass |
| 16 | |
| 17 | __opts__ = {} |
| 18 | |
| 19 | |
| 20 | def __virtual__(): |
| 21 | ''' |
| 22 | Only load this module if neutron |
| 23 | is installed on this minion. |
| 24 | ''' |
| 25 | if HAS_NEUTRON: |
| 26 | return 'neutronng' |
| 27 | return False |
| 28 | |
| 29 | |
| 30 | def _autheticate(func_name): |
| 31 | ''' |
| 32 | Authenticate requests with the salt keystone module and format return data |
| 33 | ''' |
| 34 | @wraps(func_name) |
| 35 | def decorator_method(*args, **kwargs): |
| 36 | ''' |
| 37 | Authenticate request and format return data |
| 38 | ''' |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 39 | connection_args = {'profile': kwargs.pop('profile', None)} |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 40 | nkwargs = {} |
| 41 | for kwarg in kwargs: |
| 42 | if 'connection_' in kwarg: |
| 43 | connection_args.update({kwarg: kwargs[kwarg]}) |
| 44 | elif '__' not in kwarg: |
| 45 | nkwargs.update({kwarg: kwargs[kwarg]}) |
Oleg Iurchenko | 87f5632 | 2017-10-20 00:40:50 +0300 | [diff] [blame] | 46 | kstone = __salt__['keystoneng.auth'](**connection_args) |
| 47 | endpoint_type = kwargs.get('connection_endpoint_type', 'internal') |
| 48 | neutron_interface = client.Client(session=kstone.session, endpoint_type=endpoint_type) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 49 | return_data = func_name(neutron_interface, *args, **nkwargs) |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 50 | # TODO(vsaienko) drop this formatting when all commands are updated |
| 51 | # to return dictionary |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 52 | if isinstance(return_data, list): |
| 53 | # format list as a dict for rendering |
| 54 | return {data.get('name', None) or data['id']: data |
| 55 | for data in return_data} |
| 56 | return return_data |
| 57 | return decorator_method |
| 58 | |
| 59 | |
| 60 | @_autheticate |
| 61 | def list_floatingips(neutron_interface, **kwargs): |
| 62 | ''' |
| 63 | list all floatingips |
| 64 | CLI Example: |
| 65 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 66 | salt '*' neutronng.list_floatingips |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 67 | ''' |
| 68 | return neutron_interface.list_floatingips(**kwargs)['floatingips'] |
| 69 | |
| 70 | |
| 71 | @_autheticate |
| 72 | def list_security_groups(neutron_interface, **kwargs): |
| 73 | ''' |
| 74 | list all security_groups |
| 75 | CLI Example: |
| 76 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 77 | salt '*' neutronng.list_security_groups |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 78 | ''' |
| 79 | return neutron_interface.list_security_groups(**kwargs)['security_groups'] |
| 80 | |
| 81 | |
| 82 | @_autheticate |
| 83 | def list_subnets(neutron_interface, **kwargs): |
| 84 | ''' |
| 85 | list all subnets |
| 86 | CLI Example: |
| 87 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 88 | salt '*' neutronng.list_subnets |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 89 | ''' |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 90 | return neutron_interface.list_subnets(**kwargs) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 91 | |
| 92 | |
| 93 | @_autheticate |
| 94 | def list_networks(neutron_interface, **kwargs): |
| 95 | ''' |
| 96 | list all networks |
| 97 | CLI Example: |
| 98 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 99 | salt '*' neutronng.list_networks |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 100 | ''' |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 101 | return neutron_interface.list_networks(**kwargs) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 102 | |
| 103 | |
| 104 | @_autheticate |
| 105 | def list_ports(neutron_interface, **kwargs): |
| 106 | ''' |
| 107 | list all ports |
| 108 | CLI Example: |
| 109 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 110 | salt '*' neutronng.list_ports |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 111 | ''' |
| 112 | return neutron_interface.list_ports(**kwargs)['ports'] |
| 113 | |
| 114 | |
| 115 | @_autheticate |
| 116 | def list_routers(neutron_interface, **kwargs): |
| 117 | ''' |
| 118 | list all routers |
| 119 | CLI Example: |
| 120 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 121 | salt '*' neutronng.list_routers |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 122 | ''' |
| 123 | return neutron_interface.list_routers(**kwargs)['routers'] |
| 124 | |
| 125 | @_autheticate |
| 126 | def update_floatingip(neutron_interface, fip, port_id=None): |
| 127 | ''' |
| 128 | update floating IP. Should be used to associate and disassociate |
| 129 | floating IP with instance |
| 130 | CLI Example: |
| 131 | .. code-block:: bash |
| 132 | to associate with an instance's port |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 133 | salt '*' neutronng.update_floatingip openstack-floatingip-id port-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 134 | to disassociate from an instance's port |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 135 | salt '*' neutronng.update_floatingip openstack-floatingip-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 136 | ''' |
| 137 | neutron_interface.update_floatingip(fip, {"floatingip": |
| 138 | {"port_id": port_id}}) |
| 139 | |
| 140 | |
| 141 | @_autheticate |
| 142 | def update_subnet(neutron_interface, subnet_id, **subnet_params): |
| 143 | ''' |
| 144 | update given subnet |
| 145 | CLI Example: |
| 146 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 147 | salt '*' neutronng.update_subnet openstack-subnet-id name='new_name' |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 148 | ''' |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 149 | return neutron_interface.update_subnet(subnet_id, {'subnet': subnet_params}) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 150 | |
| 151 | |
| 152 | @_autheticate |
| 153 | def update_network(neutron_interface, network_id, **net_params): |
| 154 | ''' |
| 155 | Update give network |
| 156 | CLI Example: |
| 157 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 158 | salt '*' neutronng.update_network openstack-net-id admin_state_up=false |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 159 | ''' |
| 160 | network_params = {} |
| 161 | for param in net_params: |
| 162 | if 'provider_' in param or 'router_' in param: |
| 163 | network_params[param.replace('_', ':', 1)] = net_params[param] |
| 164 | else: |
| 165 | network_params[param] = net_params[param] |
| 166 | LOG.info('ATTRIBUTES ' + str(network_params)) |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 167 | return neutron_interface.update_network(network_id, {'network': network_params}) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 168 | |
| 169 | |
| 170 | @_autheticate |
| 171 | def update_router(neutron_interface, router_id, **router_params): |
| 172 | ''' |
| 173 | update given router |
| 174 | CLI Example: |
| 175 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 176 | salt '*' neutronng.update_router openstack-router-id name='new_name' |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 177 | external_gateway='openstack-network-id' administrative_state=true |
| 178 | ''' |
| 179 | neutron_interface.update_router(router_id, {'router': router_params}) |
| 180 | |
| 181 | |
| 182 | @_autheticate |
| 183 | def router_gateway_set(neutron_interface, router_id, external_gateway): |
| 184 | ''' |
| 185 | Set external gateway for a router |
| 186 | CLI Example: |
| 187 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 188 | salt '*' neutronng.update_router openstack-router-id openstack-network-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 189 | ''' |
| 190 | neutron_interface.update_router( |
| 191 | router_id, {'router': {'external_gateway_info': |
| 192 | {'network_id': external_gateway}}}) |
| 193 | |
| 194 | |
| 195 | @_autheticate |
| 196 | def router_gateway_clear(neutron_interface, router_id): |
| 197 | ''' |
| 198 | Clear external gateway for a router |
| 199 | CLI Example: |
| 200 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 201 | salt '*' neutronng.update_router openstack-router-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 202 | ''' |
| 203 | neutron_interface.update_router( |
| 204 | router_id, {'router': {'external_gateway_info': None}}) |
| 205 | |
| 206 | |
| 207 | @_autheticate |
| 208 | def create_router(neutron_interface, **router_params): |
| 209 | ''' |
| 210 | Create OpenStack Neutron router |
| 211 | CLI Example: |
| 212 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 213 | salt '*' neutronng.create_router name=R1 |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 214 | ''' |
| 215 | response = neutron_interface.create_router({'router': router_params}) |
| 216 | if 'router' in response and 'id' in response['router']: |
| 217 | return response['router']['id'] |
| 218 | |
| 219 | |
| 220 | @_autheticate |
| 221 | def router_add_interface(neutron_interface, router_id, subnet_id): |
| 222 | ''' |
| 223 | Attach router to a subnet |
| 224 | CLI Example: |
| 225 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 226 | salt '*' neutronng.router_add_interface openstack-router-id subnet-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 227 | ''' |
| 228 | neutron_interface.add_interface_router(router_id, {'subnet_id': subnet_id}) |
| 229 | |
| 230 | |
| 231 | @_autheticate |
| 232 | def router_rem_interface(neutron_interface, router_id, subnet_id): |
| 233 | ''' |
| 234 | Dettach router from a subnet |
| 235 | CLI Example: |
| 236 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 237 | salt '*' neutronng.router_rem_interface openstack-router-id subnet-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 238 | ''' |
| 239 | neutron_interface.remove_interface_router( |
| 240 | router_id, {'subnet_id': subnet_id}) |
| 241 | |
| 242 | |
| 243 | @_autheticate |
| 244 | def create_security_group(neutron_interface, **sg_params): |
| 245 | ''' |
| 246 | Create a new security group |
| 247 | CLI Example: |
| 248 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 249 | salt '*' neutronng.create_security_group name='new_rule' |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 250 | description='test rule' |
| 251 | ''' |
| 252 | response = neutron_interface.create_security_group( |
| 253 | {'security_group': sg_params}) |
| 254 | if 'security_group' in response and 'id' in response['security_group']: |
| 255 | return response['security_group']['id'] |
| 256 | |
| 257 | |
| 258 | @_autheticate |
| 259 | def create_security_group_rule(neutron_interface, **rule_params): |
| 260 | ''' |
| 261 | Create a rule entry for a security group |
| 262 | CLI Example: |
| 263 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 264 | salt '*' neutronng.create_security_group_rule |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 265 | ''' |
| 266 | neutron_interface.create_security_group_rule( |
| 267 | {'security_group_rule': rule_params}) |
| 268 | |
| 269 | |
| 270 | @_autheticate |
| 271 | def create_floatingip(neutron_interface, **floatingip_params): |
| 272 | ''' |
| 273 | Create a new floating IP |
| 274 | CLI Example: |
| 275 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 276 | salt '*' neutronng.create_floatingip floating_network_id=ext-net-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 277 | ''' |
| 278 | response = neutron_interface.create_floatingip( |
| 279 | {'floatingip': floatingip_params}) |
| 280 | if 'floatingip' in response and 'id' in response['floatingip']: |
Jiri Broulik | de2e290 | 2017-02-13 15:03:47 +0100 | [diff] [blame] | 281 | return response |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 282 | |
| 283 | |
| 284 | @_autheticate |
| 285 | def create_subnet(neutron_interface, **subnet_params): |
| 286 | ''' |
| 287 | Create a new subnet in OpenStack |
| 288 | CLI Example: |
| 289 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 290 | salt '*' neutronng.create_subnet name='subnet name' |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 291 | network_id='openstack-network-id' cidr='192.168.10.0/24' \\ |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 292 | gateway_ip='192.168.10.1' ip_version='4' enable_dhcp=false |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 293 | ''' |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 294 | return neutron_interface.create_subnet({'subnet': subnet_params}) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 295 | |
| 296 | |
| 297 | @_autheticate |
| 298 | def create_network(neutron_interface, **net_params): |
| 299 | ''' |
| 300 | Create a new network segment in OpenStack |
| 301 | CLI Example: |
| 302 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 303 | salt '*' neutronng.create_network name=External |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 304 | provider_network_type=flat provider_physical_network=ext |
| 305 | ''' |
| 306 | network_params = {} |
| 307 | for param in net_params: |
| 308 | if 'provider_' in param or 'router_' in param: |
| 309 | network_params[param.replace('_', ':', 1)] = net_params[param] |
| 310 | else: |
| 311 | network_params[param] = net_params[param] |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 312 | return neutron_interface.create_network({'network': network_params}) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 313 | |
| 314 | |
| 315 | @_autheticate |
| 316 | def create_port(neutron_interface, **port_params): |
| 317 | ''' |
| 318 | Create a new port in OpenStack |
| 319 | CLI Example: |
| 320 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 321 | salt '*' neutronng.create_port network_id='openstack-network-id' |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 322 | ''' |
Elena Ezhova | 2045669 | 2017-07-10 14:30:27 +0400 | [diff] [blame] | 323 | return neutron_interface.create_port({'port': port_params}) |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 324 | |
| 325 | |
| 326 | @_autheticate |
| 327 | def update_port(neutron_interface, port_id, **port_params): |
| 328 | ''' |
| 329 | Create a new port in OpenStack |
| 330 | CLI Example: |
| 331 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 332 | salt '*' neutronng.update_port name='new_port_name' |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 333 | ''' |
| 334 | neutron_interface.update_port(port_id, {'port': port_params}) |
| 335 | |
| 336 | |
| 337 | @_autheticate |
| 338 | def delete_floatingip(neutron_interface, floating_ip_id): |
| 339 | ''' |
| 340 | delete a floating IP |
| 341 | CLI Example: |
| 342 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 343 | salt '*' neutronng.delete_floatingip openstack-floating-ip-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 344 | ''' |
| 345 | neutron_interface.delete_floatingip(floating_ip_id) |
| 346 | |
| 347 | |
| 348 | @_autheticate |
| 349 | def delete_security_group(neutron_interface, sg_id): |
| 350 | ''' |
| 351 | delete a security group |
| 352 | CLI Example: |
| 353 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 354 | salt '*' neutronng.delete_security_group openstack-security-group-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 355 | ''' |
| 356 | neutron_interface.delete_security_group(sg_id) |
| 357 | |
| 358 | |
| 359 | @_autheticate |
| 360 | def delete_security_group_rule(neutron_interface, rule): |
| 361 | ''' |
| 362 | delete a security group rule. pass all rule params that match the rule |
| 363 | to be deleted |
| 364 | CLI Example: |
| 365 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 366 | salt '*' neutronng.delete_security_group_rule direction='ingress' |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 367 | ethertype='ipv4' security_group_id='openstack-security-group-id' |
| 368 | port_range_min=100 port_range_max=4096 protocol='tcp' |
| 369 | remote_group_id='default' |
| 370 | ''' |
| 371 | sg_rules = neutron_interface.list_security_group_rules( |
| 372 | security_group_id=rule['security_group_id']) |
| 373 | for sg_rule in sg_rules['security_group_rules']: |
| 374 | sgr_id = sg_rule.pop('id') |
| 375 | if sg_rule == rule: |
| 376 | neutron_interface.delete_security_group_rule(sgr_id) |
| 377 | |
| 378 | |
| 379 | @_autheticate |
| 380 | def delete_subnet(neutron_interface, subnet_id): |
| 381 | ''' |
| 382 | delete given subnet |
| 383 | CLI Example: |
| 384 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 385 | salt '*' neutronng.delete_subnet openstack-subnet-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 386 | ''' |
| 387 | neutron_interface.delete_subnet(subnet_id) |
| 388 | |
| 389 | |
| 390 | @_autheticate |
| 391 | def delete_network(neutron_interface, network_id): |
| 392 | ''' |
| 393 | delete given network |
| 394 | CLI Example: |
| 395 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 396 | salt '*' neutronng.delete_network openstack-network-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 397 | ''' |
| 398 | neutron_interface.delete_network(network_id) |
| 399 | |
| 400 | |
| 401 | @_autheticate |
| 402 | def delete_router(neutron_interface, router_id): |
| 403 | ''' |
| 404 | delete given router |
| 405 | CLI Example: |
| 406 | .. code-block:: bash |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 407 | salt '*' neutronng.delete_router openstack-router-id |
Jiri Broulik | f1b3aa4 | 2017-01-26 17:08:44 +0100 | [diff] [blame] | 408 | ''' |
Your Name | 96fdc0a | 2017-05-05 12:56:28 +0000 | [diff] [blame] | 409 | neutron_interface.delete_router(router_id) |
| 410 | |
Artem | 27d70bb | 2018-05-14 10:37:18 +0300 | [diff] [blame] | 411 | |
| 412 | @_autheticate |
| 413 | def list_extensions(neutron_interface, **kwargs): |
| 414 | ''' |
| 415 | list all extensions |
| 416 | CLI Example: |
| 417 | .. code-block:: bash |
| 418 | salt '*' neutronng.list_extensions |
| 419 | ''' |
| 420 | return neutron_interface.list_extensions(**kwargs) |
Oleh Hryhorov | 4ce5d2c | 2018-11-08 18:41:20 +0200 | [diff] [blame] | 421 | |
| 422 | |
| 423 | def wait_for_api_ready(profile, retries=1, retry_timeout=10): |
| 424 | |
| 425 | response = {'status': 'up'} |
| 426 | for i in range(1, retries+1): |
| 427 | try: |
| 428 | list_routers(profile=profile) |
| 429 | except Exception as e: |
| 430 | msg = ("Error: %s " |
| 431 | "Sleeping for %ss. " |
| 432 | "Attempts %s of %s ") |
| 433 | LOG.error(msg % (e, retry_timeout, i, retries)) |
| 434 | time.sleep(retry_timeout) |
| 435 | if i == retries: |
| 436 | raise CommandExecutionError(e) |
| 437 | continue |
| 438 | return response |
| 439 | |