python-openstackclient 6.6.1__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openstackclient/api/api.py +4 -4
- openstackclient/api/compute_v2.py +352 -638
- openstackclient/api/image_v1.py +1 -1
- openstackclient/api/object_store_v1.py +3 -4
- openstackclient/common/availability_zone.py +1 -1
- openstackclient/common/clientmanager.py +16 -4
- openstackclient/common/configuration.py +1 -1
- openstackclient/common/extension.py +1 -1
- openstackclient/common/limits.py +66 -32
- openstackclient/common/module.py +3 -3
- openstackclient/common/progressbar.py +2 -2
- openstackclient/common/project_cleanup.py +5 -2
- openstackclient/common/quota.py +281 -410
- openstackclient/common/versions.py +1 -1
- openstackclient/compute/client.py +7 -116
- openstackclient/compute/v2/agent.py +75 -49
- openstackclient/compute/v2/aggregate.py +9 -9
- openstackclient/compute/v2/console.py +2 -2
- openstackclient/compute/v2/flavor.py +6 -6
- openstackclient/compute/v2/host.py +38 -33
- openstackclient/compute/v2/hypervisor.py +4 -3
- openstackclient/compute/v2/keypair.py +7 -8
- openstackclient/compute/v2/server.py +478 -396
- openstackclient/compute/v2/server_backup.py +1 -1
- openstackclient/compute/v2/server_group.py +4 -4
- openstackclient/compute/v2/server_image.py +1 -1
- openstackclient/compute/v2/server_migration.py +3 -4
- openstackclient/compute/v2/service.py +4 -4
- openstackclient/compute/v2/usage.py +3 -3
- openstackclient/identity/common.py +34 -0
- openstackclient/identity/v2_0/catalog.py +2 -2
- openstackclient/identity/v2_0/ec2creds.py +4 -4
- openstackclient/identity/v2_0/endpoint.py +4 -4
- openstackclient/identity/v2_0/project.py +6 -6
- openstackclient/identity/v2_0/role.py +5 -5
- openstackclient/identity/v2_0/role_assignment.py +1 -1
- openstackclient/identity/v2_0/service.py +4 -4
- openstackclient/identity/v2_0/token.py +2 -2
- openstackclient/identity/v2_0/user.py +7 -7
- openstackclient/identity/v3/access_rule.py +3 -3
- openstackclient/identity/v3/application_credential.py +127 -45
- openstackclient/identity/v3/catalog.py +2 -2
- openstackclient/identity/v3/consumer.py +4 -4
- openstackclient/identity/v3/credential.py +5 -5
- openstackclient/identity/v3/domain.py +5 -5
- openstackclient/identity/v3/ec2creds.py +4 -4
- openstackclient/identity/v3/endpoint.py +7 -7
- openstackclient/identity/v3/endpoint_group.py +8 -10
- openstackclient/identity/v3/federation_protocol.py +5 -5
- openstackclient/identity/v3/group.py +8 -8
- openstackclient/identity/v3/identity_provider.py +5 -5
- openstackclient/identity/v3/implied_role.py +3 -3
- openstackclient/identity/v3/limit.py +5 -5
- openstackclient/identity/v3/mapping.py +5 -5
- openstackclient/identity/v3/policy.py +5 -5
- openstackclient/identity/v3/project.py +5 -5
- openstackclient/identity/v3/region.py +5 -5
- openstackclient/identity/v3/registered_limit.py +5 -5
- openstackclient/identity/v3/role.py +7 -7
- openstackclient/identity/v3/role_assignment.py +92 -140
- openstackclient/identity/v3/service.py +64 -34
- openstackclient/identity/v3/service_provider.py +4 -4
- openstackclient/identity/v3/tag.py +2 -2
- openstackclient/identity/v3/token.py +5 -5
- openstackclient/identity/v3/trust.py +3 -3
- openstackclient/identity/v3/user.py +144 -80
- openstackclient/image/client.py +4 -4
- openstackclient/image/v1/image.py +8 -9
- openstackclient/image/v2/cache.py +12 -10
- openstackclient/image/v2/metadef_objects.py +44 -0
- openstackclient/image/v2/metadef_resource_type_association.py +189 -0
- openstackclient/image/v2/task.py +1 -1
- openstackclient/network/common.py +6 -5
- openstackclient/network/utils.py +2 -2
- openstackclient/network/v2/address_group.py +6 -6
- openstackclient/network/v2/address_scope.py +5 -5
- openstackclient/network/v2/default_security_group_rule.py +1 -1
- openstackclient/network/v2/floating_ip.py +8 -10
- openstackclient/network/v2/floating_ip_pool.py +6 -15
- openstackclient/network/v2/floating_ip_port_forwarding.py +5 -13
- openstackclient/network/v2/ip_availability.py +2 -2
- openstackclient/network/v2/l3_conntrack_helper.py +5 -5
- openstackclient/network/v2/network.py +8 -8
- openstackclient/network/v2/network_agent.py +8 -8
- openstackclient/network/v2/network_auto_allocated_topology.py +2 -2
- openstackclient/network/v2/network_flavor.py +6 -8
- openstackclient/network/v2/network_flavor_profile.py +4 -4
- openstackclient/network/v2/network_meter.py +3 -3
- openstackclient/network/v2/network_meter_rule.py +3 -3
- openstackclient/network/v2/network_qos_policy.py +5 -5
- openstackclient/network/v2/network_qos_rule.py +9 -9
- openstackclient/network/v2/network_qos_rule_type.py +1 -1
- openstackclient/network/v2/network_rbac.py +5 -5
- openstackclient/network/v2/network_segment.py +5 -5
- openstackclient/network/v2/network_segment_range.py +7 -7
- openstackclient/network/v2/network_trunk.py +7 -7
- openstackclient/network/v2/port.py +26 -12
- openstackclient/network/v2/router.py +403 -54
- openstackclient/network/v2/security_group.py +18 -14
- openstackclient/network/v2/security_group_rule.py +18 -15
- openstackclient/network/v2/subnet.py +15 -8
- openstackclient/network/v2/subnet_pool.py +6 -6
- openstackclient/object/v1/account.py +2 -2
- openstackclient/object/v1/container.py +7 -7
- openstackclient/object/v1/object.py +7 -7
- openstackclient/shell.py +4 -6
- openstackclient/tests/functional/base.py +1 -1
- openstackclient/tests/functional/common/test_extension.py +1 -1
- openstackclient/tests/functional/common/test_help.py +2 -2
- openstackclient/tests/functional/common/test_module.py +1 -1
- openstackclient/tests/functional/common/test_quota.py +43 -61
- openstackclient/tests/functional/compute/v2/common.py +2 -2
- openstackclient/tests/functional/compute/v2/test_flavor.py +2 -2
- openstackclient/tests/functional/compute/v2/test_keypair.py +1 -1
- openstackclient/tests/functional/compute/v2/test_server.py +5 -5
- openstackclient/tests/functional/compute/v2/test_server_event.py +1 -1
- openstackclient/tests/functional/identity/v2/common.py +3 -3
- openstackclient/tests/functional/identity/v3/common.py +14 -6
- openstackclient/tests/functional/identity/v3/test_application_credential.py +13 -19
- openstackclient/tests/functional/identity/v3/test_domain.py +1 -3
- openstackclient/tests/functional/identity/v3/test_endpoint.py +1 -1
- openstackclient/tests/functional/identity/v3/test_idp.py +1 -1
- openstackclient/tests/functional/identity/v3/test_limit.py +2 -2
- openstackclient/tests/functional/identity/v3/test_region.py +1 -3
- openstackclient/tests/functional/identity/v3/test_registered_limit.py +1 -1
- openstackclient/tests/functional/identity/v3/test_role.py +2 -2
- openstackclient/tests/functional/identity/v3/test_role_assignment.py +210 -0
- openstackclient/tests/functional/identity/v3/test_service.py +4 -6
- openstackclient/tests/functional/identity/v3/test_service_provider.py +1 -3
- openstackclient/tests/functional/image/base.py +1 -1
- openstackclient/tests/functional/image/v2/test_image.py +1 -1
- openstackclient/tests/functional/image/v2/test_info.py +1 -1
- openstackclient/tests/functional/network/v2/common.py +4 -6
- openstackclient/tests/functional/network/v2/test_network.py +5 -3
- openstackclient/tests/functional/network/v2/test_network_agent.py +7 -5
- openstackclient/tests/functional/network/v2/test_network_qos_rule.py +4 -4
- openstackclient/tests/functional/network/v2/test_port.py +11 -7
- openstackclient/tests/functional/network/v2/test_router.py +2 -2
- openstackclient/tests/functional/object/v1/common.py +1 -1
- openstackclient/tests/functional/object/v1/test_container.py +3 -3
- openstackclient/tests/functional/object/v1/test_object.py +9 -13
- openstackclient/tests/functional/volume/base.py +1 -1
- openstackclient/tests/functional/volume/v1/test_service.py +1 -1
- openstackclient/tests/functional/volume/v1/test_snapshot.py +2 -2
- openstackclient/tests/functional/volume/v1/test_transfer_request.py +2 -2
- openstackclient/tests/functional/volume/v1/test_volume_type.py +1 -1
- openstackclient/tests/functional/volume/v2/test_service.py +2 -2
- openstackclient/tests/functional/volume/v2/test_volume_backup.py +2 -2
- openstackclient/tests/functional/volume/v2/test_volume_snapshot.py +2 -2
- openstackclient/tests/functional/volume/v2/test_volume_type.py +1 -1
- openstackclient/tests/functional/volume/v3/test_volume_snapshot.py +2 -2
- openstackclient/tests/functional/volume/v3/test_volume_type.py +1 -1
- openstackclient/tests/unit/api/fakes.py +1 -1
- openstackclient/tests/unit/api/test_api.py +2 -2
- openstackclient/tests/unit/api/test_compute_v2.py +522 -707
- openstackclient/tests/unit/api/test_image_v1.py +1 -1
- openstackclient/tests/unit/api/test_image_v2.py +1 -1
- openstackclient/tests/unit/api/test_object_store_v1.py +4 -4
- openstackclient/tests/unit/common/test_limits.py +73 -35
- openstackclient/tests/unit/common/test_logs.py +2 -2
- openstackclient/tests/unit/common/test_module.py +4 -2
- openstackclient/tests/unit/common/test_project_cleanup.py +31 -6
- openstackclient/tests/unit/common/test_quota.py +490 -630
- openstackclient/tests/unit/compute/v2/fakes.py +37 -286
- openstackclient/tests/unit/compute/v2/test_agent.py +189 -147
- openstackclient/tests/unit/compute/v2/test_aggregate.py +18 -16
- openstackclient/tests/unit/compute/v2/test_console.py +4 -5
- openstackclient/tests/unit/compute/v2/test_flavor.py +59 -68
- openstackclient/tests/unit/compute/v2/test_host.py +83 -54
- openstackclient/tests/unit/compute/v2/test_hypervisor.py +28 -31
- openstackclient/tests/unit/compute/v2/test_hypervisor_stats.py +2 -2
- openstackclient/tests/unit/compute/v2/test_keypair.py +65 -50
- openstackclient/tests/unit/compute/v2/test_server.py +2895 -2459
- openstackclient/tests/unit/compute/v2/test_server_backup.py +1 -1
- openstackclient/tests/unit/compute/v2/test_server_event.py +14 -39
- openstackclient/tests/unit/compute/v2/test_server_group.py +28 -29
- openstackclient/tests/unit/compute/v2/test_server_migration.py +43 -68
- openstackclient/tests/unit/compute/v2/test_server_volume.py +17 -34
- openstackclient/tests/unit/compute/v2/test_service.py +34 -52
- openstackclient/tests/unit/compute/v2/test_usage.py +4 -4
- openstackclient/tests/unit/fakes.py +11 -11
- openstackclient/tests/unit/identity/v2_0/fakes.py +27 -10
- openstackclient/tests/unit/identity/v2_0/test_catalog.py +3 -3
- openstackclient/tests/unit/identity/v2_0/test_endpoint.py +7 -7
- openstackclient/tests/unit/identity/v2_0/test_project.py +8 -8
- openstackclient/tests/unit/identity/v2_0/test_role.py +10 -10
- openstackclient/tests/unit/identity/v2_0/test_role_assignment.py +4 -4
- openstackclient/tests/unit/identity/v2_0/test_service.py +6 -6
- openstackclient/tests/unit/identity/v2_0/test_token.py +4 -4
- openstackclient/tests/unit/identity/v2_0/test_user.py +8 -8
- openstackclient/tests/unit/identity/v3/fakes.py +59 -20
- openstackclient/tests/unit/identity/v3/test_access_rule.py +5 -5
- openstackclient/tests/unit/identity/v3/test_application_credential.py +212 -235
- openstackclient/tests/unit/identity/v3/test_catalog.py +3 -3
- openstackclient/tests/unit/identity/v3/test_consumer.py +7 -8
- openstackclient/tests/unit/identity/v3/test_credential.py +9 -9
- openstackclient/tests/unit/identity/v3/test_domain.py +8 -8
- openstackclient/tests/unit/identity/v3/test_endpoint.py +13 -13
- openstackclient/tests/unit/identity/v3/test_endpoint_group.py +12 -14
- openstackclient/tests/unit/identity/v3/test_group.py +12 -12
- openstackclient/tests/unit/identity/v3/test_identity_provider.py +8 -8
- openstackclient/tests/unit/identity/v3/test_implied_role.py +5 -5
- openstackclient/tests/unit/identity/v3/test_limit.py +7 -7
- openstackclient/tests/unit/identity/v3/test_mappings.py +7 -7
- openstackclient/tests/unit/identity/v3/test_oauth.py +5 -5
- openstackclient/tests/unit/identity/v3/test_project.py +16 -16
- openstackclient/tests/unit/identity/v3/test_protocol.py +7 -7
- openstackclient/tests/unit/identity/v3/test_region.py +7 -7
- openstackclient/tests/unit/identity/v3/test_registered_limit.py +12 -13
- openstackclient/tests/unit/identity/v3/test_role.py +13 -13
- openstackclient/tests/unit/identity/v3/test_role_assignment.py +410 -331
- openstackclient/tests/unit/identity/v3/test_service.py +93 -97
- openstackclient/tests/unit/identity/v3/test_service_provider.py +7 -7
- openstackclient/tests/unit/identity/v3/test_token.py +4 -4
- openstackclient/tests/unit/identity/v3/test_trust.py +9 -9
- openstackclient/tests/unit/identity/v3/test_unscoped_saml.py +4 -4
- openstackclient/tests/unit/identity/v3/test_user.py +299 -327
- openstackclient/tests/unit/image/v1/test_image.py +6 -6
- openstackclient/tests/unit/image/v2/fakes.py +46 -9
- openstackclient/tests/unit/image/v2/test_cache.py +2 -2
- openstackclient/tests/unit/image/v2/test_image.py +3 -3
- openstackclient/tests/unit/image/v2/test_metadef_objects.py +62 -0
- openstackclient/tests/unit/image/v2/test_metadef_resource_type_association.py +131 -0
- openstackclient/tests/unit/integ/base.py +1 -1
- openstackclient/tests/unit/integ/cli/test_project.py +4 -4
- openstackclient/tests/unit/integ/cli/test_shell.py +7 -7
- openstackclient/tests/unit/network/test_common.py +12 -21
- openstackclient/tests/unit/network/v2/fakes.py +64 -130
- openstackclient/tests/unit/network/v2/test_address_group.py +15 -15
- openstackclient/tests/unit/network/v2/test_address_scope.py +13 -13
- openstackclient/tests/unit/network/v2/test_default_security_group_rule.py +49 -27
- openstackclient/tests/unit/network/v2/test_floating_ip_compute.py +40 -38
- openstackclient/tests/unit/network/v2/test_floating_ip_network.py +15 -15
- openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py +4 -7
- openstackclient/tests/unit/network/v2/test_floating_ip_pool_network.py +3 -5
- openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py +11 -11
- openstackclient/tests/unit/network/v2/test_ip_availability.py +6 -6
- openstackclient/tests/unit/network/v2/test_l3_conntrack_helper.py +11 -21
- openstackclient/tests/unit/network/v2/test_local_ip.py +7 -7
- openstackclient/tests/unit/network/v2/test_local_ip_association.py +3 -5
- openstackclient/tests/unit/network/v2/test_ndp_proxy.py +13 -13
- openstackclient/tests/unit/network/v2/test_network.py +23 -28
- openstackclient/tests/unit/network/v2/test_network_agent.py +17 -21
- openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py +8 -8
- openstackclient/tests/unit/network/v2/test_network_compute.py +66 -65
- openstackclient/tests/unit/network/v2/test_network_flavor.py +17 -19
- openstackclient/tests/unit/network/v2/test_network_flavor_profile.py +13 -13
- openstackclient/tests/unit/network/v2/test_network_meter.py +11 -11
- openstackclient/tests/unit/network/v2/test_network_meter_rule.py +11 -11
- openstackclient/tests/unit/network/v2/test_network_qos_policy.py +11 -21
- openstackclient/tests/unit/network/v2/test_network_qos_rule.py +51 -77
- openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py +5 -9
- openstackclient/tests/unit/network/v2/test_network_rbac.py +12 -12
- openstackclient/tests/unit/network/v2/test_network_segment.py +11 -15
- openstackclient/tests/unit/network/v2/test_network_segment_range.py +11 -13
- openstackclient/tests/unit/network/v2/test_network_service_provider.py +3 -5
- openstackclient/tests/unit/network/v2/test_network_trunk.py +11 -11
- openstackclient/tests/unit/network/v2/test_port.py +22 -25
- openstackclient/tests/unit/network/v2/test_router.py +721 -51
- openstackclient/tests/unit/network/v2/test_security_group_compute.py +65 -49
- openstackclient/tests/unit/network/v2/test_security_group_network.py +15 -15
- openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +57 -45
- openstackclient/tests/unit/network/v2/test_security_group_rule_network.py +11 -19
- openstackclient/tests/unit/network/v2/test_subnet.py +29 -25
- openstackclient/tests/unit/network/v2/test_subnet_pool.py +15 -15
- openstackclient/tests/unit/object/v1/fakes.py +1 -1
- openstackclient/tests/unit/object/v1/test_container.py +5 -5
- openstackclient/tests/unit/object/v1/test_container_all.py +6 -6
- openstackclient/tests/unit/object/v1/test_object.py +3 -3
- openstackclient/tests/unit/object/v1/test_object_all.py +5 -5
- openstackclient/tests/unit/test_shell.py +5 -5
- openstackclient/tests/unit/utils.py +4 -1
- openstackclient/tests/unit/volume/test_find_resource.py +2 -2
- openstackclient/tests/unit/volume/v1/fakes.py +5 -6
- openstackclient/tests/unit/volume/v1/test_volume.py +5 -4
- openstackclient/tests/unit/volume/v2/fakes.py +39 -259
- openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py +5 -5
- openstackclient/tests/unit/volume/v2/test_qos_specs.py +9 -9
- openstackclient/tests/unit/volume/v2/test_volume.py +21 -87
- openstackclient/tests/unit/volume/v2/test_volume_backup.py +7 -368
- openstackclient/tests/unit/volume/v2/test_volume_snapshot.py +1 -1
- openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py +0 -44
- openstackclient/tests/unit/volume/v2/test_volume_type.py +6 -87
- openstackclient/tests/unit/volume/v3/fakes.py +505 -22
- openstackclient/tests/unit/volume/v3/test_block_storage_cleanup.py +2 -3
- openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py +10 -11
- openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py +10 -6
- openstackclient/tests/unit/volume/v3/test_block_storage_manage.py +25 -17
- openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py +6 -32
- openstackclient/tests/unit/volume/v3/test_service.py +271 -0
- openstackclient/tests/unit/volume/v3/test_volume.py +2177 -33
- openstackclient/tests/unit/volume/v3/test_volume_attachment.py +48 -52
- openstackclient/tests/unit/volume/v3/test_volume_backup.py +892 -0
- openstackclient/tests/unit/volume/v3/test_volume_group.py +19 -20
- openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py +14 -34
- openstackclient/tests/unit/volume/v3/test_volume_group_type.py +13 -16
- openstackclient/tests/unit/volume/v3/test_volume_message.py +10 -11
- openstackclient/tests/unit/volume/v3/test_volume_snapshot.py +161 -0
- openstackclient/tests/unit/volume/v3/test_volume_transfer_request.py +425 -0
- openstackclient/tests/unit/volume/v3/test_volume_type.py +1109 -0
- openstackclient/volume/v1/qos_specs.py +7 -7
- openstackclient/volume/v1/service.py +2 -2
- openstackclient/volume/v1/volume.py +12 -12
- openstackclient/volume/v1/volume_backup.py +7 -7
- openstackclient/volume/v1/volume_snapshot.py +8 -8
- openstackclient/volume/v1/volume_transfer_request.py +5 -5
- openstackclient/volume/v1/volume_type.py +7 -7
- openstackclient/volume/v2/backup_record.py +2 -2
- openstackclient/volume/v2/consistency_group.py +7 -9
- openstackclient/volume/v2/consistency_group_snapshot.py +4 -12
- openstackclient/volume/v2/qos_specs.py +7 -7
- openstackclient/volume/v2/service.py +2 -2
- openstackclient/volume/v2/volume.py +80 -80
- openstackclient/volume/v2/volume_backend.py +2 -2
- openstackclient/volume/v2/volume_backup.py +7 -217
- openstackclient/volume/v2/volume_host.py +2 -2
- openstackclient/volume/v2/volume_snapshot.py +8 -8
- openstackclient/volume/v2/volume_transfer_request.py +5 -37
- openstackclient/volume/v2/volume_type.py +7 -89
- openstackclient/volume/v3/service.py +56 -0
- openstackclient/volume/v3/volume.py +971 -0
- openstackclient/volume/v3/volume_attachment.py +31 -29
- openstackclient/volume/v3/volume_backup.py +670 -0
- openstackclient/volume/v3/volume_message.py +1 -1
- openstackclient/volume/v3/volume_snapshot.py +97 -0
- openstackclient/volume/v3/volume_transfer_request.py +233 -0
- openstackclient/volume/v3/volume_type.py +967 -0
- {python_openstackclient-6.6.1.dist-info → python_openstackclient-7.0.0.dist-info}/AUTHORS +4 -0
- {python_openstackclient-6.6.1.dist-info → python_openstackclient-7.0.0.dist-info}/METADATA +2 -3
- python_openstackclient-7.0.0.dist-info/RECORD +502 -0
- {python_openstackclient-6.6.1.dist-info → python_openstackclient-7.0.0.dist-info}/entry_points.txt +33 -27
- python_openstackclient-7.0.0.dist-info/pbr.json +1 -0
- python_openstackclient-6.6.1.dist-info/RECORD +0 -489
- python_openstackclient-6.6.1.dist-info/pbr.json +0 -1
- {python_openstackclient-6.6.1.dist-info → python_openstackclient-7.0.0.dist-info}/LICENSE +0 -0
- {python_openstackclient-6.6.1.dist-info → python_openstackclient-7.0.0.dist-info}/WHEEL +0 -0
- {python_openstackclient-6.6.1.dist-info → python_openstackclient-7.0.0.dist-info}/top_level.txt +0 -0
|
@@ -9,645 +9,359 @@
|
|
|
9
9
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
10
10
|
# License for the specific language governing permissions and limitations
|
|
11
11
|
# under the License.
|
|
12
|
-
#
|
|
13
12
|
|
|
14
|
-
"""Compute v2 API Library
|
|
13
|
+
"""Compute v2 API Library
|
|
14
|
+
|
|
15
|
+
A collection of wrappers for deprecated Compute v2 APIs that are not
|
|
16
|
+
intentionally supported by SDK. Most of these are proxy APIs.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import http
|
|
15
20
|
|
|
16
|
-
from
|
|
17
|
-
from osc_lib.api import api
|
|
21
|
+
from openstack import exceptions as sdk_exceptions
|
|
18
22
|
from osc_lib import exceptions
|
|
19
|
-
from osc_lib.i18n import _
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# TODO(dtroyer): Mingrate this to osc-lib
|
|
23
|
-
class InvalidValue(Exception):
|
|
24
|
-
"""An argument value is not valid: wrong type, out of range, etc"""
|
|
25
|
-
|
|
26
|
-
message = "Supplied value is not valid"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class APIv2(api.BaseAPI):
|
|
30
|
-
"""Compute v2 API"""
|
|
31
|
-
|
|
32
|
-
def __init__(self, **kwargs):
|
|
33
|
-
super(APIv2, self).__init__(**kwargs)
|
|
34
|
-
|
|
35
|
-
# Overrides
|
|
36
|
-
|
|
37
|
-
def _check_integer(self, value, msg=None):
|
|
38
|
-
"""Attempt to convert value to an integer
|
|
39
|
-
|
|
40
|
-
Raises InvalidValue on failure
|
|
41
|
-
|
|
42
|
-
:param value:
|
|
43
|
-
Convert this to an integer. None is converted to 0 (zero).
|
|
44
|
-
:param msg:
|
|
45
|
-
An alternate message for the exception, must include exactly
|
|
46
|
-
one substitution to receive the attempted value.
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
if value is None:
|
|
50
|
-
return 0
|
|
51
|
-
|
|
52
|
-
try:
|
|
53
|
-
value = int(value)
|
|
54
|
-
except (TypeError, ValueError):
|
|
55
|
-
if not msg:
|
|
56
|
-
msg = _("%s is not an integer") % value
|
|
57
|
-
raise InvalidValue(msg)
|
|
58
|
-
return value
|
|
59
|
-
|
|
60
|
-
# TODO(dtroyer): Override find() until these fixes get into an osc-lib
|
|
61
|
-
# minimum release
|
|
62
|
-
def find(
|
|
63
|
-
self,
|
|
64
|
-
path,
|
|
65
|
-
value=None,
|
|
66
|
-
attr=None,
|
|
67
|
-
):
|
|
68
|
-
"""Find a single resource by name or ID
|
|
69
|
-
|
|
70
|
-
:param string path:
|
|
71
|
-
The API-specific portion of the URL path
|
|
72
|
-
:param string value:
|
|
73
|
-
search expression (required, really)
|
|
74
|
-
:param string attr:
|
|
75
|
-
name of attribute for secondary search
|
|
76
|
-
"""
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
ret = self._request('GET', "/%s/%s" % (path, value)).json()
|
|
80
|
-
if isinstance(ret, dict):
|
|
81
|
-
# strip off the enclosing dict
|
|
82
|
-
key = list(ret.keys())[0]
|
|
83
|
-
ret = ret[key]
|
|
84
|
-
except (
|
|
85
|
-
ksa_exceptions.NotFound,
|
|
86
|
-
ksa_exceptions.BadRequest,
|
|
87
|
-
):
|
|
88
|
-
kwargs = {attr: value}
|
|
89
|
-
try:
|
|
90
|
-
ret = self.find_one(path, **kwargs)
|
|
91
|
-
except ksa_exceptions.NotFound:
|
|
92
|
-
msg = _("%s not found") % value
|
|
93
|
-
raise exceptions.NotFound(msg)
|
|
94
|
-
|
|
95
|
-
return ret
|
|
96
|
-
|
|
97
|
-
# Floating IPs
|
|
98
|
-
|
|
99
|
-
def floating_ip_add(
|
|
100
|
-
self,
|
|
101
|
-
server,
|
|
102
|
-
address,
|
|
103
|
-
fixed_address=None,
|
|
104
|
-
):
|
|
105
|
-
"""Add a floating IP to a server
|
|
106
|
-
|
|
107
|
-
:param server:
|
|
108
|
-
The :class:`Server` (or its ID) to add an IP to.
|
|
109
|
-
:param address:
|
|
110
|
-
The FloatingIP or string floating address to add.
|
|
111
|
-
:param fixed_address:
|
|
112
|
-
The FixedIP the floatingIP should be associated with (optional)
|
|
113
|
-
"""
|
|
114
|
-
|
|
115
|
-
url = '/servers'
|
|
116
|
-
|
|
117
|
-
server = self.find(
|
|
118
|
-
url,
|
|
119
|
-
attr='name',
|
|
120
|
-
value=server,
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
address = address.ip if hasattr(address, 'ip') else address
|
|
124
|
-
if fixed_address:
|
|
125
|
-
if hasattr(fixed_address, 'ip'):
|
|
126
|
-
fixed_address = fixed_address.ip
|
|
127
|
-
|
|
128
|
-
body = {
|
|
129
|
-
'address': address,
|
|
130
|
-
'fixed_address': fixed_address,
|
|
131
|
-
}
|
|
132
|
-
else:
|
|
133
|
-
body = {
|
|
134
|
-
'address': address,
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return self._request(
|
|
138
|
-
"POST",
|
|
139
|
-
"/%s/%s/action" % (url, server['id']),
|
|
140
|
-
json={'addFloatingIp': body},
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
def floating_ip_create(
|
|
144
|
-
self,
|
|
145
|
-
pool=None,
|
|
146
|
-
):
|
|
147
|
-
"""Create a new floating ip
|
|
148
|
-
|
|
149
|
-
https://docs.openstack.org/api-ref/compute/#create-allocate-floating-ip-address
|
|
150
|
-
|
|
151
|
-
:param pool: Name of floating IP pool
|
|
152
|
-
"""
|
|
153
|
-
|
|
154
|
-
url = "/os-floating-ips"
|
|
155
|
-
|
|
156
|
-
try:
|
|
157
|
-
return self.create(
|
|
158
|
-
url,
|
|
159
|
-
json={'pool': pool},
|
|
160
|
-
)['floating_ip']
|
|
161
|
-
except (
|
|
162
|
-
ksa_exceptions.NotFound,
|
|
163
|
-
ksa_exceptions.BadRequest,
|
|
164
|
-
):
|
|
165
|
-
msg = _("%s not found") % pool
|
|
166
|
-
raise exceptions.NotFound(msg)
|
|
167
|
-
|
|
168
|
-
def floating_ip_delete(
|
|
169
|
-
self,
|
|
170
|
-
floating_ip_id=None,
|
|
171
|
-
):
|
|
172
|
-
"""Delete a floating IP
|
|
173
|
-
|
|
174
|
-
https://docs.openstack.org/api-ref/compute/#delete-deallocate-floating-ip-address
|
|
175
|
-
|
|
176
|
-
:param string floating_ip_id:
|
|
177
|
-
Floating IP ID
|
|
178
|
-
"""
|
|
179
|
-
|
|
180
|
-
url = "/os-floating-ips"
|
|
181
|
-
|
|
182
|
-
if floating_ip_id is not None:
|
|
183
|
-
return self.delete('/%s/%s' % (url, floating_ip_id))
|
|
184
|
-
|
|
185
|
-
return None
|
|
186
|
-
|
|
187
|
-
def floating_ip_find(
|
|
188
|
-
self,
|
|
189
|
-
floating_ip=None,
|
|
190
|
-
):
|
|
191
|
-
"""Return a security group given name or ID
|
|
192
|
-
|
|
193
|
-
https://docs.openstack.org/api-ref/compute/#list-floating-ip-addresses
|
|
194
|
-
|
|
195
|
-
:param string floating_ip:
|
|
196
|
-
Floating IP address
|
|
197
|
-
:returns: A dict of the floating IP attributes
|
|
198
|
-
"""
|
|
199
|
-
|
|
200
|
-
url = "/os-floating-ips"
|
|
201
|
-
|
|
202
|
-
return self.find(
|
|
203
|
-
url,
|
|
204
|
-
attr='ip',
|
|
205
|
-
value=floating_ip,
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
def floating_ip_list(
|
|
209
|
-
self,
|
|
210
|
-
):
|
|
211
|
-
"""Get floating IPs
|
|
212
|
-
|
|
213
|
-
https://docs.openstack.org/api-ref/compute/#show-floating-ip-address-details
|
|
214
|
-
|
|
215
|
-
:returns:
|
|
216
|
-
list of floating IPs
|
|
217
|
-
"""
|
|
218
|
-
|
|
219
|
-
url = "/os-floating-ips"
|
|
220
|
-
|
|
221
|
-
return self.list(url)["floating_ips"]
|
|
222
|
-
|
|
223
|
-
def floating_ip_remove(
|
|
224
|
-
self,
|
|
225
|
-
server,
|
|
226
|
-
address,
|
|
227
|
-
):
|
|
228
|
-
"""Remove a floating IP from a server
|
|
229
|
-
|
|
230
|
-
:param server:
|
|
231
|
-
The :class:`Server` (or its ID) to add an IP to.
|
|
232
|
-
:param address:
|
|
233
|
-
The FloatingIP or string floating address to add.
|
|
234
|
-
"""
|
|
235
|
-
|
|
236
|
-
url = '/servers'
|
|
237
|
-
|
|
238
|
-
server = self.find(
|
|
239
|
-
url,
|
|
240
|
-
attr='name',
|
|
241
|
-
value=server,
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
address = address.ip if hasattr(address, 'ip') else address
|
|
245
|
-
body = {
|
|
246
|
-
'address': address,
|
|
247
|
-
}
|
|
248
23
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
:
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
from_port=None,
|
|
594
|
-
to_port=None,
|
|
595
|
-
remote_ip=None,
|
|
596
|
-
remote_group=None,
|
|
597
|
-
):
|
|
598
|
-
"""Create a new security group rule
|
|
599
|
-
|
|
600
|
-
https://docs.openstack.org/api-ref/compute/#create-security-group-rule
|
|
601
|
-
|
|
602
|
-
:param string security_group_id:
|
|
603
|
-
Security group ID
|
|
604
|
-
:param ip_protocol:
|
|
605
|
-
IP protocol, 'tcp', 'udp' or 'icmp'
|
|
606
|
-
:param from_port:
|
|
607
|
-
Source port
|
|
608
|
-
:param to_port:
|
|
609
|
-
Destination port
|
|
610
|
-
:param remote_ip:
|
|
611
|
-
Source IP address in CIDR notation
|
|
612
|
-
:param remote_group:
|
|
613
|
-
Remote security group
|
|
614
|
-
"""
|
|
615
|
-
|
|
616
|
-
url = "/os-security-group-rules"
|
|
617
|
-
|
|
618
|
-
if ip_protocol.lower() not in ['icmp', 'tcp', 'udp']:
|
|
619
|
-
raise InvalidValue(
|
|
620
|
-
"%(s) is not one of 'icmp', 'tcp', or 'udp'" % ip_protocol
|
|
621
|
-
)
|
|
622
|
-
|
|
623
|
-
params = {
|
|
624
|
-
'parent_group_id': security_group_id,
|
|
625
|
-
'ip_protocol': ip_protocol,
|
|
626
|
-
'from_port': self._check_integer(from_port),
|
|
627
|
-
'to_port': self._check_integer(to_port),
|
|
628
|
-
'cidr': remote_ip,
|
|
629
|
-
'group_id': remote_group,
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
return self.create(
|
|
633
|
-
url,
|
|
634
|
-
json={'security_group_rule': params},
|
|
635
|
-
)['security_group_rule']
|
|
636
|
-
|
|
637
|
-
def security_group_rule_delete(
|
|
638
|
-
self,
|
|
639
|
-
security_group_rule_id=None,
|
|
640
|
-
):
|
|
641
|
-
"""Delete a security group rule
|
|
642
|
-
|
|
643
|
-
https://docs.openstack.org/api-ref/compute/#delete-security-group-rule
|
|
644
|
-
|
|
645
|
-
:param string security_group_rule_id:
|
|
646
|
-
Security group rule ID
|
|
647
|
-
"""
|
|
648
|
-
|
|
649
|
-
url = "/os-security-group-rules"
|
|
650
|
-
if security_group_rule_id is not None:
|
|
651
|
-
return self.delete('/%s/%s' % (url, security_group_rule_id))
|
|
652
|
-
|
|
653
|
-
return None
|
|
24
|
+
|
|
25
|
+
# security groups
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def create_security_group(compute_client, name=None, description=None):
|
|
29
|
+
"""Create a new security group
|
|
30
|
+
|
|
31
|
+
https://docs.openstack.org/api-ref/compute/#create-security-group
|
|
32
|
+
|
|
33
|
+
:param compute_client: A compute client
|
|
34
|
+
:param str name: Security group name
|
|
35
|
+
:param str description: Security group description
|
|
36
|
+
:returns: A security group object
|
|
37
|
+
"""
|
|
38
|
+
data = {
|
|
39
|
+
'name': name,
|
|
40
|
+
'description': description,
|
|
41
|
+
}
|
|
42
|
+
response = compute_client.post(
|
|
43
|
+
'/os-security-groups', data=data, microversion='2.1'
|
|
44
|
+
)
|
|
45
|
+
sdk_exceptions.raise_from_response(response)
|
|
46
|
+
return response.json()['security_group']
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def list_security_groups(compute_client, all_projects=None):
|
|
50
|
+
"""Get all security groups
|
|
51
|
+
|
|
52
|
+
https://docs.openstack.org/api-ref/compute/#list-security-groups
|
|
53
|
+
|
|
54
|
+
:param compute_client: A compute client
|
|
55
|
+
:param bool all_projects: If true, list from all projects
|
|
56
|
+
:returns: A list of security group objects
|
|
57
|
+
"""
|
|
58
|
+
url = '/os-security-groups'
|
|
59
|
+
if all_projects is not None:
|
|
60
|
+
url += f'?all_tenants={all_projects}'
|
|
61
|
+
response = compute_client.get(url, microversion='2.1')
|
|
62
|
+
sdk_exceptions.raise_from_response(response)
|
|
63
|
+
return response.json()['security_groups']
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def find_security_group(compute_client, name_or_id):
|
|
67
|
+
"""Find the name for a given security group name or ID
|
|
68
|
+
|
|
69
|
+
https://docs.openstack.org/api-ref/compute/#show-security-group-details
|
|
70
|
+
|
|
71
|
+
:param compute_client: A compute client
|
|
72
|
+
:param name_or_id: The name or ID of the security group to look up
|
|
73
|
+
:returns: A security group object
|
|
74
|
+
:raises exception.NotFound: If a matching security group could not be
|
|
75
|
+
found or more than one match was found
|
|
76
|
+
"""
|
|
77
|
+
response = compute_client.get(
|
|
78
|
+
f'/os-security-groups/{name_or_id}', microversion='2.1'
|
|
79
|
+
)
|
|
80
|
+
if response.status_code != http.HTTPStatus.NOT_FOUND:
|
|
81
|
+
# there might be other, non-404 errors
|
|
82
|
+
sdk_exceptions.raise_from_response(response)
|
|
83
|
+
return response.json()['security_group']
|
|
84
|
+
|
|
85
|
+
response = compute_client.get('/os-security-groups', microversion='2.1')
|
|
86
|
+
sdk_exceptions.raise_from_response(response)
|
|
87
|
+
found = None
|
|
88
|
+
security_groups = response.json()['security_groups']
|
|
89
|
+
for security_group in security_groups:
|
|
90
|
+
if security_group['name'] == name_or_id:
|
|
91
|
+
if found:
|
|
92
|
+
raise exceptions.NotFound(
|
|
93
|
+
f'multiple matches found for {name_or_id}'
|
|
94
|
+
)
|
|
95
|
+
found = security_group
|
|
96
|
+
|
|
97
|
+
if not found:
|
|
98
|
+
raise exceptions.NotFound(f'{name_or_id} not found')
|
|
99
|
+
|
|
100
|
+
return found
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def update_security_group(
|
|
104
|
+
compute_client, security_group_id, name=None, description=None
|
|
105
|
+
):
|
|
106
|
+
"""Update an existing security group
|
|
107
|
+
|
|
108
|
+
https://docs.openstack.org/api-ref/compute/#update-security-group
|
|
109
|
+
|
|
110
|
+
:param compute_client: A compute client
|
|
111
|
+
:param str security_group_id: The ID of the security group to update
|
|
112
|
+
:param str name: Security group name
|
|
113
|
+
:param str description: Security group description
|
|
114
|
+
:returns: A security group object
|
|
115
|
+
"""
|
|
116
|
+
data = {}
|
|
117
|
+
if name:
|
|
118
|
+
data['name'] = name
|
|
119
|
+
if description:
|
|
120
|
+
data['description'] = description
|
|
121
|
+
response = compute_client.put(
|
|
122
|
+
f'/os-security-groups/{security_group_id}',
|
|
123
|
+
data=data,
|
|
124
|
+
microversion='2.1',
|
|
125
|
+
)
|
|
126
|
+
sdk_exceptions.raise_from_response(response)
|
|
127
|
+
return response.json()['security_group']
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def delete_security_group(compute_client, security_group_id=None):
|
|
131
|
+
"""Delete a security group
|
|
132
|
+
|
|
133
|
+
https://docs.openstack.org/api-ref/compute/#delete-security-group
|
|
134
|
+
|
|
135
|
+
:param compute_client: A compute client
|
|
136
|
+
:param str security_group_id: Security group ID
|
|
137
|
+
:returns: None
|
|
138
|
+
"""
|
|
139
|
+
response = compute_client.delete(
|
|
140
|
+
f'/os-security-groups/{security_group_id}', microversion='2.1'
|
|
141
|
+
)
|
|
142
|
+
sdk_exceptions.raise_from_response(response)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# security group rules
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def create_security_group_rule(
|
|
149
|
+
compute_client,
|
|
150
|
+
security_group_id=None,
|
|
151
|
+
ip_protocol=None,
|
|
152
|
+
from_port=None,
|
|
153
|
+
to_port=None,
|
|
154
|
+
remote_ip=None,
|
|
155
|
+
remote_group=None,
|
|
156
|
+
):
|
|
157
|
+
"""Create a new security group rule
|
|
158
|
+
|
|
159
|
+
https://docs.openstack.org/api-ref/compute/#create-security-group-rule
|
|
160
|
+
|
|
161
|
+
:param compute_client: A compute client
|
|
162
|
+
:param str security_group_id: Security group ID
|
|
163
|
+
:param str ip_protocol: IP protocol, 'tcp', 'udp' or 'icmp'
|
|
164
|
+
:param int from_port: Source port
|
|
165
|
+
:param int to_port: Destination port
|
|
166
|
+
:param str remote_ip: Source IP address in CIDR notation
|
|
167
|
+
:param str remote_group: Remote security group
|
|
168
|
+
:returns: A security group object
|
|
169
|
+
"""
|
|
170
|
+
data = {
|
|
171
|
+
'parent_group_id': security_group_id,
|
|
172
|
+
'ip_protocol': ip_protocol,
|
|
173
|
+
'from_port': from_port,
|
|
174
|
+
'to_port': to_port,
|
|
175
|
+
'cidr': remote_ip,
|
|
176
|
+
'group_id': remote_group,
|
|
177
|
+
}
|
|
178
|
+
response = compute_client.post(
|
|
179
|
+
'/os-security-group-rules', data=data, microversion='2.1'
|
|
180
|
+
)
|
|
181
|
+
sdk_exceptions.raise_from_response(response)
|
|
182
|
+
return response.json()['security_group_rule']
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def delete_security_group_rule(compute_client, security_group_rule_id=None):
|
|
186
|
+
"""Delete a security group rule
|
|
187
|
+
|
|
188
|
+
https://docs.openstack.org/api-ref/compute/#delete-security-group-rule
|
|
189
|
+
|
|
190
|
+
:param compute_client: A compute client
|
|
191
|
+
:param str security_group_rule_id: Security group rule ID
|
|
192
|
+
:returns: None
|
|
193
|
+
"""
|
|
194
|
+
response = compute_client.delete(
|
|
195
|
+
f'/os-security-group-rules/{security_group_rule_id}',
|
|
196
|
+
microversion='2.1',
|
|
197
|
+
)
|
|
198
|
+
sdk_exceptions.raise_from_response(response)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
# networks
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def create_network(compute_client, name, subnet, share_subnet=None):
|
|
205
|
+
"""Create a new network
|
|
206
|
+
|
|
207
|
+
https://docs.openstack.org/api-ref/compute/#create-network
|
|
208
|
+
|
|
209
|
+
:param compute_client: A compute client
|
|
210
|
+
:param str name: Network label
|
|
211
|
+
:param int subnet: Subnet for IPv4 fixed addresses in CIDR notation
|
|
212
|
+
:param bool share_subnet: Shared subnet between projects
|
|
213
|
+
:returns: A network object
|
|
214
|
+
"""
|
|
215
|
+
data = {
|
|
216
|
+
'label': name,
|
|
217
|
+
'cidr': subnet,
|
|
218
|
+
}
|
|
219
|
+
if share_subnet is not None:
|
|
220
|
+
data['share_address'] = share_subnet
|
|
221
|
+
|
|
222
|
+
response = compute_client.post(
|
|
223
|
+
'/os-networks', data=data, microversion='2.1'
|
|
224
|
+
)
|
|
225
|
+
sdk_exceptions.raise_from_response(response)
|
|
226
|
+
return response.json()['network']
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def list_networks(compute_client):
|
|
230
|
+
"""Get all networks
|
|
231
|
+
|
|
232
|
+
https://docs.openstack.org/api-ref/compute/#list-networks
|
|
233
|
+
|
|
234
|
+
:param compute_client: A compute client
|
|
235
|
+
:returns: A list of network objects
|
|
236
|
+
"""
|
|
237
|
+
response = compute_client.get('/os-networks', microversion='2.1')
|
|
238
|
+
sdk_exceptions.raise_from_response(response)
|
|
239
|
+
return response.json()['networks']
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def find_network(compute_client, name_or_id):
|
|
243
|
+
"""Find the ID for a given network name or ID
|
|
244
|
+
|
|
245
|
+
https://docs.openstack.org/api-ref/compute/#show-network-details
|
|
246
|
+
|
|
247
|
+
:param compute_client: A compute client
|
|
248
|
+
:param name_or_id: The name or ID of the network to look up
|
|
249
|
+
:returns: A network object
|
|
250
|
+
:raises exception.NotFound: If a matching network could not be found or
|
|
251
|
+
more than one match was found
|
|
252
|
+
"""
|
|
253
|
+
response = compute_client.get(
|
|
254
|
+
f'/os-networks/{name_or_id}', microversion='2.1'
|
|
255
|
+
)
|
|
256
|
+
if response.status_code != http.HTTPStatus.NOT_FOUND:
|
|
257
|
+
# there might be other, non-404 errors
|
|
258
|
+
sdk_exceptions.raise_from_response(response)
|
|
259
|
+
return response.json()['network']
|
|
260
|
+
|
|
261
|
+
response = compute_client.get('/os-networks', microversion='2.1')
|
|
262
|
+
sdk_exceptions.raise_from_response(response)
|
|
263
|
+
found = None
|
|
264
|
+
networks = response.json()['networks']
|
|
265
|
+
for network in networks:
|
|
266
|
+
if network['label'] == name_or_id:
|
|
267
|
+
if found:
|
|
268
|
+
raise exceptions.NotFound(
|
|
269
|
+
f'multiple matches found for {name_or_id}'
|
|
270
|
+
)
|
|
271
|
+
found = network
|
|
272
|
+
|
|
273
|
+
if not found:
|
|
274
|
+
raise exceptions.NotFound(f'{name_or_id} not found')
|
|
275
|
+
|
|
276
|
+
return found
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def delete_network(compute_client, network_id):
|
|
280
|
+
"""Delete a network
|
|
281
|
+
|
|
282
|
+
https://docs.openstack.org/api-ref/compute/#delete-network
|
|
283
|
+
|
|
284
|
+
:param compute_client: A compute client
|
|
285
|
+
:param string network_id: The network ID
|
|
286
|
+
:returns: None
|
|
287
|
+
"""
|
|
288
|
+
response = compute_client.delete(
|
|
289
|
+
f'/os-networks/{network_id}', microversion='2.1'
|
|
290
|
+
)
|
|
291
|
+
sdk_exceptions.raise_from_response(response)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
# floating ips
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def create_floating_ip(compute_client, network):
|
|
298
|
+
"""Create a new floating ip
|
|
299
|
+
|
|
300
|
+
https://docs.openstack.org/api-ref/compute/#create-allocate-floating-ip-address
|
|
301
|
+
|
|
302
|
+
:param network: Name of floating IP pool
|
|
303
|
+
:returns: A floating IP object
|
|
304
|
+
"""
|
|
305
|
+
response = compute_client.post(
|
|
306
|
+
'/os-floating-ips', data={'pool': network}, microversion='2.1'
|
|
307
|
+
)
|
|
308
|
+
sdk_exceptions.raise_from_response(response)
|
|
309
|
+
return response.json()['floating_ip']
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def list_floating_ips(compute_client):
|
|
313
|
+
"""Get all floating IPs
|
|
314
|
+
|
|
315
|
+
https://docs.openstack.org/api-ref/compute/#list-floating-ip-addresses
|
|
316
|
+
|
|
317
|
+
:returns: A list of floating IP objects
|
|
318
|
+
"""
|
|
319
|
+
response = compute_client.get('/os-floating-ips', microversion='2.1')
|
|
320
|
+
sdk_exceptions.raise_from_response(response)
|
|
321
|
+
return response.json()['floating_ips']
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def get_floating_ip(compute_client, floating_ip_id):
|
|
325
|
+
"""Get a floating IP
|
|
326
|
+
|
|
327
|
+
https://docs.openstack.org/api-ref/compute/#show-floating-ip-address-details
|
|
328
|
+
|
|
329
|
+
:param string floating_ip_id: The floating IP address
|
|
330
|
+
:returns: A floating IP object
|
|
331
|
+
"""
|
|
332
|
+
response = compute_client.get(
|
|
333
|
+
f'/os-floating-ips/{floating_ip_id}', microversion='2.1'
|
|
334
|
+
)
|
|
335
|
+
sdk_exceptions.raise_from_response(response)
|
|
336
|
+
return response.json()['floating_ip']
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def delete_floating_ip(compute_client, floating_ip_id):
|
|
340
|
+
"""Delete a floating IP
|
|
341
|
+
|
|
342
|
+
https://docs.openstack.org/api-ref/compute/#delete-deallocate-floating-ip-address
|
|
343
|
+
|
|
344
|
+
:param string floating_ip_id: The floating IP address
|
|
345
|
+
:returns: None
|
|
346
|
+
"""
|
|
347
|
+
response = compute_client.delete(
|
|
348
|
+
f'/os-floating-ips/{floating_ip_id}', microversion='2.1'
|
|
349
|
+
)
|
|
350
|
+
sdk_exceptions.raise_from_response(response)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
# floating ip pools
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def list_floating_ip_pools(compute_client):
|
|
357
|
+
"""Get all floating IP pools
|
|
358
|
+
|
|
359
|
+
https://docs.openstack.org/api-ref/compute/#list-floating-ip-pools
|
|
360
|
+
|
|
361
|
+
:param compute_client: A compute client
|
|
362
|
+
:returns: A list of floating IP pool objects
|
|
363
|
+
"""
|
|
364
|
+
response = compute_client.get('/os-floating-ip-pools', microversion='2.1')
|
|
365
|
+
sdk_exceptions.raise_from_response(response)
|
|
366
|
+
|
|
367
|
+
return response.json()['floating_ip_pools']
|