From 386374a57a342f8e0b6e2c0781c94911253b9d15 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 12 Jul 2024 21:21:43 +0900 Subject: [PATCH 01/35] feat: Create new project for migration --- src/VERSION | 1 - src/{ => plugin}/__init__.py | 0 src/plugin/main.py | 128 ++ src/setup.py | 60 - src/spaceone/__init__.py | 1 - src/spaceone/inventory/__init__.py | 1 - src/spaceone/inventory/conf/__init__.py | 0 .../inventory/conf/cloud_service_conf.py | 33 - src/spaceone/inventory/conf/global_conf.py | 23 - src/spaceone/inventory/conf/proto_conf.py | 3 - src/spaceone/inventory/connector/__init__.py | 26 - .../application_gateways/__init__.py | 1 - .../application_gateways/connector.py | 19 - .../connector/container_instances/__init__.py | 1 - .../container_instances/connector.py | 20 - .../inventory/connector/cosmos_db/__init__.py | 1 - .../connector/cosmos_db/connector.py | 23 - .../inventory/connector/disks/__init__.py | 1 - .../inventory/connector/disks/connector.py | 17 - .../connector/key_vaults/__init__.py | 1 - .../connector/key_vaults/connector.py | 50 - .../connector/load_balancers/__init__.py | 1 - .../connector/load_balancers/connector.py | 28 - .../inventory/connector/monitor/__init__.py | 1 - .../inventory/connector/monitor/connector.py | 23 - .../connector/mysql_servers/__init__.py | 1 - .../connector/mysql_servers/connector.py | 24 - .../connector/nat_gateways/__init__.py | 1 - .../connector/nat_gateways/connector.py | 26 - .../network_security_groups/__init__.py | 1 - .../network_security_groups/connector.py | 26 - .../connector/postgresql_servers/__init__.py | 1 - .../connector/postgresql_servers/connector.py | 36 - .../connector/public_ip_addresses/__init__.py | 1 - .../public_ip_addresses/connector.py | 19 - .../inventory/connector/resources/__init__.py | 1 - .../connector/resources/connector.py | 16 - .../inventory/connector/snapshots/__init__.py | 1 - .../connector/snapshots/connector.py | 17 - .../connector/sql_databases/__init__.py | 1 - .../connector/sql_databases/connector.py | 41 - .../connector/sql_servers/__init__.py | 1 - .../connector/sql_servers/connector.py | 61 - .../connector/storage_accounts/__init__.py | 1 - .../connector/storage_accounts/connector.py | 20 - .../connector/subscriptions/__init__.py | 1 - .../connector/subscriptions/connector.py | 20 - .../connector/virtual_machines/__init__.py | 1 - .../connector/virtual_machines/connector.py | 83 -- .../connector/virtual_networks/__init__.py | 1 - .../connector/virtual_networks/connector.py | 20 - .../connector/vm_scale_sets/__init__.py | 1 - .../connector/vm_scale_sets/connector.py | 44 - .../connector/web_pubsub_service/__init__.py | 1 - .../connector/web_pubsub_service/connector.py | 23 - src/spaceone/inventory/error/__init__.py | 15 - src/spaceone/inventory/error/custom.py | 56 - src/spaceone/inventory/info/__init__.py | 3 - src/spaceone/inventory/info/collector_info.py | 24 - src/spaceone/inventory/info/common_info.py | 7 - src/spaceone/inventory/info/job_info.py | 18 - src/spaceone/inventory/interface/__init__.py | 0 .../inventory/interface/grpc/__init__.py | 9 - .../inventory/interface/grpc/collector.py | 41 - src/spaceone/inventory/interface/grpc/job.py | 19 - src/spaceone/inventory/libs/__init__.py | 1 - src/spaceone/inventory/libs/connector.py | 107 -- src/spaceone/inventory/libs/manager.py | 233 ---- .../inventory/libs/schema/__init__.py | 0 src/spaceone/inventory/libs/schema/base.py | 40 - .../inventory/libs/schema/cloud_service.py | 45 - .../libs/schema/cloud_service_type.py | 36 - .../libs/schema/metadata/__init__.py | 0 .../libs/schema/metadata/dynamic_field.py | 563 -------- .../libs/schema/metadata/dynamic_layout.py | 186 --- .../libs/schema/metadata/dynamic_search.py | 14 - .../libs/schema/metadata/dynamic_widget.py | 212 --- src/spaceone/inventory/libs/schema/region.py | 16 - .../inventory/libs/schema/resource.py | 78 -- .../inventory/libs/schema/stackdriver.py | 15 - src/spaceone/inventory/libs/utils.py | 7 - src/spaceone/inventory/manager/__init__.py | 49 - .../manager/application_gateways/__init__.py | 0 .../application_gateways/instance_manager.py | 410 ------ .../manager/container_instances/__init__.py | 0 .../container_instances/container_manager.py | 208 --- .../inventory/manager/cosmos_db/__init__.py | 0 .../manager/cosmos_db/instance_manager.py | 231 ---- .../inventory/manager/disks/__init__.py | 0 .../inventory/manager/disks/disk_manager.py | 177 --- .../inventory/manager/key_vaults/__init__.py | 0 .../manager/key_vaults/instance_manager.py | 235 ---- .../manager/load_balancers/__init__.py | 0 .../load_balancers/instance_manager.py | 452 ------- .../manager/mysql_servers/__init__.py | 0 .../manager/mysql_servers/server_manager.py | 156 --- .../manager/nat_gateways/__init__.py | 0 .../manager/nat_gateways/instance_manager.py | 200 --- .../network_security_groups/__init__.py | 0 .../instance_manager.py | 317 ----- .../manager/postgresql_servers/__init__.py | 0 .../postgresql_servers/server_manager.py | 229 ---- .../manager/public_ip_addresses/__init__.py | 0 .../public_ip_addresses/ip_address_manager.py | 114 -- .../manager/resources_manager/__init__.py | 1 - .../resources_manager/resource_manager.py | 27 - .../inventory/manager/snapshots/__init__.py | 0 .../manager/snapshots/instance_manager.py | 208 --- .../manager/sql_databases/__init__.py | 0 .../manager/sql_databases/database_manager.py | 272 ---- .../inventory/manager/sql_servers/__init__.py | 0 .../manager/sql_servers/server_manager.py | 677 ---------- .../manager/storage_accounts/__init__.py | 0 .../storage_accounts/instance_manager.py | 343 ----- .../manager/subscriptions/__init__.py | 0 .../subscriptions/subscription_manager.py | 45 - .../manager/virtual_machines/__init__.py | 18 - .../manager/virtual_machines/disk_manager.py | 99 -- .../virtual_machines/instnace_manger.py | 285 ---- .../virtual_machines/load_balancer_manager.py | 115 -- .../network_security_group_manager.py | 220 --- .../manager/virtual_machines/nic_manager.py | 133 -- .../manager/virtual_machines/vm_manager.py | 416 ------ .../manager/virtual_machines/vnet_manager.py | 72 - .../manager/virtual_networks/__init__.py | 0 .../virtual_networks/instance_manager.py | 261 ---- .../manager/vm_scale_sets/__init__.py | 0 .../vm_scale_sets/scale_set_manager.py | 489 ------- .../manager/web_pubsub_service/__init__.py | 0 .../web_pubsub_service/service_manager.py | 221 --- .../Instance/instance_count.yaml | 32 - .../Instance/namespace.yaml | 8 - .../Container/container_count.yaml | 39 - .../Container/gpu_size.yaml | 38 - .../Container/memory_size.yaml | 38 - .../Container/namespace.yaml | 8 - .../Container/vcpu_count.yaml | 38 - .../CosmosDB/Instance/instance_count.yaml | 31 - .../metrics/CosmosDB/Instance/namespace.yaml | 8 - .../CosmosDB/Instance/sql_database_count.yaml | 34 - .../metrics/Disks/Disk/disk_count.yaml | 46 - .../metrics/Disks/Disk/disk_size.yaml | 52 - .../metrics/Disks/Disk/namespace.yaml | 8 - .../Instance/certificates_count.yaml | 31 - .../KeyVaults/Instance/credentials_count.yaml | 31 - .../KeyVaults/Instance/instance_count.yaml | 32 - .../metrics/KeyVaults/Instance/key_count.yaml | 31 - .../metrics/KeyVaults/Instance/namespace.yaml | 8 - .../KeyVaults/Instance/secret_count.yaml | 31 - .../Instance/instance_count.yaml | 29 - .../LoadBalancers/Instance/namespace.yaml | 8 - .../MySQLServers/Server/namespace.yaml | 8 - .../MySQLServers/Server/server_count.yaml | 29 - .../NATGateways/Instance/instance_count.yaml | 39 - .../NATGateways/Instance/namespace.yaml | 8 - .../Instance/instance_count.yaml | 30 - .../Instance/namespace.yaml | 8 - .../PostgreSQLServers/Server/namespace.yaml | 8 - .../Server/server_count.yaml | 29 - .../IpAddress/ip_addresses_count.yaml | 39 - .../IpAddress/namespace.yaml | 8 - .../SQLDatabases/Database/database_count.yaml | 42 - .../SQLDatabases/Database/database_size.yaml | 43 - .../SQLDatabases/Database/namespace.yaml | 8 - .../metrics/SQLServers/Server/namespace.yaml | 8 - .../SQLServers/Server/server_count.yaml | 36 - .../Snapshots/Instance/instance_count.yaml | 47 - .../Snapshots/Instance/instance_size.yaml | 48 - .../metrics/Snapshots/Instance/namespace.yaml | 8 - .../StorageAccounts/Instance/blob_count.yaml | 35 - .../StorageAccounts/Instance/blob_size.yaml | 36 - .../Instance/container_count.yaml | 36 - .../Instance/instance_count.yaml | 35 - .../StorageAccounts/Instance/namespace.yaml | 8 - .../VMScaleSets/ScaleSet/namespace.yaml | 8 - .../VMScaleSets/ScaleSet/sacle_set_count.yaml | 36 - .../Instance/instance_count.yaml | 34 - .../VirtualMachines/Instance/memory_size.yaml | 35 - .../VirtualMachines/Instance/namespace.yaml | 8 - .../VirtualMachines/Instance/vcpu_count.yaml | 30 - .../instance/instance_count.yaml | 32 - .../VirtualNetworks/instance/namespace.yaml | 8 - .../WebPubSubService/Hub/hub_count.yaml | 31 - .../WebPubSubService/Hub/namespace.yaml | 8 - .../WebPubSubService/Service/namespace.yaml | 8 - .../Service/service_count.yaml | 34 - src/spaceone/inventory/model/__init__.py | 4 - .../model/application_gateways/__init__.py | 0 .../application_gateways/cloud_service.py | 197 --- .../cloud_service_type.py | 237 ---- .../model/application_gateways/data.py | 983 -------------- ...application_gateways_count_by_account.yaml | 19 - .../application_gateways_count_by_region.yaml | 20 - ...cation_gateways_count_by_subscription.yaml | 16 - .../application_gateways_total_count.yaml | 16 - .../model/container_instances/__init__.py | 0 .../container_instances/cloud_service.py | 95 -- .../container_instances/cloud_service_type.py | 105 -- .../model/container_instances/data.py | 268 ---- ...ainer_Instances_count_by_subscription.yaml | 16 - .../container_instances_count_by_account.yaml | 19 - .../container_instances_count_by_region.yaml | 20 - ...ainer_instances_total_container_count.yaml | 16 - .../container_instances_total_count.yaml | 16 - .../container_instances_total_gpu_count.yaml | 18 - ...container_instances_total_memory_size.yaml | 20 - .../container_instances_total_vcpu_count.yaml | 18 - .../inventory/model/cosmos_db/__init__.py | 0 .../model/cosmos_db/cloud_service.py | 119 -- .../model/cosmos_db/cloud_service_type.py | 165 --- .../inventory/model/cosmos_db/data.py | 245 ---- .../widget/cosmosdb_count_by_account.yaml | 19 - .../widget/cosmosdb_count_by_region.yaml | 20 - .../cosmosdb_count_by_subscription.yaml | 16 - ...mosdb_databases_count_by_subscription.yaml | 18 - .../widget/cosmosdb_total_count.yaml | 16 - .../inventory/model/disks/__init__.py | 0 .../inventory/model/disks/cloud_service.py | 77 -- .../model/disks/cloud_service_type.py | 147 -- src/spaceone/inventory/model/disks/data.py | 104 -- .../disks/widget/disks_count_by_account.yaml | 19 - .../disks/widget/disks_count_by_region.yaml | 20 - .../widget/disks_count_by_resource_group.yaml | 15 - .../disks/widget/disks_size_by_region.yaml | 26 - .../disks/widget/disks_size_by_status.yaml | 21 - .../widget/disks_size_by_subscription.yaml | 21 - .../disks/widget/disks_size_by_type.yaml | 16 - .../model/disks/widget/disks_total_count.yaml | 16 - .../model/disks/widget/disks_total_size.yaml | 17 - src/spaceone/inventory/model/job_model.py | 18 - .../inventory/model/key_vaults/__init__.py | 0 .../model/key_vaults/cloud_service.py | 182 --- .../model/key_vaults/cloud_service_type.py | 150 --- .../inventory/model/key_vaults/data.py | 257 ---- .../widget/key_vaults_count_by_account.yaml | 19 - .../widget/key_vaults_count_by_region.yaml | 20 - .../key_vaults_count_by_subscription.yaml | 16 - .../widget/key_vaults_total_count.yaml | 16 - .../model/load_balancers/__init__.py | 0 .../model/load_balancers/cloud_service.py | 163 --- .../load_balancers/cloud_service_type.py | 210 --- .../inventory/model/load_balancers/data.py | 653 --------- ...ancers_backendpool_vm_count_by_region.yaml | 18 - .../load_balancers_count_by_account.yaml | 19 - .../load_balancers_count_by_region.yaml | 20 - .../load_balancers_count_by_subscription.yaml | 16 - .../widget/load_balancers_total_count.yaml | 16 - .../inventory/model/mysql_servers/__init__.py | 0 .../model/mysql_servers/cloud_service.py | 93 -- .../model/mysql_servers/cloud_service_type.py | 123 -- .../inventory/model/mysql_servers/data.py | 95 -- .../mysql_servers_count_by_account.yaml | 19 - .../widget/mysql_servers_count_by_region.yaml | 20 - .../mysql_servers_count_by_subscription.yaml | 16 - .../widget/mysql_servers_count_by_tier.yaml | 16 - .../widget/mysql_servers_total_count.yaml | 16 - .../inventory/model/nat_gateways/__init__.py | 0 .../model/nat_gateways/cloud_service.py | 75 -- .../model/nat_gateways/cloud_service_type.py | 91 -- .../inventory/model/nat_gateways/data.py | 1193 ----------------- .../widget/nat_gateways_count_by_account.yaml | 19 - .../widget/nat_gateways_count_by_region.yaml | 20 - .../nat_gateways_count_by_subscription.yaml | 16 - .../widget/nat_gateways_total_count.yaml | 16 - .../model/network_security_groups/__init__.py | 0 .../network_security_groups/cloud_service.py | 80 -- .../cloud_service_type.py | 142 -- .../model/network_security_groups/data.py | 1049 --------------- .../widget/nsg_count_by_account.yaml | 19 - .../widget/nsg_count_by_region.yaml | 20 - .../widget/nsg_count_by_subscription.yaml | 16 - .../nsg_inbound_count_by_subscription.yaml | 18 - .../nsg_outbound_count_by_subscription.yaml | 18 - .../widget/nsg_total_count.yaml | 16 - .../model/postgresql_servers/__init__.py | 0 .../model/postgresql_servers/cloud_service.py | 124 -- .../postgresql_servers/cloud_service_type.py | 226 ---- .../model/postgresql_servers/data.py | 409 ------ .../widget/postgresql_count_by_account.yaml | 19 - .../widget/postgresql_count_by_region.yaml | 20 - .../postgresql_count_by_subscription.yaml | 16 - .../widget/postgresql_count_by_tier.yaml | 16 - .../widget/postgresql_total_count.yaml | 16 - .../model/public_ip_addresses/__init__.py | 0 .../public_ip_addresses/cloud_service.py | 64 - .../public_ip_addresses/cloud_service_type.py | 90 -- .../model/public_ip_addresses/data.py | 122 -- .../public_ip_addresses_count_by_account.yaml | 19 - .../public_ip_addresses_count_by_region.yaml | 20 - ...ic_ip_addresses_count_by_subscription.yaml | 16 - .../public_ip_addresses_total_count.yaml | 11 - .../inventory/model/snapshots/__init__.py | 0 .../model/snapshots/cloud_service.py | 53 - .../model/snapshots/cloud_service_type.py | 79 -- .../inventory/model/snapshots/data.py | 131 -- .../widget/snapshots_count_by_account.yaml | 19 - .../widget/snapshots_count_by_region.yaml | 20 - .../snapshots_count_by_resource_group.yaml | 16 - .../snapshots_count_by_subscription.yaml | 16 - .../widget/snapshots_total_count.yaml | 16 - .../widget/snapshots_total_size.yaml | 18 - .../inventory/model/sql_databases/__init__.py | 0 .../model/sql_databases/cloud_service.py | 142 -- .../model/sql_databases/cloud_service_type.py | 148 -- .../inventory/model/sql_databases/data.py | 196 --- .../sql_databases_count_by_account.yaml | 19 - .../widget/sql_databases_count_by_region.yaml | 20 - .../sql_databases_count_by_subscription.yaml | 16 - .../widget/sql_databases_total_count.yaml | 16 - .../inventory/model/sql_servers/__init__.py | 0 .../model/sql_servers/cloud_service.py | 378 ------ .../model/sql_servers/cloud_service_type.py | 477 ------- .../inventory/model/sql_servers/data.py | 517 ------- .../widget/sql_databases_count_by_server.yaml | 18 - .../sql_databases_count_by_subscription.yaml | 16 - .../widget/sql_databases_count_by_tier.yaml | 18 - .../widget/sql_servers_count_by_account.yaml | 19 - .../widget/sql_servers_count_by_region.yaml | 20 - .../sql_servers_count_by_subscription.yaml | 16 - .../sql_servers_failover_count_by_region.yaml | 18 - .../sql_servers_failover_count_by_server.yaml | 18 - .../widget/sql_servers_total_count.yaml | 16 - .../model/storage_accounts/__init__.py | 0 .../model/storage_accounts/cloud_service.py | 98 -- .../storage_accounts/cloud_service_type.py | 188 --- .../inventory/model/storage_accounts/data.py | 300 ----- ...torage_accounts_blob_count_by_account.yaml | 20 - ...storage_accounts_blob_count_by_region.yaml | 26 - ...accounts_blob_count_by_resource_group.yaml | 16 - ...storage_accounts_blob_size_by_account.yaml | 23 - .../storage_accounts_blob_size_by_region.yaml | 24 - ..._accounts_blob_size_by_resource_group.yaml | 19 - .../storage_accounts_count_by_account.yaml | 19 - .../storage_accounts_count_by_region.yaml | 20 - ...rage_accounts_count_by_resource_group.yaml | 15 - .../storage_accounts_total_blob_count.yaml | 16 - .../storage_accounts_total_blob_size.yaml | 17 - .../widget/storage_accounts_total_count.yaml | 16 - .../model/virtual_machines/__init__.py | 0 .../model/virtual_machines/cloud_service.py | 290 ---- .../virtual_machines/cloud_service_type.py | 269 ---- .../inventory/model/virtual_machines/data.py | 209 --- .../virtual_machine_count_by_account.yaml | 19 - ...irtual_machine_count_by_instance_type.yaml | 20 - .../virtual_machine_count_by_region.yaml | 20 - .../virtual_machine_total_disk_size.yaml | 20 - .../virtual_machine_total_memory_size.yaml | 18 - .../virtual_machine_total_running_count.yaml | 17 - .../virtual_machine_total_vcpu_count.yaml | 16 - .../model/virtual_networks/__init__.py | 0 .../model/virtual_networks/cloud_service.py | 119 -- .../virtual_networks/cloud_service_type.py | 144 -- .../inventory/model/virtual_networks/data.py | 888 ------------ .../virtual_networks_count_by_account.yaml | 19 - .../virtual_networks_count_by_region.yaml | 20 - ...irtual_networks_count_by_subscription.yaml | 15 - ...rtual_networks_subnet_count_by_region.yaml | 18 - ...networks_subnet_count_by_subscription.yaml | 18 - .../widget/virtual_networks_total_count.yaml | 16 - .../inventory/model/vm_scale_sets/__init__.py | 0 .../model/vm_scale_sets/cloud_service.py | 296 ---- .../model/vm_scale_sets/cloud_service_type.py | 106 -- .../inventory/model/vm_scale_sets/data.py | 877 ------------ .../widget/vm_scale_sets_count_by_region.yaml | 20 - .../vm_scale_sets_count_by_subscription.yaml | 15 - .../vm_scale_sets_total_instance_count.yaml | 11 - .../model/web_pubsub_service/__init__.py | 0 .../model/web_pubsub_service/cloud_service.py | 202 --- .../web_pubsub_service/cloud_service_type.py | 151 --- .../model/web_pubsub_service/data.py | 222 --- .../web_pubsub_hub_count_by_account.yaml | 16 - .../web_pubsub_hub_count_by_region.yaml | 20 - ...eb_pubsub_hub_count_by_resource_group.yaml | 15 - ..._pubsub_hub_event_handler_total_count.yaml | 16 - .../widget/web_pubsub_hub_total_count.yaml | 16 - .../web_pubsub_svc_count_by_account.yaml | 16 - .../web_pubsub_svc_count_by_region.yaml | 20 - ...eb_pubsub_svc_count_by_resource_group.yaml | 15 - .../widget/web_pubsub_svc_total_count.yaml | 16 - .../web_pubsub_svc_total_unit_count.yaml | 16 - .../web_pubsub_svc_unit_count_by_tier.yaml | 16 - src/spaceone/inventory/service/__init__.py | 2 - .../inventory/service/collector_service.py | 181 --- src/spaceone/inventory/service/job_service.py | 49 - test/__init__.py | 0 test/api/config.yml | 7 - test/api/scenario.json | 1 - test/api/test_cloud_service_api.py | 73 - test/connector/__init__.py | 0 test/connector/test_disk_connector.py | 47 - .../connector/test_load_balancer_connector.py | 47 - test/connector/test_snapshot_connector.py | 47 - test/manager/__init__.py | 0 .../test_application_gateway_manager.py | 44 - test/manager/test_cosmos_db_manager.py | 49 - test/manager/test_disk_manager.py | 45 - test/manager/test_key_vault_manager.py | 50 - test/manager/test_load_balancer_manager.py | 45 - test/manager/test_mysql_server_manager.py | 45 - test/manager/test_nat_gateway_manager.py | 44 - .../test_network_security_group_manager.py | 44 - .../manager/test_postgresql_server_manager.py | 49 - .../manager/test_public_ip_address_manager.py | 44 - test/manager/test_snapshot_manager.py | 45 - test/manager/test_sql_server_manaer.py | 45 - test/manager/test_storage_account_manager.py | 48 - test/manager/test_virtualnetwork_manager.py | 44 - test/manager/test_vmss_manager.py | 45 - 408 files changed, 128 insertions(+), 28757 deletions(-) delete mode 100644 src/VERSION rename src/{ => plugin}/__init__.py (100%) create mode 100644 src/plugin/main.py delete mode 100644 src/setup.py delete mode 100644 src/spaceone/__init__.py delete mode 100644 src/spaceone/inventory/__init__.py delete mode 100644 src/spaceone/inventory/conf/__init__.py delete mode 100644 src/spaceone/inventory/conf/cloud_service_conf.py delete mode 100644 src/spaceone/inventory/conf/global_conf.py delete mode 100644 src/spaceone/inventory/conf/proto_conf.py delete mode 100644 src/spaceone/inventory/connector/__init__.py delete mode 100644 src/spaceone/inventory/connector/application_gateways/__init__.py delete mode 100644 src/spaceone/inventory/connector/application_gateways/connector.py delete mode 100644 src/spaceone/inventory/connector/container_instances/__init__.py delete mode 100644 src/spaceone/inventory/connector/container_instances/connector.py delete mode 100644 src/spaceone/inventory/connector/cosmos_db/__init__.py delete mode 100644 src/spaceone/inventory/connector/cosmos_db/connector.py delete mode 100644 src/spaceone/inventory/connector/disks/__init__.py delete mode 100644 src/spaceone/inventory/connector/disks/connector.py delete mode 100644 src/spaceone/inventory/connector/key_vaults/__init__.py delete mode 100644 src/spaceone/inventory/connector/key_vaults/connector.py delete mode 100644 src/spaceone/inventory/connector/load_balancers/__init__.py delete mode 100644 src/spaceone/inventory/connector/load_balancers/connector.py delete mode 100644 src/spaceone/inventory/connector/monitor/__init__.py delete mode 100644 src/spaceone/inventory/connector/monitor/connector.py delete mode 100644 src/spaceone/inventory/connector/mysql_servers/__init__.py delete mode 100644 src/spaceone/inventory/connector/mysql_servers/connector.py delete mode 100644 src/spaceone/inventory/connector/nat_gateways/__init__.py delete mode 100644 src/spaceone/inventory/connector/nat_gateways/connector.py delete mode 100644 src/spaceone/inventory/connector/network_security_groups/__init__.py delete mode 100644 src/spaceone/inventory/connector/network_security_groups/connector.py delete mode 100644 src/spaceone/inventory/connector/postgresql_servers/__init__.py delete mode 100644 src/spaceone/inventory/connector/postgresql_servers/connector.py delete mode 100644 src/spaceone/inventory/connector/public_ip_addresses/__init__.py delete mode 100644 src/spaceone/inventory/connector/public_ip_addresses/connector.py delete mode 100644 src/spaceone/inventory/connector/resources/__init__.py delete mode 100644 src/spaceone/inventory/connector/resources/connector.py delete mode 100644 src/spaceone/inventory/connector/snapshots/__init__.py delete mode 100644 src/spaceone/inventory/connector/snapshots/connector.py delete mode 100644 src/spaceone/inventory/connector/sql_databases/__init__.py delete mode 100644 src/spaceone/inventory/connector/sql_databases/connector.py delete mode 100644 src/spaceone/inventory/connector/sql_servers/__init__.py delete mode 100644 src/spaceone/inventory/connector/sql_servers/connector.py delete mode 100644 src/spaceone/inventory/connector/storage_accounts/__init__.py delete mode 100644 src/spaceone/inventory/connector/storage_accounts/connector.py delete mode 100644 src/spaceone/inventory/connector/subscriptions/__init__.py delete mode 100644 src/spaceone/inventory/connector/subscriptions/connector.py delete mode 100644 src/spaceone/inventory/connector/virtual_machines/__init__.py delete mode 100644 src/spaceone/inventory/connector/virtual_machines/connector.py delete mode 100644 src/spaceone/inventory/connector/virtual_networks/__init__.py delete mode 100644 src/spaceone/inventory/connector/virtual_networks/connector.py delete mode 100644 src/spaceone/inventory/connector/vm_scale_sets/__init__.py delete mode 100644 src/spaceone/inventory/connector/vm_scale_sets/connector.py delete mode 100644 src/spaceone/inventory/connector/web_pubsub_service/__init__.py delete mode 100644 src/spaceone/inventory/connector/web_pubsub_service/connector.py delete mode 100644 src/spaceone/inventory/error/__init__.py delete mode 100644 src/spaceone/inventory/error/custom.py delete mode 100644 src/spaceone/inventory/info/__init__.py delete mode 100644 src/spaceone/inventory/info/collector_info.py delete mode 100644 src/spaceone/inventory/info/common_info.py delete mode 100644 src/spaceone/inventory/info/job_info.py delete mode 100644 src/spaceone/inventory/interface/__init__.py delete mode 100644 src/spaceone/inventory/interface/grpc/__init__.py delete mode 100644 src/spaceone/inventory/interface/grpc/collector.py delete mode 100644 src/spaceone/inventory/interface/grpc/job.py delete mode 100644 src/spaceone/inventory/libs/__init__.py delete mode 100644 src/spaceone/inventory/libs/connector.py delete mode 100644 src/spaceone/inventory/libs/manager.py delete mode 100644 src/spaceone/inventory/libs/schema/__init__.py delete mode 100644 src/spaceone/inventory/libs/schema/base.py delete mode 100644 src/spaceone/inventory/libs/schema/cloud_service.py delete mode 100644 src/spaceone/inventory/libs/schema/cloud_service_type.py delete mode 100644 src/spaceone/inventory/libs/schema/metadata/__init__.py delete mode 100644 src/spaceone/inventory/libs/schema/metadata/dynamic_field.py delete mode 100644 src/spaceone/inventory/libs/schema/metadata/dynamic_layout.py delete mode 100644 src/spaceone/inventory/libs/schema/metadata/dynamic_search.py delete mode 100644 src/spaceone/inventory/libs/schema/metadata/dynamic_widget.py delete mode 100644 src/spaceone/inventory/libs/schema/region.py delete mode 100644 src/spaceone/inventory/libs/schema/resource.py delete mode 100644 src/spaceone/inventory/libs/schema/stackdriver.py delete mode 100644 src/spaceone/inventory/libs/utils.py delete mode 100644 src/spaceone/inventory/manager/__init__.py delete mode 100644 src/spaceone/inventory/manager/application_gateways/__init__.py delete mode 100644 src/spaceone/inventory/manager/application_gateways/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/container_instances/__init__.py delete mode 100644 src/spaceone/inventory/manager/container_instances/container_manager.py delete mode 100644 src/spaceone/inventory/manager/cosmos_db/__init__.py delete mode 100644 src/spaceone/inventory/manager/cosmos_db/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/disks/__init__.py delete mode 100644 src/spaceone/inventory/manager/disks/disk_manager.py delete mode 100644 src/spaceone/inventory/manager/key_vaults/__init__.py delete mode 100644 src/spaceone/inventory/manager/key_vaults/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/load_balancers/__init__.py delete mode 100644 src/spaceone/inventory/manager/load_balancers/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/mysql_servers/__init__.py delete mode 100644 src/spaceone/inventory/manager/mysql_servers/server_manager.py delete mode 100644 src/spaceone/inventory/manager/nat_gateways/__init__.py delete mode 100644 src/spaceone/inventory/manager/nat_gateways/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/network_security_groups/__init__.py delete mode 100644 src/spaceone/inventory/manager/network_security_groups/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/postgresql_servers/__init__.py delete mode 100644 src/spaceone/inventory/manager/postgresql_servers/server_manager.py delete mode 100644 src/spaceone/inventory/manager/public_ip_addresses/__init__.py delete mode 100644 src/spaceone/inventory/manager/public_ip_addresses/ip_address_manager.py delete mode 100644 src/spaceone/inventory/manager/resources_manager/__init__.py delete mode 100644 src/spaceone/inventory/manager/resources_manager/resource_manager.py delete mode 100644 src/spaceone/inventory/manager/snapshots/__init__.py delete mode 100644 src/spaceone/inventory/manager/snapshots/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/sql_databases/__init__.py delete mode 100644 src/spaceone/inventory/manager/sql_databases/database_manager.py delete mode 100644 src/spaceone/inventory/manager/sql_servers/__init__.py delete mode 100644 src/spaceone/inventory/manager/sql_servers/server_manager.py delete mode 100644 src/spaceone/inventory/manager/storage_accounts/__init__.py delete mode 100644 src/spaceone/inventory/manager/storage_accounts/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/subscriptions/__init__.py delete mode 100644 src/spaceone/inventory/manager/subscriptions/subscription_manager.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/__init__.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/disk_manager.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/instnace_manger.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/load_balancer_manager.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/network_security_group_manager.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/nic_manager.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/vm_manager.py delete mode 100644 src/spaceone/inventory/manager/virtual_machines/vnet_manager.py delete mode 100644 src/spaceone/inventory/manager/virtual_networks/__init__.py delete mode 100644 src/spaceone/inventory/manager/virtual_networks/instance_manager.py delete mode 100644 src/spaceone/inventory/manager/vm_scale_sets/__init__.py delete mode 100644 src/spaceone/inventory/manager/vm_scale_sets/scale_set_manager.py delete mode 100644 src/spaceone/inventory/manager/web_pubsub_service/__init__.py delete mode 100644 src/spaceone/inventory/manager/web_pubsub_service/service_manager.py delete mode 100644 src/spaceone/inventory/metrics/ApplicationGateways/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/ApplicationGateways/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/ContainerInstances/Container/container_count.yaml delete mode 100644 src/spaceone/inventory/metrics/ContainerInstances/Container/gpu_size.yaml delete mode 100644 src/spaceone/inventory/metrics/ContainerInstances/Container/memory_size.yaml delete mode 100644 src/spaceone/inventory/metrics/ContainerInstances/Container/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/ContainerInstances/Container/vcpu_count.yaml delete mode 100644 src/spaceone/inventory/metrics/CosmosDB/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/CosmosDB/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/CosmosDB/Instance/sql_database_count.yaml delete mode 100644 src/spaceone/inventory/metrics/Disks/Disk/disk_count.yaml delete mode 100644 src/spaceone/inventory/metrics/Disks/Disk/disk_size.yaml delete mode 100644 src/spaceone/inventory/metrics/Disks/Disk/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/KeyVaults/Instance/certificates_count.yaml delete mode 100644 src/spaceone/inventory/metrics/KeyVaults/Instance/credentials_count.yaml delete mode 100644 src/spaceone/inventory/metrics/KeyVaults/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/KeyVaults/Instance/key_count.yaml delete mode 100644 src/spaceone/inventory/metrics/KeyVaults/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/KeyVaults/Instance/secret_count.yaml delete mode 100644 src/spaceone/inventory/metrics/LoadBalancers/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/LoadBalancers/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/MySQLServers/Server/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/MySQLServers/Server/server_count.yaml delete mode 100644 src/spaceone/inventory/metrics/NATGateways/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/NATGateways/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/PostgreSQLServers/Server/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/PostgreSQLServers/Server/server_count.yaml delete mode 100644 src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml delete mode 100644 src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/SQLDatabases/Database/database_count.yaml delete mode 100644 src/spaceone/inventory/metrics/SQLDatabases/Database/database_size.yaml delete mode 100644 src/spaceone/inventory/metrics/SQLDatabases/Database/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/SQLServers/Server/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/SQLServers/Server/server_count.yaml delete mode 100644 src/spaceone/inventory/metrics/Snapshots/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/Snapshots/Instance/instance_size.yaml delete mode 100644 src/spaceone/inventory/metrics/Snapshots/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_count.yaml delete mode 100644 src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_size.yaml delete mode 100644 src/spaceone/inventory/metrics/StorageAccounts/Instance/container_count.yaml delete mode 100644 src/spaceone/inventory/metrics/StorageAccounts/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/StorageAccounts/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml delete mode 100644 src/spaceone/inventory/metrics/VirtualMachines/Instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/VirtualMachines/Instance/memory_size.yaml delete mode 100644 src/spaceone/inventory/metrics/VirtualMachines/Instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/VirtualMachines/Instance/vcpu_count.yaml delete mode 100644 src/spaceone/inventory/metrics/VirtualNetworks/instance/instance_count.yaml delete mode 100644 src/spaceone/inventory/metrics/VirtualNetworks/instance/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/WebPubSubService/Hub/hub_count.yaml delete mode 100644 src/spaceone/inventory/metrics/WebPubSubService/Hub/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/WebPubSubService/Service/namespace.yaml delete mode 100644 src/spaceone/inventory/metrics/WebPubSubService/Service/service_count.yaml delete mode 100644 src/spaceone/inventory/model/__init__.py delete mode 100644 src/spaceone/inventory/model/application_gateways/__init__.py delete mode 100644 src/spaceone/inventory/model/application_gateways/cloud_service.py delete mode 100644 src/spaceone/inventory/model/application_gateways/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/application_gateways/data.py delete mode 100644 src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/application_gateways/widget/application_gateways_total_count.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/__init__.py delete mode 100644 src/spaceone/inventory/model/container_instances/cloud_service.py delete mode 100644 src/spaceone/inventory/model/container_instances/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/container_instances/data.py delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_Instances_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_instances_total_container_count.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_instances_total_count.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_instances_total_gpu_count.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_instances_total_memory_size.yaml delete mode 100644 src/spaceone/inventory/model/container_instances/widget/container_instances_total_vcpu_count.yaml delete mode 100644 src/spaceone/inventory/model/cosmos_db/__init__.py delete mode 100644 src/spaceone/inventory/model/cosmos_db/cloud_service.py delete mode 100644 src/spaceone/inventory/model/cosmos_db/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/cosmos_db/data.py delete mode 100644 src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_databases_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_total_count.yaml delete mode 100644 src/spaceone/inventory/model/disks/__init__.py delete mode 100644 src/spaceone/inventory/model/disks/cloud_service.py delete mode 100644 src/spaceone/inventory/model/disks/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/disks/data.py delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_count_by_resource_group.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_size_by_region.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_size_by_status.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_size_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_size_by_type.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_total_count.yaml delete mode 100644 src/spaceone/inventory/model/disks/widget/disks_total_size.yaml delete mode 100644 src/spaceone/inventory/model/job_model.py delete mode 100644 src/spaceone/inventory/model/key_vaults/__init__.py delete mode 100644 src/spaceone/inventory/model/key_vaults/cloud_service.py delete mode 100644 src/spaceone/inventory/model/key_vaults/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/key_vaults/data.py delete mode 100644 src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/key_vaults/widget/key_vaults_total_count.yaml delete mode 100644 src/spaceone/inventory/model/load_balancers/__init__.py delete mode 100644 src/spaceone/inventory/model/load_balancers/cloud_service.py delete mode 100644 src/spaceone/inventory/model/load_balancers/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/load_balancers/data.py delete mode 100644 src/spaceone/inventory/model/load_balancers/widget/load_balancers_backendpool_vm_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/load_balancers/widget/load_balancers_total_count.yaml delete mode 100644 src/spaceone/inventory/model/mysql_servers/__init__.py delete mode 100644 src/spaceone/inventory/model/mysql_servers/cloud_service.py delete mode 100644 src/spaceone/inventory/model/mysql_servers/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/mysql_servers/data.py delete mode 100644 src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_tier.yaml delete mode 100644 src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_total_count.yaml delete mode 100644 src/spaceone/inventory/model/nat_gateways/__init__.py delete mode 100644 src/spaceone/inventory/model/nat_gateways/cloud_service.py delete mode 100644 src/spaceone/inventory/model/nat_gateways/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/nat_gateways/data.py delete mode 100644 src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_total_count.yaml delete mode 100644 src/spaceone/inventory/model/network_security_groups/__init__.py delete mode 100644 src/spaceone/inventory/model/network_security_groups/cloud_service.py delete mode 100644 src/spaceone/inventory/model/network_security_groups/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/network_security_groups/data.py delete mode 100644 src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/network_security_groups/widget/nsg_inbound_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/network_security_groups/widget/nsg_outbound_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/network_security_groups/widget/nsg_total_count.yaml delete mode 100644 src/spaceone/inventory/model/postgresql_servers/__init__.py delete mode 100644 src/spaceone/inventory/model/postgresql_servers/cloud_service.py delete mode 100644 src/spaceone/inventory/model/postgresql_servers/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/postgresql_servers/data.py delete mode 100644 src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_tier.yaml delete mode 100644 src/spaceone/inventory/model/postgresql_servers/widget/postgresql_total_count.yaml delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/__init__.py delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/cloud_service.py delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/data.py delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_total_count.yaml delete mode 100644 src/spaceone/inventory/model/snapshots/__init__.py delete mode 100644 src/spaceone/inventory/model/snapshots/cloud_service.py delete mode 100644 src/spaceone/inventory/model/snapshots/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/snapshots/data.py delete mode 100644 src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_resource_group.yaml delete mode 100644 src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/snapshots/widget/snapshots_total_count.yaml delete mode 100644 src/spaceone/inventory/model/snapshots/widget/snapshots_total_size.yaml delete mode 100644 src/spaceone/inventory/model/sql_databases/__init__.py delete mode 100644 src/spaceone/inventory/model/sql_databases/cloud_service.py delete mode 100644 src/spaceone/inventory/model/sql_databases/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/sql_databases/data.py delete mode 100644 src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/sql_databases/widget/sql_databases_total_count.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/__init__.py delete mode 100644 src/spaceone/inventory/model/sql_servers/cloud_service.py delete mode 100644 src/spaceone/inventory/model/sql_servers/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/sql_servers/data.py delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_server.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_tier.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_server.yaml delete mode 100644 src/spaceone/inventory/model/sql_servers/widget/sql_servers_total_count.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/__init__.py delete mode 100644 src/spaceone/inventory/model/storage_accounts/cloud_service.py delete mode 100644 src/spaceone/inventory/model/storage_accounts/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/storage_accounts/data.py delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_resource_group.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_account.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_region.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_resource_group.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_resource_group.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_count.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_size.yaml delete mode 100644 src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_count.yaml delete mode 100644 src/spaceone/inventory/model/virtual_machines/__init__.py delete mode 100644 src/spaceone/inventory/model/virtual_machines/cloud_service.py delete mode 100644 src/spaceone/inventory/model/virtual_machines/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/virtual_machines/data.py delete mode 100644 src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_instance_type.yaml delete mode 100644 src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_disk_size.yaml delete mode 100644 src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_memory_size.yaml delete mode 100644 src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_running_count.yaml delete mode 100644 src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_vcpu_count.yaml delete mode 100644 src/spaceone/inventory/model/virtual_networks/__init__.py delete mode 100644 src/spaceone/inventory/model/virtual_networks/cloud_service.py delete mode 100644 src/spaceone/inventory/model/virtual_networks/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/virtual_networks/data.py delete mode 100644 src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_total_count.yaml delete mode 100644 src/spaceone/inventory/model/vm_scale_sets/__init__.py delete mode 100644 src/spaceone/inventory/model/vm_scale_sets/cloud_service.py delete mode 100644 src/spaceone/inventory/model/vm_scale_sets/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/vm_scale_sets/data.py delete mode 100644 src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_subscription.yaml delete mode 100644 src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_total_instance_count.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/__init__.py delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/cloud_service.py delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/cloud_service_type.py delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/data.py delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_resource_group.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_event_handler_total_count.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_total_count.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_account.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_region.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_resource_group.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_count.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_unit_count.yaml delete mode 100644 src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_unit_count_by_tier.yaml delete mode 100644 src/spaceone/inventory/service/__init__.py delete mode 100644 src/spaceone/inventory/service/collector_service.py delete mode 100644 src/spaceone/inventory/service/job_service.py delete mode 100644 test/__init__.py delete mode 100644 test/api/config.yml delete mode 100644 test/api/scenario.json delete mode 100644 test/api/test_cloud_service_api.py delete mode 100644 test/connector/__init__.py delete mode 100644 test/connector/test_disk_connector.py delete mode 100644 test/connector/test_load_balancer_connector.py delete mode 100644 test/connector/test_snapshot_connector.py delete mode 100644 test/manager/__init__.py delete mode 100644 test/manager/test_application_gateway_manager.py delete mode 100644 test/manager/test_cosmos_db_manager.py delete mode 100644 test/manager/test_disk_manager.py delete mode 100644 test/manager/test_key_vault_manager.py delete mode 100644 test/manager/test_load_balancer_manager.py delete mode 100644 test/manager/test_mysql_server_manager.py delete mode 100644 test/manager/test_nat_gateway_manager.py delete mode 100644 test/manager/test_network_security_group_manager.py delete mode 100644 test/manager/test_postgresql_server_manager.py delete mode 100644 test/manager/test_public_ip_address_manager.py delete mode 100644 test/manager/test_snapshot_manager.py delete mode 100644 test/manager/test_sql_server_manaer.py delete mode 100644 test/manager/test_storage_account_manager.py delete mode 100644 test/manager/test_virtualnetwork_manager.py delete mode 100644 test/manager/test_vmss_manager.py diff --git a/src/VERSION b/src/VERSION deleted file mode 100644 index bd8bf882..00000000 --- a/src/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.7.0 diff --git a/src/__init__.py b/src/plugin/__init__.py similarity index 100% rename from src/__init__.py rename to src/plugin/__init__.py diff --git a/src/plugin/main.py b/src/plugin/main.py new file mode 100644 index 00000000..5c2baf11 --- /dev/null +++ b/src/plugin/main.py @@ -0,0 +1,128 @@ +from spaceone.inventory.plugin.collector.lib.server import CollectorPluginServer + +app = CollectorPluginServer() + + +@app.route('Collector.init') +def collector_init(params: dict) -> dict: + """ init plugin by options + + Args: + params (CollectorInitRequest): { + 'options': 'dict', # Required + 'domain_id': 'str' + } + + Returns: + PluginResponse: { + 'metadata': 'dict' + } + """ + pass + + +@app.route('Collector.verify') +def collector_verify(params: dict) -> None: + """ Verifying collector plugin + + Args: + params (CollectorVerifyRequest): { + 'options': 'dict', # Required + 'secret_data': 'dict', # Required + 'schema': 'str', + 'domain_id': 'str' + } + + Returns: + None + """ + pass + + +@app.route('Collector.collect') +def collector_collect(params: dict) -> dict: + """ Collect external data + + Args: + params (CollectorCollectRequest): { + 'options': 'dict', # Required + 'secret_data': 'dict', # Required + 'schema': 'str', + 'task_options': 'dict', + 'domain_id': 'str' + } + + Returns: + Generator[ResourceResponse, None, None] + { + 'state': 'SUCCESS | FAILURE', + 'resource_type': 'inventory.CloudService | inventory.CloudServiceType | inventory.Region', + 'cloud_service_type': CloudServiceType, + 'cloud_service': CloudService, + 'region': Region, + 'match_keys': 'list', + 'error_message': 'str' + 'metadata': 'dict' + } + + CloudServiceType + { + 'name': 'str', # Required + 'group': 'str', # Required + 'provider': 'str', # Required + 'is_primary': 'bool', + 'is_major': 'bool', + 'metadata': 'dict', # Required + 'service_code': 'str', + 'tags': 'dict' + 'labels': 'list' + } + + CloudService + { + 'name': 'str', + 'cloud_service_type': 'str', # Required + 'cloud_service_group': 'str', # Required + 'provider': 'str', # Required + 'ip_addresses' : 'list', + 'account' : 'str', + 'instance_type': 'str', + 'instance_size': 'float', + 'region_code': 'str', + 'data': 'dict' # Required + 'metadata': 'dict' # Required + 'reference': 'dict' + 'tags' : 'dict' + } + + Region + { + 'name': 'str', + 'region_code': 'str', # Required + 'provider': 'str', # Required + 'tags': 'dict' + } + + Only one of the cloud_service_type, cloud_service and region fields is required. + """ + pass + + +@app.route('Job.get_tasks') +def job_get_tasks(params: dict) -> dict: + """ Get job tasks + + Args: + params (JobGetTaskRequest): { + 'options': 'dict', # Required + 'secret_data': 'dict', # Required + 'domain_id': 'str' + } + + Returns: + TasksResponse: { + 'tasks': 'list' + } + + """ + pass diff --git a/src/setup.py b/src/setup.py deleted file mode 100644 index 96eff2e2..00000000 --- a/src/setup.py +++ /dev/null @@ -1,60 +0,0 @@ -# -# Copyright 2020 The SpaceONE Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -from setuptools import setup, find_packages - -with open("VERSION", "r") as f: - VERSION = f.read().strip() - f.close() - -setup( - name="plugin-azure-cloud-services", - version=VERSION, - description="MS Azure cloud service inventory collector", - long_description="", - url="https://cloudforet.io/", - author="Cloudforet Admin", - author_email="admin@cloudforet.io", - license="Apache License 2.0", - packages=find_packages(), - install_requires=[ - "spaceone-api", - "schematics", - "adal", - "msrestazure", - "azure-identity", - "azure-mgmt-resource", - "azure-mgmt-compute", - "azure-mgmt-network", - "azure-mgmt-sql", - "azure-mgmt-monitor", - "azure-mgmt-storage", - "azure-mgmt-keyvault", - "azure-keyvault-certificates", - "azure-keyvault-secrets", - "azure-mgmt-rdbms", - "azure-mgmt-cosmosdb", - "azure-mgmt-containerinstance", - "azure-mgmt-webpubsub", - ], - package_data={ - "spaceone": [ - "inventory/model/*/widget/*.yaml", - "inventory/metrics/**/**/*.yaml", - ] - }, - zip_safe=False, -) diff --git a/src/spaceone/__init__.py b/src/spaceone/__init__.py deleted file mode 100644 index 0260537a..00000000 --- a/src/spaceone/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) \ No newline at end of file diff --git a/src/spaceone/inventory/__init__.py b/src/spaceone/inventory/__init__.py deleted file mode 100644 index 03e14242..00000000 --- a/src/spaceone/inventory/__init__.py +++ /dev/null @@ -1 +0,0 @@ -name = 'inventory' diff --git a/src/spaceone/inventory/conf/__init__.py b/src/spaceone/inventory/conf/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/conf/cloud_service_conf.py b/src/spaceone/inventory/conf/cloud_service_conf.py deleted file mode 100644 index 213486c0..00000000 --- a/src/spaceone/inventory/conf/cloud_service_conf.py +++ /dev/null @@ -1,33 +0,0 @@ -MAX_WORKER = 20 -SUPPORTED_FEATURES = ["garbage_collection"] -SUPPORTED_SCHEDULES = ["hours"] -SUPPORTED_RESOURCE_TYPE = [ - "inventory.CloudService", - "inventory.CloudServiceType", - "inventory.Region", -] -FILTER_FORMAT = [] - -ASSET_URL = "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure" - -CLOUD_SERVICE_GROUP_MAP = { - "VirtualMachines": "VirtualMachinesManager", - "ApplicationGateways": "ApplicationGatewaysManager", - "ContainerInstances": "ContainerInstancesManager", - "CosmosDB": "CosmosDBManager", - "Disks": "DisksManager", - "KeyVaults": "KeyVaultsManager", - "LoadBalancers": "LoadBalancersManager", - "MySQLServers": "MySQLServersManager", - "SQLServers": "SQLServersManager", - "SQLDatabases": "SQLDatabasesManager", - "NATGateways": "NATGatewaysManager", - "NetworkSecurityGroups": "NetworkSecurityGroupsManager", - "PostgreSQLServers": "PostgreSQLServersManager", - "PublicIPAddresses": "PublicIPAddressesManager", - "Snapshots": "SnapshotsManager", - "StorageAccounts": "StorageAccountsManager", - "VirtualNetworks": "VirtualNetworksManager", - "VMScaleSets": "VmScaleSetsManager", - "WebPubSubService": "WebPubSubServiceManager", -} diff --git a/src/spaceone/inventory/conf/global_conf.py b/src/spaceone/inventory/conf/global_conf.py deleted file mode 100644 index 9f5fe214..00000000 --- a/src/spaceone/inventory/conf/global_conf.py +++ /dev/null @@ -1,23 +0,0 @@ -CONNECTORS = { - 'AzureConnector': { - 'backend': 'spaceone.inventory.libs.connector.AzureConnector', - }, -} - -LOG = { - 'filters': { - 'masking': { - 'rules': { - 'Collector.collect': [ - 'secret_data' - ] - } - } - } -} - -HANDLERS = { -} - -ENDPOINTS = { -} diff --git a/src/spaceone/inventory/conf/proto_conf.py b/src/spaceone/inventory/conf/proto_conf.py deleted file mode 100644 index 8b47c389..00000000 --- a/src/spaceone/inventory/conf/proto_conf.py +++ /dev/null @@ -1,3 +0,0 @@ -PROTO = { - 'spaceone.inventory.api.plugin.collector': ['Collector'] -} diff --git a/src/spaceone/inventory/connector/__init__.py b/src/spaceone/inventory/connector/__init__.py deleted file mode 100644 index f115e398..00000000 --- a/src/spaceone/inventory/connector/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -from spaceone.inventory.connector.disks import DisksConnector -from spaceone.inventory.connector.subscriptions import SubscriptionsConnector -from spaceone.inventory.connector.snapshots import SnapshotsConnector -from spaceone.inventory.connector.vm_scale_sets import VmScaleSetsConnector -from spaceone.inventory.connector.load_balancers import LoadBalancersConnector -from spaceone.inventory.connector.monitor import MonitorConnector -from spaceone.inventory.connector.virtual_networks import VirtualNetworksConnector -from spaceone.inventory.connector.application_gateways import ( - ApplicationGatewaysConnector, -) -from spaceone.inventory.connector.public_ip_addresses import PublicIPAddressesConnector -from spaceone.inventory.connector.network_security_groups import ( - NetworkSecurityGroupsConnector, -) -from spaceone.inventory.connector.nat_gateways import NATGatewaysConnector -from spaceone.inventory.connector.storage_accounts import StorageAccountsConnector -from spaceone.inventory.connector.key_vaults import KeyVaultsConnector -from spaceone.inventory.connector.mysql_servers import MySQLServersConnector -from spaceone.inventory.connector.cosmos_db import CosmosDBConnector -from spaceone.inventory.connector.postgresql_servers import PostgreSQLServersConnector -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector -from spaceone.inventory.connector.sql_servers import SQLServersConnector -from spaceone.inventory.connector.sql_databases import SQLDatabasesConnector -from spaceone.inventory.connector.container_instances import ContainerInstancesConnector -from spaceone.inventory.connector.web_pubsub_service import WebPubSubServiceConnector -from spaceone.inventory.connector.resources import ResourcesConnector diff --git a/src/spaceone/inventory/connector/application_gateways/__init__.py b/src/spaceone/inventory/connector/application_gateways/__init__.py deleted file mode 100644 index ab761c67..00000000 --- a/src/spaceone/inventory/connector/application_gateways/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.application_gateways.connector import ApplicationGatewaysConnector diff --git a/src/spaceone/inventory/connector/application_gateways/connector.py b/src/spaceone/inventory/connector/application_gateways/connector.py deleted file mode 100644 index 78d88a59..00000000 --- a/src/spaceone/inventory/connector/application_gateways/connector.py +++ /dev/null @@ -1,19 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * -__all__ = ['ApplicationGatewaysConnector'] -_LOGGER = logging.getLogger(__name__) - - -class ApplicationGatewaysConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_all_application_gateways(self): - return self.network_client.application_gateways.list_all() - - def get_public_ip_addresses(self, public_ip_address_name, resource_group_name): - return self.network_client.public_ip_addresses.get(public_ip_address_name, resource_group_name) diff --git a/src/spaceone/inventory/connector/container_instances/__init__.py b/src/spaceone/inventory/connector/container_instances/__init__.py deleted file mode 100644 index 365e445f..00000000 --- a/src/spaceone/inventory/connector/container_instances/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.container_instances.connector import ContainerInstancesConnector \ No newline at end of file diff --git a/src/spaceone/inventory/connector/container_instances/connector.py b/src/spaceone/inventory/connector/container_instances/connector.py deleted file mode 100644 index eec76bd0..00000000 --- a/src/spaceone/inventory/connector/container_instances/connector.py +++ /dev/null @@ -1,20 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * -__all__ = ['ContainerInstancesConnector'] -_LOGGER = logging.getLogger(__name__) - - -class ContainerInstancesConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_container_groups(self): - return self.container_instance_client.container_groups.list() - - def get_container_groups(self, resource_group_name, container_group_name): - return self.container_instance_client.container_groups.get(resource_group_name=resource_group_name, - container_group_name=container_group_name) diff --git a/src/spaceone/inventory/connector/cosmos_db/__init__.py b/src/spaceone/inventory/connector/cosmos_db/__init__.py deleted file mode 100644 index 5c953b3c..00000000 --- a/src/spaceone/inventory/connector/cosmos_db/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.cosmos_db.connector import CosmosDBConnector diff --git a/src/spaceone/inventory/connector/cosmos_db/connector.py b/src/spaceone/inventory/connector/cosmos_db/connector.py deleted file mode 100644 index 81580ea0..00000000 --- a/src/spaceone/inventory/connector/cosmos_db/connector.py +++ /dev/null @@ -1,23 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * -__all__ = ['CosmosDBConnector'] -_LOGGER = logging.getLogger(__name__) - - -class CosmosDBConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_all_cosmos_db_accounts(self): - return self.cosmosdb_client.database_accounts.list() - - def list_keys(self, account_name, resource_group_name): - return self.cosmosdb_client.database_accounts.list_keys(account_name= account_name, resource_group_name=resource_group_name) - - def list_sql_resources(self, account_name, resource_group_name): - return self.cosmosdb_client.sql_resources.list_sql_databases(account_name=account_name, resource_group_name=resource_group_name) - diff --git a/src/spaceone/inventory/connector/disks/__init__.py b/src/spaceone/inventory/connector/disks/__init__.py deleted file mode 100644 index ffe994ec..00000000 --- a/src/spaceone/inventory/connector/disks/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.disks.connector import DisksConnector diff --git a/src/spaceone/inventory/connector/disks/connector.py b/src/spaceone/inventory/connector/disks/connector.py deleted file mode 100644 index 7e8ab93b..00000000 --- a/src/spaceone/inventory/connector/disks/connector.py +++ /dev/null @@ -1,17 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * -from spaceone.inventory.error.custom import * -__all__ = ['DisksConnector'] -_LOGGER = logging.getLogger(__name__) - - -class DisksConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_disks(self): - return self.compute_client.disks.list() diff --git a/src/spaceone/inventory/connector/key_vaults/__init__.py b/src/spaceone/inventory/connector/key_vaults/__init__.py deleted file mode 100644 index 85ef27b4..00000000 --- a/src/spaceone/inventory/connector/key_vaults/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.key_vaults.connector import KeyVaultsConnector diff --git a/src/spaceone/inventory/connector/key_vaults/connector.py b/src/spaceone/inventory/connector/key_vaults/connector.py deleted file mode 100644 index 47ed5ed2..00000000 --- a/src/spaceone/inventory/connector/key_vaults/connector.py +++ /dev/null @@ -1,50 +0,0 @@ -import logging - -import azure.core.exceptions - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * -from azure.keyvault.secrets import SecretClient -from azure.keyvault.certificates import CertificateClient -from azure.identity import DefaultAzureCredential - -__all__ = ["KeyVaultsConnector"] -_LOGGER = logging.getLogger(__name__) - - -class KeyVaultsConnector(AzureConnector): - def __init__(self, **kwargs): - super().__init__(**kwargs) - - self.set_connect(kwargs.get("secret_data")) - # self.key_vault_secret_client = None - # self.key_vault_certificate_client = None - - def init_key_vault_secret_client(self, subscription_id, vault_uri): - credential = DefaultAzureCredential() - key_vault_secret_client = SecretClient( - credential=credential, subscription_id=subscription_id, vault_url=vault_uri - ) - return key_vault_secret_client - - def init_key_vault_certificate_client(self, subscription_id, vault_uri): - credential = DefaultAzureCredential() - key_vault_certificate_client = CertificateClient( - credential=credential, subscription_id=subscription_id, vault_url=vault_uri - ) - return key_vault_certificate_client - - def list_all_key_vaults(self): - return self.key_vault_client.vaults.list_by_subscription() - - def get_key_vaults(self): - return self.key_vault_client.vaults.get() - - def list_keys(self, resource_group_name, vault_name): - return self.key_vault_client.keys.list( - resource_group_name=resource_group_name, vault_name=vault_name - ) - - def list_secrets(self): - # return self.key_vault_secrets_client.list_properties_of_secrets() - return self.key_vault_client.secrets.list() diff --git a/src/spaceone/inventory/connector/load_balancers/__init__.py b/src/spaceone/inventory/connector/load_balancers/__init__.py deleted file mode 100644 index d0cba497..00000000 --- a/src/spaceone/inventory/connector/load_balancers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.load_balancers.connector import LoadBalancersConnector diff --git a/src/spaceone/inventory/connector/load_balancers/connector.py b/src/spaceone/inventory/connector/load_balancers/connector.py deleted file mode 100644 index 68ebdcb4..00000000 --- a/src/spaceone/inventory/connector/load_balancers/connector.py +++ /dev/null @@ -1,28 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * -__all__ = ['LoadBalancersConnector'] -_LOGGER = logging.getLogger(__name__) - - -class LoadBalancersConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_load_balancers(self): - return self.network_client.load_balancers.list_all() - - def get_subnets(self, resource_group_name, vnet_name, subnet_name): - return self.network_client.subnets.get(resource_group_name, vnet_name, subnet_name) - - def list_load_balancer_backend_address_pools(self, resource_group_name, lb_name): - return self.network_client.load_balancer_backend_address_pools.list(resource_group_name, lb_name) - - def list_load_balancer_network_interfaces(self, resource_group_name, lb_name): - return self.network_client.load_balancer_network_interfaces.list(resource_group_name, lb_name) - - def list_network_interface_ip_configurations(self, resource_group_name, network_interface_name): - return self.network_client.network_interface_ip_configurations.list(resource_group_name, network_interface_name) diff --git a/src/spaceone/inventory/connector/monitor/__init__.py b/src/spaceone/inventory/connector/monitor/__init__.py deleted file mode 100644 index bb96c8c2..00000000 --- a/src/spaceone/inventory/connector/monitor/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.monitor.connector import MonitorConnector diff --git a/src/spaceone/inventory/connector/monitor/connector.py b/src/spaceone/inventory/connector/monitor/connector.py deleted file mode 100644 index f862a10f..00000000 --- a/src/spaceone/inventory/connector/monitor/connector.py +++ /dev/null @@ -1,23 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * - -__all__ = ['MonitorConnector'] -_LOGGER = logging.getLogger(__name__) - - -class MonitorConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_diagnostic_settings(self, resource_uri): - return self.monitor_client.diagnostic_settings.list(resource_uri=resource_uri) - - def list_metrics(self, resource_uri, metricnames, aggregation, timespan=None, interval=None): - return self.monitor_client.metrics.list(resource_uri, metricnames=metricnames, aggregation=aggregation, - timespan=timespan, interval=interval) - - diff --git a/src/spaceone/inventory/connector/mysql_servers/__init__.py b/src/spaceone/inventory/connector/mysql_servers/__init__.py deleted file mode 100644 index 57c79cc4..00000000 --- a/src/spaceone/inventory/connector/mysql_servers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.mysql_servers.connector import MySQLServersConnector \ No newline at end of file diff --git a/src/spaceone/inventory/connector/mysql_servers/connector.py b/src/spaceone/inventory/connector/mysql_servers/connector.py deleted file mode 100644 index 786fef46..00000000 --- a/src/spaceone/inventory/connector/mysql_servers/connector.py +++ /dev/null @@ -1,24 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * - -__all__ = ['MySQLServersConnector'] -_LOGGER = logging.getLogger(__name__) - - -class MySQLServersConnector(AzureConnector): - - def __init__(self, secret_data=None, **kwargs): - super().__init__(**kwargs) - - self.set_connect(secret_data) - - def list_servers(self): - return self.mysql_client.servers.list() - - def list_firewall_rules_by_server(self, resource_group_name, server_name): - return self.mysql_client.firewall_rules.list_by_server(resource_group_name=resource_group_name, server_name=server_name) - - def list_server_parameters(self, resource_group_name, server_name): - return self.mysql_client.server_parameters._list_update_configurations_initial(resource_group_name=resource_group_name, server_name=server_name, value=[]) diff --git a/src/spaceone/inventory/connector/nat_gateways/__init__.py b/src/spaceone/inventory/connector/nat_gateways/__init__.py deleted file mode 100644 index 7916f095..00000000 --- a/src/spaceone/inventory/connector/nat_gateways/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.nat_gateways.connector import NATGatewaysConnector diff --git a/src/spaceone/inventory/connector/nat_gateways/connector.py b/src/spaceone/inventory/connector/nat_gateways/connector.py deleted file mode 100644 index 1d3844b9..00000000 --- a/src/spaceone/inventory/connector/nat_gateways/connector.py +++ /dev/null @@ -1,26 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * - -__all__ = ['NATGatewaysConnector'] -_LOGGER = logging.getLogger(__name__) - - -class NATGatewaysConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_all_nat_gateways(self): - return self.network_client.nat_gateways.list_all() - - def get_public_ip_addresses(self, resource_group_name, public_ip_address_name): - return self.network_client.public_ip_addresses.get(resource_group_name, public_ip_address_name) - - def get_public_ip_prefixes(self, resource_group_name, public_ip_prefixes_name): - return self.network_client.public_ip_prefixes.get(resource_group_name, public_ip_prefixes_name) - - def get_subnet(self, resource_group_name, subnet_name, vnet_name): - return self.network_client.subnets.get(resource_group_name=resource_group_name, virtual_network_name=vnet_name, subnet_name=subnet_name) \ No newline at end of file diff --git a/src/spaceone/inventory/connector/network_security_groups/__init__.py b/src/spaceone/inventory/connector/network_security_groups/__init__.py deleted file mode 100644 index d58bcd6f..00000000 --- a/src/spaceone/inventory/connector/network_security_groups/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.network_security_groups.connector import NetworkSecurityGroupsConnector diff --git a/src/spaceone/inventory/connector/network_security_groups/connector.py b/src/spaceone/inventory/connector/network_security_groups/connector.py deleted file mode 100644 index 2a6c76a8..00000000 --- a/src/spaceone/inventory/connector/network_security_groups/connector.py +++ /dev/null @@ -1,26 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * - -__all__ = ['NetworkSecurityGroupsConnector'] -_LOGGER = logging.getLogger(__name__) - - -class NetworkSecurityGroupsConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_all_network_security_groups(self): - return self.network_client.network_security_groups.list_all() - - def list_all_network_interfaces(self): - return self.network_client.network_interfaces.list_all() - - def get_network_interfaces(self, network_interface_name, resource_group): - return self.network_client.network_interfaces.get(network_interface_name=network_interface_name, resource_group_name=resource_group) - - def get_subnet(self, resource_group_name, subnet_name, virtual_network_name): - return self.network_client.subnets.get(resource_group_name=resource_group_name, subnet_name=subnet_name, virtual_network_name=virtual_network_name) diff --git a/src/spaceone/inventory/connector/postgresql_servers/__init__.py b/src/spaceone/inventory/connector/postgresql_servers/__init__.py deleted file mode 100644 index 8352c38a..00000000 --- a/src/spaceone/inventory/connector/postgresql_servers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.postgresql_servers.connector import PostgreSQLServersConnector diff --git a/src/spaceone/inventory/connector/postgresql_servers/connector.py b/src/spaceone/inventory/connector/postgresql_servers/connector.py deleted file mode 100644 index 1f876bbe..00000000 --- a/src/spaceone/inventory/connector/postgresql_servers/connector.py +++ /dev/null @@ -1,36 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * - -__all__ = ["PostgreSQLServersConnector"] -_LOGGER = logging.getLogger(__name__) - - -class PostgreSQLServersConnector(AzureConnector): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get("secret_data")) - - def list_servers(self): - return self.postgre_sql_client.servers.list() - - def list_firewall_rules_by_server(self, resource_group_name, server_name): - return self.postgre_sql_client.firewall_rules.list_by_server( - resource_group_name=resource_group_name, server_name=server_name - ) - - def list_virtual_network_rules_by_server(self, resource_group_name, server_name): - return self.postgre_sql_client.virtual_network_rules.list_by_server( - resource_group_name=resource_group_name, server_name=server_name - ) - - def list_replicas_by_server(self, resource_group_name, server_name): - return self.postgre_sql_client.replicas.list_by_server( - resource_group_name=resource_group_name, server_name=server_name - ) - - def list_server_administrators(self, resource_group_name, server_name): - return self.postgre_sql_client.server_administrators.list( - resource_group_name=resource_group_name, server_name=server_name - ) diff --git a/src/spaceone/inventory/connector/public_ip_addresses/__init__.py b/src/spaceone/inventory/connector/public_ip_addresses/__init__.py deleted file mode 100644 index 9506c9de..00000000 --- a/src/spaceone/inventory/connector/public_ip_addresses/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.public_ip_addresses.connector import PublicIPAddressesConnector diff --git a/src/spaceone/inventory/connector/public_ip_addresses/connector.py b/src/spaceone/inventory/connector/public_ip_addresses/connector.py deleted file mode 100644 index 113c9c23..00000000 --- a/src/spaceone/inventory/connector/public_ip_addresses/connector.py +++ /dev/null @@ -1,19 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * -from spaceone.inventory.error.custom import * - -__all__ = ['PublicIPAddressesConnector'] -_LOGGER = logging.getLogger(__name__) - - -class PublicIPAddressesConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_all_public_ip_addresses(self): - return self.network_client.public_ip_addresses.list_all() - diff --git a/src/spaceone/inventory/connector/resources/__init__.py b/src/spaceone/inventory/connector/resources/__init__.py deleted file mode 100644 index a9bfc517..00000000 --- a/src/spaceone/inventory/connector/resources/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.resources.connector import ResourcesConnector diff --git a/src/spaceone/inventory/connector/resources/connector.py b/src/spaceone/inventory/connector/resources/connector.py deleted file mode 100644 index 042cccc7..00000000 --- a/src/spaceone/inventory/connector/resources/connector.py +++ /dev/null @@ -1,16 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * - -__all__ = ["ResourcesConnector"] -_LOGGER = logging.getLogger(__name__) - - -class ResourcesConnector(AzureConnector): - def __init__(self, **kwargs): - super().__init__() - self.set_connect(kwargs.get("secret_data")) - - def list_resources(self) -> list: - return self.resource_client.resources.list() diff --git a/src/spaceone/inventory/connector/snapshots/__init__.py b/src/spaceone/inventory/connector/snapshots/__init__.py deleted file mode 100644 index fb929336..00000000 --- a/src/spaceone/inventory/connector/snapshots/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.snapshots.connector import SnapshotsConnector diff --git a/src/spaceone/inventory/connector/snapshots/connector.py b/src/spaceone/inventory/connector/snapshots/connector.py deleted file mode 100644 index 2ae34560..00000000 --- a/src/spaceone/inventory/connector/snapshots/connector.py +++ /dev/null @@ -1,17 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * -from spaceone.inventory.error.custom import * -__all__ = ['SnapshotsConnector'] -_LOGGER = logging.getLogger(__name__) - - -class SnapshotsConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_snapshots(self): - return self.compute_client.snapshots.list() diff --git a/src/spaceone/inventory/connector/sql_databases/__init__.py b/src/spaceone/inventory/connector/sql_databases/__init__.py deleted file mode 100644 index 7a3fa935..00000000 --- a/src/spaceone/inventory/connector/sql_databases/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.sql_databases.connector import SQLDatabasesConnector diff --git a/src/spaceone/inventory/connector/sql_databases/connector.py b/src/spaceone/inventory/connector/sql_databases/connector.py deleted file mode 100644 index 4420833a..00000000 --- a/src/spaceone/inventory/connector/sql_databases/connector.py +++ /dev/null @@ -1,41 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector - -__all__ = ['SQLDatabasesConnector'] -_LOGGER = logging.getLogger(__name__) - - -class SQLDatabasesConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_servers(self): - return self.sql_client.servers.list() - - def list_databases_in_server(self, resource_group_name, server_name): - return self.sql_client.databases.list_by_server(resource_group_name=resource_group_name, server_name=server_name) - - def list_sync_groups_by_databases(self, resource_group, server_name, database_name): - return self.sql_client.sync_groups.list_by_database(resource_group_name=resource_group, - database_name=database_name, - server_name=server_name) - - def list_sync_agents_by_server(self, resource_group, server_name): - return self.sql_client.sync_agents.list_by_server(resource_group_name=resource_group, server_name=server_name) - - def list_replication_link_by_server(self, resource_group_name, server_name): - return self.sql_client.replication_links.list_by_server(resource_group_name=resource_group_name, - server_name=server_name) - - def list_replication_link(self, resource_group_name, server_name, database_name): - return self.sql_client.replication_links.list_by_database(resource_group_name=resource_group_name, - server_name=server_name, database_name=database_name) - - def get_database_auditing_settings(self, resource_group_name, server_name, database_name): - return self.sql_client.database_blob_auditing_policies.get(resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name) - diff --git a/src/spaceone/inventory/connector/sql_servers/__init__.py b/src/spaceone/inventory/connector/sql_servers/__init__.py deleted file mode 100644 index 80e74dda..00000000 --- a/src/spaceone/inventory/connector/sql_servers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.sql_servers.connector import SQLServersConnector diff --git a/src/spaceone/inventory/connector/sql_servers/connector.py b/src/spaceone/inventory/connector/sql_servers/connector.py deleted file mode 100644 index 72532e39..00000000 --- a/src/spaceone/inventory/connector/sql_servers/connector.py +++ /dev/null @@ -1,61 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * -__all__ = ['SQLServersConnector'] -_LOGGER = logging.getLogger(__name__) - - -class SQLServersConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_servers(self): - return self.sql_client.servers.list() - - def list_server_azure_ad_administrators(self, resource_group, server_name): - return self.sql_client.server_azure_ad_administrators.list_by_server(resource_group, server_name) - - def get_server_automatic_tuning(self, resource_group, server_name): - return self.sql_client.server_automatic_tuning.get(resource_group, server_name) - - def get_server_auditing_settings(self, resource_group, server_name): - return self.sql_client.server_blob_auditing_policies.get(resource_group, server_name) - - def list_failover_groups(self, resource_group, server_name): - return self.sql_client.failover_groups.list_by_server(resource_group, server_name) - - def list_encryption_protectors(self, resource_group, server_name): - return self.sql_client.encryption_protectors.list_by_server(resource_group_name=resource_group, server_name=server_name) - - def list_databases_by_server(self, resource_group_name, server_name): - return self.sql_client.databases.list_by_server(resource_group_name=resource_group_name, server_name=server_name) - - def list_elastic_pools_by_server(self, resource_group, server_name): - return self.sql_client.elastic_pools.list_by_server(resource_group, server_name) - - def list_databases_by_elastic_pool(self, elastic_pool_name, resource_group, server_name): - return self.sql_client.databases.list_by_elastic_pool(elastic_pool_name=elastic_pool_name, resource_group_name=resource_group, server_name=server_name) - - def list_restorable_dropped_databases_by_server(self, resource_group, server_name): - return self.sql_client.restorable_dropped_databases.list_by_server(resource_group_name=resource_group, server_name=server_name) - - def list_firewall_rules_by_server(self, resource_group, server_name): - return self.sql_client.firewall_rules.list_by_server(resource_group_name=resource_group, server_name=server_name) - - def list_virtual_network_rules_by_server(self, resource_group, server_name): - return self.sql_client.virtual_network_rules.list_by_server(resource_group_name=resource_group, server_name=server_name) - - def list_sync_groups_by_databases(self, resource_group, server_name, database_name): - return self.sql_client.sync_groups.list_by_database(resource_group_name=resource_group, database_name=database_name, server_name=server_name) - - def list_sync_agents_by_server(self, resource_group, server_name): - return self.sql_client.sync_agents.list_by_server(resource_group_name=resource_group, server_name=server_name) - - def list_data_masking_rules_by_database(self, resource_group, server_name, database_name): - return self.sql_client.data_masking_rules.list_by_database(resource_group_name=resource_group, server_name=server_name, database_name=database_name) - - def list_replication_link(self, resource_group, server_name, database_name): - return self.sql_client.replication_links.list_by_database(resource_group_name=resource_group, server_name=server_name, database_name=database_name) diff --git a/src/spaceone/inventory/connector/storage_accounts/__init__.py b/src/spaceone/inventory/connector/storage_accounts/__init__.py deleted file mode 100644 index 0aeda247..00000000 --- a/src/spaceone/inventory/connector/storage_accounts/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.storage_accounts.connector import StorageAccountsConnector diff --git a/src/spaceone/inventory/connector/storage_accounts/connector.py b/src/spaceone/inventory/connector/storage_accounts/connector.py deleted file mode 100644 index c6660791..00000000 --- a/src/spaceone/inventory/connector/storage_accounts/connector.py +++ /dev/null @@ -1,20 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector - -__all__ = ["StorageAccountsConnector"] -_LOGGER = logging.getLogger(__name__) - - -class StorageAccountsConnector(AzureConnector): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get("secret_data")) - - def list_storage_accounts(self): - return self.storage_client.storage_accounts.list() - - def list_blob_containers(self, rg_name, account_name): - return self.storage_client.blob_containers.list( - resource_group_name=rg_name, account_name=account_name - ) diff --git a/src/spaceone/inventory/connector/subscriptions/__init__.py b/src/spaceone/inventory/connector/subscriptions/__init__.py deleted file mode 100644 index 0e17f88a..00000000 --- a/src/spaceone/inventory/connector/subscriptions/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.subscriptions.connector import SubscriptionsConnector diff --git a/src/spaceone/inventory/connector/subscriptions/connector.py b/src/spaceone/inventory/connector/subscriptions/connector.py deleted file mode 100644 index dd4ef91b..00000000 --- a/src/spaceone/inventory/connector/subscriptions/connector.py +++ /dev/null @@ -1,20 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error import * - -__all__ = ['SubscriptionsConnector'] -_LOGGER = logging.getLogger(__name__) - - -class SubscriptionsConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__() - self.set_connect(kwargs.get('secret_data')) - - def get_subscription_info(self, subscription_id): - return self.subscription_client.subscriptions.get(subscription_id) - - def list_location_info(self, subscription_id): - return self.subscription_client.subscriptions.list_locations(subscription_id) diff --git a/src/spaceone/inventory/connector/virtual_machines/__init__.py b/src/spaceone/inventory/connector/virtual_machines/__init__.py deleted file mode 100644 index 1d16d2db..00000000 --- a/src/spaceone/inventory/connector/virtual_machines/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.virtual_machines.connector import VirtualMachinesConnector diff --git a/src/spaceone/inventory/connector/virtual_machines/connector.py b/src/spaceone/inventory/connector/virtual_machines/connector.py deleted file mode 100644 index 3200de2c..00000000 --- a/src/spaceone/inventory/connector/virtual_machines/connector.py +++ /dev/null @@ -1,83 +0,0 @@ -import logging -from spaceone.inventory.libs.connector import AzureConnector - -__all__ = ['VirtualMachinesConnector'] -_LOGGER = logging.getLogger(__name__) -DEFAULT_REGION = '' - - -class VirtualMachinesConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_resource_groups(self): - return self.resource_client.resource_groups.list() - - def list_tenants(self): - return self.subscription_client.tenants.list() - - def list_vms_in_rg(self, resource_group_name, **query): - return list(self.compute_client.virtual_machines.list(resource_group_name=resource_group_name, **query)) - - def list_all_vms(self, **query): - return list(self.compute_client.virtual_machines.list_all(**query)) - - def get_vm(self, resource_group_name, vm_name): - return self.compute_client.virtual_machines.get(resource_group_name, vm_name, expand='instanceView') - - # todo : deprecated - def list_virtual_machine_sizes(self, location): - return self.compute_client.virtual_machine_sizes.list(location=location) - - def list_resources_in_rg(self, resource_group_name): - return self.resource_client.resources.list_by_resource_group(resource_group_name=resource_group_name) - - def list_network_interfaces(self): - return self.network_client.network_interfaces.list_all() - - def list_network_interfaces_in_rg(self, resource_group_name): - return self.network_client.network_interfaces.list(resource_group_name) - - def list_disks(self): - return self.compute_client.disks.list() - - def list_virtual_networks(self): - return self.network_client.virtual_networks.list_all() - - def list_virtual_networks_in_rg(self, resource_group_name): - return self.network_client.virtual_networks.list(resource_group_name) - - def list_public_ip_addresses(self): - return self.network_client.public_ip_addresses.list_all() - - def list_public_ip_addresses_in_rg(self, resource_group_name): - return self.network_client.public_ip_addresses.list(resource_group_name) - - def list_load_balancers(self): - return self.network_client.load_balancers.list_all() - - def list_load_balancers_in_rg(self, resource_group_name): - return self.network_client.load_balancers.list(resource_group_name) - - def list_load_balancer_network_interfaces_in_rg(self, resource_group_name, lb_name): - return self.network_client.load_balancer_network_interfaces.list(resource_group_name, lb_name) - - def list_network_security_groups(self): - return self.network_client.network_security_groups.list_all() - - def list_network_security_groups_in_rg(self, resource_group_name): - return self.network_client.network_security_groups.list(resource_group_name) - - def get_subscription_info(self, subscription_id): - return self.subscription_client.subscriptions.get(subscription_id) - - def list_scale_set_vms(self, resource_group_name, scale_set_name): - return self.compute_client.virtual_machine_scale_set_vms.list(resource_group_name, scale_set_name) - - def list_virtual_machine_scale_sets_in_rg(self, resource_group_name): - return self.compute_client.virtual_machine_scale_sets.list(resource_group_name) - - def list_skus(self): - return self.compute_client.resource_skus.list() diff --git a/src/spaceone/inventory/connector/virtual_networks/__init__.py b/src/spaceone/inventory/connector/virtual_networks/__init__.py deleted file mode 100644 index ae6d5ec0..00000000 --- a/src/spaceone/inventory/connector/virtual_networks/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.virtual_networks.connector import VirtualNetworksConnector diff --git a/src/spaceone/inventory/connector/virtual_networks/connector.py b/src/spaceone/inventory/connector/virtual_networks/connector.py deleted file mode 100644 index bbe8be89..00000000 --- a/src/spaceone/inventory/connector/virtual_networks/connector.py +++ /dev/null @@ -1,20 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * - -__all__ = ['VirtualNetworksConnector'] -_LOGGER = logging.getLogger(__name__) - - -class VirtualNetworksConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_all_virtual_networks(self): - return self.network_client.virtual_networks.list_all() - - def list_all_firewalls(self, resource_group_name): - return self.network_client.azure_firewalls.list(resource_group_name) diff --git a/src/spaceone/inventory/connector/vm_scale_sets/__init__.py b/src/spaceone/inventory/connector/vm_scale_sets/__init__.py deleted file mode 100644 index e5b0b6ab..00000000 --- a/src/spaceone/inventory/connector/vm_scale_sets/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.vm_scale_sets.connector import VmScaleSetsConnector diff --git a/src/spaceone/inventory/connector/vm_scale_sets/connector.py b/src/spaceone/inventory/connector/vm_scale_sets/connector.py deleted file mode 100644 index 313f9233..00000000 --- a/src/spaceone/inventory/connector/vm_scale_sets/connector.py +++ /dev/null @@ -1,44 +0,0 @@ -import logging - -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.error.custom import * - -__all__ = ["VmScaleSetsConnector"] -_LOGGER = logging.getLogger(__name__) - - -class VmScaleSetsConnector(AzureConnector): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get("secret_data")) - - def list_vm_scale_sets(self): - return self.compute_client.virtual_machine_scale_sets.list_all() - - def list_vm_scale_set_vms(self, resource_group, vm_scale_set_name): - return self.compute_client.virtual_machine_scale_set_vms.list( - resource_group, vm_scale_set_name - ) - - def get_vm_scale_set_instance_view( - self, resource_group, vm_scale_set_name, instance_id - ): - return self.compute_client.virtual_machine_scale_set_vms.get_instance_view( - resource_group_name=resource_group, - vm_scale_set_name=vm_scale_set_name, - instance_id="0", - ) - - def list_vm_scale_set_instance_view( - self, resource_group, vm_scale_set_name, instance_id - ): - return self.compute_client.virtual_machine_scale_set_vms.list( - resource_group_name=resource_group, - vm_scale_set_name=vm_scale_set_name, - instance_id=instance_id, - ) - - def list_auto_scale_settings(self, resource_group): - return self.monitor_client.autoscale_settings.list_by_resource_group( - resource_group_name=resource_group - ) diff --git a/src/spaceone/inventory/connector/web_pubsub_service/__init__.py b/src/spaceone/inventory/connector/web_pubsub_service/__init__.py deleted file mode 100644 index e7f37c08..00000000 --- a/src/spaceone/inventory/connector/web_pubsub_service/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from spaceone.inventory.connector.web_pubsub_service.connector import WebPubSubServiceConnector \ No newline at end of file diff --git a/src/spaceone/inventory/connector/web_pubsub_service/connector.py b/src/spaceone/inventory/connector/web_pubsub_service/connector.py deleted file mode 100644 index 9e3ee6bd..00000000 --- a/src/spaceone/inventory/connector/web_pubsub_service/connector.py +++ /dev/null @@ -1,23 +0,0 @@ -import logging -from spaceone.inventory.libs.connector import AzureConnector - -__all__ = ['WebPubSubServiceConnector'] -_LOGGER = logging.getLogger(__name__) - - -class WebPubSubServiceConnector(AzureConnector): - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.set_connect(kwargs.get('secret_data')) - - def list_by_subscription(self): - return self.web_pubsub_service_client.web_pub_sub.list_by_subscription() - - def list_hubs(self, resource_group_name, resource_name): - return self.web_pubsub_service_client.web_pub_sub_hubs.list(resource_group_name=resource_group_name, - resource_name=resource_name) - - def list_keys(self, resource_group_name, resource_name): - return self.web_pubsub_service_client.web_pub_sub.list_keys(resource_group_name=resource_group_name, - resource_name=resource_name) diff --git a/src/spaceone/inventory/error/__init__.py b/src/spaceone/inventory/error/__init__.py deleted file mode 100644 index 47e6a897..00000000 --- a/src/spaceone/inventory/error/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -import inspect, pkgutil - -__all__ = [] - -for loader, module_name, is_pkg in pkgutil.walk_packages(__path__): - module = loader.find_module(module_name).load_module(module_name) - if hasattr(module, '__all__'): - for target in getattr(module, '__all__'): - globals()[target] = getattr(module, target) - __all__.append(target) - else: - for name, object in inspect.getmembers(module): - if inspect.isclass(object) or inspect.isfunction(object): - globals()[name] = object - __all__.append(name) diff --git a/src/spaceone/inventory/error/custom.py b/src/spaceone/inventory/error/custom.py deleted file mode 100644 index c3d9ff0c..00000000 --- a/src/spaceone/inventory/error/custom.py +++ /dev/null @@ -1,56 +0,0 @@ -from spaceone.core.error import ERROR_BASE - - -class ERROR_REPOSITORY_BACKEND(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Repository backend has problem. ({host})' - - -class ERROR_DRIVER(ERROR_BASE): - status_code = 'INTERNAL' - message = '{message}' - - -class ERROR_NOT_INITIALIZED_EXCEPTION(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Collector is not initialized. Please call initialize() method before using it.' - - -class ERROR_CONNECTOR_INITIALIZE(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Connector is failed to initialized. Connector = {field}.' - - -class ERROR_CONNECTOR(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Connector is failed to connect. Connector = {field}.' - - -class ERROR_KEY_VAULTS(ERROR_BASE): - status_code = 'INTERNAL' - message = 'KeyVault manager is failed to get sub resources. {field}.' - - -class ERROR_KEY_VAULTS_PERMISSION(ERROR_BASE): - status_code = 'INTERNAL' - message = 'KeyVault secret and certification information is failed. Please check the permission.' - - -class ERROR_PARSE_ID_FROM_RESOURCE_GROUP(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Parse resource name from resource ID is failed. Please check the variation.' - - -class ERROR_MANAGER_GET_ADDITIONAL_RESOURCE_INFO(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Get an additional information of the resource is failed. Please check the variation. Manager = {field}' - - -class ERROR_GET_RESOURCE_NAME_FROM_ID(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Get resource name from id is failed. field = {e}.' - - -class ERROR_CONNECTOR_GET_ADDITIONAL_RESOURCE_INFO(ERROR_BASE): - status_code = 'INTERNAL' - message = 'Get an additional information of the resource is failed. Please check the variation. Connector = {field}' diff --git a/src/spaceone/inventory/info/__init__.py b/src/spaceone/inventory/info/__init__.py deleted file mode 100644 index 93b875f7..00000000 --- a/src/spaceone/inventory/info/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from spaceone.inventory.info.collector_info import * -from spaceone.inventory.info.job_info import * -from spaceone.inventory.info.common_info import * diff --git a/src/spaceone/inventory/info/collector_info.py b/src/spaceone/inventory/info/collector_info.py deleted file mode 100644 index f073c936..00000000 --- a/src/spaceone/inventory/info/collector_info.py +++ /dev/null @@ -1,24 +0,0 @@ -__all__ = ['PluginInfo', 'ResourceInfo'] - -import functools -from spaceone.api.inventory.plugin import collector_pb2 -from spaceone.core.pygrpc.message_type import * - - -def PluginInfo(result): - result['metadata'] = change_struct_type(result['metadata']) - return collector_pb2.PluginInfo(**result) - - -def ResourceInfo(resource_dict): - if 'resource' in resource_dict: - resource_dict.update({ - 'resource': change_struct_type(resource_dict['resource']) - }) - - if 'match_rules' in resource_dict: - resource_dict.update({ - 'match_rules': change_struct_type(resource_dict['match_rules']) - }) - - return collector_pb2.ResourceInfo(**resource_dict) diff --git a/src/spaceone/inventory/info/common_info.py b/src/spaceone/inventory/info/common_info.py deleted file mode 100644 index ae10b58c..00000000 --- a/src/spaceone/inventory/info/common_info.py +++ /dev/null @@ -1,7 +0,0 @@ -__all__ = ['EmptyInfo'] - -from google.protobuf.empty_pb2 import Empty - -def EmptyInfo(): - return Empty() - diff --git a/src/spaceone/inventory/info/job_info.py b/src/spaceone/inventory/info/job_info.py deleted file mode 100644 index 18f24ab8..00000000 --- a/src/spaceone/inventory/info/job_info.py +++ /dev/null @@ -1,18 +0,0 @@ -__all__ = ["TasksInfo", "TaskInfo"] - -import functools -from spaceone.api.inventory.plugin import job_pb2 -from spaceone.core.pygrpc.message_type import * - - -def TaskInfo(task_data): - info = {"task_options": change_struct_type(task_data["task_options"])} - return job_pb2.TaskInfo(**info) - - -def TasksInfo(result, **kwargs): - tasks_data = result.get("tasks", []) - - return job_pb2.TasksInfo( - tasks=list(map(functools.partial(TaskInfo, **kwargs), tasks_data)), - ) diff --git a/src/spaceone/inventory/interface/__init__.py b/src/spaceone/inventory/interface/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/interface/grpc/__init__.py b/src/spaceone/inventory/interface/grpc/__init__.py deleted file mode 100644 index edf6ec13..00000000 --- a/src/spaceone/inventory/interface/grpc/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -from spaceone.core.pygrpc.server import GRPCServer -from spaceone.inventory.interface.grpc.collector import Collector -from spaceone.inventory.interface.grpc.job import Job - -_all_ = ["app"] - -app = GRPCServer() -app.add_service(Collector) -app.add_service(Job) diff --git a/src/spaceone/inventory/interface/grpc/collector.py b/src/spaceone/inventory/interface/grpc/collector.py deleted file mode 100644 index 05b6ddef..00000000 --- a/src/spaceone/inventory/interface/grpc/collector.py +++ /dev/null @@ -1,41 +0,0 @@ -from spaceone.api.inventory.plugin import collector_pb2_grpc, collector_pb2 -from spaceone.core.pygrpc import BaseAPI -from spaceone.core.pygrpc.message_type import * -from spaceone.inventory.service import CollectorService -import traceback -import logging - -_LOGGER = logging.getLogger(__name__) - - -class Collector(BaseAPI, collector_pb2_grpc.CollectorServicer): - pb2 = collector_pb2 - pb2_grpc = collector_pb2_grpc - - def init(self, request, context): - params, metadata = self.parse_request(request, context) - - with self.locator.get_service("CollectorService", metadata) as collector_svc: - data = collector_svc.init(params) - return self.locator.get_info("PluginInfo", data) - - def verify(self, request, context): - params, metadata = self.parse_request(request, context) - - collector_svc: CollectorService = self.locator.get_service( - "CollectorService", metadata - ) - - with collector_svc: - collector_svc.verify(params) - return self.locator.get_info("EmptyInfo") - - def collect(self, request, context): - params, metadata = self.parse_request(request, context) - collector_svc: CollectorService = self.locator.get_service( - "CollectorService", metadata - ) - - with collector_svc: - for resource in collector_svc.collect(params): - yield self.locator.get_info("ResourceInfo", resource) diff --git a/src/spaceone/inventory/interface/grpc/job.py b/src/spaceone/inventory/interface/grpc/job.py deleted file mode 100644 index df496f25..00000000 --- a/src/spaceone/inventory/interface/grpc/job.py +++ /dev/null @@ -1,19 +0,0 @@ -from spaceone.api.inventory.plugin import job_pb2_grpc, job_pb2 -from spaceone.core.pygrpc import BaseAPI -from spaceone.core.pygrpc.message_type import * -from spaceone.inventory.service import JobService -import traceback -import logging - -_LOGGER = logging.getLogger(__name__) - - -class Job(BaseAPI, job_pb2_grpc.JobServicer): - pb2 = job_pb2 - pb2_grpc = job_pb2_grpc - - def get_tasks(self, request, context): - params, metadata = self.parse_request(request, context) - - with self.locator.get_service("JobService", metadata) as job_svc: - return self.locator.get_info("TasksInfo", job_svc.get_tasks(params)) diff --git a/src/spaceone/inventory/libs/__init__.py b/src/spaceone/inventory/libs/__init__.py deleted file mode 100644 index 8b137891..00000000 --- a/src/spaceone/inventory/libs/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/spaceone/inventory/libs/connector.py b/src/spaceone/inventory/libs/connector.py deleted file mode 100644 index c92ff1e7..00000000 --- a/src/spaceone/inventory/libs/connector.py +++ /dev/null @@ -1,107 +0,0 @@ -import os -import logging - -from azure.identity import DefaultAzureCredential -from azure.mgmt.compute import ComputeManagementClient -from azure.mgmt.resource import ResourceManagementClient -from azure.mgmt.resource import SubscriptionClient -from azure.mgmt.network import NetworkManagementClient -from azure.mgmt.sql import SqlManagementClient -from azure.mgmt.monitor import MonitorManagementClient -from azure.mgmt.storage import StorageManagementClient -from azure.mgmt.keyvault import KeyVaultManagementClient -from azure.mgmt.rdbms.mysql import MySQLManagementClient -from azure.mgmt.cosmosdb import CosmosDBManagementClient -from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient -from azure.mgmt.containerinstance import ContainerInstanceManagementClient -from azure.mgmt.webpubsub import WebPubSubManagementClient -from spaceone.core.connector import BaseConnector - -DEFAULT_SCHEMA = "azure_client_secret" -_LOGGER = logging.getLogger(__name__) - - -class AzureConnector(BaseConnector): - def __init__(self, *args, **kwargs): - """ - kwargs - - schema - - options - - secret_data - - secret_data(dict) - - type: .. - - project_id: ... - - token_uri: ... - - ... - """ - - super().__init__(*args, **kwargs) - self.compute_client = None - self.resource_client = None - self.subscription_client = None - self.network_client = None - self.sql_client = None - self.monitor_client = None - self.storage_client = None - self.blob_client = None - self.key_vault_client = None - self.mysql_client = None - self.cosmosdb_client = None - self.postgre_sql_client = None - self.container_instance_client = None - self.web_pubsub_service_client = None - - def set_connect(self, secret_data): - subscription_id = secret_data["subscription_id"] - - os.environ["AZURE_SUBSCRIPTION_ID"] = subscription_id - os.environ["AZURE_TENANT_ID"] = secret_data["tenant_id"] - os.environ["AZURE_CLIENT_ID"] = secret_data["client_id"] - os.environ["AZURE_CLIENT_SECRET"] = secret_data["client_secret"] - - credential = DefaultAzureCredential() - - self.compute_client = ComputeManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.resource_client = ResourceManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.network_client = NetworkManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.subscription_client: SubscriptionClient = SubscriptionClient( - credential=credential - ) - self.sql_client = SqlManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.monitor_client = MonitorManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.storage_client = StorageManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.key_vault_client = KeyVaultManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.mysql_client = MySQLManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.cosmosdb_client = CosmosDBManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.postgre_sql_client = PostgreSQLManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.container_instance_client = ContainerInstanceManagementClient( - credential=credential, subscription_id=subscription_id - ) - self.web_pubsub_service_client = WebPubSubManagementClient( - credential=credential, subscription_id=subscription_id - ) - - def verify(self, **kwargs): - self.set_connect(kwargs["secret_data"]) - return "ACTIVE" diff --git a/src/spaceone/inventory/libs/manager.py b/src/spaceone/inventory/libs/manager.py deleted file mode 100644 index 75e91033..00000000 --- a/src/spaceone/inventory/libs/manager.py +++ /dev/null @@ -1,233 +0,0 @@ -import logging -import json -import os - -from spaceone.core.manager import BaseManager -from spaceone.inventory.libs.connector import AzureConnector -from spaceone.inventory.libs.schema.region import RegionResource, RegionResponse -from spaceone.inventory.libs.schema.resource import RegionResourceResponse -from spaceone.inventory.libs.schema.resource import ErrorResourceResponse -from spaceone.inventory.error.custom import * -from collections.abc import Iterable - -_LOGGER = logging.getLogger(__name__) - - -class AzureManager(BaseManager): - connector_name = None - cloud_service_types = [] - response_schema = None - collected_region_codes = [] - region_info = {} - - def verify(self, options, secret_data, **kwargs): - """Check collector's status.""" - connector = AzureConnector() - params = {"secret_data": secret_data} - connector.verify(**params) - - def collect_cloud_service_type(self, params): - options = params.get("options", {}) - - for cloud_service_type in self.cloud_service_types: - if "service_code_mappers" in options: - svc_code_maps = options["service_code_mappers"] - if ( - getattr(cloud_service_type.resource, "service_code") - and cloud_service_type.resource.service_code in svc_code_maps - ): - cloud_service_type.resource.service_code = svc_code_maps[ - cloud_service_type.resource.service_code - ] - - if "custom_asset_url" in options: - _tags = cloud_service_type.resource.tags - - if "spaceone:icon" in _tags: - _icon = _tags["spaceone:icon"] - _tags[ - "spaceone:icon" - ] = f'{options["custom_asset_url"]}/{_icon.split("/")[-1]}' - - yield cloud_service_type - - def collect_cloud_service(self, params) -> list: - raise NotImplemented - - def collect_resources(self, params) -> list: - total_resources = [] - - try: - subscription_manager = self.locator.get_manager("SubscriptionsManager") - self.region_info = subscription_manager.list_location_info(params) - - total_resources.extend(self.collect_cloud_service_type(params)) - resources, error_resources = self.collect_cloud_service(params) - - total_resources.extend(resources) - total_resources.extend(error_resources) - - regions = self.collect_region() - total_resources.extend(regions) - - except Exception as e: - error_resource_response = self.generate_error_response( - e, - self.cloud_service_types[0].resource.group, - self.cloud_service_types[0].resource.name, - ) - total_resources.append(error_resource_response) - _LOGGER.error(f"[collect] {e}", exc_info=True) - - return total_resources - - def collect_region(self): - results = [] - try: - for region_code in self.collected_region_codes: - if region := self.match_region_info(region_code): - results.append(RegionResourceResponse({"resource": region})) - - except Exception as e: - _LOGGER.error(f"[collect] {e}", exc_info=True) - - if type(e) is dict: - error_resource_response = ErrorResourceResponse( - { - "message": json.dumps(e), - "resource": {"resource_type": "inventory.Region"}, - } - ) - else: - error_resource_response = ErrorResourceResponse( - { - "message": str(e), - "resource": {"resource_type": "inventory.Region"}, - } - ) - results.append(error_resource_response) - - return results - - def set_region_code(self, region): - if region not in self.region_info: - region = "global" - - if region not in self.collected_region_codes: - self.collected_region_codes.append(region) - - def convert_nested_dictionary(self, cloud_svc_object): - cloud_svc_dict = {} - if hasattr( - cloud_svc_object, "__dict__" - ): # if cloud_svc_object is not a dictionary type but has dict method - cloud_svc_dict = cloud_svc_object.__dict__ - elif isinstance(cloud_svc_object, dict): - cloud_svc_dict = cloud_svc_object - elif not isinstance( - cloud_svc_object, list - ): # if cloud_svc_object is one of type like int, float, char, ... - return cloud_svc_object - - # if cloud_svc_object is dictionary type - for key, value in cloud_svc_dict.items(): - if hasattr(value, "__dict__") or isinstance(value, dict): - cloud_svc_dict[key] = self.convert_nested_dictionary(value) - if "azure" in str(type(value)): - cloud_svc_dict[key] = self.convert_nested_dictionary(value) - elif isinstance(value, list): - value_list = [] - for v in value: - value_list.append(self.convert_nested_dictionary(v)) - cloud_svc_dict[key] = value_list - - return cloud_svc_dict - - def match_region_info(self, region_code): - match_region_info = self.region_info.get(region_code) - - if match_region_info: - region_info = match_region_info.copy() - region_info.update({"region_code": region_code}) - return RegionResource(region_info, strict=False) - - return None - - @staticmethod - def convert_tag_format(tags): - convert_tags = [] - - if tags: - for k, v in tags.items(): - convert_tags.append({"key": k, "value": v}) - - return convert_tags - - @staticmethod - def convert_dictionary(obj): - return vars(obj) - - @staticmethod - def get_resource_group_from_id(dict_id): - resource_group = dict_id.split("/")[4] - return resource_group - - @staticmethod - def generate_error_response(e, cloud_service_group, cloud_service_type): - if type(e) is dict: - error_resource_response = ErrorResourceResponse( - { - "message": json.dumps(e), - "resource": { - "cloud_service_group": cloud_service_group, - "cloud_service_type": cloud_service_type, - }, - } - ) - else: - error_resource_response = ErrorResourceResponse( - { - "message": str(e), - "resource": { - "cloud_service_group": cloud_service_group, - "cloud_service_type": cloud_service_type, - }, - } - ) - return error_resource_response - - @staticmethod - def generate_resource_error_response( - e, cloud_service_group, cloud_service_type, resource_id - ): - if type(e) is dict: - error_resource_response = ErrorResourceResponse( - { - "message": json.dumps(e), - "resource": { - "cloud_service_group": cloud_service_group, - "cloud_service_type": cloud_service_type, - "resource_id": resource_id, - }, - } - ) - else: - error_resource_response = ErrorResourceResponse( - { - "message": str(e), - "resource": { - "cloud_service_group": cloud_service_group, - "cloud_service_type": cloud_service_type, - "resource_id": resource_id, - }, - } - ) - return error_resource_response - - @staticmethod - def update_tenant_id_from_secret_data( - cloud_service_data: dict, secret_data: dict - ) -> dict: - if tenant_id := secret_data.get("tenant_id"): - cloud_service_data.update({"tenant_id": tenant_id}) - return cloud_service_data diff --git a/src/spaceone/inventory/libs/schema/__init__.py b/src/spaceone/inventory/libs/schema/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/libs/schema/base.py b/src/spaceone/inventory/libs/schema/base.py deleted file mode 100644 index 085bb5dc..00000000 --- a/src/spaceone/inventory/libs/schema/base.py +++ /dev/null @@ -1,40 +0,0 @@ -from schematics import Model -from schematics.types import ListType, StringType, PolyModelType, DictType, ModelType -from spaceone.inventory.libs.schema.metadata.dynamic_layout import BaseLayoutField -from spaceone.inventory.libs.schema.metadata.dynamic_search import BaseDynamicSearch -from spaceone.inventory.libs.schema.metadata.dynamic_widget import BaseDynamicWidget - - -class MetaDataViewSubData(Model): - layouts = ListType(PolyModelType(BaseLayoutField)) - - -class MetaDataViewTable(Model): - layout = PolyModelType(BaseLayoutField) - - -class MetaDataView(Model): - table = PolyModelType(MetaDataViewTable, serialize_when_none=False) - sub_data = PolyModelType(MetaDataViewSubData, serialize_when_none=False) - search = ListType(PolyModelType(BaseDynamicSearch), serialize_when_none=False) - widget = ListType(PolyModelType(BaseDynamicWidget), serialize_when_none=False) - - -class BaseMetaData(Model): - view = ModelType(MetaDataView) - - -class BaseResponse(Model): - state = StringType(default='SUCCESS', choices=('SUCCESS', 'FAILURE', 'TIMEOUT')) - resource_type = StringType(required=True) - match_rules = DictType(ListType(StringType), default={}) - resource = PolyModelType(Model, default={}) - - -class ReferenceModel(Model): - class Option: - serialize_when_none = False - - resource_id = StringType(required=False, serialize_when_none=False) - external_link = StringType(required=False, serialize_when_none=False) - diff --git a/src/spaceone/inventory/libs/schema/cloud_service.py b/src/spaceone/inventory/libs/schema/cloud_service.py deleted file mode 100644 index 4d9a898e..00000000 --- a/src/spaceone/inventory/libs/schema/cloud_service.py +++ /dev/null @@ -1,45 +0,0 @@ -from schematics import Model -from schematics.types import ListType, StringType, PolyModelType, DictType, ModelType, IntType, DateTimeType, FloatType -from .base import BaseMetaData, BaseResponse, MetaDataView, MetaDataViewSubData, ReferenceModel - - -class CloudServiceMeta(BaseMetaData): - @classmethod - def set(cls): - sub_data = MetaDataViewSubData() - return cls({'view': MetaDataView({'sub_data': sub_data})}) - - @classmethod - def set_layouts(cls, layouts=[]): - sub_data = MetaDataViewSubData({'layouts': layouts}) - return cls({'view': MetaDataView({'sub_data': sub_data})}) - - -class Tags(Model): - key = StringType() - value = StringType() - - -class CloudServiceResource(Model): - provider = StringType(default="azure") - cloud_service_type = StringType() - cloud_service_group = StringType() - name = StringType(default='') - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - account = StringType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - tags = DictType(StringType, serialize_when_none=False) - data = PolyModelType(Model, default=lambda: {}) - reference = ModelType(ReferenceModel) - region_code = StringType() - _metadata = PolyModelType(CloudServiceMeta, serialize_when_none=False, serialized_name='metadata') - - -class CloudServiceResponse(BaseResponse): - state = StringType(default='SUCCESS') - match_rules = DictType(ListType(StringType), default={ - '1': ['reference.resource_id', 'provider', 'cloud_service_type', 'cloud_service_group', 'account'] - }) - resource_type = StringType(default='inventory.CloudService') - resource = PolyModelType(CloudServiceResource) diff --git a/src/spaceone/inventory/libs/schema/cloud_service_type.py b/src/spaceone/inventory/libs/schema/cloud_service_type.py deleted file mode 100644 index d2f63066..00000000 --- a/src/spaceone/inventory/libs/schema/cloud_service_type.py +++ /dev/null @@ -1,36 +0,0 @@ -from schematics import Model -from schematics.types import ListType, StringType, PolyModelType, DictType, BooleanType -from spaceone.inventory.libs.schema.metadata.dynamic_layout import QuerySearchTableDynamicLayout -from .base import BaseMetaData, BaseResponse, MetaDataViewTable, MetaDataView - - -class CloudServiceTypeMeta(BaseMetaData): - @classmethod - def set_fields(cls, name='', fields=[]): - _table = MetaDataViewTable({'layout': QuerySearchTableDynamicLayout.set_fields(name, fields)}) - return cls({'view': MetaDataView({'table': _table})}) - - @classmethod - def set_meta(cls, name='', fields=[], search=[], widget=[]): - table_meta = MetaDataViewTable({'layout': QuerySearchTableDynamicLayout.set_fields(name, fields)}) - return cls({'view': MetaDataView({'table': table_meta, 'search': search, 'widget': widget})}) - - -class CloudServiceTypeResource(Model): - name = StringType() - provider = StringType(default='azure') - group = StringType() - _metadata = PolyModelType(CloudServiceTypeMeta, serialize_when_none=False, serialized_name='metadata') - labels = ListType(StringType(), serialize_when_none=False) - tags = DictType(StringType, serialize_when_none=False) - is_primary = BooleanType(default=False) - is_major = BooleanType(default=False) - resource_type = StringType(default='inventory.CloudService') - service_code = StringType(serialize_when_none=False) - - -class CloudServiceTypeResponse(BaseResponse): - resource_type = StringType(default='inventory.CloudServiceType') - match_rules = DictType(ListType(StringType), default={'1': ['name', 'group', 'provider']}) - resource = PolyModelType(CloudServiceTypeResource) - diff --git a/src/spaceone/inventory/libs/schema/metadata/__init__.py b/src/spaceone/inventory/libs/schema/metadata/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/libs/schema/metadata/dynamic_field.py b/src/spaceone/inventory/libs/schema/metadata/dynamic_field.py deleted file mode 100644 index 04caa8bf..00000000 --- a/src/spaceone/inventory/libs/schema/metadata/dynamic_field.py +++ /dev/null @@ -1,563 +0,0 @@ -import math -from schematics import Model -from schematics.types import ( - ModelType, - StringType, - PolyModelType, - DictType, - BooleanType, - BaseType, -) -from spaceone.inventory.libs.schema.metadata.dynamic_search import BaseDynamicSearch - -BACKGROUND_COLORS = [ - "black", - "white", - "gray", - "gray.100", - "gray.200", - "gray.300", - "gray.400", - "gray.500", - "gray.600", - "gray.700", - "gray.800", - "gray.900", - "red", - "red.100", - "red.200", - "red.300", - "red.400", - "red.500", - "red.600", - "red.700", - "red.800", - "red.900", - "coral", - "coral.100", - "coral.200", - "coral.300", - "coral.400", - "coral.500", - "coral.600", - "coral.700", - "coral.800", - "coral.900", - "yellow", - "yellow.100", - "yellow.200", - "yellow.300", - "yellow.400", - "yellow.500", - "yellow.600", - "yellow.700", - "yellow.800", - "yellow.900", - "green", - "green.100", - "green.200", - "green.300", - "green.400", - "green.500", - "green.600", - "green.700", - "green.800", - "green.900", - "blue", - "blue.100", - "blue.200", - "blue.300", - "blue.400", - "blue.500", - "blue.600", - "blue.700", - "blue.800", - "blue.900", - "violet", - "violet.100", - "violet.200", - "violet.300", - "violet.400", - "violet.500", - "violet.600", - "violet.700", - "violet.800", - "violet.900", - "peacock", - "peacock.100", - "peacock.200", - "peacock.300", - "peacock.400", - "peacock.500", - "peacock.600", - "peacock.700", - "peacock.800", - "peacock.900", - "indigo", - "indigo.100", - "indigo.200", - "indigo.300", - "indigo.400", - "indigo.500", - "indigo.600", - "indigo.700", - "indigo.800", - "indigo.900", -] - -TYPE_BADGE = ["primary", "indigo.500", "coral.600", "peacock.500", "green.500"] - - -class FieldReference(Model): - resource_type = StringType() - reference_key = StringType(serialize_when_none=False) - - -class Icon(Model): - image = StringType(serialize_when_none=False) - color = StringType(default="green", choices=BACKGROUND_COLORS) - - -class BaseField(Model): - type = StringType( - choices=[ - "text", - "state", - "badge", - "list", - "dict", - "datetime", - "image", - "enum", - "progress", - "size", - ], - serialize_when_none=False, - ) - options = PolyModelType( - [Model, DictType(PolyModelType(Model))], serialize_when_none=False - ) - - -class FieldViewOption(Model): - link = StringType(serialize_when_none=False) - variables = StringType(serialize_when_none=False) - sortable = BooleanType(serialize_when_none=False) - sort_key = StringType(serialize_when_none=False) - translation_id = StringType(serialize_when_none=False) - default = StringType(serialize_when_none=False) - is_optional = BooleanType(serialize_when_none=False) - postfix = StringType(serialize_when_none=False) - prefix = StringType(serialize_when_none=False) - field_description = StringType(serialize_when_none=False) - - -class BaseDynamicField(BaseField): - name = StringType(serialize_when_none=False) - key = StringType(serialize_when_none=False) - reference = ModelType(FieldReference, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - return cls({"key": key, "name": name, **kwargs}) - - -class TextDyFieldOptions(FieldViewOption): - pass - - -class BadgeDyFieldOptions(FieldViewOption): - text_color = StringType(serialize_when_none=False) - shape = StringType(serialize_when_none=False, choices=["SQUARE", "ROUND"]) - outline_color = StringType(serialize_when_none=False, choices=BACKGROUND_COLORS) - background_color = StringType(serialize_when_none=False, choices=BACKGROUND_COLORS) - - -class StateDyFieldOptions(FieldViewOption): - text_color = StringType(serialize_when_none=False) - icon = ModelType(Icon, serialize_when_none=False) - - -class ImageDyFieldOptions(FieldViewOption): - image_url = StringType(default="") - width = StringType(serialize_when_none=False) - height = StringType(serialize_when_none=False) - - -class DateTimeDyFieldOptions(FieldViewOption): - source_type = StringType(default="timestamp", choices=["iso8601", "timestamp"]) - source_format = StringType(serialize_when_none=False) - display_format = StringType(serialize_when_none=False) - - -class ProgressFieldOptions(FieldViewOption): - unit = StringType(serialize_when_none=False) - - -class SizeFieldOptions(FieldViewOption): - display_unit = StringType( - serialize_when_none=False, choices=("BYTES", "KB", "MB", "GB", "TB", "PB") - ) - source_unit = StringType( - serialize_when_none=False, choices=("BYTES", "KB", "MB", "GB", "TB", "PB") - ) - - -class TextDyField(BaseDynamicField): - type = StringType(default="text") - options = PolyModelType(TextDyFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - if "options" in kwargs: - _data_source.update({"options": TextDyFieldOptions(kwargs.get("options"))}) - - if "reference" in kwargs: - _data_source.update({"reference": kwargs.get("reference")}) - - return cls(_data_source) - - -class StateDyField(BaseDynamicField): - type = StringType(default="state") - options = PolyModelType(StateDyFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - if "options" in kwargs: - _data_source.update({"options": StateDyFieldOptions(kwargs.get("options"))}) - - if "reference" in kwargs: - _data_source.update({"reference": kwargs.get("reference")}) - - return cls(_data_source) - - -class BadgeDyField(BaseDynamicField): - type = StringType(default="badge") - options = PolyModelType(BadgeDyFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - - if "options" in kwargs: - _data_source.update({"options": BadgeDyFieldOptions(kwargs.get("options"))}) - else: - _data_source.update( - { - "options": BadgeDyFieldOptions( - {"background_color": "gray.200", "text_color": "gray.900"} - ) - } - ) - - if "reference" in kwargs: - _data_source.update({"reference": kwargs.get("reference")}) - - return cls(_data_source) - - -class ImageDyField(BaseDynamicField): - type = StringType(default="image") - options = PolyModelType(ImageDyFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - if "options" in kwargs: - _data_source.update({"options": ImageDyFieldOptions(kwargs.get("options"))}) - - if "reference" in kwargs: - _data_source.update({"reference": kwargs.get("reference")}) - - return cls(_data_source) - - -class DateTimeDyField(BaseDynamicField): - type = StringType(default="datetime") - options = PolyModelType(DateTimeDyFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - if "options" in kwargs: - _data_source.update( - {"options": DateTimeDyFieldOptions(kwargs.get("options"))} - ) - - if "reference" in kwargs: - _data_source.update({"reference": kwargs.get("reference")}) - - return cls(_data_source) - - -class DictDyField(BaseDynamicField): - type = StringType(default="dict") - options = PolyModelType(FieldViewOption, serialize_when_none=False) - - -class StateItemDyField(BaseField): - type = StringType(default="state") - options = PolyModelType(StateDyFieldOptions, serialize_when_none=False) - - @classmethod - def set(cls, options): - return cls({"options": StateDyFieldOptions(options)}) - - -class BadgeItemDyField(BaseField): - type = StringType(default="badge") - options = PolyModelType(BadgeDyFieldOptions, serialize_when_none=False) - - @classmethod - def set(cls, options): - return cls({"options": BadgeDyFieldOptions(options)}) - - -class ImageItemDyField(BaseField): - type = StringType(default="image") - options = PolyModelType(ImageDyFieldOptions, serialize_when_none=False) - - @classmethod - def set(cls, options): - return cls({"options": ImageDyFieldOptions(options)}) - - -class DatetimeItemDyField(BaseField): - type = StringType(default="datetime") - options = PolyModelType(DateTimeDyFieldOptions, serialize_when_none=False) - - @classmethod - def set(cls, options): - return cls({"options": DateTimeDyFieldOptions(options)}) - - -class ListDyFieldOptions(FieldViewOption): - item = PolyModelType( - [BadgeItemDyField, StateDyField, DateTimeDyField, DictDyField], - serialize_when_none=False, - ) - sub_key = StringType(serialize_when_none=False) - delimiter = StringType(serialize_when_none=False) - - -class ListDyField(BaseDynamicField): - type = StringType(default="list") - options = PolyModelType(ListDyFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - if "default_badge" in kwargs: - _default_badge = kwargs.get("default_badge") - _list_options = {"delimiter": " "} - - if "type" in _default_badge and _default_badge.get("type") == "outline": - _list_options.update( - {"item": BadgeItemDyField.set({"outline_color": "violet.500"})} - ) - elif "type" in _default_badge and _default_badge.get("type") == "inline": - _list_options.update( - {"item": BadgeItemDyField.set({"background_color": "violet.500"})} - ) - - if "sub_key" in _default_badge: - _list_options.update({"sub_key": _default_badge.get("sub_key")}) - - if "delimiter" in _default_badge: - _list_options.update({"delimiter": _default_badge.get("delimiter")}) - - _data_source.update({"options": ListDyFieldOptions(_list_options)}) - - if "options" in kwargs: - _data_source.update({"options": ListDyFieldOptions(kwargs.get("options"))}) - - if "reference" in kwargs: - _data_source.update({"reference": kwargs.get("reference")}) - - return cls(_data_source) - - -class EnumOptionDyField(FieldViewOption): - items = DictType( - PolyModelType( - [StateItemDyField, BadgeItemDyField, ImageItemDyField, DatetimeItemDyField] - ), - serialize_when_none=False, - default={}, - ) - - -class EnumDyField(BaseDynamicField): - type = StringType(default="enum") - options = DictType( - PolyModelType( - [ - StateItemDyField, - BadgeItemDyField, - ImageItemDyField, - DatetimeItemDyField, - EnumOptionDyField, - ] - ), - serialize_when_none=False, - default={}, - ) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - _default_badge = kwargs.get("default_badge", {}) - _default_state = kwargs.get("default_state", {}) - _default_outline_badge = kwargs.get("default_outline_badge", []) - - _options_dic = {} - - for _key in _default_outline_badge: - _round_index = len(TYPE_BADGE) - _index = _default_outline_badge.index(_key) - _num = math.floor(_index / len(TYPE_BADGE)) - - if _num > 0: - _round_index = len(TYPE_BADGE) * _num - - if _round_index - 1 < _index: - _index = _index - _round_index - - _options_dic[_key] = BadgeItemDyField.set( - {"outline_color": TYPE_BADGE[_index]} - ) - - for _key in _default_badge: - for _badge in _default_badge[_key]: - _options_dic[_badge] = BadgeItemDyField.set({"background_color": _key}) - - for _key in _default_state: - for _state in _default_state[_key]: - _state_options = {"icon": {"color": "gray.400"}} - - if _key == "safe": - _state_options = {"icon": {"color": "green.500"}} - elif _key == "disable": - _state_options.update({"text_color": "gray.400"}) - elif _key == "warning": - _state_options = {"icon": {"color": "yellow.500"}} - elif _key == "available": - _state_options = {"icon": {"color": "blue.400"}} - elif _key == "alert": - _state_options = { - "text_color": "red.500", - "icon": {"color": "red.500"}, - } - - _options_dic[_state] = StateItemDyField.set(_state_options) - - _data_source.update({"options": _options_dic}) - - if "options" in kwargs: - _data_source.update({"options": kwargs.get("options")}) - - if "reference" in kwargs: - _data_source.update({"reference": kwargs.get("reference")}) - return cls(_data_source) - - -class ProgressField(BaseDynamicField): - type = StringType(default="progress") - options = PolyModelType( - ProgressFieldOptions, - serialize_when_none=False, - ) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - - if "options" in kwargs: - _data_source.update({"options": kwargs.get("options")}) - - return cls(_data_source) - - -class SizeField(BaseDynamicField): - type = StringType(default="size") - options = PolyModelType(SizeFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - - if "options" in kwargs: - _data_source.update({"options": kwargs.get("options")}) - - return cls(_data_source) - - -class SearchEnumField(Model): - label = StringType(serialize_when_none=False) - icon = ModelType(Icon, serialize_when_none=False) - - @classmethod - def set_field(cls, label=None, icon=None): - return_dic = {} - - if label is not None: - return_dic.update({"label": label}) - - if icon is not None: - return_dic.update({"icon": Icon(icon)}) - - return cls(return_dic) - - -class SearchField(BaseDynamicSearch): - enums = DictType(ModelType(SearchEnumField), serialize_when_none=False) - reference = StringType(serialize_when_none=False) - - @classmethod - def set(cls, name="", key="", data_type=None, enums=None, reference=None): - return_dic = {"name": name, "key": key} - - if data_type is not None: - return_dic.update({"data_type": data_type}) - - if reference is not None: - return_dic.update({"reference": reference}) - - if enums is not None: - convert_enums = {} - for enum_key in enums: - enum_v = enums[enum_key] - convert_enums[enum_key] = SearchEnumField.set_field(**enum_v) - - return_dic.update({"enums": convert_enums}) - - return cls(return_dic) - - -class MoreLayoutField(Model): - name = StringType(default="") - type = StringType(default="popup") - options = DictType(BaseType, serialize_when_none=False) - - -class MoreFieldOptions(FieldViewOption): - sub_key = StringType(serialize_when_none=False) - layout = PolyModelType(MoreLayoutField, serialize_when_none=False) - - -class MoreField(BaseDynamicField): - type = StringType(default="more") - options = PolyModelType(MoreFieldOptions, serialize_when_none=False) - - @classmethod - def data_source(cls, name, key, **kwargs): - _data_source = {"key": key, "name": name} - - if "options" in kwargs: - _data_source.update({"options": kwargs.get("options")}) - - return cls(_data_source) diff --git a/src/spaceone/inventory/libs/schema/metadata/dynamic_layout.py b/src/spaceone/inventory/libs/schema/metadata/dynamic_layout.py deleted file mode 100644 index 2c9987f9..00000000 --- a/src/spaceone/inventory/libs/schema/metadata/dynamic_layout.py +++ /dev/null @@ -1,186 +0,0 @@ -from schematics import Model -from schematics.types import StringType, PolyModelType, ListType -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - BaseDynamicField, - TextDyField, -) - - -class LayoutOptions(Model): - class Options: - serialize_when_none = False - - root_path = StringType(serialize_when_none=False) - - -class BaseLayoutField(Model): - @staticmethod - def _set_fields(fields=[], **kwargs): - _options = {"fields": fields} - for k, v in kwargs.items(): - if v is not None: - _options[k] = v - return _options - - name = StringType(default="") - type = StringType( - default="item", - choices=( - "item", - "table", - "query-search-table", - "simple-table", - "list", - "raw", - "html", - ), - ) - options = PolyModelType(LayoutOptions, serialize_when_none=False) - - -class ItemLayoutOption(LayoutOptions): - fields = ListType(PolyModelType(BaseDynamicField)) - - -class SimpleTableLayoutOption(LayoutOptions): - fields = ListType(PolyModelType(BaseDynamicField)) - - -class TableLayoutOption(LayoutOptions): - fields = ListType(PolyModelType(BaseDynamicField)) - - -class QuerySearchTableLayoutOption(LayoutOptions): - fields = ListType(PolyModelType(BaseDynamicField)) - - -class RawLayoutOption(LayoutOptions): - class Options: - serialize_when_none = False - - -class HTMLLayoutOption(LayoutOptions): - class Options: - serialize_when_none = False - - -class ListLayoutOption(LayoutOptions): - layouts = ListType(PolyModelType(BaseLayoutField)) - - -class ItemDynamicLayout(BaseLayoutField): - type = StringType(default="item") - options = PolyModelType(ItemLayoutOption) - - @classmethod - def set(cls, name="", root_path=""): - return cls( - {"name": name, "options": ItemLayoutOption({"root_path": root_path})} - ) - - @classmethod - def set_fields(cls, name="", root_path=None, fields=[]): - _options = cls._set_fields(fields, root_path=root_path) - return cls({"name": name, "options": ItemLayoutOption(_options)}) - - -class TableDynamicLayout(BaseLayoutField): - type = StringType(default="table") - options = PolyModelType(TableLayoutOption) - - @classmethod - def set(cls, name="", root_path=""): - return cls( - name=name, - root_path=root_path, - options=TableLayoutOption({"root_path": root_path}), - ) - - @classmethod - def set_fields(cls, name="", root_path=None, fields=[]): - _options = cls._set_fields(fields, root_path=root_path) - return cls({"name": name, "options": TableLayoutOption(_options)}) - - -class QuerySearchTableDynamicLayout(BaseLayoutField): - type = StringType(default="query-search-table") - options = PolyModelType(QuerySearchTableLayoutOption) - - @classmethod - def set(cls, name="", root_path=""): - return cls( - name=name, options=QuerySearchTableLayoutOption({"root_path": root_path}) - ) - - @classmethod - def set_fields(cls, name, fields: list = None, root_path=None): - if fields is None: - fields = [] - _options = cls._set_fields(fields, root_path=root_path) - return cls({"name": name, "options": QuerySearchTableLayoutOption(_options)}) - - -class SimpleTableDynamicLayout(BaseLayoutField): - type = StringType(default="simple-table") - options = PolyModelType(SimpleTableLayoutOption) - - @classmethod - def set(cls, name="", root_path=""): - return cls( - {"name": name, "options": SimpleTableLayoutOption({"root_path": root_path})} - ) - - @classmethod - def set_fields(cls, name="", root_path=None, fields=[]): - _options = cls._set_fields(fields, root_path=root_path) - return cls({"name": name, "options": SimpleTableLayoutOption(_options)}) - - @classmethod - def set_tags(cls, name="Tags", root_path="data.tags", fields=None): - if fields is None: - fields = [ - TextDyField.data_source("Key", "key"), - TextDyField.data_source("Value", "value"), - ] - return cls.set_fields(name, root_path, fields) - - -class ListDynamicLayout(BaseLayoutField): - type = StringType(default="list") - options = PolyModelType(ListLayoutOption) - - @classmethod - def set(cls, name="", layouts=[]): - return cls(name=name, options=ListLayoutOption({"layouts": layouts})) - - @classmethod - def set_layouts(cls, name="", layouts=[]): - return cls({"name": name, "options": ListLayoutOption({"layouts": layouts})}) - - -class RawDynamicLayout(BaseLayoutField): - type = StringType(default="raw") - options = PolyModelType(RawLayoutOption) - - @classmethod - def set(cls, name="", root_path=None): - if root_path is None: - _options = RawLayoutOption() - else: - _options = RawLayoutOption({"root_path": root_path}) - - return cls({"name": name, "options": _options}) - - -class HTMLDynamicLayout(BaseLayoutField): - type = StringType(default="html") - options = PolyModelType(HTMLLayoutOption) - - @classmethod - def set(cls, name="", root_path=None): - if root_path is None: - _options = HTMLLayoutOption() - else: - _options = HTMLLayoutOption({"root_path": root_path}) - - return cls({"name": name, "options": _options}) diff --git a/src/spaceone/inventory/libs/schema/metadata/dynamic_search.py b/src/spaceone/inventory/libs/schema/metadata/dynamic_search.py deleted file mode 100644 index c8d28edf..00000000 --- a/src/spaceone/inventory/libs/schema/metadata/dynamic_search.py +++ /dev/null @@ -1,14 +0,0 @@ -from schematics import Model -from schematics.types import StringType, ListType, PolyModelType - - -class BaseDynamicSearch(Model): - name = StringType() - key = StringType() - data_type = StringType(choices=['string', 'integer', 'float', 'boolean', 'datetime'], - serialize_when_none=False) - - -class BaseDynamicSearchItem(Model): - title = StringType(default="Properties") - items = ListType(PolyModelType(BaseDynamicSearch), serialize_when_none=False) diff --git a/src/spaceone/inventory/libs/schema/metadata/dynamic_widget.py b/src/spaceone/inventory/libs/schema/metadata/dynamic_widget.py deleted file mode 100644 index 2c20172b..00000000 --- a/src/spaceone/inventory/libs/schema/metadata/dynamic_widget.py +++ /dev/null @@ -1,212 +0,0 @@ -from schematics import Model -from schematics.types import StringType, ListType, BooleanType, ModelType, PolyModelType, BaseType -from .dynamic_field import TextDyField, StateDyField, BadgeDyField, ListDyField, DictDyField, DateTimeDyField, \ - ImageDyField, EnumDyField, SizeField, ProgressField - - -class BaseDynamicWidgetKeyFields(Model): - key = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - - -class BaseDynamicWidgetGroupCondition(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - operator = StringType(serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateUnwind(Model): - path = StringType(serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateGroupKeys(BaseDynamicWidgetKeyFields): - date_format = StringType(serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateGroupFields(Model): - key = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - operator = StringType(serialize_when_none=False) - _fields = ListType(ModelType(BaseDynamicWidgetKeyFields), serialize_when_none=False, serialized_name='fields') - condition = ModelType(BaseDynamicWidgetGroupCondition, serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateGroup(Model): - keys = ListType(ModelType(BaseDynamicWidgetQueryAggregateGroupKeys), serialize_when_none=False) - _fields = ListType(ModelType(BaseDynamicWidgetQueryAggregateGroupFields), serialize_when_none=False, serialized_name='fields') - - -class BaseDynamicWidgetQueryAggregateCount(Model): - name = StringType(serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateSortKey(Model): - key = StringType(serialize_when_none=False) - desc = BooleanType(serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateSort(Model): - key = StringType(serialize_when_none=False) - desc = BooleanType(serialize_when_none=False) - keys = ListType(ModelType(BaseDynamicWidgetQueryAggregateSortKey), serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateProjectField(Model): - key = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - operator = StringType(serialize_when_none=False) - - -class BaseDynamicWidgetQueryAggregateProject(Model): - _fields = ListType(ModelType(BaseDynamicWidgetQueryAggregateProjectField), serialize_when_none=False, serialized_name='fields') - - -class BaseDynamicWidgetQueryAggregate(Model): - unwind = ModelType(BaseDynamicWidgetQueryAggregateUnwind, serialize_when_none=False) - group = ModelType(BaseDynamicWidgetQueryAggregateGroup, serialize_when_none=False) - count = ModelType(BaseDynamicWidgetQueryAggregateCount, serialize_when_none=False) - sort = ModelType(BaseDynamicWidgetQueryAggregateSort, serialize_when_none=False) - project = ModelType(BaseDynamicWidgetQueryAggregateProject, serialize_when_none=False) # add - - -class BaseDynamicWidgetQueryFilter(Model): - key = StringType(serialize_when_none=False) - # value = PolyModelType([StringType], serialize_when_none=False) - # change StringType -> BaseType - value = BaseType(serialize_when_none=False) - operator = StringType(serialize_when_none=False) - - -class BaseDynamicWidgetQuery(Model): - aggregate = ListType(ModelType(BaseDynamicWidgetQueryAggregate), serialize_when_none=False) - filter = ListType(ModelType(BaseDynamicWidgetQueryFilter), serialize_when_none=False) - - -class BaseDynamicWidgetOptions(Model): - value_options = PolyModelType([TextDyField, StateDyField, BadgeDyField, ListDyField, DictDyField, DateTimeDyField, - ImageDyField, EnumDyField, SizeField, ProgressField], serialize_when_none=False) - name_options = PolyModelType([TextDyField, StateDyField, BadgeDyField, ListDyField, DictDyField, DateTimeDyField, - ImageDyField, EnumDyField, SizeField, ProgressField], serialize_when_none=False) - chart_type = StringType(choices=('COLUMN', 'DONUT', 'TREEMAP'), serialize_when_none=False) - - -class BaseDynamicWidget(Model): - name = StringType(serialize_when_none=False) - type = StringType(choices=('card', 'chart'), serialize_when_none=False) - options = ModelType(BaseDynamicWidgetOptions, serialize_when_none=False) - query = ModelType(BaseDynamicWidgetQuery, serialize_when_none=False) - - @classmethod - def set(cls, cloud_service_group, cloud_service_type, name, query, options={}): - # Query : aggregate - query_aggrs = [] - for _aggregate in query.get('aggregate', []): - _aggr_dict = {} - if 'unwind' in _aggregate: - _aggr_dict['unwind'] = BaseDynamicWidgetQueryAggregateUnwind(_aggregate['unwind']) - - if 'group' in _aggregate: - _aggr_group = _aggregate['group'] - _aggr_group_keys = [BaseDynamicWidgetQueryAggregateGroupKeys(_aggr_group_key) - for _aggr_group_key in _aggr_group.get('keys', [])] - - _aggr_group_fields = [] - for _aggr_group_field in _aggr_group.get('fields', []): - _aggr_group_field_fields = [BaseDynamicWidgetKeyFields(_aggr_group_field_fields) for - _aggr_group_field_fields in _aggr_group_field.get('fields', [])] - - if _aggr_group_field_fields: - _aggr_group_field['fields'] = _aggr_group_field_fields - - if 'condition' in _aggr_group_field: - _aggr_group_field['condition'] = BaseDynamicWidgetGroupCondition(_aggr_group_field['condition']) - - _aggr_group_fields.append(BaseDynamicWidgetQueryAggregateGroupFields(_aggr_group_field)) - - if _aggr_group_keys: - _aggr_group['keys'] = _aggr_group_keys - - if _aggr_group_fields: - _aggr_group['fields'] = _aggr_group_fields - - _aggr_dict['group'] = BaseDynamicWidgetQueryAggregateGroup(_aggr_group) - - if 'count' in _aggregate: - _aggr_dict['count'] = BaseDynamicWidgetQueryAggregateCount(_aggregate['count']) - - if 'sort' in _aggregate: - _aggr_sort = _aggregate['sort'] - - _aggr_sort_keys = [BaseDynamicWidgetQueryAggregateSortKey(_aggr_sort_key) - for _aggr_sort_key in _aggr_sort.get('keys', [])] - - if _aggr_sort_keys: - _aggr_sort['keys'] = _aggr_sort_keys - - _aggr_dict['sort'] = BaseDynamicWidgetQueryAggregateSort(_aggr_sort) - - if 'project' in _aggregate: - _aggr_project = _aggregate['project'] - _aggr_project_fields = [BaseDynamicWidgetQueryAggregateProjectField(_aggr_project_field) - for _aggr_project_field in _aggr_project.get('fields', [])] - - _aggr_dict['project'] = BaseDynamicWidgetQueryAggregateProject({'fields': _aggr_project_fields}) - query_aggrs.append(BaseDynamicWidgetQueryAggregate(_aggr_dict)) - - query['aggregate'] = query_aggrs - - # Query : filter - filter = [{'key': 'provider', 'value': 'azure', 'operator': 'eq'}, - {'key': 'cloud_service_group', 'value': cloud_service_group, 'operator': 'eq'}, - {'key': 'cloud_service_type', 'value': cloud_service_type, 'operator': 'eq'}] - - if 'filter' in query: - query['filter'].extend(filter) - else: - query.update({'filter': filter}) - - query['filter'] = [BaseDynamicWidgetQueryFilter(_filter) for _filter in query['filter']] - - if options: - field_type_maps = { - 'text': TextDyField, - 'state': StateDyField, - 'badge': BadgeDyField, - 'list': ListDyField, - 'dict': DictDyField, - 'datetime': DateTimeDyField, - 'image': ImageDyField, - 'enum': EnumDyField, - 'size': SizeField, - 'progress': ProgressField - } - - if 'name_options' in options: - _name_options = options['name_options'] - _type = _name_options.get('type', 'text') - - if _type in field_type_maps: - options['name_options'] = field_type_maps[_type](_name_options) - - if 'value_options' in options: - _value_options = options['value_options'] - _type = _value_options.get('type', 'text') - - if _type in field_type_maps: - options['value_options'] = field_type_maps[_type](_value_options) - - _dic = { - 'name': name, - 'query': BaseDynamicWidgetQuery(query), - 'options': BaseDynamicWidgetOptions(options) - } - - return cls(_dic) - - -class CardWidget(BaseDynamicWidget): - type = StringType(default='card') - - -class ChartWidget(BaseDynamicWidget): - type = StringType(default='chart') diff --git a/src/spaceone/inventory/libs/schema/region.py b/src/spaceone/inventory/libs/schema/region.py deleted file mode 100644 index 6079fa0e..00000000 --- a/src/spaceone/inventory/libs/schema/region.py +++ /dev/null @@ -1,16 +0,0 @@ -from schematics import Model -from schematics.types import ListType, StringType, PolyModelType, DictType -from .base import BaseResponse - - -class RegionResource(Model): - name = StringType(default="") - region_code = StringType() - provider = StringType(default="azure") - tags = DictType(StringType) - - -class RegionResponse(BaseResponse): - resource_type = StringType(default='inventory.Region') - match_rules = DictType(ListType(StringType), default={'1': ['region_code', 'provider']}) - resource = PolyModelType(RegionResource) \ No newline at end of file diff --git a/src/spaceone/inventory/libs/schema/resource.py b/src/spaceone/inventory/libs/schema/resource.py deleted file mode 100644 index 3da160c9..00000000 --- a/src/spaceone/inventory/libs/schema/resource.py +++ /dev/null @@ -1,78 +0,0 @@ -from schematics import Model -from schematics.types import StringType, DictType, ListType, ModelType, PolyModelType -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource -from spaceone.inventory.libs.schema.region import RegionResource - - -class ErrorResource(Model): - resource_type = StringType(default="inventory.CloudService") - provider = StringType(default="azure") - cloud_service_group = StringType(default="") - cloud_service_type = StringType(default="") - resource_id = StringType(serialize_when_none=False) - - -class ResourceResponse(Model): - state = StringType() - message = StringType(default="") - resource_type = StringType() - match_rules = DictType(ListType(StringType), serialize_when_none=False) - resource = DictType(StringType, default={}) - - -class CloudServiceResourceResponse(ResourceResponse): - state = StringType(default="SUCCESS") - resource_type = StringType(default="inventory.CloudService") - match_rules = DictType( - ListType(StringType), - default={ - "1": [ - "reference.resource_id", - "provider", - "cloud_service_type", - "cloud_service_group", - ] - }, - ) - resource = PolyModelType(CloudServiceTypeResource) - - -class RegionResourceResponse(ResourceResponse): - state = StringType(default="SUCCESS") - resource_type = StringType(default="inventory.Region") - match_rules = DictType( - ListType(StringType), default={"1": ["region_code", "provider"]} - ) - resource = PolyModelType(RegionResource) - - -class CloudServiceTypeResourceResponse(ResourceResponse): - state = StringType(default="SUCCESS") - resource_type = StringType(default="inventory.CloudServiceType") - match_rules = DictType( - ListType(StringType), default={"1": ["name", "group", "provider"]} - ) - resource = PolyModelType(CloudServiceTypeResource) - - -class ErrorResourceResponse(ResourceResponse): - state = StringType(default="FAILURE") - resource_type = StringType(default="inventory.ErrorResource") - resource = ModelType(ErrorResource, default={}) - - -class AzureMonitorModel(Model): - resource_id = StringType() - - -class AzureTags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class AzureCloudService(Model): - tenant_id = StringType(serialized_name=False) - subscription_id = StringType(serialize_when_none=False) - subscription_name = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - azure_monitor = ModelType(AzureMonitorModel, serialize_when_none=False) diff --git a/src/spaceone/inventory/libs/schema/stackdriver.py b/src/spaceone/inventory/libs/schema/stackdriver.py deleted file mode 100644 index 65ba6a69..00000000 --- a/src/spaceone/inventory/libs/schema/stackdriver.py +++ /dev/null @@ -1,15 +0,0 @@ -from schematics import Model -from schematics.types import ListType, StringType, ModelType - - -class StackDriverFilters(Model): - key = StringType() - value = StringType() - - -class StackDriverModel(Model): - class Option: - serialize_when_none = False - - type = StringType() - filters = ListType(ModelType(StackDriverFilters), default=[]) diff --git a/src/spaceone/inventory/libs/utils.py b/src/spaceone/inventory/libs/utils.py deleted file mode 100644 index 5c1eafc6..00000000 --- a/src/spaceone/inventory/libs/utils.py +++ /dev/null @@ -1,7 +0,0 @@ -import yaml - -def get_data_from_yaml(file_path): - with open(file_path) as f: - dict = yaml.load(f, Loader=yaml.FullLoader) - - return dict diff --git a/src/spaceone/inventory/manager/__init__.py b/src/spaceone/inventory/manager/__init__.py deleted file mode 100644 index c6b75e21..00000000 --- a/src/spaceone/inventory/manager/__init__.py +++ /dev/null @@ -1,49 +0,0 @@ -from spaceone.inventory.manager.disks.disk_manager import DisksManager -from spaceone.inventory.manager.subscriptions.subscription_manager import ( - SubscriptionsManager, -) -from spaceone.inventory.manager.snapshots.instance_manager import SnapshotsManager -from spaceone.inventory.manager.vm_scale_sets.scale_set_manager import ( - VmScaleSetsManager, -) -from spaceone.inventory.manager.load_balancers.instance_manager import ( - LoadBalancersManager, -) -from spaceone.inventory.manager.sql_databases.database_manager import ( - SQLDatabasesManager, -) -from spaceone.inventory.manager.sql_servers.server_manager import SQLServersManager -from spaceone.inventory.manager.virtual_networks.instance_manager import ( - VirtualNetworksManager, -) -from spaceone.inventory.manager.application_gateways.instance_manager import ( - ApplicationGatewaysManager, -) -from spaceone.inventory.manager.public_ip_addresses.ip_address_manager import ( - PublicIPAddressesManager, -) -from spaceone.inventory.manager.network_security_groups.instance_manager import ( - NetworkSecurityGroupsManager, -) -from spaceone.inventory.manager.nat_gateways.instance_manager import NATGatewaysManager -from spaceone.inventory.manager.storage_accounts.instance_manager import ( - StorageAccountsManager, -) -from spaceone.inventory.manager.key_vaults.instance_manager import KeyVaultsManager -from spaceone.inventory.manager.mysql_servers.server_manager import MySQLServersManager -from spaceone.inventory.manager.cosmos_db.instance_manager import CosmosDBManager -from spaceone.inventory.manager.postgresql_servers.server_manager import ( - PostgreSQLServersManager, -) -from spaceone.inventory.manager.virtual_machines.instnace_manger import ( - VirtualMachinesManager, -) -from spaceone.inventory.manager.container_instances.container_manager import ( - ContainerInstancesManager, -) -from spaceone.inventory.manager.web_pubsub_service.service_manager import ( - WebPubSubServiceManager, -) -from spaceone.inventory.manager.resources_manager.resource_manager import ( - ResourcesManager, -) diff --git a/src/spaceone/inventory/manager/application_gateways/__init__.py b/src/spaceone/inventory/manager/application_gateways/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/application_gateways/instance_manager.py b/src/spaceone/inventory/manager/application_gateways/instance_manager.py deleted file mode 100644 index c2e5ce6a..00000000 --- a/src/spaceone/inventory/manager/application_gateways/instance_manager.py +++ /dev/null @@ -1,410 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.application_gateways import ( - ApplicationGatewaysConnector, -) -from spaceone.inventory.model.application_gateways.cloud_service import * -from spaceone.inventory.model.application_gateways.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.application_gateways.data import * - -_LOGGER = logging.getLogger(__name__) - - -class ApplicationGatewaysManager(AzureManager): - connector_name = "ApplicationGatewaysConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : list of azure application gateway data resource information - ErrorResourceResponse (list) : list of error resource information - """ - - _LOGGER.debug(f"** Application Gateway START **") - - start_time = time.time() - subscription_info = params["subscription_info"] - - application_gateway_conn: ApplicationGatewaysConnector = ( - self.locator.get_connector(self.connector_name, **params) - ) - application_gateways_responses = [] - error_responses = [] - - application_gateways_list = ( - application_gateway_conn.list_all_application_gateways() - ) - for application_gateway in application_gateways_list: - application_gateway_id = "" - - try: - application_gateway_dict = self.convert_nested_dictionary( - application_gateway - ) - application_gateway_id = application_gateway_dict["id"] - - # update application_gateway_dict - application_gateway_dict.update( - { - "resource_group": self.get_resource_group_from_id( - application_gateway_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": application_gateway_id}, - } - ) - - backend_address_pools = application_gateway_dict.get( - "backend_address_pools", [] - ) - url_path_maps = application_gateway_dict.get("url_path_maps", []) - request_routing_rules = application_gateway_dict.get( - "request_routing_rules", [] - ) - rewrite_rule_sets = application_gateway_dict.get( - "rewrite_rule_sets", [] - ) - frontend_ip_configurations = application_gateway_dict.get( - "frontend_ip_configurations", [] - ) - ip_configurations = application_gateway_dict.get( - "gateway_ip_configurations", [] - ) - - for frontend_ip_configuration_dict in frontend_ip_configurations: - if ( - frontend_ip_configuration_dict.get("private_ip_address") - is not None - ): - application_gateway_dict.update( - { - "private_ip_address": frontend_ip_configuration_dict[ - "private_ip_address" - ] - } - ) - frontend_ip_configuration_dict.update( - { - "ip_type": "Private", - "ip_address": frontend_ip_configuration_dict[ - "private_ip_address" - ], - } - ) - elif ( - frontend_ip_configuration_dict.get("public_ip_address") - is not None - ): - public_ip_address_name = frontend_ip_configuration_dict[ - "public_ip_address" - ]["id"].split("/")[8] - public_ip_address_dict = self.get_public_ip_address( - application_gateway_conn, - application_gateway_dict["resource_group"], - public_ip_address_name, - ) - application_gateway_dict.update( - {"public_ip_address": public_ip_address_dict} - ) - frontend_ip_configuration_dict.update( - { - "ip_type": "Public", - "ip_address": f'{public_ip_address_dict.get("ip_address", "-")} ({public_ip_address_dict.get("name","")})', - "associated_listener": self.get_associated_listener( - frontend_ip_configuration_dict, - application_gateway_dict.get("http_listeners", []), - ), - } - ) - - for ip_configuration in ip_configurations: - application_gateway_dict.update( - { - "virtual_network": ip_configuration.get("subnet")[ - "id" - ].split("/")[8], - "subnet": ip_configuration.get("subnet")["id"].split("/")[ - 10 - ], - } - ) - - if ( - application_gateway_dict.get("backend_http_settings_collection") - is not None - ): - for backend_setting in application_gateway_dict[ - "backend_http_settings_collection" - ]: - if backend_setting.get("probe") is not None: - custom_probe = backend_setting["probe"]["id"].split("/")[10] - backend_setting.update({"custom_probe": custom_probe}) - - if application_gateway_dict.get("http_listeners") is not None: - custom_error_configurations_list = [] - - for http_listener in application_gateway_dict["http_listeners"]: - # Update Port information - if http_listener.get("frontend_port") is not None: - frontend_port_id = http_listener["frontend_port"]["id"] - http_listener["frontend_port"].update( - { - "port": self.get_port( - frontend_port_id, - application_gateway_dict.get( - "frontend_ports", [] - ), - ) - } - ) - http_listener.update( - { - "port": http_listener.get("frontend_port", {}).get( - "port", "" - ) - } - ) - - # Update custom error configuration - if http_listener.get("custom_error_configurations") is not None: - for custom_error_conf in http_listener[ - "custom_error_configurations" - ]: - custom_error_conf.update( - {"listener_name": http_listener["name"]} - ) - custom_error_configurations_list.append( - custom_error_conf - ) - - application_gateway_dict.update( - { - "custom_error_configurations": custom_error_configurations_list - } - ) - - for rewrite_rule in rewrite_rule_sets: - rewrite_rule_id = rewrite_rule.get("id") - rewrite_config_rule_displays = ( - self.list_rewrite_config_rule_display(rewrite_rule) - ) - rewrite_rule.update( - {"rewrite_rules_display": rewrite_config_rule_displays} - ) - - rules_applied_list = self.list_rewrite_rule_rules_applied( - rewrite_rule_id, request_routing_rules, url_path_maps - ) - rewrite_rule.update({"rules_applied": rules_applied_list}) - - # Update request routing rules - for request_routing_rule in request_routing_rules: - if request_routing_rule.get("http_listener") is not None: - request_routing_rule.update( - { - "http_listener_name": request_routing_rule[ - "http_listener" - ]["id"].split("/")[10] - } - ) - # Find http listener attached to this rule, and put rule's name to http_listeners dict - http_applied_rules_list = [] - http_listener_id = request_routing_rule["http_listener"]["id"] - - for request_routing_rule in application_gateway_dict.get( - "request_routing_rules", [] - ): - if http_listener_id in request_routing_rule.get( - "http_listener" - ).get("id", ""): - http_applied_rules_list.append( - request_routing_rule["name"] - ) - - self.update_http_listeners_list( - application_gateway_dict["http_listeners"], - http_listener_id, - http_applied_rules_list, - ) - - for backend_address_pool in backend_address_pools: - backend_address_pool_associated_rules = ( - self.get_backend_pool_associated_rules( - backend_address_pool, url_path_maps, request_routing_rules - ) - ) - backend_address_pool.update( - {"associated_rules": backend_address_pool_associated_rules} - ) - - backend_addresses = backend_address_pool.get( - "backend_addresses", [] - ) - backend_addresses_display = [ - backend_address.get("fqdn") - for backend_address in backend_addresses - ] - backend_address_pool.update( - {"backend_addresses_display": backend_addresses_display} - ) - - application_gateway_data = ApplicationGateway( - application_gateway_dict, strict=False - ) - application_gateway_resource = ApplicationGatewayResource( - { - "data": application_gateway_data, - "tags": application_gateway_dict.get("tags", {}), - "region_code": application_gateway_data.location, - "reference": ReferenceModel( - application_gateway_data.reference() - ), - "name": application_gateway_data.name, - "instance_type": application_gateway_data.sku.name, - "account": application_gateway_data.subscription_id, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(application_gateway_data["location"]) - application_gateways_responses.append( - ApplicationGatewayResponse( - {"resource": application_gateway_resource} - ) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {application_gateway_id} {e}", exc_info=True - ) - error_response = self.generate_resource_error_response( - e, "Network", "ApplicationGateway", application_gateway_id - ) - error_responses.append(error_response) - - _LOGGER.debug( - f"** Application Gateway Finished {time.time() - start_time} Seconds **" - ) - return application_gateways_responses, error_responses - - def get_public_ip_address( - self, application_gateway_conn, resource_group_name, pip_name - ): - public_ip_address_obj = application_gateway_conn.get_public_ip_addresses( - resource_group_name, pip_name - ) - public_ip_address_dict = self.convert_nested_dictionary(public_ip_address_obj) - - # _LOGGER.debug(f'[Public IP Address]{public_ip_address_dict}') - - return public_ip_address_dict - - @staticmethod - def get_associated_listener(frontend_ip_configuration_dict, http_listeners_list): - associated_listener = [] - for http_listener in http_listeners_list: - if http_listener.get("frontend_ip_configuration") is not None: - if frontend_ip_configuration_dict["id"] in http_listener.get( - "frontend_ip_configuration", {} - ).get("id", ""): - associated_listener.append(http_listener.get("name")) - return associated_listener - - @staticmethod - def get_port(port_id, frontend_ports_list): - port = 0 - for fe_port in frontend_ports_list: - if port_id == fe_port.get("id"): - port = fe_port.get("port") - break - return port - - @staticmethod - def get_backend_pool_associated_rules( - backend_address_pool, url_path_maps, request_routing_rules - ): - backend_address_pool_associated_rules = [] - backend_address_pool_id = backend_address_pool.get("id") - - for url_path_map in url_path_maps: - default_backend_address_pool = url_path_map.get( - "default_backend_address_pool" - ) - if ( - default_backend_address_pool is not None - and default_backend_address_pool.get("id") == backend_address_pool_id - ): - backend_address_pool_associated_rules.append(url_path_map.get("name")) - - for request_routing_rule in request_routing_rules: - request_backend_address_pool = request_routing_rule.get( - "backend_address_pool" - ) - if ( - request_backend_address_pool is not None - and request_backend_address_pool.get("id") == backend_address_pool_id - ): - backend_address_pool_associated_rules.append( - request_routing_rule.get("name") - ) - return backend_address_pool_associated_rules - - @staticmethod - def update_http_listeners_list( - http_listeners_list, http_listener_id, http_applied_rules - ): - for http_listener in http_listeners_list: - if http_listener["id"] == http_listener_id: - http_listener.update({"associated_rules": http_applied_rules}) - - @staticmethod - def list_rewrite_config_rule_display(rewrite_rule): - rewrite_config_rule_displays = [] - rewrite_rule_list = rewrite_rule.get("rewrite_rules", []) - for rule in rewrite_rule_list: - rewrite_config_rule_displays.append( - str(rule.get("name")) + ", " + str(rule.get("rule_sequence")) - ) - return rewrite_config_rule_displays - - @staticmethod - def list_rewrite_rule_rules_applied( - rewrite_rule_id, request_routing_rules, url_path_maps - ): - rules_applied_list = [] - for request_routing_rule in request_routing_rules: - if request_routing_rule.get("rewrite_rule_set") is not None: - if ( - request_routing_rule["rewrite_rule_set"].get("id") - == rewrite_rule_id - ): - rules_applied_list.append(request_routing_rule["name"]) - - for url_path_map in url_path_maps: - if url_path_map.get("default_rewrite_rule_set") is not None: - if ( - url_path_map["default_rewrite_rule_set"].get("id") - == rewrite_rule_id - ): - rules_applied_list.append(url_path_map["name"]) - - if url_path_map.get("path_rules") is not None: - for path_rule in url_path_map["path_rules"]: - if path_rule.get("rewrite_rule_set") is not None: - if path_rule["rewrite_rule_set"].get("id") == rewrite_rule_id: - rules_applied_list.append(url_path_map["name"]) - return rules_applied_list diff --git a/src/spaceone/inventory/manager/container_instances/__init__.py b/src/spaceone/inventory/manager/container_instances/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/container_instances/container_manager.py b/src/spaceone/inventory/manager/container_instances/container_manager.py deleted file mode 100644 index e6d17068..00000000 --- a/src/spaceone/inventory/manager/container_instances/container_manager.py +++ /dev/null @@ -1,208 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.connector.container_instances import ContainerInstancesConnector -from spaceone.inventory.model.container_instances.cloud_service import * -from spaceone.inventory.model.container_instances.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.container_instances.data import * -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.core.utils import * - -_LOGGER = logging.getLogger(__name__) - - -class ContainerInstancesManager(AzureManager): - connector_name = "ContainerInstancesConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : list of azure container instances data resource information - ErrorResourceResponse (list) : list of error resource information - """ - - _LOGGER.debug(f"** Container Instances START **") - start_time = time.time() - secret_data = params.get("secret_data", {}) - subscription_info = params["subscription_info"] - - container_instances_conn: ContainerInstancesConnector = ( - self.locator.get_connector(self.connector_name, **params) - ) - container_instances_responses = [] - error_responses = [] - - container_instances = container_instances_conn.list_container_groups() - for container_instance in container_instances: - container_instance_id = "" - try: - container_instance_dict = self.convert_nested_dictionary( - container_instance - ) - container_instance_id = container_instance_dict["id"] - - # if bug fix these code will be deleted - resource_group_name = self.get_resource_group_from_id( - container_instance_id - ) - container_group_name = container_instance_dict["name"] - - container_instance = container_instances_conn.get_container_groups( - resource_group_name=resource_group_name, - container_group_name=container_group_name, - ) - container_instance_dict = self.convert_nested_dictionary( - container_instance - ) - time.sleep(0.2) # end code - - # Update data info in Container Instance's Raw Data - _cpu_count_display = 0 - _gpu_count_display = 0 - _memory_size_display = 0.0 - - for container in container_instance_dict["containers"]: - _cpu_count_display += int(container["resources"]["requests"]["cpu"]) - _memory_size_display += float( - container["resources"]["requests"]["memory_in_gb"] - ) - _gpu_count_display += int(self._get_gpu_count_display(container)) - - # Set detail volume info for container - if container_instance_dict["volumes"] is not None: - for volume in container_instance_dict["volumes"]: - self._set_volumes_detail_info( - volume, container_instance_dict["containers"] - ) - - # Set Container Instance volume type and volume count - self._set_container_instance_volume_type( - container_instance_dict["volumes"] - ) - container_instance_dict["volume_count_display"] = len( - container_instance_dict["volumes"] - ) - - container_instance_dict = self.update_tenant_id_from_secret_data( - container_instance_dict, secret_data - ) - - container_instance_dict.update( - { - "resource_group": self.get_resource_group_from_id( - container_instance_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": container_instance_id}, - "container_count_display": len( - container_instance_dict["containers"] - ), - "cpu_count_display": _cpu_count_display, - "memory_size_display": _memory_size_display, - "gpu_count_display": _gpu_count_display, - } - ) - - container_instance_data = ContainerInstance( - container_instance_dict, strict=False - ) - - # Update resource info of Container Instance - container_instance_resource = ContainerInstanceResource( - { - "name": container_instance_data.name, - "account": container_instance_dict["subscription_id"], - "data": container_instance_data, - "tags": container_instance_dict.get("tags", {}), - "region_code": container_instance_data.location, - "reference": ReferenceModel( - container_instance_data.reference() - ), - } - ) - - self.set_region_code(container_instance_data["location"]) - container_instances_responses.append( - ContainerInstanceResponse({"resource": container_instance_resource}) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {container_instance_id} {e}", exc_info=True - ) - error_response = self.generate_resource_error_response( - e, "Container", "ContainerInstances", container_instance_id - ) - error_responses.append(error_response) - - _LOGGER.debug( - f"** Container Instances Finished {time.time() - start_time} Seconds **" - ) - return container_instances_responses, error_responses - - @staticmethod - def _set_container_instance_volume_type(volumes): - for volume in volumes: - if volume.get("git_repo") is not None: - volume["volume_type"] = "Git repo" - elif volume.get("azure_file") is not None: - volume["volume_type"] = "Azure file" - elif volume.get("empty_dir") is not None: - volume["volume_type"] = "Empty directory" - elif volume.get("secret") is not None: - volume["volume_type"] = "Secret" - - @staticmethod - def _set_volumes_detail_info(volume, containers): - for container in containers: - if volume_mounts := container["volume_mounts"]: - container["volume_mount_count_display"] = len(volume_mounts) - for volume_mount in volume_mounts: - if volume_mount["name"] == volume["name"]: - volume.update( - { - "mount_path": volume_mount["mount_path"], - "container_name": container["name"], - } - ) - return - - @staticmethod - def _get_gpu_count_display(container): - _gpu_count = 0 - if ( - _gpu_info := container.get("resources", {}) - .get("requests", {}) - .get("gpu", {}) - ): - _gpu_count = _gpu_info.get("count", 0) - return _gpu_count - - @staticmethod - def _convert_start_time_datetime_to_iso861(container): - if ( - _start_time := container.get("instance_view", {}) - .get("current_state", {}) - .get("start_time") - ): - _start_time = datetime_to_iso8601(_start_time) - container["instance_view"]["current_state"]["start_time"] = _start_time - elif ( - _finish_time := container.get("instance_view", {}) - .get("current_state", {}) - .get("_finish_time") - ): - _finish_time = datetime_to_iso8601(_finish_time) - container["instance_view"]["current_state"]["finished_time"] = _finish_time diff --git a/src/spaceone/inventory/manager/cosmos_db/__init__.py b/src/spaceone/inventory/manager/cosmos_db/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/cosmos_db/instance_manager.py b/src/spaceone/inventory/manager/cosmos_db/instance_manager.py deleted file mode 100644 index dadc059d..00000000 --- a/src/spaceone/inventory/manager/cosmos_db/instance_manager.py +++ /dev/null @@ -1,231 +0,0 @@ -import time -import logging -from spaceone.core.utils import * -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.cosmos_db import CosmosDBConnector -from spaceone.inventory.model.cosmos_db.cloud_service import * -from spaceone.inventory.model.cosmos_db.cloud_service_type import CLOUD_SERVICE_TYPES -from spaceone.inventory.model.cosmos_db.data import * - -_LOGGER = logging.getLogger(__name__) - - -class CosmosDBManager(AzureManager): - connector_name = "CosmosDBConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure cosmosdb data resource information - ErrorResourceResponse (list) : list of error resource information - - - """ - _LOGGER.debug(f"** CosmosDB START **") - - start_time = time.time() - subscription_info = params["subscription_info"] - cosmos_db_conn: CosmosDBConnector = self.locator.get_connector( - self.connector_name, **params - ) - - cosmos_db_account_responses = [] - error_responses = [] - - cosmos_db_accounts_list = cosmos_db_conn.list_all_cosmos_db_accounts() - - for cosmos_db_account in cosmos_db_accounts_list: - cosmos_db_account_id = "" - - try: - cosmos_db_account_dict = self.convert_nested_dictionary( - cosmos_db_account - ) - cosmos_db_account_id = cosmos_db_account_dict.get("id") - cosmos_db_account_dict["location"] = ( - cosmos_db_account_dict["location"].replace(" ", "").lower() - ) - - # update cosmosdb_dict - cosmos_db_account_dict = self.update_tenant_id_from_secret_data( - cosmos_db_account_dict, params["secret_data"] - ) - cosmos_db_account_dict.update( - { - "resource_group": self.get_resource_group_from_id( - cosmos_db_account_dict["id"] - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": cosmos_db_account_id}, - } - ) - - if cosmos_db_account_dict.get("capabilities") is not None: - cosmos_db_account_dict.update( - { - "capability_display": self.get_capability_type( - cosmos_db_account_dict["capabilities"] - ) - } - ) - - if cosmos_db_account_dict.get("virtual_network_rules") is not None: - cosmos_db_account_dict.update( - { - "virtual_network_display": self.get_virtual_networks( - cosmos_db_account_dict["virtual_network_rules"] - ) - } - ) - - if ( - cosmos_db_account_dict.get("private_endpoint_connections") - is not None - ): - for private_connection in cosmos_db_account_dict[ - "private_endpoint_connections" - ]: - private_connection.update( - { - "private_endpoint": self.get_private_endpoint_name( - private_connection["private_endpoint"] - ), - "name": self.get_private_connection_name( - private_connection["id"] - ), - } - ) - if cosmos_db_account_dict.get("cors") is not None: - cosmos_db_account_dict.update( - { - "cors_display": self.get_cors_display( - cosmos_db_account_dict["cors"] - ) - } - ) - - if cosmos_db_account_dict.get("name") is not None: - sql_databases = self.get_sql_resources( - cosmos_db_conn, - cosmos_db_account_dict["name"], - cosmos_db_account_dict["resource_group"], - ) - - cosmos_db_account_dict.update( - { - # "keys": self.get_keys( - # cosmos_db_conn, - # cosmos_db_account_dict["name"], - # cosmos_db_account_dict["resource_group"], - # ), - "sql_databases": sql_databases, - "sql_databases_count_display": len(sql_databases), - } - ) - - cosmos_db_account_data = DatabaseAccountGetResults( - cosmos_db_account_dict, strict=False - ) - cosmos_db_resource = CosmosDBResource( - { - "data": cosmos_db_account_data, - "tags": cosmos_db_account_dict.get("tags", {}), - "region_code": cosmos_db_account_data.location, - "reference": ReferenceModel(cosmos_db_account_data.reference()), - "name": cosmos_db_account_data.name, - "account": cosmos_db_account_data.subscription_id, - "instance_type": cosmos_db_account_data.database_account_offer_type, - "launched_at": datetime_to_iso8601( - cosmos_db_account_data.system_data.created_at - ), - } - ) - - # Must set_region_code method for region collection - self.set_region_code(cosmos_db_account_data["location"]) - cosmos_db_account_responses.append( - CosmosDBResponse({"resource": cosmos_db_resource}) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {cosmos_db_account_id} {e}", exc_info=True - ) - error_response = self.generate_resource_error_response( - e, "Database", "AzureCosmosDB", cosmos_db_account_id - ) - error_responses.append(error_response) - - _LOGGER.debug(f"** CosmosDB Finished {time.time() - start_time} Seconds **") - - return cosmos_db_account_responses, error_responses - - def get_keys(self, cosmos_db_conn, account_name, resource_group): - keys_obj = cosmos_db_conn.list_keys( - account_name=account_name, resource_group_name=resource_group - ) - key_dict = self.convert_nested_dictionary(keys_obj) - return key_dict - - def get_sql_resources(self, cosmos_db_conn, account_name, resource_group): - sql_resources = [] - sql_resources_obj = cosmos_db_conn.list_sql_resources( - account_name=account_name, resource_group_name=resource_group - ) - - for sql in sql_resources_obj: - sql_dict = self.convert_nested_dictionary(sql) - sql_resources.append(sql_dict) - return sql_resources - - @staticmethod - def get_capability_type(capabilities): - if capabilities: - capability_str_list = [] - for capability in capabilities: - capability_str_list.append(capability.get("name")) - - if "EnableServerless" in capability_str_list: - return "Serverless" - else: - return "Provisioned Throughput" - - @staticmethod - def get_virtual_networks(virtual_network_rules): - virtual_network_rules_display = [] - - for virtual_network in virtual_network_rules: - virtual_network_name = virtual_network["id"].split("/")[8] - virtual_network_rules_display.append(virtual_network_name) - - return virtual_network_rules_display - - @staticmethod - def get_private_endpoint_name(private_endpoint): - if private_endpoint.get("id") is not None: - private_endpoint.update({"name": private_endpoint["id"].split("/")[8]}) - return private_endpoint - - @staticmethod - def get_private_connection_name(private_connection_id): - private_connection_name = private_connection_id.split("/")[10] - return private_connection_name - - @staticmethod - def get_cors_display(cors_list): - cors_display = [] - - for cors in cors_list: - cors_display.append(cors.get("allowed_origins", "")) - return cors_display diff --git a/src/spaceone/inventory/manager/disks/__init__.py b/src/spaceone/inventory/manager/disks/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/disks/disk_manager.py b/src/spaceone/inventory/manager/disks/disk_manager.py deleted file mode 100644 index 46f25cfa..00000000 --- a/src/spaceone/inventory/manager/disks/disk_manager.py +++ /dev/null @@ -1,177 +0,0 @@ -import time -import logging -from spaceone.core.utils import * -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.model.disks.cloud_service import * -from spaceone.inventory.connector.disks import DisksConnector -from spaceone.inventory.model.disks.cloud_service_type import CLOUD_SERVICE_TYPES - -_LOGGER = logging.getLogger(__name__) - - -class DisksManager(AzureManager): - connector_name = "DisksConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure disk data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug(f"** Disk START **") - start_time = time.time() - subscription_info = params["subscription_info"] - - disk_conn: DisksConnector = self.locator.get_connector( - self.connector_name, **params - ) - disk_responses = [] - error_responses = [] - - disks = disk_conn.list_disks() - for disk in disks: - disk_id = "" - - try: - disk_dict = self.convert_nested_dictionary(disk) - disk_id = disk_dict["id"] - - # Switch DiskStorageAccountType to disk_sku_name for user-friendly words. (ex.Premium SSD, Standard HDD..) - if disk_dict.get("sku") is not None: - sku_dict = disk_dict["sku"] - sku_dict.update({"name": self.get_disk_sku_name(sku_dict["name"])}) - disk_dict.update({"sku": sku_dict}) - - # update disk_data dict - disk_dict.update( - { - "resource_group": self.get_resource_group_from_id( - disk_dict["id"] - ), # parse resource_group from ID - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "size": disk_dict["disk_size_bytes"], - "tier_display": self.get_tier_display( - disk_dict["disk_iops_read_write"], - disk_dict["disk_m_bps_read_write"], - ), - "azure_monitor": {"resource_id": disk_id}, - "time_created": datetime_to_iso8601(disk_dict["time_created"]), - } - ) - - # Update Network access policy to user-friendly words - if disk_dict.get("network_access_policy") is not None: - disk_dict.update( - { - "network_access_policy_display": self.get_network_access_policy( - disk_dict["network_access_policy"] - ) - } - ) - - # get attached vm's name - if disk_dict.get("managed_by") is not None: - managed_by = disk_dict["managed_by"] - disk_dict.update( - { - "managed_by": self.get_attached_vm_name_from_managed_by( - managed_by - ) - } - ) - - max_shares = disk_dict.get("max_shares") - if max_shares is not None and max_shares > 0: - disk_dict.update({"enable_shared_disk_display": True}) - - if disk_dict.get("bursting_enabled") is None: - disk_dict["bursting_enabled"] = False - - disk_dict = self.update_tenant_id_from_secret_data( - disk_dict, params.get("secret_data", {}) - ) - - disk_data = Disk(disk_dict, strict=False) - - disk_resource = DiskResource( - { - "data": disk_data, - "region_code": disk_data.location, - "reference": ReferenceModel(disk_data.reference()), - "tags": disk_dict.get("tags", {}), - "name": disk_data.name, - "account": disk_data.subscription_id, - "instance_type": disk_data.sku.name, - "instance_size": float(disk_data.disk_size_bytes), - } - ) - - # Must set_region_code method for region collection - self.set_region_code(disk_data["location"]) - # _LOGGER.debug(f'[DISK INFO: {disk_resource.to_primitive()}]') - disk_responses.append(DiskResponse({"resource": disk_resource})) - - except Exception as e: - _LOGGER.error(f"[list_instances] {disk_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, - resource_id=disk_id, - cloud_service_group="Compute", - cloud_service_type="Disk", - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** Disk Finished {time.time() - start_time} Seconds **") - return disk_responses, error_responses - - @staticmethod - def get_attached_vm_name_from_managed_by(managed_by): - attached_vm_name = managed_by.split("/")[8] - return attached_vm_name - - @staticmethod - def get_disk_sku_name(sku_tier): - if sku_tier == "Premium_LRS": - sku_name = "Premium SSD" - elif sku_tier == "StandardSSD_LRS": - sku_name = "Standard SSD" - elif sku_tier == "Standard_LRS": - sku_name = "Standard HDD" - else: - sku_name = "Ultra SSD" - return sku_name - - @staticmethod - def get_network_access_policy(network_access_policy): - network_access_policy_display = "" - if network_access_policy == "AllowAll": - network_access_policy_display = "Public endpoint (all network)" - elif network_access_policy == "AllowPrivate": - network_access_policy_display = "Private endpoint (through disk access)" - elif network_access_policy == "DenyAll": - network_access_policy_display = "Deny all" - - return network_access_policy_display - - @staticmethod - def get_tier_display(disk_iops_read_write, disk_m_bps_read_write): - tier_display = ( - str(disk_iops_read_write) - + " IOPS" - + ", " - + str(disk_m_bps_read_write) - + " Mbps" - ) - return tier_display diff --git a/src/spaceone/inventory/manager/key_vaults/__init__.py b/src/spaceone/inventory/manager/key_vaults/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/key_vaults/instance_manager.py b/src/spaceone/inventory/manager/key_vaults/instance_manager.py deleted file mode 100644 index f826373e..00000000 --- a/src/spaceone/inventory/manager/key_vaults/instance_manager.py +++ /dev/null @@ -1,235 +0,0 @@ -import time -import logging - -import azure.core.exceptions - -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.key_vaults import KeyVaultsConnector -from spaceone.inventory.model.key_vaults.cloud_service import * -from spaceone.inventory.model.key_vaults.cloud_service_type import CLOUD_SERVICE_TYPES -from spaceone.inventory.model.key_vaults.data import * - -_LOGGER = logging.getLogger(__name__) - - -class KeyVaultsManager(AzureManager): - connector_name = "KeyVaultsConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params: dict): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure key vault data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug(f"** Key Vault START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - key_vault_conn: KeyVaultsConnector = self.locator.get_connector( - self.connector_name, **params - ) - - key_vault_responses = [] - error_responses = [] - - key_vaults_obj_list = key_vault_conn.list_all_key_vaults() - - for key_vault in key_vaults_obj_list: - key_vault_id = "" - - try: - key_vault_dict = self.convert_nested_dictionary(key_vault) - key_vault_id = key_vault_dict["id"] - - key_vault_dict = self.update_tenant_id_from_secret_data( - key_vault_dict, params.get("secret_data", {}) - ) - - key_vault_dict.update( - { - "resource_group": self.get_resource_group_from_id( - key_vault_id - ), # parse resource_group from ID - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": key_vault_id}, - } - ) - - resource_group_name = key_vault_dict.get("resource_group", "") - subscription_id = key_vault_dict.get("subscription_id", "") - - # Get list of keys, secrets - if key_vault_dict.get("properties", {}).get("vault_uri") is not None: - vault_name = key_vault_dict["name"] - vault_uri = key_vault_dict["properties"]["vault_uri"] - - keys = self.list_keys( - key_vault_conn, resource_group_name, vault_name - ) - secrets, secrets_permissions_display = self.list_secrets( - key_vault_conn, subscription_id, vault_uri - ) - ( - certificates, - certificates_permissions_display, - ) = self.list_certificates( - key_vault_conn, subscription_id, vault_uri - ) - - key_vault_dict.update( - { - "keys": keys, - "secrets": secrets, - "certificates": certificates, - "key_count": len(keys), - "secret_count": len(secrets), - "certificate_count": len(certificates), - "total_credentials_count": len(keys) - + len(secrets) - + len(certificates), - "keys_permissions_description_display": "Microsoft.KeyVault/vaults/read", - "secrets_permissions_description_display": secrets_permissions_display, - "certificates_permissions_description_display": certificates_permissions_display, - } - ) - - # Get name of private connection from ID - if ( - key_vault_dict.get("properties", {}).get( - "private_endpoint_connections" - ) - is not None - ): - key_vault_dict["properties"].update( - { - "private_endpoint_connections": self.get_private_endpoint_name( - key_vault_dict["properties"][ - "private_endpoint_connections" - ] - ) - } - ) - - # Change purge protection to user-friendly word - if ( - key_vault_dict.get("properties", {}).get("enable_purge_protection") - is not None - ): - key_vault_dict["properties"].update( - { - "enable_purge_protection_str": "Disabled" - if key_vault_dict["properties"]["enable_purge_protection"] - is False - else "Enabled" - } - ) - if sku := key_vault_dict.get("properties", {}).get("sku"): - key_vault_dict["sku"] = sku - - # switch tags form - - key_vault_data = KeyVault(key_vault_dict, strict=False) - - key_vault_resource = KeyVaultResource( - { - "data": key_vault_data, - "region_code": key_vault_data.location, - "reference": ReferenceModel(key_vault_data.reference()), - "name": key_vault_data.name, - "instance_type": key_vault_data.properties.sku.name, - "account": key_vault_data.subscription_id, - "tags": key_vault_dict.get("tags", {}), - } - ) - - # Must set_region_code method for region collection - self.set_region_code(key_vault_data["location"]) - # _LOGGER.debug(f'[KEY VAULT INFO]{key_vault_resource.to_primitive()}') - key_vault_responses.append( - KeyVaultResponse({"resource": key_vault_resource}) - ) - - except Exception as e: - _LOGGER.error(f"[list_instances] {key_vault_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, "KeyVault", "KeyVault", key_vault_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** Key Vault Finished {time.time() - start_time} Seconds **") - return key_vault_responses, error_responses - - def list_keys(self, key_vault_conn, resource_group_name, vault_name): - keys = [] - keys_obj_list = key_vault_conn.list_keys( - resource_group_name=resource_group_name, vault_name=vault_name - ) - - if keys_obj_list: - for key in keys_obj_list: - key_dict = self.convert_nested_dictionary(key) - keys.append(key_dict) - return keys - - def list_secrets(self, key_vault_conn, subscription_id, vault_uri): - secrets = [] - permissions_display = "Microsoft.KeyVault/vaults/secrets/read, Microsoft.KeyVault/vaults/secrets/readMetadata/action" - - try: - key_vault_secret_client = key_vault_conn.init_key_vault_secret_client( - subscription_id=subscription_id, vault_uri=vault_uri - ) - - secrets_obj_list = key_vault_secret_client.list_properties_of_secrets() - - if secrets_obj_list: - for secret in secrets_obj_list: - secret_dict = self.convert_nested_dictionary(secret) - secrets.append(secret_dict) - except azure.core.exceptions.HttpResponseError as e: - _LOGGER.error(f"[list_secrets] {e}", exc_info=True) - permissions_display = "If you want to see the secretes list, please grant 'List' permission(Microsoft.KeyVault/vaults/secrets/read, Microsoft.KeyVault/vaults/secrets/readMetadata/action) to the service principal. or assign built-in role KeyVault Reader to the service principal.(https://learn.microsoft.com/en-us/azure/key-vault/general/rbac-guide?tabs=azure-cli#azure-built-in-roles-for-key-vault-data-plane-operations)" - return secrets, permissions_display - - def list_certificates(self, key_vault_conn, subscription_id, vault_uri): - certificates = [] - permissions_display = "Microsoft.KeyVault/vaults/secrets/readMetadata/action, Microsoft.KeyVault/vaults/certificates/read" - try: - key_vault_certificate_client = ( - key_vault_conn.init_key_vault_certificate_client( - subscription_id=subscription_id, vault_uri=vault_uri - ) - ) - - certificate_obj_list = ( - key_vault_certificate_client.list_properties_of_certificates() - ) - - if certificate_obj_list: - for certificate in certificate_obj_list: - secret_dict = self.convert_nested_dictionary(certificate) - certificates.append(secret_dict) - except azure.core.exceptions.HttpResponseError as e: - _LOGGER.error(f"[list_secrets] {e}", exc_info=True) - permissions_display = "If you want to see the secretes list, please grant 'List' permission(Microsoft.KeyVault/vaults/secrets/read, Microsoft.KeyVault/vaults/secrets/readMetadata/action) to the service principal. or assign built-in role 'KeyVault Reader' to the service principal.(https://learn.microsoft.com/en-us/azure/key-vault/general/rbac-guide?tabs=azure-cli#azure-built-in-roles-for-key-vault-data-plane-operations)" - - return certificates, permissions_display - - @staticmethod - def get_private_endpoint_name(private_endpoint_connections): - for private_endpoint in private_endpoint_connections: - private_endpoint.update({"name": private_endpoint["id"].split("/")[10]}) - return private_endpoint_connections diff --git a/src/spaceone/inventory/manager/load_balancers/__init__.py b/src/spaceone/inventory/manager/load_balancers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/load_balancers/instance_manager.py b/src/spaceone/inventory/manager/load_balancers/instance_manager.py deleted file mode 100644 index 26336136..00000000 --- a/src/spaceone/inventory/manager/load_balancers/instance_manager.py +++ /dev/null @@ -1,452 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.load_balancers import LoadBalancersConnector -from spaceone.inventory.model.load_balancers.cloud_service import * -from spaceone.inventory.model.load_balancers.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.load_balancers.data import * - -_LOGGER = logging.getLogger(__name__) - - -class LoadBalancersManager(AzureManager): - connector_name = "LoadBalancersConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ " - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure load balancer data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug(f"** LoadBalancer START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - load_balancer_conn: LoadBalancersConnector = self.locator.get_connector( - self.connector_name, **params - ) - load_balancer_responses = [] - error_responses = [] - load_balancers = load_balancer_conn.list_load_balancers() - - for load_balancer in load_balancers: - load_balancer_id = "" - - try: - load_balancer_dict = self.convert_nested_dictionary(load_balancer) - load_balancer_dict = self.update_tenant_id_from_secret_data( - load_balancer_dict, params["secret_data"] - ) - - load_balancer_id = load_balancer_dict["id"] - - load_balancer_dict.update( - { - "resource_group": self.get_resource_group_from_id( - load_balancer_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": load_balancer_id}, - } - ) - - # Get Network Interfaces attached in this load balancer - load_balancer_dict.update( - { - "network_interfaces": self.get_network_interfaces( - load_balancer_conn, - load_balancer_dict["resource_group"], - load_balancer_dict["name"], - ) - } - ) - - # Get Frontend IP Configurations information - if load_balancer_dict.get("frontend_ip_configurations") is not None: - private_ip_address_list = list() - used_by_list = list() - - for fic in load_balancer_dict["frontend_ip_configurations"]: - if fic.get( - "subnet" - ): # If the 'public' type, Skip this part because there isn't subnet information for them. - fic["subnet"][ - "address_prefix" - ] = self.get_frontend_address_prefix( - load_balancer_conn, fic["subnet"] - ) - fic["subnet"]["name"] = self.get_frontend_ip_subnet_name( - fic["subnet"]["id"] - ) - - # Get used inbound NAT rules - if fic.get("inbound_nat_rules") is not None: - load_balancer_dict.update( - { - "frontend_ip_configurations_used_by_display": self.get_frontend_ip_configurations_used_by_display( - used_by_list, fic["inbound_nat_rules"] - ) - } - ) - - # Get used load balancing NAT rules - if fic.get("load_balancing_rules") is not None: - load_balancer_dict.update( - { - "frontend_ip_configurations_used_by_display": self.get_frontend_ip_configurations_used_by_display( - used_by_list, fic["load_balancing_rules"] - ), - } - ) - - # Get all of private ip addresses - private_ip_address_list.append(fic["private_ip_address"]) - - load_balancer_dict.update( - {"private_ip_address_display": private_ip_address_list} - ) - - # Since Azure python sdk returns only one backend pool, delete the backend pool list first, and then use the new API connection - if load_balancer_dict.get("backend_address_pools") is not None: - load_balancer_dict["backend_address_pools"].clear() - load_balancer_dict.update( - { - "backend_address_pools": self.list_load_balancer_backend_address_pools( - load_balancer_conn, - load_balancer_dict["resource_group"], - load_balancer_dict["name"], - ) - } - ) - # get backend address pool's count - load_balancer_dict.update( - { - "backend_address_pools_count_display": self.get_backend_address_pools_count( - load_balancer_dict["backend_address_pools"] - ) - } - ) - - # Get load balancing Rules for display - if load_balancer_dict.get("load_balancing_rules") is not None: - load_balancer_dict.update( - { - "load_balancing_rules_display": self.get_load_balancing_rules_display( - load_balancer_dict["load_balancing_rules"] - ), - } - ) - - for lbr in load_balancer_dict["load_balancing_rules"]: - if lbr.get("backend_address_pool") is not None: - lbr.update( - { - "backend_address_pool_display": self.get_backend_address_pool_name( - lbr["backend_address_pool"] - ), - } - ) - - if lbr.get("load_distribution") is not None: - lbr.update( - { - "load_distribution_display": self.get_load_distribution_display( - lbr["load_distribution"] - ) - } - ) - - if lbr.get("frontend_ip_configuration") is not None: - lbr.update( - { - "frontend_ip_configuration_display": self.get_frontend_ip_configuration_display( - lbr["frontend_ip_configuration"] - ) - } - ) - - # Get Inbound NAT Rules for display - if load_balancer_dict.get("inbound_nat_rules") is not None: - load_balancer_dict.update( - { - "inbound_nat_rules_display": self.get_nat_rules_display( - load_balancer_dict["inbound_nat_rules"] - ) - } - ) - for inr in load_balancer_dict["inbound_nat_rules"]: - inr.update( - { - "frontend_ip_configuration_display": self.get_frontend_ip_configuration_display( - inr["frontend_ip_configuration"] - ), - "port_mapping_display": self.get_port_mapping_display( - inr["frontend_port"], inr["backend_port"] - ), - "target_virtual_machine": self.get_matched_vm_info( - inr["backend_ip_configuration"]["id"], - load_balancer_dict["network_interfaces"], - ), - } - ) - - # Get Health Probes for display - if load_balancer_dict.get("probes") is not None: - load_balancer_dict.update( - { - "probes_display": self.get_probe_display_list( - load_balancer_dict["probes"] - ) - } - ) - - load_balancer_data = LoadBalancer(load_balancer_dict, strict=False) - load_balancer_resource = LoadBalancerResource( - { - "data": load_balancer_data, - "region_code": load_balancer_data.location, - "reference": ReferenceModel(load_balancer_data.reference()), - "tags": load_balancer_dict.get("tags", {}), - "name": load_balancer_data.name, - "instance_type": load_balancer_data.sku.name, - "account": load_balancer_data.subscription_id, - } - ) - # Must set_region_code method for region collection - self.set_region_code(load_balancer_data["location"]) - - # _LOGGER.debug(f'[LOAD BALANCER INFO] {load_balancer_resource.to_primitive()}') - load_balancer_responses.append( - LoadBalancerResponse({"resource": load_balancer_resource}) - ) - - except Exception as e: - _LOGGER.error(f"[list_instances] {load_balancer_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, "Network", "LoadBalancer", load_balancer_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** LoadBalancer Finished {time.time() - start_time} Seconds **") - return load_balancer_responses, error_responses - - def get_network_interfaces(self, load_balancer_conn, rg_name, lb_name): - network_interface_object_list = list( - load_balancer_conn.list_load_balancer_network_interfaces(rg_name, lb_name) - ) - network_interface_list = [] - - # network_interfaces >> network_interfaces >> ip_configurations - for nil in network_interface_object_list: - network_interface_dict = self.convert_nested_dictionary(nil) - nic_rg_name = network_interface_dict.get("id", "").split("/")[4] - - if network_interface_dict.get("ip_configurations") is not None: - # Get LB's name, VMs name attached to Backend Pool - for ip_configuration in network_interface_dict["ip_configurations"]: - if ( - ip_configuration.get("load_balancer_backend_address_pools") - is not None - ): - for ic in ip_configuration[ - "load_balancer_backend_address_pools" - ]: - # Get backend address vm name - backend_pool_vm_name = ic["id"].split("/")[10] - - network_interface_dict.update( - { - "load_balancer_backend_address_pools_name_display": backend_pool_vm_name, - } - ) - - # Get the primary ip configuration from a network interface card - network_interface_dict.update( - { - "private_ip_display": self.get_ip_configuration_display( - network_interface_dict["ip_configurations"] - ) - } - ) - - # 2) Get VM's name which is attached to this network interface card - if network_interface_dict.get("virtual_machine") is not None: - network_interface_dict.update( - { - "virtual_machine_name_display": network_interface_dict[ - "virtual_machine" - ]["id"].split("/")[8] - } - ) - - network_interface_list.append(network_interface_dict) - - return network_interface_list - - def get_ip_configurations_list( - self, load_balancer_conn, rg_name, network_interface_name - ): - ip_configuration_list = [] - if network_interface_name: - ip_configurations_object = ( - load_balancer_conn.list_network_interface_ip_configurations( - rg_name, network_interface_name - ) - ) - ip_configurations_object_list = list(ip_configurations_object) - - if ip_configurations_object_list: - for ip_configuration_object in ip_configurations_object_list: - ip_object_dict = self.convert_nested_dictionary( - ip_configuration_object - ) - ip_configuration_list.append(ip_object_dict) - - return ip_configuration_list - - def list_load_balancer_backend_address_pools(self, conn, rg_name, lb_name): - backend_pools_list = list() # return result list - - backend_pools_object = conn.list_load_balancer_backend_address_pools( - rg_name, lb_name - ) - backend_pools_object_list = list( - backend_pools_object - ) # Since return type is ItemPagedClass, change to the list before convert dictionary - - # Loop for converting backend pools objects to dictionary - for bp in backend_pools_object_list: - backend_pool_dict = self.convert_nested_dictionary(bp) - backend_pools_list.append(backend_pool_dict) - - return backend_pools_list - - @staticmethod - def get_ip_configuration_display(ip_configurations_list): - ic_list = list() - for ic in ip_configurations_list: - ic_list.append(ic["private_ip_address"]) - return ic_list - - @staticmethod - def get_frontend_address_prefix(conn, subnet): - # Parse Vnet, LB name from subnet id - subnet_id = subnet["id"] - resource_group_name = subnet_id.split("/")[4] - vnet_name = subnet_id.split("/")[8] - subnet_name = subnet_id.split("/")[10] - - # API request for subnet dictionary - subnet = conn.get_subnets(resource_group_name, vnet_name, subnet_name) - - return subnet.address_prefix - - @staticmethod - def get_frontend_ip_subnet_name(subnet_id): - subnet_name = subnet_id.split("/")[10] - return subnet_name - - @staticmethod - def get_frontend_ip_configurations_used_by_display(used_by_list, used_object_list): - for used_object in used_object_list: - used_by_list.append(used_object["id"].split("/")[10]) - - return used_by_list - - @staticmethod - def get_backend_address_pools_count(backend_address_dict): - backend_address_pools_count = len(backend_address_dict) - - if backend_address_pools_count == 1: - backend_address_pools_count_display = ( - str(backend_address_pools_count) + " backend pool" - ) - else: - backend_address_pools_count_display = ( - str(backend_address_pools_count) + " backend pools" - ) - - return backend_address_pools_count_display - - @staticmethod - def get_matched_vm_info(find_key, find_list_pool): - matched_vm_list = list() - for find_object in find_list_pool: - if ( - find_object["id"] in find_key - ): # if network interface card's id matches to the backend configuration's id - if find_object.get("virtual_machine") is not None: - matched_vm_list.append( - (find_object["virtual_machine"]["id"]).split("/")[8] - ) - return matched_vm_list - - @staticmethod - def get_probe_display_list(probes_list): - probe_display_list = list() - for probe in probes_list: - probe_display_list.append(probe["name"]) - return probe_display_list - - @staticmethod - def get_load_balancing_rules_display(load_balancing_rules_list): - lbr_name_list = list() - for lbr in load_balancing_rules_list: - lbr_name_list.append( - lbr["name"] - ) # 'name' key always exists if there are load balancing rules. - - return lbr_name_list - - @staticmethod - def get_nat_rules_display(inbound_nat_rules_list): - nat_rules_list = list() - for inr in inbound_nat_rules_list: - nat_rules_list.append( - inr["name"] - ) # 'name' key always exists if there are inbound NAT rules. - - return nat_rules_list - - @staticmethod - def get_backend_address_pool_name( - lbr_backend_address_pool, - ): # id must exist if there is a backend address pool object - return lbr_backend_address_pool["id"].split("/")[10] - - @staticmethod - def get_load_distribution_display(lbr_load_distribution): - if lbr_load_distribution == "Default": - lbr_load_distribution_display = "None" - elif lbr_load_distribution == "SourceIPProtocol": - lbr_load_distribution_display = "Client IP and Protocol" - elif lbr_load_distribution == "SourceIP": - lbr_load_distribution_display = "Client IP" - - return lbr_load_distribution_display - - @staticmethod - def get_frontend_ip_configuration_display(lbr_frontend_ip_configuration_dict): - return lbr_frontend_ip_configuration_dict["id"].split("/")[10] - - @staticmethod - def get_port_mapping_display(frontend_port, backend_port): - if frontend_port == backend_port: - port_mapping_display = "Default" - else: - port_mapping_display = "Custom" - return port_mapping_display diff --git a/src/spaceone/inventory/manager/mysql_servers/__init__.py b/src/spaceone/inventory/manager/mysql_servers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/mysql_servers/server_manager.py b/src/spaceone/inventory/manager/mysql_servers/server_manager.py deleted file mode 100644 index 83868dda..00000000 --- a/src/spaceone/inventory/manager/mysql_servers/server_manager.py +++ /dev/null @@ -1,156 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.mysql_servers import MySQLServersConnector -from spaceone.inventory.model.mysql_servers.cloud_service import * -from spaceone.inventory.model.mysql_servers.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.mysql_servers.data import * - -_LOGGER = logging.getLogger(__name__) - - -class MySQLServersManager(AzureManager): - connector_name = "MySQLServersConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (dict) : dictionary of mysql servers data resource information - ErrorResourceResponse (list) : list of error resource information - """ - - _LOGGER.debug(f"** MySQL Servers START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - mysql_servers_conn: MySQLServersConnector = self.locator.get_connector( - self.connector_name, **params - ) - mysql_server_responses = [] - error_responses = [] - - mysql_servers_obj_list = mysql_servers_conn.list_servers() - - for mysql_server in mysql_servers_obj_list: - mysql_server_id = "" - - try: - mysql_server_dict = self.convert_nested_dictionary(mysql_server) - mysql_server_id = mysql_server_dict["id"] - - mysql_server_dict.update( - { - "resource_group": self.get_resource_group_from_id( - mysql_server_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": mysql_server_id}, - } - ) - - if mysql_server_dict.get("name") is not None: - resource_group = mysql_server_dict.get("resource_group", "") - server_name = mysql_server_dict["name"] - mysql_server_dict.update( - { - "firewall_rules": self.get_firewall_rules_by_server( - mysql_servers_conn, resource_group, server_name - ), - } - ) - - if mysql_server_dict.get("firewall_rules") is not None: - mysql_server_dict.update( - { - "allow_azure_services_access": self.get_azure_service_access( - mysql_server_dict["firewall_rules"] - ) - } - ) - - if mysql_server_dict.get("storage_profile") is not None: - mysql_server_dict["storage_profile"].update( - { - "storage_gb": self.get_storage_gb( - mysql_server_dict["storage_profile"].get( - "storage_mb", "" - ) - ) - } - ) - - mysql_server_data = MySQLServer(mysql_server_dict, strict=False) - mysql_server_resource = MySQLServerResource( - { - "data": mysql_server_data, - "tags": mysql_server_dict.get("tags", {}), - "region_code": mysql_server_data.location, - "reference": ReferenceModel(mysql_server_data.reference()), - "name": mysql_server_data.name, - "account": mysql_server_data.subscription_id, - "instance_type": mysql_server_data.sku.tier, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(mysql_server_data["location"]) - # _LOGGER.debug(f'[MYSQL SERVER INFO] {mysql_server_resource.to_primitive()}') - mysql_server_responses.append( - MySQLServerResponse({"resource": mysql_server_resource}) - ) - - except Exception as e: - _LOGGER.error(f"[list_instances] {mysql_server_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, "Database", "MySQLServer", mysql_server_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** MySQL Server Finished {time.time() - start_time} Seconds **") - return mysql_server_responses, error_responses - - def get_firewall_rules_by_server( - self, mysql_servers_conn, resource_group, server_name - ): - firewall_rules = [] - firewall_rules_obj = mysql_servers_conn.list_firewall_rules_by_server( - resource_group_name=resource_group, server_name=server_name - ) - for firewall_rule in firewall_rules_obj: - firewall_dict = self.convert_nested_dictionary(firewall_rule) - firewall_rules.append(firewall_dict) - - return firewall_rules - - @staticmethod - def get_azure_service_access(firewall_rules): - firewall_rule_name_list = [] - - for firewall_rule in firewall_rules: - if firewall_rule.get("name") is not None: - firewall_rule_name_list.append(firewall_rule["name"]) - - if "AllowAllWindowsAzureIps" in firewall_rule_name_list: - return True - - return False - - @staticmethod - def get_storage_gb(storage_mb): - if storage_mb: - storage_gb = int(storage_mb / 1024) - return storage_gb diff --git a/src/spaceone/inventory/manager/nat_gateways/__init__.py b/src/spaceone/inventory/manager/nat_gateways/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/nat_gateways/instance_manager.py b/src/spaceone/inventory/manager/nat_gateways/instance_manager.py deleted file mode 100644 index 9948eea6..00000000 --- a/src/spaceone/inventory/manager/nat_gateways/instance_manager.py +++ /dev/null @@ -1,200 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.nat_gateways import NATGatewaysConnector -from spaceone.inventory.model.nat_gateways.cloud_service import * -from spaceone.inventory.model.nat_gateways.cloud_service_type import CLOUD_SERVICE_TYPES -from spaceone.inventory.model.nat_gateways.data import * - -_LOGGER = logging.getLogger(__name__) - - -class NATGatewaysManager(AzureManager): - connector_name = "NATGatewaysConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (dict) : dictionary of azure nat gateway data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug(f"** NAT Gateway START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - nat_gateway_conn: NATGatewaysConnector = self.locator.get_connector( - self.connector_name, **params - ) - nat_gateway_responses = [] - error_responses = [] - - nat_gateways = nat_gateway_conn.list_all_nat_gateways() - - for nat_gateway in nat_gateways: - nat_gateway_id = "" - - try: - nat_gateway_dict = self.convert_nested_dictionary(nat_gateway) - nat_gateway_id = nat_gateway_dict["id"] - - if ( - sku_tier := nat_gateway_dict["sku"] - .get("additional_properties") - .get("tier") - ): - nat_gateway_dict["sku"]["tier"] = sku_tier - - nat_gateway_dict = self.update_tenant_id_from_secret_data( - nat_gateway_dict, params["secret_data"] - ) - - # update application_gateway_dict - nat_gateway_dict.update( - { - "resource_group": self.get_resource_group_from_id( - nat_gateway_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": nat_gateway_id}, - } - ) - - if nat_gateway_dict.get("public_ip_addresses") is not None: - # Get Count of Public IP Address - nat_gateway_dict.update( - { - "public_ip_addresses_count": len( - nat_gateway_dict["public_ip_addresses"] - ) - } - ) - - # Get Public IP Address Dictionary - if not nat_gateway_dict["public_ip_addresses"]: - break - - pip_list = [] - - for pip in nat_gateway_dict["public_ip_addresses"]: - public_ip_prefixes_id = pip["id"] - pip_dict = self.get_public_ip_address_dict( - nat_gateway_conn, public_ip_prefixes_id - ) - pip_list.append(pip_dict) - nat_gateway_dict["public_ip_addresses"] = pip_list - - if nat_gateway_dict.get("public_ip_prefixes") is not None: - nat_gateway_dict.update( - { - "public_ip_prefixes_count": len( - nat_gateway_dict["public_ip_addresses"] - ) - } - ) - - # Get Public IP Address Dictionary - if not nat_gateway_dict["public_ip_prefixes"]: - break - - pip_list = [] - - for pip in nat_gateway_dict["public_ip_prefixes"]: - public_ip_prefixes_id = pip["id"] - pip_dict = self.get_public_ip_prefixes_dict( - nat_gateway_conn, public_ip_prefixes_id - ) - pip_list.append(pip_dict) - - nat_gateway_dict["public_ip_prefixes"] = pip_list - - if nat_gateway_dict.get("subnets") is not None: - nat_gateway_dict.update( - { - "subnets": self.get_subnets( - nat_gateway_conn, nat_gateway_dict["subnets"] - ), - "subnets_count": len(nat_gateway_dict["subnets"]), - } - ) - - nat_gateway_data = NatGateway(nat_gateway_dict, strict=False) - nat_gateway_resource = NatGatewayResource( - { - "data": nat_gateway_data, - "tags": nat_gateway_dict.get("tags", {}), - "region_code": nat_gateway_data.location, - "reference": ReferenceModel(nat_gateway_data.reference()), - "name": nat_gateway_data.name, - "account": nat_gateway_data.subscription_id, - "instance_type": nat_gateway_data.sku.name, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(nat_gateway_data["location"]) - # _LOGGER.debug(f'[NAT GATEWAYS INFO] {nat_gateway_resource.to_primitive()}') - nat_gateway_responses.append( - NatGatewayResponse({"resource": nat_gateway_resource}) - ) - - except Exception as e: - _LOGGER.error(f"[list_instances] {nat_gateway_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, "Network", "NATGateway", nat_gateway_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** NAT Gateway Finished {time.time() - start_time} Seconds **") - return nat_gateway_responses, error_responses - - def get_public_ip_address_dict(self, nat_gateway_conn, pip_id): - pip_name = pip_id.split("/")[8] - resource_group_name = pip_id.split("/")[4] - pip_obj = nat_gateway_conn.get_public_ip_addresses( - resource_group_name=resource_group_name, public_ip_address_name=pip_name - ) - pip_dict = self.convert_nested_dictionary(pip_obj) - return pip_dict - - def get_public_ip_prefixes_dict(self, nat_gateway_conn, pip_id): - pip_name = pip_id.split("/")[8] - resource_group_name = pip_id.split("/")[4] - pip_obj = nat_gateway_conn.get_public_ip_prefixes( - resource_group_name=resource_group_name, public_ip_prefixes_name=pip_name - ) - - pip_dict = self.convert_nested_dictionary(pip_obj) - return pip_dict - - def get_subnets(self, nat_gateway_conn, subnets): - subnet_list = [] - - for subnet in subnets: - resource_group_name = subnet["id"].split("/")[4] - subnet_name = subnet["id"].split("/")[10] - vnet_name = subnet["id"].split("/")[8] - - subnet_obj = nat_gateway_conn.get_subnet( - resource_group_name=resource_group_name, - subnet_name=subnet_name, - vnet_name=vnet_name, - ) - subnet_dict = self.convert_nested_dictionary(subnet_obj) - subnet_dict.update({"virtual_network": vnet_name}) - - subnet_list.append(subnet_dict) - - return subnet_list diff --git a/src/spaceone/inventory/manager/network_security_groups/__init__.py b/src/spaceone/inventory/manager/network_security_groups/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/network_security_groups/instance_manager.py b/src/spaceone/inventory/manager/network_security_groups/instance_manager.py deleted file mode 100644 index 68e61580..00000000 --- a/src/spaceone/inventory/manager/network_security_groups/instance_manager.py +++ /dev/null @@ -1,317 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.network_security_groups import ( - NetworkSecurityGroupsConnector, -) -from spaceone.inventory.model.network_security_groups.cloud_service import * -from spaceone.inventory.model.network_security_groups.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.network_security_groups.data import * - -_LOGGER = logging.getLogger(__name__) - - -class NetworkSecurityGroupsManager(AzureManager): - connector_name = "NetworkSecurityGroupsConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure network security group data resource information - ErrorResourceResponse (list) : list of error resource information - - - """ - _LOGGER.debug("** Network Security Group START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - # cloud_service_info = self.get_cloud - - network_security_group_conn: NetworkSecurityGroupsConnector = ( - self.locator.get_connector(self.connector_name, **params) - ) - - network_security_group_responses = [] - error_responses = [] - network_security_groups = ( - network_security_group_conn.list_all_network_security_groups() - ) - network_interfaces = [ - self.convert_nested_dictionary(ni) - for ni in network_security_group_conn.list_all_network_interfaces() - ] - - for network_security_group in network_security_groups: - network_security_group_id = "" - - try: - network_security_group_dict = self.convert_nested_dictionary( - network_security_group - ) - network_security_group_id = network_security_group_dict["id"] - inbound_rules = [] - outbound_rules = [] - - if network_security_group_dict.get("security_rules") is not None: - # update custom security rules - inbound, outbound = self.split_security_rules( - network_security_group_dict, "security_rules" - ) - for ib in inbound: - inbound_rules.append(ib) - for ob in outbound: - outbound_rules.append(ob) - - # update default security rules - if ( - network_security_group_dict.get("default_security_rules") - is not None - ): - inbound, outbound = self.split_security_rules( - network_security_group_dict, "default_security_rules" - ) - for ib in inbound: - inbound_rules.append(ib) - for ob in outbound: - outbound_rules.append(ob) - - network_security_group_dict.update( - { - "inbound_security_rules": inbound_rules, - "outbound_security_rules": outbound_rules, - } - ) - # TODO : update network interface name - """ - # get network interfaces - if network_security_group_dict.get('network_interfaces') is not None: - new_network_interfaces_list, virtual_machines_display_str = self.get_network_interfaces(self, network_security_group_conn, network_security_group_dict['network_interfaces']) - network_security_group_dict['network_interfaces'] = new_network_interfaces_list # Remove existing list, append new list - network_security_group_dict.update({ - 'virtual_machines_display': virtual_machines_display_str - }) - """ - - virtual_machines_display_str = self.get_virtual_machine_name( - network_interfaces, network_security_group_id - ) - if virtual_machines_display_str is not None: - network_security_group_dict.update( - {"virtual_machines_display": virtual_machines_display_str} - ) - - # Change Subnet models to ID - if network_security_group_dict.get("network_interfaces") is not None: - self.replace_subnet_model_to_id( - network_security_group_dict["network_interfaces"] - ) - - # Get private ip address and public ip address - if network_security_group_dict.get("network_interfaces") is not None: - self.get_ip_addresses( - network_security_group_dict["network_interfaces"] - ) - - # Get Subnet information - if network_security_group_dict.get("subnets") is not None: - network_security_group_dict["subnets"] = self.get_subnet( - network_security_group_conn, - network_security_group_dict["subnets"], - ) - - if network_security_group_dict.get("subnets"): - for subnet in network_security_group_dict["subnets"]: - subnet.update( - { - "virtual_network": self.get_virtual_network( - subnet["id"] - ) - } - ) - - # update application_gateway_dict - network_security_group_dict = self.update_tenant_id_from_secret_data( - network_security_group_dict, params["secret_data"] - ) - network_security_group_dict.update( - { - "resource_group": self.get_resource_group_from_id( - network_security_group_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": network_security_group_id}, - } - ) - - network_security_group_data = NetworkSecurityGroup( - network_security_group_dict, strict=False - ) - - network_security_group_resource = NetworkSecurityGroupResource( - { - "data": network_security_group_data, - "tags": network_security_group_dict.get("tags", {}), - "region_code": network_security_group_data.location, - "reference": ReferenceModel( - network_security_group_data.reference() - ), - "name": network_security_group_data.name, - "account": network_security_group_data.subscription_id, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(network_security_group_data["location"]) - # _LOGGER.debug(f'[NETWORK SECURITY GROUP INFO] {network_security_group_resource.to_primitive()}') - network_security_group_responses.append( - NetworkSecurityGroupResponse( - {"resource": network_security_group_resource} - ) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {network_security_group_id} {e}", exc_info=True - ) - error_resource_response = self.generate_resource_error_response( - e, "Network", "NetworkSecurityGroup", network_security_group_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug( - f"** Network Security Group Finished {time.time() - start_time} Seconds **" - ) - return network_security_group_responses, error_responses - - def get_network_interfaces( - self, network_security_group_conn, network_interfaces_list - ): - network_interfaces_new_list = [] - virtual_machines_display_list = [] - virtual_machines_str = "" - - for network_interface in network_interfaces_list: - resource_group = network_interface["id"].split("/")[4] - network_interface_name = network_interface["id"].split("/")[ - 8 - ] # TODO : network interface name diverse - network_interface_obj = network_security_group_conn.get_network_interfaces( - network_interface_name, resource_group - ) - network_interface_dict = self.convert_nested_dictionary( - network_interface_obj - ) - - if network_interface_dict["id"] == network_interface["id"]: - # Get virtual machine display - if network_interface_dict.get("virtual_machine") is not None: - virtual_machine_display = network_interface_dict["virtual_machine"][ - "id" - ].split("/")[8] - virtual_machines_display_list.append(virtual_machine_display) - network_interface_dict.update( - {"virtual_machine_display": virtual_machine_display} - ) - network_interfaces_new_list.append(network_interface_dict) - virtual_machines_str = ", ".join(virtual_machines_display_list) - - return network_interfaces_new_list, virtual_machines_str - - def get_subnet(self, network_security_group_conn, subnets_list): - subnets_full_list = [] - if subnets_list: - for subnet in subnets_list: - resource_group_name = subnet["id"].split("/")[4] - subnet_name = subnet["id"].split("/")[10] - virtual_network_name = subnet["id"].split("/")[8] - - subnet_obj = network_security_group_conn.get_subnet( - resource_group_name, subnet_name, virtual_network_name - ) - subnet_dict = self.convert_nested_dictionary(subnet_obj) - subnets_full_list.append(subnet_dict) - - return subnets_full_list - return - - @staticmethod - def split_security_rules(network_security_group_dict, mode): - inbound_security_rules = [] - outbound_security_rules = [] - rule_list = [] - - if mode == "security_rules": - rule_list = network_security_group_dict["security_rules"] - elif mode == "default_security_rules": - rule_list = network_security_group_dict["default_security_rules"] - - for security_rule in rule_list: - if security_rule.get("direction", "") == "Inbound": - inbound_security_rules.append(security_rule) - elif security_rule.get("direction", "") == "Outbound": - outbound_security_rules.append(security_rule) - - return inbound_security_rules, outbound_security_rules - - @staticmethod - def replace_subnet_model_to_id(network_interfaces_list): - for network_interface in network_interfaces_list: - if network_interface.get("ip_configurations") is not None: - for ip_configuration in network_interface["ip_configurations"]: - ip_configuration["subnet"] = ip_configuration.get("subnet", {}).get( - "id", "" - ) - return - - @staticmethod - def get_ip_addresses(network_interfaces_list): - if network_interfaces_list: - for network_interface in network_interfaces_list: - if network_interface.get("ip_configurations") is not None: - for ip_configuration in network_interface["ip_configurations"]: - private_ip_address = ip_configuration["private_ip_address"] - network_interface.update( - {"private_ip_address": private_ip_address} - ) - - if ip_configuration.get("public_ip_address") is not None: - public_ip_address = ip_configuration["public_ip_address"][ - "id" - ].split("/")[8] - network_interface.update( - { - "public_ip_address": public_ip_address, - } - ) - return - - @staticmethod - def get_virtual_network(subnet_id): - virtual_network = subnet_id.split("/")[8] - return virtual_network - - @staticmethod - def get_virtual_machine_name(network_interfaces, network_security_group_id): - virtual_machine_name = None - for network_interface in network_interfaces: - if _network_security_group := network_interface["network_security_group"]: - if ( - _network_security_group["id"].split("/")[-1] - == network_security_group_id.split("/")[-1] - ): - return virtual_machine_name - return virtual_machine_name diff --git a/src/spaceone/inventory/manager/postgresql_servers/__init__.py b/src/spaceone/inventory/manager/postgresql_servers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/postgresql_servers/server_manager.py b/src/spaceone/inventory/manager/postgresql_servers/server_manager.py deleted file mode 100644 index 5878c0c1..00000000 --- a/src/spaceone/inventory/manager/postgresql_servers/server_manager.py +++ /dev/null @@ -1,229 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.postgresql_servers import PostgreSQLServersConnector -from spaceone.inventory.model.postgresql_servers.cloud_service import * -from spaceone.inventory.model.postgresql_servers.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.postgresql_servers.data import * - -_LOGGER = logging.getLogger(__name__) - - -class PostgreSQLServersManager(AzureManager): - connector_name = "PostgreSQLServersConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure postgresql servers data resource information - ErrorResourceResponse (list) : list of error resource information - - - """ - _LOGGER.debug(f"** Postgre SQL Servers START **") - - start_time = time.time() - - subscription_info = params["subscription_info"] - postgre_sql_conn: PostgreSQLServersConnector = self.locator.get_connector( - self.connector_name, **params - ) - postgre_sql_server_responses = [] - error_responses = [] - postgre_sql_servers = postgre_sql_conn.list_servers() - - for postgre_sql_server in postgre_sql_servers: - postgre_sql_server_id = "" - - try: - postgre_sql_server_dict = self.convert_nested_dictionary( - postgre_sql_server - ) - postgre_sql_server_id = postgre_sql_server_dict["id"] - - # update application_gateway_dict - postgre_sql_server_dict = self.update_tenant_id_from_secret_data( - postgre_sql_server_dict, params["secret_data"] - ) - postgre_sql_server_dict.update( - { - "resource_group": self.get_resource_group_from_id( - postgre_sql_server_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": postgre_sql_server_id}, - } - ) - - if postgre_sql_server_dict.get("name") is not None: - resource_group = postgre_sql_server_dict["resource_group"] - server_name = postgre_sql_server_dict["name"] - postgre_sql_server_dict.update( - { - "firewall_rules": self.list_firewall_rules_by_server( - postgre_sql_conn, resource_group, server_name - ), - "virtual_network_rules": self.list_virtual_network_rules_by_server( - postgre_sql_conn, resource_group, server_name - ), - "replicas": self.list_replicas_by_server( - postgre_sql_conn, resource_group, server_name - ), - "server_administrators": self.list_server_administrators( - postgre_sql_conn, resource_group, server_name - ), - } - ) - - postgre_sql_server_data = PostgreSQLServer( - postgre_sql_server_dict, strict=False - ) - postgre_sql_server_resource = PostgreSQLServerResource( - { - "data": postgre_sql_server_data, - "region_code": postgre_sql_server_data.location, - "reference": ReferenceModel( - postgre_sql_server_data.reference() - ), - "tags": postgre_sql_server_dict.get("tags", {}), - "name": postgre_sql_server_data.name, - "account": postgre_sql_server_data.subscription_id, - "instance_type": postgre_sql_server_data.sku.tier, - "instance_size": float( - postgre_sql_server_data.storage_profile.storage_mb - ), - } - ) - - # Must set_region_code method for region collection - self.set_region_code(postgre_sql_server_data["location"]) - # _LOGGER.debug(f'[POSTGRESQL SERVERS INFO] {postgre_sql_server_resource.to_primitive()}') - postgre_sql_server_responses.append( - PostgreSQLServerResponse({"resource": postgre_sql_server_resource}) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {postgre_sql_server_id} {e}", exc_info=True - ) - error_resource_response = self.generate_resource_error_response( - e, "Database", "PostgreSQLServer", postgre_sql_server_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug( - f"** PostgreSQLServer Finished {time.time() - start_time} Seconds **" - ) - return postgre_sql_server_responses, error_responses - - def get_sql_resources(self, cosmos_db_conn, account_name, resource_group): - sql_resources = [] - sql_resources_obj = cosmos_db_conn.list_sql_resources( - account_name=account_name, resource_group_name=resource_group - ) - - for sql in sql_resources_obj: - sql_dict = self.convert_nested_dictionary(sql) - sql_resources.append(sql_dict) - return sql_resources - - def list_firewall_rules_by_server(self, postgresql_conn, resource_group, name): - firewall_rules = [] - firewall_rules_obj = postgresql_conn.list_firewall_rules_by_server( - resource_group_name=resource_group, server_name=name - ) - - for firewall_rule in firewall_rules_obj: - firewall_rule_dict = self.convert_nested_dictionary(firewall_rule) - firewall_rules.append(firewall_rule_dict) - - return firewall_rules - - def list_virtual_network_rules_by_server( - self, postgresql_conn, resource_group, name - ): - virtual_network_rules = [] - virtual_network_rules_obj = ( - postgresql_conn.list_virtual_network_rules_by_server( - resource_group_name=resource_group, server_name=name - ) - ) - - for virtual_network in virtual_network_rules_obj: - virtual_network_dict = self.convert_nested_dictionary(virtual_network) - if virtual_network_dict.get("virtual_network_subnet_id") is not None: - virtual_network_dict.update( - { - "subnet_name": self.get_subnet_name( - virtual_network_dict["virtual_network_subnet_id"] - ), - "virtual_network_name_display": self.get_virtual_network_name( - virtual_network_dict["virtual_network_subnet_id"] - ), - } - ) - virtual_network_rules.append(virtual_network_dict) - - return virtual_network_rules - - def list_replicas_by_server(self, postgresql_conn, resource_group, name): - replicas_list = [] - replicas_obj = postgresql_conn.list_replicas_by_server( - resource_group_name=resource_group, server_name=name - ) - for replica in replicas_obj: - replica_dict = self.convert_nested_dictionary(replica) - if replica_dict.get("master_server_id") is not None: - replica_dict.update( - { - "master_server_name": self.get_replica_master_server_name( - replica_dict["master_server_id"] - ) - } - ) - - replicas_list.append(replica_dict) - return replicas_list - - def list_server_administrators(self, postgresql_conn, resource_group, name): - server_administrators = [] - server_admin_obj = postgresql_conn.list_server_administrators( - resource_group_name=resource_group, server_name=name - ) - for server_admin in server_admin_obj: - server_admin_dict = self.convert_nested_dictionary(server_admin) - server_administrators.append(server_admin_dict) - - return server_administrators - - @staticmethod - def get_subnet_name(subnet_id): - subnet_name = "" - if subnet_id: - subnet_name = subnet_id.split("/")[10] - return subnet_name - - @staticmethod - def get_virtual_network_name(subnet_id): - virtual_network_name = "" - if subnet_id: - virtual_network_name = subnet_id.split("/")[8] - return virtual_network_name - - @staticmethod - def get_replica_master_server_name(master_server_id): - master_server_name = master_server_id.split("/")[8] - return master_server_name diff --git a/src/spaceone/inventory/manager/public_ip_addresses/__init__.py b/src/spaceone/inventory/manager/public_ip_addresses/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/public_ip_addresses/ip_address_manager.py b/src/spaceone/inventory/manager/public_ip_addresses/ip_address_manager.py deleted file mode 100644 index 17873a44..00000000 --- a/src/spaceone/inventory/manager/public_ip_addresses/ip_address_manager.py +++ /dev/null @@ -1,114 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.public_ip_addresses import PublicIPAddressesConnector -from spaceone.inventory.model.public_ip_addresses.cloud_service import * -from spaceone.inventory.model.public_ip_addresses.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.public_ip_addresses.data import * - -_LOGGER = logging.getLogger(__name__) - - -class PublicIPAddressesManager(AzureManager): - connector_name = "PublicIPAddressesConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure public ip address data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug("** Public IP Address START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - public_ip_address_conn: PublicIPAddressesConnector = self.locator.get_connector( - self.connector_name, **params - ) - public_ip_address_responses = [] - error_responses = [] - - public_ip_addresses_list = public_ip_address_conn.list_all_public_ip_addresses() - - for public_ip_address in public_ip_addresses_list: - public_ip_address_id = "" - - try: - public_ip_address_dict = self.convert_nested_dictionary( - public_ip_address - ) - public_ip_address_id = public_ip_address_dict["id"] - - # update application_gateway_dict - public_ip_address_dict.update( - { - "resource_group": self.get_resource_group_from_id( - public_ip_address_id - ), - # parse resource_group from ID - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": public_ip_address_id}, - } - ) - - if public_ip_address_dict.get("ip_configuration") is not None: - associated_to = public_ip_address_dict["ip_configuration"][ - "id" - ].split("/")[8] - if associated_to: - public_ip_address_dict.update({"associated_to": associated_to}) - - public_ip_address_dict = self.update_tenant_id_from_secret_data( - public_ip_address_dict, params.get("secret_data", {}) - ) - - public_ip_address_data = PublicIPAddress( - public_ip_address_dict, strict=False - ) - public_ip_address_resource = PublicIPAddressResource( - { - "data": public_ip_address_data, - "tags": public_ip_address_dict.get("tags", {}), - "region_code": public_ip_address_data.location, - "reference": ReferenceModel(public_ip_address_data.reference()), - "name": public_ip_address_data.name, - "account": public_ip_address_data.subscription_id, - "instance_type": public_ip_address_data.sku.name, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(public_ip_address_data["location"]) - # _LOGGER.debug(f'[PUBLIC IP ADDRESS INFO IN PIP MANAGER] {public_ip_address_resource.to_primitive()}') - public_ip_address_responses.append( - PublicIPAddressResponse({"resource": public_ip_address_resource}) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {public_ip_address_id} {e}", exc_info=True - ) - error_resource_response = self.generate_resource_error_response( - e, "Network", "PublicIPAddress", public_ip_address_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug( - f"** Public IP Address Finished {time.time() - start_time} Seconds **" - ) - return public_ip_address_responses, error_responses diff --git a/src/spaceone/inventory/manager/resources_manager/__init__.py b/src/spaceone/inventory/manager/resources_manager/__init__.py deleted file mode 100644 index 8b137891..00000000 --- a/src/spaceone/inventory/manager/resources_manager/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/spaceone/inventory/manager/resources_manager/resource_manager.py b/src/spaceone/inventory/manager/resources_manager/resource_manager.py deleted file mode 100644 index 86372dd0..00000000 --- a/src/spaceone/inventory/manager/resources_manager/resource_manager.py +++ /dev/null @@ -1,27 +0,0 @@ -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.connector.resources import ResourcesConnector - -_LOGGER = logging.getLogger(__name__) - - -class ResourcesManager(AzureManager): - connector_name = "ResourcesConnector" - - def collect_exist_resources(self, params: dict) -> list: - """ " """ - - resources_info = [] - resources_conn: ResourcesConnector = self.locator.get_connector( - self.connector_name, **params - ) - - resources_obj = resources_conn.list_resources() - - for resource_obj in resources_obj: - resource_info = self.convert_nested_dictionary(resource_obj) - type = resource_info.get("type").split("/")[1] - if type not in resources_info: - resources_info.append(type) - - return resources_info diff --git a/src/spaceone/inventory/manager/snapshots/__init__.py b/src/spaceone/inventory/manager/snapshots/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/snapshots/instance_manager.py b/src/spaceone/inventory/manager/snapshots/instance_manager.py deleted file mode 100644 index f5157356..00000000 --- a/src/spaceone/inventory/manager/snapshots/instance_manager.py +++ /dev/null @@ -1,208 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.model.snapshots.cloud_service import * -from spaceone.inventory.connector.snapshots import SnapshotsConnector -from spaceone.inventory.model.snapshots.cloud_service_type import CLOUD_SERVICE_TYPES -from spaceone.core.utils import * - -_LOGGER = logging.getLogger(__name__) - - -class SnapshotsManager(AzureManager): - connector_name = "SnapshotsConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure snapshot data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug("** Snapshot START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - snapshot_conn: SnapshotsConnector = self.locator.get_connector( - self.connector_name, **params - ) - snapshot_responses = [] - error_responses = [] - - snapshots = snapshot_conn.list_snapshots() - - for snapshot in snapshots: - snapshot_id = "" - try: - snapshot_dict = self.convert_nested_dictionary(snapshot) - snapshot_id = snapshot_dict["id"] - - # update sku_dict - # switch SnapshotStorageAccountType to snapshot_sku_name for user-friendly words. - # (ex.Premium_LRS -> Premium SSD, Standard HDD..) - sku_dict = snapshot_dict.get("sku", {}) - sku_dict.update( - {"name": self.get_disk_sku_name(sku_dict.get("name", ""))} - ) - - # update encryption_dict type to user-friendly words - # (ex.EncryptionAtRestWithPlatformKey -> Platform-managed key...) - if snapshot_dict.get("encryption", {}).get("type") is not None: - type = snapshot_dict["encryption"]["type"] - encryption_type = "" - if type == "EncryptionAtRestWithPlatformKey": - encryption_type = "Platform-managed key" - elif type == "EncryptionAtRestWithPlatformAndCustomerKeys": - encryption_type = "Platform and customer managed key" - elif type == "EncryptionAtRestWithCustomerKey": - encryption_type = "Customer-managed key" - - snapshot_dict["encryption"].update( - {"type_display": encryption_type} - ) - - # update snapshot_dict - snapshot_dict = self.update_tenant_id_from_secret_data( - snapshot_dict, params["secret_data"] - ) - snapshot_dict.update( - { - "resource_group": self.get_resource_group_from_id( - snapshot_id - ), # parse resource_group from ID - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "size": snapshot_dict["disk_size_bytes"], - "sku": sku_dict, - "incremental_display": self.get_incremental_display( - snapshot_dict["incremental"] - ), - "azure_monitor": {"resource_id": snapshot_id}, - "time_created": datetime_to_iso8601( - snapshot_dict["time_created"] - ), - } - ) - - if snapshot_dict.get("network_access_policy") is not None: - snapshot_dict.update( - { - "network_access_policy_display": self.get_network_access_policy( - snapshot_dict["network_access_policy"] - ) - } - ) - - # get attached vm's name - if snapshot_dict.get("managed_by") is not None: - snapshot_dict.update( - { - "managed_by": self.get_attached_vm_name_from_managed_by( - snapshot_dict["managed_by"] - ) - } - ) - - # get source_disk_name from source_resource_id - if snapshot_dict.get("creation_data") is not None: - source_resource_id = snapshot_dict["creation_data"].get( - "source_resource_id", "" - ) - snapshot_dict.update( - { - "source_disk_name": self.get_source_disk_name( - source_resource_id - ) - } - ) - - snapshot_data = Snapshot(snapshot_dict, strict=False) - snapshot_resource = SnapshotResource( - { - "data": snapshot_data, - "region_code": snapshot_data.location, - "reference": ReferenceModel(snapshot_data.reference()), - "tags": snapshot_dict.get("tags", {}), - "name": snapshot_data.name, - "account": snapshot_data.subscription_id, - "instance_size": float(snapshot_data.disk_size_bytes), - "instance_type": snapshot_data.sku.name, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(snapshot_data["location"]) - # _LOGGER.debug(f'[SNAPSHOT INFO] {snapshot_resource.to_primitive()}') - snapshot_responses.append( - SnapshotResponse({"resource": snapshot_resource}) - ) - - except Exception as e: - _LOGGER.error(f"[list_instances] {snapshot_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, "Compute", "Snapshot", snapshot_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** Snapshot Finished {time.time() - start_time} Seconds **") - return snapshot_responses, error_responses - - @staticmethod - def get_attached_vm_name_from_managed_by(managed_by): - attached_vm_name = "" - if managed_by: - attached_vm_name = managed_by.split("/")[8] # parse attached_ from ID - return attached_vm_name - - @staticmethod - def get_disk_sku_name(sku_tier): - sku_name = "" - if sku_tier == "Premium_LRS": - sku_name = "Premium SSD" - elif sku_tier == "Standard_ZRS": - sku_name = "Standard zone" - elif sku_tier == "Standard_LRS": - sku_name = "Standard HDD" - - return sku_name - - @staticmethod - def get_network_access_policy(network_access_policy): - network_access_policy_display = "" - if network_access_policy == "AllowAll": - network_access_policy_display = "Public endpoint (all network)" - elif network_access_policy == "AllowPrivate": - network_access_policy_display = "Private endpoint (through disk access)" - elif network_access_policy == "DenyAll": - network_access_policy_display = "Deny all" - - return network_access_policy_display - - @staticmethod - def get_incremental_display(incremental): - if incremental is False: - incremental_display = "Full" - else: - incremental_display = "Incremental" - - return incremental_display - - @staticmethod - def get_source_disk_name(source_resource_id): - source_disk_name = "" - if source_resource_id: - source_disk_name = source_resource_id.split("/")[ - 8 - ] # parse source_disk_name from source_resource_id - return source_disk_name diff --git a/src/spaceone/inventory/manager/sql_databases/__init__.py b/src/spaceone/inventory/manager/sql_databases/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/sql_databases/database_manager.py b/src/spaceone/inventory/manager/sql_databases/database_manager.py deleted file mode 100644 index 19dd98d7..00000000 --- a/src/spaceone/inventory/manager/sql_databases/database_manager.py +++ /dev/null @@ -1,272 +0,0 @@ -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.model.sql_databases.cloud_service import * -from spaceone.inventory.model.sql_databases.cloud_service_type import CLOUD_SERVICE_TYPES -from spaceone.inventory.model.sql_databases.data import * -from spaceone.inventory.connector.sql_databases import SQLDatabasesConnector -from spaceone.inventory.connector.monitor import MonitorConnector -from spaceone.core.utils import * - -_LOGGER = logging.getLogger(__name__) - - -class SQLDatabasesManager(AzureManager): - connector_name = 'SQLDatabasesConnector' - monitor_connector_name = 'MonitorConnector' - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure sql databases data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug(f'** SQL Databases START *') - start_time = time.time() - - subscription_info = params['subscription_info'] - sql_databases_conn: SQLDatabasesConnector = self.locator.get_connector(self.connector_name, **params) - sql_monitor_conn: MonitorConnector = self.locator.get_connector(self.monitor_connector_name, **params) - - sql_database_responses = [] - error_responses = [] - - sql_servers = sql_databases_conn.list_servers() - for sql_server in sql_servers: - sql_database_id = '' - try: - sql_server_dict = self.convert_nested_dictionary(sql_server) - - # get resource_group_name and server_name from sql_server for sql_databases list - server_name = sql_server_dict['name'] - resource_group_name = self.get_resource_group_from_id(sql_server_dict['id']) - server_admin_name = sql_server_dict.get('administrator_login') - - # get list - sql_databases = sql_databases_conn.list_databases_in_server(resource_group_name, server_name) - replication_links = self.list_replication_links( - sql_databases_conn.list_replication_link_by_server(resource_group_name=resource_group_name, - server_name=server_name)) - - # database for loop - for sql_database in sql_databases: - sql_database_dict = self.convert_nested_dictionary(sql_database) - database_name = sql_database_dict['name'] - current_sku_tier = sql_database_dict.get('current_sku').get('tier') - - if sql_database_dict.get('sku'): - if sql_database_dict.get('name') != 'master': # No pricing tier for system database - sql_database_dict.update({ - 'pricing_tier_display': self.get_pricing_tier_display(sql_database_dict['sku']), - 'service_tier_display': sql_database_dict['sku'].get('tier') - }) - if db_id := sql_database_dict.get('id'): - sql_database_dict.update({ - 'server_name': db_id.split('/')[8], - 'subscription_id': db_id.split('/')[2], - 'resource_group': db_id.split('/')[4], - 'azure_monitor': {'resource_id': db_id} - }) - - if compute_tier := sql_database_dict.get('kind'): - sql_database_dict.update({ - 'compute_tier': self.get_db_compute_tier(compute_tier) - }) - - if sql_database_dict.get('max_size_bytes'): - sql_database_dict.update({ - 'max_size_gb': sql_database_dict['max_size_bytes'] / 1073741824 # 2^30 - }) - - # Get Sync Groups by databases - if current_sku_tier != 'DataWarehouse': - sql_database_sync_groups = sql_databases_conn.list_sync_groups_by_databases( - resource_group=resource_group_name, - server_name=server_name, - database_name=database_name) - - sql_database_dict.update({ - 'sync_group': self.get_sync_group_by_databases(sql_database_sync_groups) - }) - - if sql_database_dict.get('sync_group'): - sql_database_dict.update({ - 'sync_group_display': self.get_sync_group_display(sql_database_dict['sync_group']) - }) - - # Get Sync Agents by servers - sql_database_dict.update({ - 'sync_agent': self.get_sync_agent_by_servers(sql_databases_conn, resource_group_name, - server_name) - }) - - if sql_database_dict['sync_agent']: - sql_database_dict.update({ - 'sync_agent_display': self.get_sync_agent_display(sql_database_dict['sync_agent']) - }) - ''' - # Get Data masking rules - database_dict.update({ - 'data_masking_rules': self.list_data_masking_rules(self, sql_servers_conn, rg_name, server_name, database_dict['name']) - }) - ''' - - # Get Diagnostic Settings - sql_database_dict.update({ - 'diagnostic_settings_resource': self.list_diagnostics_settings(sql_monitor_conn, - sql_database_dict['id']) - }) - - # Get Database Replication Type - sql_database_dict.update({ - 'replication_link': self.list_replication_link_in_database(replication_links, - database_name=database_name) - }) - - # Get azure_ad_admin name - if server_admin_name is not None: - sql_database_dict.update({ - 'administrator_login': server_admin_name - }) - - # Get Database Auditing settings - sql_database_dict.update({ - 'database_auditing_settings': self.get_database_auditing_settings(sql_databases_conn, - resource_group_name, - server_name, - database_name=database_name) - }) - - sql_database_dict.update({ - 'resource_group': resource_group_name, - 'subscription_id': subscription_info['subscription_id'], - 'subscription_name': subscription_info['subscription_name'], - 'azure_monitor': {'resource_id': sql_database_id} - }) - - sql_database_data = SQLDatabase(sql_database_dict, strict=False) - sql_database_resource = SQLDatabaseResource({ - 'name': database_name, - 'region_code': sql_database_data.location, - 'reference': ReferenceModel(sql_database_data.reference()), - 'data': sql_database_data, - 'account': subscription_info['subscription_id'], - 'instance_type': sql_database_data.sku.tier, - 'instance_size': float(sql_database_data.max_size_gb), - 'launched_at': datetime_to_iso8601(sql_database_data.creation_date), - 'tags': sql_database_dict.get('tags', {}) - }) - - # Must set_region_code method for region collection - self.set_region_code(sql_database_dict['location']) - - sql_database_responses.append(SQLDatabaseResponse({'resource': sql_database_resource})) - - except Exception as e: - _LOGGER.error(f'[list_instances] {sql_database_id} {e}', exc_info=True) - error_resource_response = self.generate_resource_error_response(e, 'Database', 'SQLDatabse', - sql_database_id) - error_responses.append(error_resource_response) - - _LOGGER.debug(f'** SQL Databases Finished {time.time() - start_time} Seconds **') - return sql_database_responses, error_responses - - def get_sync_group_by_databases(self, replication_links_from_params: list) -> list: - sync_groups = [] - for sync_group in replication_links_from_params: - sync_group_dict = self.convert_nested_dictionary(sync_group) - sync_group_dict['automatic_sync'] = True if sync_group_dict['interval'] > 0 else True - sync_groups.append(sync_group_dict) - - return sync_groups - - def get_sync_agent_by_servers(self, sql_servers_conn, rg_name, server_name): - sync_agent_list = list() - sync_agent_obj = sql_servers_conn.list_sync_agents_by_server(rg_name, server_name) - - for sync_agent in sync_agent_obj: - sync_agent_dict = self.convert_nested_dictionary(sync_agent) - sync_agent_list.append(sync_agent_dict) - - return sync_agent_list - - def list_diagnostics_settings(self, sql_monitor_conn, resource_uri): - diagnostic_settings_list = list() - diagnostic_settings_objs = sql_monitor_conn.list_diagnostic_settings(resource_uri=resource_uri) - - for diagnostic_setting in diagnostic_settings_objs: - diagnostic_setting_dict = self.convert_nested_dictionary(diagnostic_setting) - diagnostic_settings_list.append(diagnostic_setting_dict) - - return diagnostic_settings_list - - def list_replication_links(self, replication_links_from_params) -> list: - replication_links = [] - for replication_link in replication_links_from_params: - replication_link_dict = self.convert_nested_dictionary(replication_link) - replication_link_dict['replica_state'] = 'Online' if replication_link_dict['role'] == 'Primary' \ - else 'Readable' - replication_links.append(replication_link_dict) - - return replication_links - - def get_database_auditing_settings(self, sql_databases_conn, resource_group_name, server_name, database_name): - database_auditing_settings = sql_databases_conn.get_database_auditing_settings( - resource_group_name=resource_group_name, - server_name=server_name, - database_name=database_name) - return self.convert_nested_dictionary(database_auditing_settings) - - @staticmethod - def get_pricing_tier_display(sku_dict): - if sku_dict['name'] in ['Basic', 'Standard', 'Premium']: - pricing_tier = f'{sku_dict["tier"]}: {sku_dict["capacity"]} DTU' - else: - pricing_tier = f'{str(sku_dict["tier"])} : {str(sku_dict["family"])} , {str(sku_dict["capacity"])} vCores' - return pricing_tier - - @staticmethod - def get_db_compute_tier(kind): - if 'serverless' in kind: - compute_tier = 'Serverless' - else: - compute_tier = 'Provisioned' - - return compute_tier - - @staticmethod - def get_sync_group_display(sync_group_list): - sync_group_display_list = [] - for sync_group in sync_group_list: - sync_display = f"{sync_group['name']} / {sync_group['conflict_resolution_policy']} / {sync_group['sync_state']}" - sync_group_display_list.append(sync_display) - - return sync_group_display_list - - @staticmethod - def get_sync_agent_display(sync_agent_list): - sync_agent_display_list = [] - for sync_agent in sync_agent_list: - sync_display = f"{sync_agent['name']} / {sync_agent['state']}" - sync_agent_display_list.append(sync_display) - - return sync_agent_display_list - - @staticmethod - def list_replication_link_in_database(replication_links_from_params, database_name) -> list: - replication_links = [] - for replication_link in replication_links_from_params: - if replication_link['partner_database'] == database_name: - replication_links.append(replication_link) - - return replication_links diff --git a/src/spaceone/inventory/manager/sql_servers/__init__.py b/src/spaceone/inventory/manager/sql_servers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/sql_servers/server_manager.py b/src/spaceone/inventory/manager/sql_servers/server_manager.py deleted file mode 100644 index f8285a37..00000000 --- a/src/spaceone/inventory/manager/sql_servers/server_manager.py +++ /dev/null @@ -1,677 +0,0 @@ -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.model.sql_servers.cloud_service import * -from spaceone.inventory.model.sql_databases.cloud_service import * -from spaceone.inventory.connector.sql_servers import SQLServersConnector -from spaceone.inventory.connector.monitor import MonitorConnector -from spaceone.inventory.model.sql_servers.cloud_service_type import CLOUD_SERVICE_TYPES -from spaceone.inventory.model.sql_databases.data import * -from spaceone.inventory.model.sql_servers.data import * -from spaceone.inventory.manager.sql_databases.database_manager import ( - SQLDatabasesManager, -) -from spaceone.core.utils import * - -_LOGGER = logging.getLogger(__name__) - - -class SQLServersManager(AzureManager): - connector_name = "SQLServersConnector" - monitor_connector_name = "MonitorConnector" - - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure sql servers data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug(f"** SQL Servers START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - sql_servers_conn: SQLServersConnector = self.locator.get_connector( - self.connector_name, **params - ) - sql_servers_monitor_conn: MonitorConnector = self.locator.get_connector( - self.monitor_connector_name, **params - ) - - sql_server_responses = [] - error_responses = [] - - sql_servers = sql_servers_conn.list_servers() - - for sql_server in sql_servers: - sql_server_id = "" - - try: - sql_server_dict = self.convert_nested_dictionary(sql_server) - sql_server_id = sql_server_dict["id"] - - # update sql_servers_data dict - sql_server_dict = self.update_tenant_id_from_secret_data( - sql_server_dict, params["secret_data"] - ) - sql_server_dict.update( - { - "resource_group": self.get_resource_group_from_id( - sql_server_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": sql_server_id}, - } - ) - - resource_group_name = sql_server_dict["resource_group"] - name = sql_server_dict["name"] - - # Get Server Auditing Settings, Failover groups. azure ad administrators - server_auditing_settings_dict = self.get_server_auditing_settings( - sql_servers_conn, resource_group_name, name - ) - failover_group_list = self.list_failover_groups( - sql_servers_conn, resource_group_name, name - ) - transparent_data_encryption_dict = self.list_encryption_protectors( - sql_servers_conn, resource_group_name, name - ) - azure_ad_admin_list = self.list_azure_ad_administrators( - sql_servers_conn, resource_group_name, name - ) - server_automatic_tuning_dict = self.get_server_automatic_tuning( - sql_servers_conn, resource_group_name, name - ) - databases_list = self.list_databases( - sql_servers_conn=sql_servers_conn, - sql_monitor_conn=sql_servers_monitor_conn, - resource_group_name=resource_group_name, - server_name=name, - server_admin_name=sql_server_dict.get("administrator_login"), - ) - elastic_pools_list = self.list_elastic_pools( - sql_servers_conn, resource_group_name, name - ) - deleted_databases_list = self.list_deleted_databases( - sql_servers_conn, resource_group_name, name - ) - virtual_network_rules_list = self.list_virtual_network_rules( - sql_servers_conn, resource_group_name, name - ) - firewall_rules_list = self.list_firewall_rules( - sql_servers_conn, resource_group_name, name - ) - - sql_server_dict.update( - { - "azure_ad_administrators": azure_ad_admin_list, - "server_auditing_settings": server_auditing_settings_dict, - "failover_groups": failover_group_list, - "server_automatic_tuning": server_automatic_tuning_dict, - "databases": databases_list, - "elastic_pools": elastic_pools_list, - "deleted_databases": deleted_databases_list, - "virtual_network_rules": virtual_network_rules_list, - "firewall_rules": firewall_rules_list, - "encryption_protectors": transparent_data_encryption_dict, - } - ) - - if sql_server_dict.get("azure_ad_administrators") is not None: - sql_server_dict.update( - { - "azure_ad_admin_name": self.get_azure_ad_admin_name( - sql_server_dict["azure_ad_administrators"] - ) - } - ) - - if sql_server_dict.get("private_endpoint_connections") is not None: - sql_server_dict.update( - { - "private_endpoint_connections": self.get_private_endpoint_connections( - sql_server_dict["private_endpoint_connections"] - ) - } - ) - - sql_server_data = SQLServer(sql_server_dict, strict=False) - sql_server_resource = SQLServerResource( - { - "data": sql_server_data, - "region_code": sql_server_data.location, - "reference": ReferenceModel(sql_server_data.reference()), - "tags": sql_server_dict.get("tags", {}), - "name": sql_server_data.name, - "account": sql_server_data.subscription_id, - } - ) - sql_server_responses.append( - SQLServerResponse({"resource": sql_server_resource}) - ) - # _LOGGER.debug(f'[SQL SERVER INFO] {sql_server_resource.to_primitive()}') - - # Must set_region_code method for region collection - self.set_region_code(sql_server_data["location"]) - - except Exception as e: - _LOGGER.error(f"[list_instances] {sql_server_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, "Database", "SQLServer", sql_server_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** SQL Servers Finished {time.time() - start_time} Seconds **") - - return sql_server_responses, error_responses - - def list_elastic_pools(self, sql_servers_conn, rg_name, server_name): - elastic_pools_list = [] - elastic_pools = sql_servers_conn.list_elastic_pools_by_server( - resource_group=rg_name, server_name=server_name - ) - - for elastic_pool in elastic_pools: - elastic_pool_dict = self.convert_nested_dictionary(elastic_pool) - - # Get Databases list by elastic pool - elastic_pool_dict["databases"] = self.get_databases_by_elastic_pools( - sql_servers_conn, elastic_pool_dict["name"], rg_name, server_name - ) - - # Get pricing tier for display - if elastic_pool_dict.get("per_database_settings") is not None: - elastic_pool_dict.update( - { - "pricing_tier_display": self.get_pricing_tier_display( - elastic_pool_dict["sku"] - ), - "per_db_settings_display": self.get_per_db_settings( - elastic_pool_dict["per_database_settings"] - ), - "number_of_databases": len(elastic_pool_dict["databases"]), - "unit_display": elastic_pool_dict["sku"]["tier"], - "server_name_display": elastic_pool_dict["id"].split("/")[8], - "resource_group_display": elastic_pool_dict["id"].split("/")[4], - "max_size_gb": elastic_pool_dict["max_size_bytes"] / 1073741824, - } - ) - - elastic_pools_list.append(elastic_pool_dict) - - return elastic_pools_list - - def get_databases_by_elastic_pools( - self, sql_servers_conn, elastic_pool_name, rg_name, server_name - ): - databases_obj = sql_servers_conn.list_databases_by_elastic_pool( - elastic_pool_name, rg_name, server_name - ) - databases_list = [] - for database in databases_obj: - database_dict = self.convert_nested_dictionary(database) - databases_list.append(database_dict) - - return databases_list - - def list_deleted_databases(self, sql_servers_conn, rg_name, server_name): - deleted_databases_obj = ( - sql_servers_conn.list_restorable_dropped_databases_by_server( - resource_group=rg_name, server_name=server_name - ) - ) - deleted_databases_list = [] - for deleted_database in deleted_databases_obj: - deleted_database_dict = self.convert_nested_dictionary(deleted_database) - deleted_databases_list.append(deleted_database_dict) - - return deleted_databases_list - - def list_firewall_rules(self, sql_servers_conn, rg_name, server_name): - firewall_obj = sql_servers_conn.list_firewall_rules_by_server( - resource_group=rg_name, server_name=server_name - ) - firewall_list = [] - for firewall in firewall_obj: - firewall_rule_dict = self.convert_nested_dictionary(firewall) - firewall_list.append(firewall_rule_dict) - - return firewall_list - - def list_virtual_network_rules(self, sql_servers_conn, rg_name, server_name): - virtual_network_rule_obj = ( - sql_servers_conn.list_virtual_network_rules_by_server( - resource_group=rg_name, server_name=server_name - ) - ) - virtual_network_rules_list = [] - - for virtual_network_rule in virtual_network_rule_obj: - virtual_network_rule_dict = self.convert_nested_dictionary( - virtual_network_rule - ) - - if ( - virtual_network_rule_dict.get("id") is not None - ): # Get Virtual Network's name - virtual_network_rule_dict.update( - { - "virtual_network_name_display": virtual_network_rule_dict[ - "virtual_network_subnet_id" - ].split("/")[8], - "subscription_id": virtual_network_rule_dict["id"].split("/")[ - 2 - ], - "resource_group": virtual_network_rule_dict["id"].split("/")[4], - } - ) - virtual_network_rules_list.append(virtual_network_rule_dict) - - return virtual_network_rules_list - - def list_encryption_protectors(self, sql_servers_conn, rg_name, server_name): - encryption_protectors_list = [] - encryption_protectors_obj = sql_servers_conn.list_encryption_protectors( - resource_group=rg_name, server_name=server_name - ) - - for encryption_protector in encryption_protectors_obj: - encryption_protectors_dict = self.convert_nested_dictionary( - encryption_protector - ) - encryption_protectors_list.append(encryption_protectors_dict) - - return encryption_protectors_list - - def list_azure_ad_administrators(self, sql_servers_conn, rg_name, server_name): - ad_admin_list = [] # return list - ad_admin_obj = sql_servers_conn.list_server_azure_ad_administrators( - resource_group=rg_name, server_name=server_name - ) - - for ad_admin in ad_admin_obj: - ad_admin_list.append(self.convert_dictionary(ad_admin)) - - return ad_admin_list - - def get_server_automatic_tuning(self, sql_servers_conn, rg_name, server_name): - server_automatic_tuning_obj = sql_servers_conn.get_server_automatic_tuning( - rg_name, server_name - ) - server_automatic_tuning_dict = self.convert_nested_dictionary( - server_automatic_tuning_obj - ) - server_automatic_tuning_dict.update( - { - "options": self.get_server_automatic_tuning_options( - server_automatic_tuning_dict["options"] - ) - } - ) - - return server_automatic_tuning_dict - - def get_server_automatic_tuning_options(self, options_dict): - options_list = [] - created_index_dict = self.convert_nested_dictionary(options_dict["createIndex"]) - drop_index_dict = self.convert_nested_dictionary(options_dict["dropIndex"]) - force_plan_dict = self.convert_nested_dictionary( - options_dict["forceLastGoodPlan"] - ) - - created_index_dict.update({"tuning_type": "createIndex"}) - drop_index_dict.update({"tuning_type": "dropIndex"}) - force_plan_dict.update({"tuning_type": "forceLastGoodPlan"}) - - options_list.append(created_index_dict) - options_list.append(drop_index_dict) - options_list.append(force_plan_dict) - - return options_list - - def get_server_auditing_settings(self, sql_servers_conn, rg_name, server_name): - server_auditing_settings_obj = sql_servers_conn.get_server_auditing_settings( - rg_name, server_name - ) - server_auditing_settings_dict = self.convert_nested_dictionary( - server_auditing_settings_obj - ) - - return server_auditing_settings_dict - - def list_failover_groups(self, sql_servers_conn, rg_name, server_name): - failover_groups_list = [] - failover_groups_obj = sql_servers_conn.list_failover_groups( - rg_name, server_name - ) - for failover in failover_groups_obj: - failover_dict = self.convert_nested_dictionary(failover) - - if failover_dict.get("id") is not None: # Get Primary server's name - failover_dict.update( - {"primary_server": failover_dict["id"].split("/")[8]} - ) - - if ( - failover_dict.get("partner_servers") is not None - ): # Get Secondary Server's name - failover_dict.update( - { - "secondary_server": self.get_failover_secondary_server( - failover_dict["partner_servers"] - ) - } - ) - - if failover_dict.get("read_write_endpoint") is not None: - failover_dict.update( - { - "failover_policy_display": failover_dict[ - "read_write_endpoint" - ].get("failover_policy"), - "grace_period_display": failover_dict[ - "read_write_endpoint" - ].get("failover_with_data_loss_grace_period_minutes"), - } - ) - - failover_groups_list.append(failover_dict) - - return failover_groups_list - - def list_data_masking_rules( - self, sql_servers_conn, rg_name, server_name, database_name - ): - data_masking_rules_list = [] - data_masking_rule_obj = sql_servers_conn.list_data_masking_rules_by_database( - resource_group=rg_name, server_name=server_name, database_name=database_name - ) - - for data_masking_rule in data_masking_rule_obj: - data_masking_dict = self.convert_nested_dictionary(data_masking_rule) - data_masking_rules_list.append(data_masking_dict) - - return data_masking_rules_list - - def list_databases( - self, - sql_servers_conn, - sql_monitor_conn, - resource_group_name, - server_name, - server_admin_name, - ): - databases_list = [] - databases = sql_servers_conn.list_databases_by_server( - resource_group_name=resource_group_name, server_name=server_name - ) - - for database in databases: - database_dict = self.convert_nested_dictionary(database) - if database_dict.get("sku"): - if ( - database_dict.get("name") != "master" - ): # No pricing tier for system database - database_dict.update( - { - "pricing_tier_display": self.get_pricing_tier_display( - database_dict["sku"] - ), - "service_tier_display": database_dict["sku"].get("tier"), - } - ) - - if db_id := database_dict.get("id"): - database_dict.update( - { - "server_name": db_id.split("/")[8], - "subscription_id": db_id.split("/")[2], - "resource_group": db_id.split("/")[4], - "azure_monitor": {"resource_id": db_id}, - } - ) - - if compute_tier := database_dict.get("kind"): - database_dict.update( - {"compute_tier": self.get_db_compute_tier(compute_tier)} - ) - - if database_dict.get("max_size_bytes"): - database_dict.update( - { - "max_size_gb": database_dict["max_size_bytes"] - / 1073741824 # 2의 30승 - } - ) - - # Get Sync Groups by databases - if database_dict.get("service_tier_display") != "DataWarehouse": - database_dict.update( - { - "sync_group": self.get_sync_group_by_databases( - sql_servers_conn, - resource_group_name, - server_name, - database_dict["name"], - ), - } - ) - - if database_dict.get("sync_group"): - database_dict.update( - { - "sync_group_display": self.get_sync_group_display( - database_dict["sync_group"] - ) - } - ) - - # Get Sync Agents by servers - database_dict.update( - { - "sync_agent": self.get_sync_agent_by_servers( - sql_servers_conn, resource_group_name, server_name - ) - } - ) - - if database_dict.get("sync_agent"): - database_dict.update( - { - "sync_agent_display": self.get_sync_agent_display( - database_dict["sync_agent"] - ) - } - ) - """ - # Get Data masking rules - database_dict.update({ - 'data_masking_rules': self.list_data_masking_rules(self, sql_servers_conn, rg_name, server_name, database_dict['name']) - }) - """ - - # Get Diagnostic Settings - database_dict.update( - { - "diagnostic_settings_resource": self.list_diagnostics_settings( - sql_monitor_conn, database_dict["id"] - ) - } - ) - - # Get Database Replication Type - database_dict.update( - { - "replication_link": self.list_replication_link( - sql_servers_conn, - resource_group_name, - server_name, - database_dict["name"], - ) - } - ) - - # Get azure_ad_admin name - if server_admin_name is not None: - database_dict.update({"administrator_login": server_admin_name}) - - # switch tags form - tags = database_dict.get("tags", {}) - _tags = self.convert_tag_format(tags) - database_dict.update({"tags": _tags}) - - databases_list.append(database_dict) - - return databases_list - - def get_sync_agent_by_servers(self, sql_servers_conn, rg_name, server_name): - sync_agent_list = [] - sync_agent_obj = sql_servers_conn.list_sync_agents_by_server( - rg_name, server_name - ) - - for sync_agent in sync_agent_obj: - sync_agent_dict = self.convert_nested_dictionary(sync_agent) - sync_agent_list.append(sync_agent_dict) - - return sync_agent_list - - def list_diagnostics_settings(self, sql_monitor_conn, resource_uri): - diagnostic_settings_list = [] - diagnostic_settings_objs = sql_monitor_conn.list_diagnostic_settings( - resource_uri=resource_uri - ) - - for diagnostic_setting in diagnostic_settings_objs: - diagnostic_setting_dict = self.convert_nested_dictionary(diagnostic_setting) - diagnostic_settings_list.append(diagnostic_setting_dict) - - return diagnostic_settings_list - - def list_replication_link( - self, sql_servers_conn, rg_name, server_name, database_name - ): - replication_link_list = [] - replication_link_obj = sql_servers_conn.list_replication_link( - rg_name, server_name, database_name - ) - - for replication_link in replication_link_obj: - replication_link_dict = self.convert_nested_dictionary(replication_link) - replication_link_list.append(replication_link_dict) - - return replication_link_list - - def get_sync_group_by_databases( - self, sql_servers_conn, resource_group_name, server_name, database_name - ): - sync_group_obj = sql_servers_conn.list_sync_groups_by_databases( - resource_group=resource_group_name, - server_name=server_name, - database_name=database_name, - ) - sync_group_list = [] - for sync_group in sync_group_obj: - sync_group_dict = self.convert_nested_dictionary(sync_group) - sync_group_list.append(sync_group_dict) - return sync_group_list - - @staticmethod - def get_private_endpoint_connections(private_endpoint_connection_list): - for pec in private_endpoint_connection_list: - if pec.get("id") is not None: - pec.update({"connection_id": pec["id"].split("/")[10]}) - - if pec.get("properties") is not None: - pec.update( - { - "private_endpoint_name": pec["properties"] - .get("private_endpoint") - .get("id") - .split("/")[8], - "description": pec["properties"] - .get("private_link_service_connection_state") - .get("description"), - "status": pec["properties"] - .get("private_link_service_connection_state") - .get("status"), - } - ) - - return private_endpoint_connection_list - - @staticmethod - def get_per_db_settings(per_database_settings_dict): - per_db_settings = ( - f"{str(per_database_settings_dict['min_capacity'])} - " - f"{str(per_database_settings_dict['max_capacity'])} vCores" - ) - return per_db_settings - - @staticmethod - def get_failover_secondary_server(partner_servers): - secondary_server = None - - for partner_server in partner_servers: - if partner_server["replication_role"] == "Secondary": - secondary_server = partner_server["id"].split("/")[8] - - return secondary_server - - @staticmethod - def get_azure_ad_admin_name(azure_ad_administrators_list): - az_admin_name = "" - - for az_admin in azure_ad_administrators_list: - if az_admin.get("login") is not None: - az_admin_name = az_admin.get("login") - - return az_admin_name - - @staticmethod - def get_db_compute_tier(kind): - if "serverless" in kind: - compute_tier = "Serverless" - else: - compute_tier = "Provisioned" - - return compute_tier - - @staticmethod - def get_sync_agent_display(sync_agent_list): - sync_agent_display_list = [] - for sync_agent in sync_agent_list: - sync_display = f"{sync_agent['name']} / {sync_agent['state']}" - sync_agent_display_list.append(sync_display) - - return sync_agent_display_list - - @staticmethod - def get_pricing_tier_display(sku_dict): - pricing_tier = None - if sku_dict.get("capacity") is not None: - pricing_tier = f'{str(sku_dict["tier"])} : {str(sku_dict["family"])} , {str(sku_dict["capacity"])} vCores' - - return pricing_tier - - @staticmethod - def get_sync_group_display(sync_group_list): - sync_group_display_list = [] - for sync_group in sync_group_list: - sync_display = f"{sync_group['name']} / {sync_group['conflict_resolution_policy']} / {sync_group['sync_state']}" - sync_group_display_list.append(sync_display) - - return sync_group_display_list diff --git a/src/spaceone/inventory/manager/storage_accounts/__init__.py b/src/spaceone/inventory/manager/storage_accounts/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/storage_accounts/instance_manager.py b/src/spaceone/inventory/manager/storage_accounts/instance_manager.py deleted file mode 100644 index 8383aa21..00000000 --- a/src/spaceone/inventory/manager/storage_accounts/instance_manager.py +++ /dev/null @@ -1,343 +0,0 @@ -import datetime -import logging -import time - -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.storage_accounts import StorageAccountsConnector -from spaceone.inventory.connector.monitor import MonitorConnector -from spaceone.inventory.model.storage_accounts.cloud_service import * -from spaceone.inventory.model.storage_accounts.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.storage_accounts.data import * - -_LOGGER = logging.getLogger(__name__) - - -class StorageAccountsManager(AzureManager): - connector_name = "StorageAccountsConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure storage account data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug("** Storage Account START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - storage_account_conn: StorageAccountsConnector = self.locator.get_connector( - self.connector_name, **params - ) - monitor_conn: MonitorConnector = self.locator.get_connector( - "MonitorConnector", **params - ) - - storage_account_responses = [] - error_responses = [] - - storage_accounts = storage_account_conn.list_storage_accounts() - - for storage_account in storage_accounts: - storage_account_id = "" - - try: - storage_account_dict = self.convert_nested_dictionary(storage_account) - kind = storage_account_dict.get("kind") - storage_account_id = storage_account_dict["id"] - resource_group = self.get_resource_group_from_id(storage_account_id) - - if storage_account_dict.get("network_rule_set") is not None: - storage_account_dict.update( - { - "network_rule_set": self.get_network_rule_set( - storage_account_dict["network_rule_set"] - ) - } - ) - - # https://learn.microsoft.com/en-us/rest/api/storagerp/storage-accounts/list?view=rest-storagerp-2023-01-01&tabs=HTTP#kind - if storage_account_dict.get("name") is not None and kind not in [ - "FileStorage" - ]: - container_count = self.get_blob_containers_count( - storage_account_conn, - resource_group, - storage_account_dict["name"], - ) - - storage_account_dict.update( - {"container_count_display": container_count} - ) - - if storage_account_dict.get("routing_preference") is not None: - storage_account_dict.update( - {"routing_preference_display": "Internet routing"} - ) - else: - storage_account_dict.update( - {"routing_preference_display": "Microsoft network routing"} - ) - - storage_account_dict = self.update_tenant_id_from_secret_data( - storage_account_dict, params["secret_data"] - ) - storage_account_dict.update( - { - "resource_group": resource_group, - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": storage_account_id}, - "blob_count_display": self._get_blob_count_from_monitoring( - monitor_conn, storage_account_id - ), - "blob_size_display": self._get_blob_size_from_monitoring( - monitor_conn, storage_account_id - ), - } - ) - - storage_account_data = StorageAccount( - storage_account_dict, strict=False - ) - storage_account_resource = StorageAccountResource( - { - "data": storage_account_data, - "tags": storage_account_dict.get("tags", {}), - "region_code": storage_account_data.location, - "reference": ReferenceModel(storage_account_data.reference()), - "name": storage_account_data.name, - "account": storage_account_data.subscription_id, - "instance_type": storage_account_data.sku.tier, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(storage_account_data["location"]) - storage_account_responses.append( - StorageAccountResponse({"resource": storage_account_resource}) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {storage_account_id} {e}", exc_info=True - ) - error_resource_response = self.generate_resource_error_response( - e, "Storage", "StorageAccount", storage_account_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug( - f"** Storage Account Finished {time.time() - start_time} Seconds **" - ) - return storage_account_responses, error_responses - - def get_public_ip_address( - self, application_gateway_conn, resource_group_name, pip_name - ): - public_ip_address_obj = application_gateway_conn.get_public_ip_addresses( - resource_group_name, pip_name - ) - public_ip_address_dict = self.convert_nested_dictionary(public_ip_address_obj) - - return public_ip_address_dict - - def get_network_rule_set(self, network_rule_dict): - if network_rule_dict.get("virtual_network_rules") is not None: - network_rule_dict.update( - { - "virtual_networks": self.get_virtual_network_names( - network_rule_dict["virtual_network_rules"] - ), - "is_public_access_allowed": False, - } - ) - if not network_rule_dict.get( - "virtual_network_rules" - ): # if virtual_network_rules are empty, this SA is public allowable - network_rule_dict.update({"is_public_access_allowed": True}) - - if network_rule_dict.get("ip_rules") is not None: - firewall_address_list = [] - for rule in network_rule_dict["ip_rules"]: - firewall_address_list.append(rule["ip_address_or_range"]) - - network_rule_dict.update({"firewall_address_range": firewall_address_list}) - - if network_rule_dict.get("resource_access_rules") is not None: - resource_access_rules_list = [] - for rule in network_rule_dict["resource_access_rules"]: - try: - resource_type = rule.get("resource_id").split("/")[6] - resource_access_rules_list.append(resource_type) - - except Exception as e: - _LOGGER.error(f"[ERROR: Azure Storage Account Network Rules]: {e}") - - network_rule_dict.update( - {"resource_access_rules_display": resource_access_rules_list} - ) - - return network_rule_dict - - def list_blob_containers(self, storage_conn, rg_name, account_name): - blob_containers_list = [] - blob_containers_obj = storage_conn.list_blob_containers( - rg_name=rg_name, account_name=account_name - ) - for blob_container in blob_containers_obj: - blob_dict = self.convert_nested_dictionary(blob_container) - blob_containers_list.append(blob_dict) - - return blob_containers_list - - def _get_blob_count_from_monitoring(self, monitor_conn, storage_account_id): - timespan = self._get_timespan_from_now(1) - aggregation = "total" - interval = "PT1H" - container_blob_count_metric = self._get_metric_data( - monitor_conn, - f"{storage_account_id}/blobServices/default", - metricnames="BlobCount", - aggregation=aggregation, - timespan=timespan, - interval=interval, - ) - - container_blob_count_metric_dict = self.convert_nested_dictionary( - container_blob_count_metric - ) - return self._get_timeseries_data_from_metric( - container_blob_count_metric_dict, aggregation - ) - - def _get_blob_size_from_monitoring(self, monitor_conn, storage_account_id): - timespan = self._get_timespan_from_now(1) - aggregation = "total" - interval = "PT1H" - container_blob_capacity_metric = self._get_metric_data( - monitor_conn, - f"{storage_account_id}/blobServices/default", - metricnames="BlobCapacity", - aggregation=aggregation, - timespan=timespan, - interval=interval, - ) - container_blob_capacity_metric_dict = self.convert_nested_dictionary( - container_blob_capacity_metric - ) - return self._get_timeseries_data_from_metric( - container_blob_capacity_metric_dict, aggregation - ) - - @staticmethod - def _get_timeseries_data_from_metric(metric_dict, aggregation): - try: - timeseries_data = metric_dict["value"][0]["timeseries"][0]["data"][0].get( - aggregation - ) - return timeseries_data if timeseries_data is not None else 0 - except Exception as e: - _LOGGER.warning(f"[_get_timeseries_data_from_metric]: {e}") - return 0 - - @staticmethod - def get_associated_listener(frontend_ip_configuration_dict, http_listeners_list): - associated_listener = "" - for http_listener in http_listeners_list: - if http_listener.get("frontend_ip_configuration") is not None: - if frontend_ip_configuration_dict["id"] in http_listener.get( - "frontend_ip_configuration", {} - ).get("id", ""): - associated_listener = http_listener.get("name", "-") - else: - associated_listener = "-" - - return associated_listener - - @staticmethod - def get_port(port_id, frontend_ports_list): - port = 0 - for fe_port in frontend_ports_list: - if port_id in fe_port["id"]: - port = fe_port.get("port", 0) - return port - else: - return port - - @staticmethod - def update_backend_pool_dict(backend_pool_list, backend_pool_id, request_rules): - for backend_pool in backend_pool_list: - if backend_pool["id"] == backend_pool_id: - backend_pool.update({"associated_rules": request_rules}) - - @staticmethod - def update_rewrite_ruleset_dict( - rewrite_rule_sets_list, rewrite_rule_id, applied_rules_list - ): - for rewrite_rule in rewrite_rule_sets_list: - if rewrite_rule["id"] == rewrite_rule_id: - rewrite_rule.update({"rules_applied": applied_rules_list}) - - @staticmethod - def update_http_listeners_list( - http_listeners_list, http_listener_id, http_applied_rules - ): - for http_listener in http_listeners_list: - if http_listener["id"] == http_listener_id: - http_listener.update({"associated_rules": http_applied_rules}) - - @staticmethod - def get_virtual_network_names(virtual_network_rules): - names = [] - try: - for virtual_network_rule in virtual_network_rules: - name = virtual_network_rule["virtual_network_resource_id"].split("/")[8] - names.append(name) - - except Exception as e: - _LOGGER.error(f"[ERROR: Azure Storage Account Network Rule Get Name]: {e}") - - return names - - @staticmethod - def _get_metric_data( - monitor_conn, - resource_uri, - metricnames, - aggregation=None, - timespan=None, - interval=None, - ): - return monitor_conn.list_metrics( - resource_uri, - metricnames=metricnames, - aggregation=aggregation, - timespan=timespan, - interval=interval, - ) - - @staticmethod - def _get_timespan_from_now(hours): - time_now = datetime.datetime.utcnow() - datetime.timedelta(hours=1) - time_now_hours_ago = time_now - datetime.timedelta(hours=hours) - return "{}/{}".format(time_now_hours_ago, time_now) - - @staticmethod - def get_blob_containers_count(storage_conn, rg_name, account_name): - blob_containers_obj = storage_conn.list_blob_containers( - rg_name=rg_name, account_name=account_name - ) - return len(list(blob_containers_obj)) diff --git a/src/spaceone/inventory/manager/subscriptions/__init__.py b/src/spaceone/inventory/manager/subscriptions/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/subscriptions/subscription_manager.py b/src/spaceone/inventory/manager/subscriptions/subscription_manager.py deleted file mode 100644 index e3dc66e5..00000000 --- a/src/spaceone/inventory/manager/subscriptions/subscription_manager.py +++ /dev/null @@ -1,45 +0,0 @@ -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.connector.subscriptions import SubscriptionsConnector -import re - - -class SubscriptionsManager(AzureManager): - connector_name = 'SubscriptionsConnector' - - def get_subscription_info(self, params): - secret_data = params['secret_data'] - subscription_connector: SubscriptionsConnector = self.locator.get_connector(self.connector_name, secret_data=secret_data) - subscription_info = subscription_connector.get_subscription_info(secret_data['subscription_id']) - - return { - 'subscription_id': subscription_info.subscription_id, - 'subscription_name': subscription_info.display_name, - 'tenant_id': subscription_info.tenant_id - } - - def list_location_info(self, params): - secret_data = params['secret_data'] - subscription_connector: SubscriptionsConnector = self.locator.get_connector(self.connector_name, secret_data=secret_data) - location_infos = subscription_connector.list_location_info(secret_data['subscription_id']) - - region_info = {} - for location_info in location_infos: - _loc_info = self.convert_nested_dictionary(location_info) - _name = f'{re.sub(r"[/()]", "", _loc_info.get("regional_display_name"))} ({_loc_info.get("metadata").get("physical_location")})' - _latitude = _loc_info.get('metadata', {}).get('latitude') - _longitude = _loc_info.get('metadata', {}).get('longitude') - _continent = _loc_info.get('metadata', {}).get('geography_group') - - if _name and _latitude and _longitude and _continent: - region_info.update({ - _loc_info['name']: { - 'name': _name, - 'tags': { - 'latitude': _latitude, - 'longitude': _longitude, - 'continent': _continent.replace(' ', '_').lower() - } - } - }) - - return region_info diff --git a/src/spaceone/inventory/manager/virtual_machines/__init__.py b/src/spaceone/inventory/manager/virtual_machines/__init__.py deleted file mode 100644 index 5296d8a4..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -from spaceone.inventory.manager.virtual_machines.disk_manager import ( - VirtualMachineDiskManager, -) -from spaceone.inventory.manager.virtual_machines.load_balancer_manager import ( - VirtualMachineLoadBalancerManager, -) -from spaceone.inventory.manager.virtual_machines.network_security_group_manager import ( - VirtualMachineNetworkSecurityGroupManager, -) -from spaceone.inventory.manager.virtual_machines.nic_manager import ( - VirtualMachineNICManager, -) -from spaceone.inventory.manager.virtual_machines.vm_manager import ( - VirtualMachineVmManager, -) -from spaceone.inventory.manager.virtual_machines.vnet_manager import ( - VirtualMachineVNetManager, -) diff --git a/src/spaceone/inventory/manager/virtual_machines/disk_manager.py b/src/spaceone/inventory/manager/virtual_machines/disk_manager.py deleted file mode 100644 index ea10b3d5..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/disk_manager.py +++ /dev/null @@ -1,99 +0,0 @@ -from spaceone.core.manager import BaseManager -from spaceone.inventory.model.virtual_machines.data import Disk -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector - - -class VirtualMachineDiskManager(BaseManager): - - def __init__(self, params, azure_vm_connector=None, **kwargs): - super().__init__(**kwargs) - self.params = params - self.azure_vm_connector: VirtualMachinesConnector = azure_vm_connector - - def get_disk_info(self, vm, list_disks): - ''' - disk_data = { - "device_index": 0, - "device": "", - "disk_type": "disk", - "size": 100, - "tags": { - "disk_name": "", - "caching": "None" | "ReadOnly" | "ReadWrite" - "storage_account_type": "Standard_LRS" | "Premium_LRS" | "StandardSSD_LRS" | "UltraSSD_LRS" - "disk_encryption_set": "PMK" | "CMK" - "iops": 60, - "throughput_mbps": 200 - } - } - ''' - - disk_data = [] - index = 0 - - os_disk = vm.storage_profile.os_disk - volume_data = self.get_volume_data(os_disk, list_disks, index) - volume_data.update({ - 'disk_type': 'os_disk' - }) - disk_data.append(Disk(volume_data, strict=False)) - index += 1 - - data_disks = vm.storage_profile.data_disks - if data_disks: - for data_disk in data_disks: - volume_data_sub = self.get_volume_data(data_disk, list_disks, index) - volume_data_sub.update({ - 'disk_type': 'data_disk' - }) - disk_data.append(Disk(volume_data_sub, strict=False)) - index += 1 - - return disk_data - - def get_volume_data(self, disk, list_disks, index): - volume_data = { - 'device_index': index, - 'size': disk.disk_size_gb * 1073741824 if disk.disk_size_gb is not None else 0, - 'tags': { - 'disk_name': disk.name if disk.name is not None else '', - 'caching': disk.caching if disk.caching is not None else '', - } - } - - if getattr(disk, 'managed_disk') and disk.managed_disk is not None: - encryption = self.get_disk_encryption(disk) - volume_data['tags'].update({'disk_encryption_set': encryption}) - if disk.managed_disk.id is not None: - volume_data['tags'].update({'disk_id': disk.managed_disk.id}) - if disk.managed_disk.storage_account_type is not None: - volume_data['tags'].update({'storage_account_type': disk.managed_disk.storage_account_type}) - - map_disk = self.get_mapping_disk_info(disk, list_disks) - - if map_disk: - volume_data['tags'].update({ - 'iops': map_disk.disk_iops_read_write, - 'throughput_mbps': map_disk.disk_m_bps_read_write - }) - return volume_data - - @staticmethod - def get_mapping_disk_info(disk, list_disks): - if list_disks: - list_disks = [] - - if getattr(disk, 'managed_disk') and disk.managed_disk: - disk_name = disk.managed_disk.id.split('/')[-1] - for disk_info in list_disks: - if disk_info.name == disk_name: - return disk_info - - return None - - @staticmethod - def get_disk_encryption(disk): - if disk.managed_disk.disk_encryption_set: - return 'CMK' - else: - return 'PMK' diff --git a/src/spaceone/inventory/manager/virtual_machines/instnace_manger.py b/src/spaceone/inventory/manager/virtual_machines/instnace_manger.py deleted file mode 100644 index ff715fff..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/instnace_manger.py +++ /dev/null @@ -1,285 +0,0 @@ -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector -from spaceone.inventory.manager.virtual_machines import ( - VirtualMachineDiskManager, - VirtualMachineLoadBalancerManager, - VirtualMachineNetworkSecurityGroupManager, - VirtualMachineNICManager, - VirtualMachineVmManager, - VirtualMachineVNetManager, -) -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.model.virtual_machines.data import * -from spaceone.inventory.libs.schema.resource import ( - ErrorResourceResponse, - CloudServiceResourceResponse, - AzureMonitorModel, -) -from spaceone.core.utils import * -from spaceone.inventory.model.virtual_machines.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.virtual_machines.cloud_service import * - -_LOGGER = logging.getLogger(__name__) - - -class VirtualMachinesManager(AzureManager): - connector_name = "VirtualMachinesConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - # refactoring - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure vm scale set data resource information - ErrorResourceResponse (list) : list of error resource information - """ - - _LOGGER.debug("** VirtualMachine START **") - start_time = time.time() - - servers = [] - errors = [] - - azure_vm_connector: VirtualMachinesConnector = self.locator.get_connector( - self.connector_name, **params - ) - - # call all managers - vm_manager: VirtualMachineVmManager = VirtualMachineVmManager( - params, azure_vm_connector=azure_vm_connector - ) - disk_manager: VirtualMachineDiskManager = VirtualMachineDiskManager( - params, azure_vm_connector=azure_vm_connector - ) - load_balancer_manager: VirtualMachineLoadBalancerManager = ( - VirtualMachineLoadBalancerManager( - params, azure_vm_connector=azure_vm_connector - ) - ) - network_security_group_manager: VirtualMachineNetworkSecurityGroupManager = ( - VirtualMachineNetworkSecurityGroupManager( - params, azure_vm_connector=azure_vm_connector - ) - ) - nic_manager: VirtualMachineNICManager = VirtualMachineNICManager( - params, azure_vm_connector=azure_vm_connector - ) - vnet_manager: VirtualMachineVNetManager = VirtualMachineVNetManager( - params, azure_vm_connector=azure_vm_connector - ) - - vms = list(azure_vm_connector.list_all_vms()) - resource_groups = list(azure_vm_connector.list_resource_groups()) - load_balancers = list(azure_vm_connector.list_load_balancers()) - network_security_groups = list( - azure_vm_connector.list_network_security_groups() - ) - network_interfaces = list(azure_vm_connector.list_network_interfaces()) - disks = list(azure_vm_connector.list_disks()) - public_ip_addresses = list(azure_vm_connector.list_public_ip_addresses()) - virtual_networks = list(azure_vm_connector.list_virtual_networks()) - skus = list(azure_vm_connector.list_skus()) - - subscription_id = params["secret_data"].get("subscription_id") - subscription_info = azure_vm_connector.get_subscription_info(subscription_id) - subscription_data = { - "subscription_id": subscription_info.subscription_id, - "subscription_name": subscription_info.display_name, - "tenant_id": subscription_info.tenant_id, - } - - for vm in vms: - try: - vnet_data = None - subnet_data = None - lb_vos = [] - resource_group, resource_group_name = self.get_resource_info_in_vm( - vm, resource_groups - ) - skus_dict = self.get_skus_resource(skus) - - disk_vos = disk_manager.get_disk_info(vm, disks) - nic_vos, primary_ip = nic_manager.get_nic_info( - vm, network_interfaces, public_ip_addresses, virtual_networks - ) - - vm_resource = vm_manager.get_vm_info( - vm, - disk_vos, - nic_vos, - resource_group, - subscription_id, - network_security_groups, - primary_ip, - skus_dict, - ) - - if load_balancers is not None: - lb_vos = load_balancer_manager.get_load_balancer_info( - vm, load_balancers, public_ip_addresses - ) - - nsg_vos = ( - network_security_group_manager.get_network_security_group_info( - vm, network_security_groups, network_interfaces - ) - ) - - nic_name = vm.network_profile.network_interfaces[0].id.split("/")[-1] - - if nic_name is not None: - vnet_subnet_dict = vnet_manager.get_vnet_subnet_info( - nic_name, network_interfaces, virtual_networks - ) - - if vnet_subnet_dict.get("vnet_info"): - vnet_data = vnet_subnet_dict["vnet_info"] - - if vnet_subnet_dict.get("subnet_info"): - subnet_data = vnet_subnet_dict["subnet_info"] - - vm_resource.update({"tags": self.get_tags(vm.tags)}) - - resource_id = f'/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Compute/virtualMachines/{vm_resource["name"]}' - - # update vm_resource data - vm_resource["data"].update( - { - "tenant_id": subscription_data["tenant_id"], - "subscription_name": subscription_data["subscription_name"], - "subscription_id": subscription_data["subscription_id"], - "resource_group": resource_group_name, - } - ) - - vm_resource["data"].update( - { - "load_balancer": lb_vos, - "security_group": nsg_vos, - "vnet": vnet_data, - "subnet": subnet_data, - "azure_monitor": AzureMonitorModel( - {"resource_id": resource_id}, strict=False - ), - "activity_log": ActivityLog( - {"resource_uri": resource_id}, strict=False - ), - } - ) - - vm_resource["data"]["compute"]["account"] = subscription_data[ - "subscription_name" - ] - vm_resource.update( - { - "reference": ReferenceModel( - { - "resource_id": vm_resource["data"]["compute"][ - "instance_id" - ], - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Compute/virtualMachines/{vm_resource['data']['compute']['instance_name']}/overview", - } - ), - "account": subscription_data["subscription_id"], - "instance_type": vm_resource["data"]["compute"][ - "instance_type" - ], - "launched_at": datetime_to_iso8601( - vm_resource["data"]["compute"]["launched_at"] - ), - "tags": vm.tags, - } - ) - - self.set_region_code(vm_resource["region_code"]) - - vm_resource_vo = VirtualMachineResource(vm_resource, strict=False) - servers.append(VirtualMachineResponse({"resource": vm_resource_vo})) - except Exception as e: - _LOGGER.error(f"[list_instances] [{vm.id}] {e}") - - if type(e) is dict: - error_resource_response = ErrorResourceResponse( - {"message": json.dumps(e)} - ) - else: - error_resource_response = ErrorResourceResponse( - {"message": str(e), "resource": {"resource_id": vm.id}} - ) - - errors.append(error_resource_response) - - _LOGGER.debug( - f"** VirtualMachine Finished {time.time() - start_time} Seconds **" - ) - return servers, errors - - @staticmethod - def get_tags(tags): - tags_result = [] - if tags: - for k, v in tags.items(): - tags_result.append({"key": k, "value": v}) - - return tags_result - - @staticmethod - def get_resource_info_in_vm(vm, resource_groups): - for rg in resource_groups: - vm_info = vm.id.split("/") - for info in vm_info: - if info == rg.name.upper(): - resource_group = rg - resource_group_name = rg.name - return resource_group, resource_group_name - - @staticmethod - def get_resources_in_resource_group(resources, resource_group_name): - infos = [] - for resource in resources: - id_info = resource.id.split("/") - for info in id_info: - if info == resource_group_name.upper(): - infos.append(resource) - return infos - - @staticmethod - def get_skus_resource(skus): - skus_dict = {} - for sku in skus: - if sku.resource_type == "virtualMachines": - location = sku.locations[0].lower() - if location not in skus_dict: - skus_dict[location] = [] - info = {} - # get sku information for discriminating Instance type - info.update( - { - "resource_type": sku.resource_type, - "name": sku.name, - "tier": sku.tier, - "size": sku.size, - "family": sku.family, - } - ) - - # get cpu and memory information - for capa in sku.capabilities: - if capa.name == "vCPUs": - info["core"] = capa.value - elif capa.name == "MemoryGB": - info["memory"] = capa.value - skus_dict[location].append(info) - - return skus_dict diff --git a/src/spaceone/inventory/manager/virtual_machines/load_balancer_manager.py b/src/spaceone/inventory/manager/virtual_machines/load_balancer_manager.py deleted file mode 100644 index 898b1a18..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/load_balancer_manager.py +++ /dev/null @@ -1,115 +0,0 @@ -from spaceone.core.manager import BaseManager -from spaceone.inventory.model.virtual_machines.data import LoadBalancer -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector - - -class VirtualMachineLoadBalancerManager(BaseManager): - def __init__(self, params, azure_vm_connector=None, **kwargs): - super().__init__(**kwargs) - self.params = params - self.azure_vm_connector: VirtualMachinesConnector = azure_vm_connector - - def get_load_balancer_info(self, vm, load_balancers, public_ip_addresses): - """ - lb_data = { - "type" = "application" | "network", - "endpoint" = "", - "port" = [] - "name" = "" - "protocol" = [] - "scheme" = "internet-facing" | "internal" - "tags" = { - "lb_id" = "" - } - } - """ - lb_data = [] - match_load_balancers = self.get_load_balancers_from_nic( - vm.network_profile.network_interfaces, load_balancers - ) - - for match_load_balancer in match_load_balancers: - ports, protocols = self.get_lb_port_protocol(match_load_balancer) - load_balancer_data = { - "type": "network", - "scheme": self.get_lb_scheme(match_load_balancer), - "endpoint": self.get_lb_endpoint( - match_load_balancer, public_ip_addresses - ), - "port": ports, - "name": match_load_balancer.name, - "protocol": protocols, - "tags": {"lb_id": match_load_balancer.id}, - } - lb_data.append(LoadBalancer(load_balancer_data, strict=False)) - - return lb_data - - def get_lb_endpoint(self, match_load_balancer, public_ip_addresses): - frontend_ip_configurations = match_load_balancer.frontend_ip_configurations - - if public_ip_addresses: - public_ip_addresses = [] - - if frontend_ip_configurations: - frontend_ip_configurations = [] - - if self.get_lb_scheme(match_load_balancer) == "internet-facing": - for ip in frontend_ip_configurations: - public_ip_address_name = ip.public_ip_address.id.split("/")[-1] - for pub_ip in public_ip_addresses: - if public_ip_address_name == pub_ip.name: - return pub_ip.ip_address - - elif self.get_lb_scheme(match_load_balancer) == "internal": - for ip in frontend_ip_configurations: - return ip.private_ip_address - - return "" - - @staticmethod - def get_load_balancers_from_nic(network_interfaces, load_balancers): - match_load_balancers = [] - - if network_interfaces: - network_interfaces = [] - - if load_balancers: - load_balancers = [] - - vm_nics = [] - for nic in network_interfaces: - vm_nics.append(nic.id.split("/")[-1]) - - for vm_nic in vm_nics: - for lb in load_balancers: - if lb.backend_address_pools: - for be in lb.backend_address_pools: - if be.backend_ip_configurations: - for ip_conf in be.backend_ip_configurations: - nic_name = ip_conf.id.split("/")[-3] - if nic_name == vm_nic: - match_load_balancers.append(lb) - - return match_load_balancers - - @staticmethod - def get_lb_scheme(match_load_balancer): - frontend_ip_configurations = match_load_balancer.frontend_ip_configurations - for fe_ip_conf in frontend_ip_configurations: - if fe_ip_conf.public_ip_address: - return "internet-facing" - else: - return "internal" - - @staticmethod - def get_lb_port_protocol(match_load_balancer): - ports = [] - protocols = [] - lb_rules = match_load_balancer.load_balancing_rules - if lb_rules: - for lbr in lb_rules: - ports.append(lbr.frontend_port) - protocols.append(lbr.protocol.upper()) - - return ports, protocols diff --git a/src/spaceone/inventory/manager/virtual_machines/network_security_group_manager.py b/src/spaceone/inventory/manager/virtual_machines/network_security_group_manager.py deleted file mode 100644 index 709ae778..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/network_security_group_manager.py +++ /dev/null @@ -1,220 +0,0 @@ -from spaceone.core.manager import BaseManager -from spaceone.inventory.model.virtual_machines.data import SecurityGroup -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector - - -class VirtualMachineNetworkSecurityGroupManager(BaseManager): - def __init__(self, params, azure_vm_connector=None, **kwargs): - super().__init__(**kwargs) - self.params = params - self.azure_vm_connector: VirtualMachinesConnector = azure_vm_connector - - def get_network_security_group_info( - self, vm, network_security_groups, network_interfaces - ): - """ - nsg_data = { - "protocol" = "", - "remote" = "", - "remote_cidr" = "", - "remote_id" = "", - "security_group_name" = "", - "security_group_id" = "", - "description" = "", - "direction" = "inbound" | "outbound", - "port_range_min" = 0, - "port_range_max" = 0, - "port" = "", - "priority" = 0 - } - """ - - nsg_data = [] - - network_security_groups_data = [] - - if ( - getattr(vm.network_profile, "network_interfaces") - and vm.network_profile.network_interfaces - ): - vm_network_interfaces = vm.network_profile.network_interfaces - else: - vm_network_interfaces = [] - - match_network_security_groups = self.get_network_security_group_from_nic( - vm_network_interfaces, network_interfaces, network_security_groups - ) - for network_security_group in match_network_security_groups: - sg_id = network_security_group.id - - security_rules = network_security_group.security_rules - security_data = self.get_nsg_security_rules(security_rules, sg_id) - network_security_groups_data.extend(security_data) - - default_security_rules = network_security_group.default_security_rules - default_security_data = self.get_nsg_security_rules( - default_security_rules, sg_id - ) - network_security_groups_data.extend(default_security_data) - - for nsg in network_security_groups_data: - nsg_data.append(SecurityGroup(nsg, strict=False)) - - return nsg_data - - def get_nsg_security_rules(self, security_rules, sg_id): - result = [] - for s_rule in security_rules: - security_rule_data = { - "protocol": self.get_nsg_protocol(s_rule.protocol), - "remote_id": s_rule.id, - "security_group_name": s_rule.id.split("/")[-3], - "description": s_rule.description, - "direction": s_rule.direction.lower(), - "priority": s_rule.priority, - "security_group_id": sg_id, - "action": s_rule.access.lower(), - } - - remote_data = self.get_nsg_remote(s_rule) - security_rule_data.update(remote_data) - port_data = self.get_nsg_port(s_rule) - security_rule_data.update(port_data) - - result.append(security_rule_data) - - return result - - @staticmethod - def get_nsg_protocol(protocol): - if protocol == "*": - return "ALL" - return protocol - - @staticmethod - def get_network_security_group_from_nic( - vm_network_interfaces, network_interfaces, network_security_groups - ): - nsgs = [] - for vm_nic in vm_network_interfaces: - vm_nic_name = vm_nic.id.split("/")[-1] - for nic in network_interfaces: - if vm_nic_name == nic.name: - if ( - getattr(nic, "network_security_group") - and nic.network_security_group - ): - nsg_name = nic.network_security_group.id.split("/")[-1] - for nsg in network_security_groups: - if nsg.name == nsg_name: - nsgs.append(nsg) - break - break - - return nsgs - - @staticmethod - def get_nsg_remote(s_rule): - remote_result = {} - if s_rule.source_address_prefix is not None: - if "/" in s_rule.source_address_prefix: - remote_result.update( - { - "remote": s_rule.source_address_prefix, - "remote_cidr": s_rule.source_address_prefix, - } - ) - elif s_rule.source_address_prefix == "*": - remote_result.update({"remote": "*", "remote_cidr": "*"}) - else: - remote_result.update({"remote": s_rule.source_address_prefix}) - - else: - address_prefixes = s_rule.source_address_prefixes - remote = "" - - if address_prefixes: - for prfx in address_prefixes: - remote += prfx - remote += ", " - - remote = remote[:-2] - - remote_result.update({"remote": remote, "remote_cidr": remote}) - - if len(remote_result) > 0: - return remote_result - - return None - - @staticmethod - def get_nsg_port(s_rule): - port_result = {} - - if ( - getattr(s_rule, "destination_port_range") - and s_rule.destination_port_range is not None - ): - if "-" in s_rule.destination_port_range: - port_min = s_rule.destination_port_range.split("-")[0] - port_max = s_rule.destination_port_range.split("-")[1] - port_result.update( - { - "port_range_min": port_min, - "port_range_max": port_max, - "port": s_rule.destination_port_range, - } - ) - elif s_rule.destination_port_range == "*": - port_result.update( - {"port_range_min": 0, "port_range_max": 0, "port": "*"} - ) - else: - port_result.update( - { - "port_range_min": s_rule.destination_port_range, - "port_range_max": s_rule.destination_port_range, - "port": s_rule.destination_port_range, - } - ) - else: - if ( - getattr(s_rule, "destination_port_ranges") - and s_rule.destination_port_ranges - ): - port_ranges = s_rule.destination_port_ranges - if not port_ranges: - port_ranges = [] - - port_min = 0 - port_max = 0 - all_port = "" - ports = [] - - for port in port_ranges: - if "-" in port: # ex. ['33-55'] - for i in port.split("-"): - ports.append(i) - else: # ex. ['8080'] - ports.append(port) - - ports = list(map(int, ports)) # Change to int list - - if ports: - port_min = min(ports) - port_max = max(ports) - - all_port = ", ".join(map(str, ports)) # Update string - - port_result.update( - { - "port_range_min": port_min, - "port_range_max": port_max, - "port": all_port, - } - ) - - if len(port_result) > 0: - return port_result - - return None diff --git a/src/spaceone/inventory/manager/virtual_machines/nic_manager.py b/src/spaceone/inventory/manager/virtual_machines/nic_manager.py deleted file mode 100644 index 80525382..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/nic_manager.py +++ /dev/null @@ -1,133 +0,0 @@ -from spaceone.core.manager import BaseManager -from spaceone.inventory.model.virtual_machines.data import NIC, NICTags -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector - - -class VirtualMachineNICManager(BaseManager): - def __init__(self, params, azure_vm_connector=None, **kwargs): - super().__init__(**kwargs) - self.params = params - self.azure_vm_connector: VirtualMachinesConnector = azure_vm_connector - - def get_nic_info( - self, vm, network_interfaces, public_ip_addresses, virtual_networks - ): - """ - nic_data = { - "device_index": 0, - "device": "", - "nic_type": "", - "ip_addresses": [], - "cidr": "", - "mac_address": "", - "public_ip_address": "", - "tags": { - "nic_id": "" - } - } - """ - - nic_data = [] - index = 0 - - vm_network_interfaces = vm.network_profile.network_interfaces - - if vm_network_interfaces is None: - vm_network_interfaces = [] - - match_network_interfaces = self.get_network_interfaces( - vm_network_interfaces, network_interfaces - ) - - for vm_nic in match_network_interfaces: - ip_configurations = self.get_ip_configurations(vm_nic) - - network_data = { - "device_index": index, - "cidr": self.get_nic_cidr(ip_configurations, virtual_networks), - "ip_addresses": self.get_nic_ip_addresses(ip_configurations), - "mac_address": vm_nic.mac_address, - "public_ip_address": self.get_nic_public_ip_addresses( - ip_configurations, public_ip_addresses - ), - "tags": self.get_tags(vm_nic), - } - - primary_ip = self.get_primary_ip_addresses( - self.get_ip_configurations(vm_nic) - ) - - index += 1 - nic_data.append(NIC(network_data, strict=False)) - - return nic_data, primary_ip - - @staticmethod - def get_nic_public_ip_addresses(ip_configurations, public_ip_addresses): - for ip_conf in ip_configurations: - if getattr(ip_conf, "public_ip_address") and ip_conf.public_ip_address: - ip_name = ip_conf.public_ip_address.id.split("/")[-1] - for pub_ip in public_ip_addresses: - if ip_name == pub_ip.name: - return pub_ip.ip_address - - return None - - @staticmethod - def get_nic_cidr(ip_configurations, virtual_networks): - if ip_configurations: - subnet_name = ip_configurations[0].subnet.id.split("/")[-1] - for vnet in virtual_networks: - for subnet in vnet.subnets: - if subnet_name == subnet.name: - return subnet.address_prefix - - return None - - @staticmethod - def get_nic_ip_addresses(ip_configurations): - ip_addresses = [] - for ip_conf in ip_configurations: - ip_addresses.append(ip_conf.private_ip_address) - - if ip_addresses: - return ip_addresses - - return None - - @staticmethod - def get_primary_ip_addresses(ip_configurations): - result = {} - for ip_conf in ip_configurations: - result.update({ip_conf.private_ip_address: ip_conf.primary}) - - return result - - @staticmethod - def get_ip_configurations(vm_nic): - result = [] - if getattr(vm_nic, "ip_configurations") and vm_nic.ip_configurations: - for ip in vm_nic.ip_configurations: - result.append(ip) - - return result - - @staticmethod - def get_tags(vm_nic): - return { - "name": vm_nic.name, - "etag": vm_nic.etag, - "enable_accelerated_networking": vm_nic.enable_accelerated_networking, - "enable_ip_forwarding": vm_nic.enable_ip_forwarding, - } - - @staticmethod - def get_network_interfaces(vm_network_interfaces, network_interfaces): - result = [] - for vm_nic in vm_network_interfaces: - for nic in network_interfaces: - if vm_nic.id.split("/")[-1] == nic.name: - result.append(nic) - break - - return result diff --git a/src/spaceone/inventory/manager/virtual_machines/vm_manager.py b/src/spaceone/inventory/manager/virtual_machines/vm_manager.py deleted file mode 100644 index 58a4e9ce..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/vm_manager.py +++ /dev/null @@ -1,416 +0,0 @@ -from spaceone.core.manager import BaseManager -from spaceone.inventory.model.virtual_machines.data import Compute, Azure, OS, Hardware, ResourceGroup -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector - - -class VirtualMachineVmManager(BaseManager): - - def __init__(self, params, azure_vm_connector=None, **kwargs): - super().__init__(**kwargs) - self.params = params - self.azure_vm_connector: VirtualMachinesConnector = azure_vm_connector - - def get_vm_info(self, vm, disks, nics, resource_group, subscription, network_security_groups, primary_ip, skus_dict): - ''' - server_data = { - "name": "" - "ip_addresses": [], - "data": { - "primary_ip_address": "", - "os": { - "os_distro": "", - "os_arch": "", - "os_details": "", - "os_type": "LINUX" | "WINDOWS" - }, - "azure": { - "boot_diagnostics": "true" | "false", - "ultra_ssd_enabled": "true" | "false", - "write_accelerator_enabled": "true" | "false", - "priority": "Regular" | "Low" | "Spot", - "tags": { - "key": "", - "value": "" - }, - }, - "hardware": { - "core": 0, - "memory": 0 - }, - "compute": { - "keypair": "", - "availability_zone": "", - "instance_state": "", - "instance_type": "", - "launched_at": "datetime", - "instance_id": "", - "instance_name": "", - "security_groups": [ - { - "id": "", - "name": "", - "display": "" - }, - ... - ], - "image": "", - "account": "", - "tags": { - "id": "" - } - }, - "nics": [ - { nics_info }, - ... - ], - "disks": [ - { disk_info }, - ... - ] - } - } - ''' - - resource_group_name = resource_group.name - - vm_dict = self.get_vm_dict(vm, nics) - os_data = self.get_os_data(vm.storage_profile) - azure_data = self.get_azure_data(vm) - compute_data = self.get_compute_data(vm, resource_group_name, network_security_groups, subscription) - resource_group_data = self.get_resource_group_data(resource_group) - hardware_data = self.get_hardware_data(vm, skus_dict, compute_data) - - vm_dict.update({ - 'data': { - 'os': os_data, - 'hardware': hardware_data, - 'azure': azure_data, - 'compute': compute_data, - 'resource_group': resource_group_data, - 'disks': disks, - 'nics': nics, - 'primary_ip_address': self.get_primary_ip_address(primary_ip) - } - }) - - return vm_dict - - def get_vm_dict(self, vm, nic_vos): - vm_data = { - 'name': vm.name, - 'region_code': vm.location, - 'ip_addresses': self.get_ip_addresses(nic_vos), - } - return vm_data - - def get_os_data(self, vm_storage_profile): - if vm_storage_profile.image_reference is not None: - try: - os_type = self.get_os_type(vm_storage_profile.os_disk) - image_reference = vm_storage_profile.image_reference - offer = vm_storage_profile.image_reference.offer - - if os_type and offer is not None: - try: - os_data = { - 'os_distro': self.get_os_distro(os_type, offer), - 'details': self.get_os_details(image_reference), - 'os_type': os_type - } - return OS(os_data, strict=False) - - except Exception as e: - print(f'[ERROR: GET OS Distro Data]: {e}') - - except Exception as e: - print(f'[ERROR: GET OS Data]: {e}') - - def get_compute_data(self, vm, resource_group_name, network_security_groups, subscription_id): - vm_info = self.azure_vm_connector.get_vm(resource_group_name, vm.name) - compute_data = { - # 'keypair': self.get_keypair(vm.os_profile.linux_configuration), - 'keypair': '', # TODO: not implemented yet - 'instance_state': self.get_instance_state(vm_info.instance_view.statuses), - 'instance_type': vm.hardware_profile.vm_size, - 'launched_at': self.get_launched_time(vm_info.instance_view.statuses), - 'instance_id': vm.id, - 'instance_name': vm.name, - 'security_groups': self.get_security_groups(vm.network_profile.network_interfaces, network_security_groups), - 'image': self.get_image_detail(vm.location, vm.storage_profile.image_reference, subscription_id), - 'tags': { - 'vm_id': vm.vm_id - } - } - - if vm.zones: - compute_data.update({ - 'az': f'{vm.location}-{vm.zones[0]}' - }) - else: - compute_data.update({ - 'az': vm.location - }) - - return Compute(compute_data, strict=False) - - def get_azure_data(self, vm): - azure_data = { - 'ultra_ssd_enabled': self.get_ultra_ssd_enabled(vm.additional_capabilities), - 'write_accelerator_enabled': self.get_write_accelerator_enabled(vm.storage_profile.os_disk), - 'priority': self.get_vm_priority(vm), - 'tags': self.get_tags(vm.tags) - } - - if getattr(vm, 'diagnostics_profile') and getattr(vm.diagnostics_profile, "boot_diagnostics") and vm.diagnostics_profile.boot_diagnostics: - azure_data.update({ - 'boot_diagnostics': self.get_boot_diagnostics(vm.diagnostics_profile.boot_diagnostics) - }) - - return Azure(azure_data, strict=False) - - def get_vm_size(self, location): - return self.azure_vm_connector.list_virtual_machine_sizes(location) - - @staticmethod - def get_hardware_data(vm, skus_dict, compute_data): - """ - skus_dict = [ - { - 'memory': '0.75', - 'family': 'basicAFamily', - 'name': 'Basic_A0', - 'resource_type': 'virtualMachines', - 'size': 'A0', - 'tier': 'Basic', - 'core': '1'}, - }, - ] - """ - - location = vm.location.lower() - instance_type = compute_data.instance_type - - hardware_data = Hardware(strict=False) - for sku in skus_dict[location]: - if sku['name'] == instance_type: - hardware_data = Hardware(sku, strict=False) - return hardware_data - - def get_os_distro(self, os_type, offer): - return self.extract_os_distro(os_type, offer) - - @staticmethod - def get_write_accelerator_enabled(os_disk): - if hasattr(os_disk.write_accelerator_enabled, 'os_disk.write_accelerator_enabled'): - return os_disk.write_accelerator_enabled - return False - - @staticmethod - def get_boot_diagnostics(boot_diagnostics): - if hasattr(boot_diagnostics.enabled, 'boot_diagnostics.enabled'): - return boot_diagnostics.enabled - return True - - @staticmethod - def get_keypair(linux_configuration): - if hasattr(linux_configuration, 'ssh') and linux_configuration.ssh: - key = linux_configuration.ssh.public_keys[0] - - return key.path.split('/')[2] - return "" - - @staticmethod - def get_ip_addresses(nic_vos): - ip_addrs = [] - for nic_vo in nic_vos: - ip_addrs.extend(nic_vo.ip_addresses) - - if nic_vo.public_ip_address: - ip_addrs.append(nic_vo.public_ip_address) - - return list(set(ip_addrs)) - - @staticmethod - def get_primary_ip_address(primary_ip): - for key, value in primary_ip.items(): - if value: - return key - - return '' - - @staticmethod - def get_vm_priority(vm): - if hasattr(vm, 'priority') and vm.priority: - return vm.priority - else: - return 'Regular' - - @staticmethod - def get_vm_hardware_info(list_sizes, size): - result = {} - for list_size in list_sizes: - if list_size.name == size: - result.update({ - 'core': list_size.number_of_cores, - 'memory': round(float(list_size.memory_in_mb / 1024), 2) - }) - break - - return result - - @staticmethod - def get_security_groups(vm_network_interfaces, network_security_groups): - security_groups = [] - nic_names = [] - - if vm_network_interfaces is None: - vm_network_interfaces = [] - - for vm_nic in vm_network_interfaces: - nic_name = vm_nic.id.split('/')[-1] - nic_names.append(nic_name) - - for nsg in network_security_groups: - network_interfaces = nsg.network_interfaces - if network_interfaces: - for nic in network_interfaces: - nic_name2 = nic.id.split('/')[-1] - for nic_name in nic_names: - if nic_name == nic_name2: - nsg_data = { - 'display': nsg.name, - 'id': nsg.id, - 'name': nsg.name - } - security_groups.append(nsg_data) - break - break - if len(security_groups) > 0: - return security_groups - return None - - @staticmethod - def get_launched_time(statuses): - if statuses is None: - statuses = [] - - for status in statuses: - if status.display_status == 'Provisioning succeeded': - return status.time.isoformat() - - return None - - @staticmethod - def get_instance_state(statuses): - try: - if statuses: - return statuses[-1].code.split('/')[-1].upper() - except Exception: - pass - - return None - - @staticmethod - def get_resource_group_data(resource_group): - resource_group_data = { - 'resource_group_name': resource_group.name, - 'resource_group_id': resource_group.id - } - return ResourceGroup(resource_group_data, strict=False) - - @staticmethod - def get_ultra_ssd_enabled(additional_capabilities): - if additional_capabilities: - return additional_capabilities.ultra_ssd_enabled - else: - return False - - @staticmethod - def get_os_type(os_disk): - if os_disk.os_type is not None: - return os_disk.os_type.upper() - - @staticmethod - def extract_os_distro(os_type, offer): - if offer is not None and os_type is not None: - try: - offer.lower() - - if os_type == 'LINUX': - os_map = { - 'suse': 'suse', - 'rhel': 'redhat', - 'centos': 'centos', - 'cent': 'centos', - 'fedora': 'fedora', - 'ubuntu': 'ubuntu', - 'ubuntuserver': 'ubuntu', - 'oracle': 'oraclelinux', - 'oraclelinux': 'oraclelinux', - 'debian': 'debian' - } - - for key in os_map: - if key in offer: - return os_map[key] - - return 'linux' - - elif os_type == 'WINDOWS': - os_distro_string = None - offer_splits = offer.split('-') - - version_cmps = ['2016', '2019', '2012'] - - for cmp in version_cmps: - if cmp in offer_splits: - os_distro_string = f'win{cmp}' - - if os_distro_string is not None and 'R2_RTM' in offer_splits: - os_distro_string = f'{os_distro_string}r2' - - if os_distro_string is None: - os_distro_string = 'windows' - - return os_distro_string - - except Exception as e: - print(f'[ERROR: Cannot extract os distro info]: {e}') - - @staticmethod - def get_os_details(image_reference): - if image_reference: - publisher = image_reference.publisher - offer = image_reference.offer - sku = image_reference.sku - if publisher and offer and sku: - os_details = f'{publisher}, {offer}, {sku}' - return os_details - - return None - - @staticmethod - def get_image_detail(location, image_reference, subscription_id): - publisher = getattr(image_reference, "publisher", None) - offer = getattr(image_reference, "offer", None) - sku = getattr(image_reference, "sku", None) - version = getattr(image_reference, "exact_version", None) - - if publisher and offer and sku and version: - image_detail = f'/Subscriptions/{subscription_id}/Providers/Microsoft.Compute/Locations/{location}' \ - f'/Publishers/{publisher}/ArtifactTypes/VMImage/Offers/{offer}/Skus/{sku}/Versions/{version}' - return image_detail - - return None - - @staticmethod - def get_tags(tags): - tags_result = [] - if tags: - for k, v in tags.items(): - tags_result.append({ - 'key': k, - 'value': v - }) - - return tags_result diff --git a/src/spaceone/inventory/manager/virtual_machines/vnet_manager.py b/src/spaceone/inventory/manager/virtual_machines/vnet_manager.py deleted file mode 100644 index 0155eb5a..00000000 --- a/src/spaceone/inventory/manager/virtual_machines/vnet_manager.py +++ /dev/null @@ -1,72 +0,0 @@ -from spaceone.core.manager import BaseManager -from spaceone.inventory.model.virtual_machines.data import VNet, Subnet -from spaceone.inventory.connector.virtual_machines import VirtualMachinesConnector - - -class VirtualMachineVNetManager(BaseManager): - - def __init__(self, params, azure_vm_connector=None, **kwargs): - super().__init__(**kwargs) - self.params = params - self.azure_vm_connector: VirtualMachinesConnector = azure_vm_connector - - def get_vnet_subnet_info(self, nic_name, network_interfaces, virtual_networks): - ''' - vnet_subnet_dict = { - "vnet_info": vnet_data, - "subnet_info": subnet_data - } - ''' - vnet_info_dict = {} - - for nic in network_interfaces: - if nic.name == nic_name: - vnet_name = nic.ip_configurations[0].subnet.id.split('/')[-3] - - if vnet_name is not None and len(virtual_networks) > 0: - for vnet in virtual_networks: - if vnet.name == vnet_name: - subnet_info = self.convert_subnet_info(vnet.subnets[0]) # Get attached subnets - vnet_info = self.convert_vnet_info(vnet) - if subnet_info is not None: - vnet_info_dict['subnet_info'] = subnet_info - if vnet_info is not None: - vnet_info_dict['vnet_info'] = vnet_info - - return vnet_info_dict - - @staticmethod - def convert_vnet_info(vnet): - ''' - vnet_data = { - "vnet_id" = "", - "vnet_name" = "", - "cidr" = "" - } - ''' - - vnet_data = { - 'vnet_id': vnet.id, - 'vnet_name': vnet.name, - 'cidr': vnet.address_space.address_prefixes[0] - } - - return VNet(vnet_data, strict=False) - - @staticmethod - def convert_subnet_info(subnet): - ''' - subnet_data = { - "subnet_name": "", - "subnet_id": "", - "cidr": "" - } - ''' - - subnet_data = { - 'subnet_name': subnet.name, - 'subnet_id': subnet.id, - 'cidr': subnet.address_prefix - } - - return Subnet(subnet_data, strict=False) diff --git a/src/spaceone/inventory/manager/virtual_networks/__init__.py b/src/spaceone/inventory/manager/virtual_networks/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/virtual_networks/instance_manager.py b/src/spaceone/inventory/manager/virtual_networks/instance_manager.py deleted file mode 100644 index d4f6d97f..00000000 --- a/src/spaceone/inventory/manager/virtual_networks/instance_manager.py +++ /dev/null @@ -1,261 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.virtual_networks import VirtualNetworksConnector -from spaceone.inventory.model.virtual_networks.cloud_service import * -from spaceone.inventory.model.virtual_networks.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.virtual_networks.data import * - -_LOGGER = logging.getLogger(__name__) - - -class VirtualNetworksManager(AzureManager): - connector_name = "VirtualNetworksConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of virtual network data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug("** Vnet START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - vnet_conn: VirtualNetworksConnector = self.locator.get_connector( - self.connector_name, **params - ) - virtual_network_responses = [] - error_responses = [] - - virtual_networks = vnet_conn.list_all_virtual_networks() - - for virtual_network in virtual_networks: - virtual_network_id = "" - - try: - vnet_dict = self.convert_nested_dictionary(virtual_network) - virtual_network_id = vnet_dict["id"] - - # update vnet_dict - vnet_dict = self.update_tenant_id_from_secret_data( - vnet_dict, params["secret_data"] - ) - vnet_dict.update( - { - "resource_group": self.get_resource_group_from_id( - virtual_network_id - ), - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": virtual_network_id}, - } - ) - - if vnet_dict.get("subnets") is not None: - subnets = vnet_dict["subnets"] - resource_group = vnet_dict["resource_group"] - - # Change attached network interfaces objects to id - self.change_subnet_object_to_ids_list(subnets) - - vnet_dict.update( - { - "subnets": self.update_subnet_info(subnets), - "service_endpoints": self.get_service_endpoints(subnets), - "private_endpoints": self.get_private_endpoints(subnets), - "azure_firewall": self.get_azure_firewall( - vnet_conn, subnets, resource_group - ), - "connected_devices": self.get_connected_devices(subnets), - } - ) - - # If not 'custom dns servers', add default azure dns server dict to vnet - if vnet_dict.get("dhcp_options") is None: - dhcp_option_dict = {"dns_servers": ["Azure provided DNS service"]} - vnet_dict.update({"dhcp_options": dhcp_option_dict}) - - """ - # Get IP Address Range, Count - if vnet_dict.get('address_space') is not None: - if vnet_dict['address_space'].get('address_prefixes') is not None: - for address_space in vnet_dict['address_space']['address_prefixes']: # ex. address_space = '10.0.0.0/16' - ip = IPNetwork(address_space) - # vnet_dict['address_space']['address_count'] = ip.size - """ - - vnet_data = VirtualNetwork(vnet_dict, strict=False) - vnet_resource = VirtualNetworkResource( - { - "data": vnet_data, - "region_code": vnet_data.location, - "reference": ReferenceModel(vnet_data.reference()), - "name": vnet_data.name, - "account": vnet_data.subscription_id, - "tags": vnet_dict.get("tags", {}), - } - ) - - # Must set_region_code method for region collection - self.set_region_code(vnet_data["location"]) - # _LOGGER.debug(f'[VNET INFO] {vnet_resource.to_primitive()}') - virtual_network_responses.append( - VirtualNetworkResponse({"resource": vnet_resource}) - ) - - except Exception as e: - _LOGGER.error( - f"[list_instances] {virtual_network_id} {e}", exc_info=True - ) - error_resource_response = self.generate_resource_error_response( - e, "Network", "VirtualNetwork", virtual_network_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug( - f"** Virtual Network Finished {time.time() - start_time} Seconds **" - ) - return virtual_network_responses, error_responses - - def get_azure_firewall(self, vnet_conn, subnet_list, resource_group_name): - # Get Azure firewall information - azure_firewall_list = [] - for subnet in subnet_list: - if subnet.get("connected_devices_list"): - for device in subnet["connected_devices_list"]: - if ( - device["type"] == "azureFirewalls" - ): # The subnet which has 'AzureFirewall' is typed as 'azureFirewalls' - firewall_obj = vnet_conn.list_all_firewalls( - resource_group_name - ) # List all firewalls in the resource group - for firewall in firewall_obj: - firewall_dict = self.convert_nested_dictionary(firewall) - for ip_configuration in firewall_dict["ip_configurations"]: - if ip_configuration.get("subnet") is not None: - if ( - subnet["id"] in ip_configuration["subnet"]["id"] - ): # If subnet id matches the firewall's subnet id - firewall_dict["subnet"] = subnet["id"].split( - "/" - )[10] - azure_firewall_list.append(firewall_dict) - - return azure_firewall_list - - @staticmethod - def change_subnet_object_to_ids_list(subnets_dict): - subnet_id_list = [] - for subnet in subnets_dict: - subnet_id_list.append(subnet["id"]) - if subnet.get("private_endpoints") is not None: - for private_endpoint in subnet["private_endpoints"]: - if private_endpoint.get("network_interfaces") is not None: - for ni in private_endpoint["network_interfaces"]: - if ni.get("network_security_group") is not None: - ni["network_interfaces"] = ni["id"] - ni["subnets"] = subnet_id_list - - return subnet_id_list - - @staticmethod - def update_subnet_info(subnet_list): - """ - : subnets_dict = { - ip_configurations= [ - { - 'id': '/subscriptions/xxx/resourceGroups/xxx/Microsoft.Network/[DeviceType]/[DeviceName] - }, - ... - ] - } - :return - subnets_dict = { - connected_devices_list = [ - { - 'device' :, - 'type' :, - 'ip_address' : , - 'subnet': - } - ] - - 'network_security_group' : { - 'id' : , - 'name' : - } - } - ... - """ - - for subnet in subnet_list: - # Get network security group's name - if subnet.get("network_security_group") is not None: - subnet["network_security_group"]["name"] = subnet[ - "network_security_group" - ]["id"].split("/")[8] - - # Get private endpoints - if subnet.get("private_endpoints") is not None: - for private_endpoint in subnet["private_endpoints"]: - private_endpoint.update( - { - "name": private_endpoint["id"].split("/")[8], - "subnet": subnet["name"], - "resource_group": private_endpoint["id"].split("/")[4], - } - ) - - return subnet_list - - @staticmethod - def get_service_endpoints(subnet_list): - service_endpoint_list = [] - for subnet in subnet_list: - # Put subnet name to service endpoints dictionary - if subnet.get("service_endpoints") is not None: - for service_endpoint in subnet["service_endpoints"]: - service_endpoint["subnet"] = subnet["name"] - service_endpoint_list.append(service_endpoint) - - return service_endpoint_list - - @staticmethod - def get_private_endpoints(subnet_list): - private_endpoint_list = [] - for subnet in subnet_list: - if subnet.get("private_endpoints") is not None: - for private_endpoint in subnet["private_endpoints"]: - private_endpoint_list.append(private_endpoint) - - return private_endpoint_list - - @staticmethod - def get_connected_devices(subnet_list): - connected_devices_list = [] - for subnet in subnet_list: - device_dict = {} - - if subnet.get("ip_configurations") is not None: - for ip_configuration in subnet["ip_configurations"]: - device_dict["name"] = subnet["name"] - device_dict["type"] = ip_configuration["id"].split("/")[7] - device_dict["device"] = ip_configuration["id"].split("/")[8] - connected_devices_list.append(device_dict) - - return connected_devices_list diff --git a/src/spaceone/inventory/manager/vm_scale_sets/__init__.py b/src/spaceone/inventory/manager/vm_scale_sets/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/vm_scale_sets/scale_set_manager.py b/src/spaceone/inventory/manager/vm_scale_sets/scale_set_manager.py deleted file mode 100644 index 92463cb4..00000000 --- a/src/spaceone/inventory/manager/vm_scale_sets/scale_set_manager.py +++ /dev/null @@ -1,489 +0,0 @@ -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.inventory.connector.vm_scale_sets import VmScaleSetsConnector -from spaceone.inventory.model.vm_scale_sets.cloud_service import * -from spaceone.inventory.model.vm_scale_sets.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.model.vm_scale_sets.data import * - -_LOGGER = logging.getLogger(__name__) - - -class VmScaleSetsManager(AzureManager): - connector_name = "VmScaleSetsConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - Response: - CloudServiceResponse (list) : dictionary of azure vm scale set data resource information - ErrorResourceResponse (list) : list of error resource information - - """ - _LOGGER.debug("** VmScaleSet START **") - start_time = time.time() - - subscription_info = params["subscription_info"] - - vm_scale_set_conn: VmScaleSetsConnector = self.locator.get_connector( - self.connector_name, **params - ) - vm_scale_set_responses = [] - error_responses = [] - - vm_scale_sets = vm_scale_set_conn.list_vm_scale_sets() - - for vm_scale_set in vm_scale_sets: - vm_scale_set_id = "" - - try: - vm_scale_set_dict = self.convert_nested_dictionary(vm_scale_set) - vm_scale_set_id = vm_scale_set_dict["id"] - - # update vm_scale_set_dict - vm_scale_set_dict.update( - { - "resource_group": self.get_resource_group_from_id( - vm_scale_set_id - ), # parse resource_group from ID - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": vm_scale_set_id}, - } - ) - - if vm_scale_set_dict.get( - "proximity_placement_group" - ): # if it has a key -> get value -> check if it isn't None / if no 'Key' -> return None - vm_scale_set_dict.update( - { - "proximity_placement_group_display": self.get_proximity_placement_group_name( - vm_scale_set_dict["proximity_placement_group"]["id"] - ) - } - ) - - # Get Instance termination notification display - if vm_scale_set_dict.get("virtual_machine_profile") is not None: - if ( - vm_scale_set_dict["virtual_machine_profile"].get( - "scheduled_events_profile" - ) - is not None - ): - if vm_scale_set.virtual_machine_profile[ - "scheduled_events_profile" - ]["terminate_notification_profile"]["enable"]: - terminate_notification_display = "On" - else: - terminate_notification_display = "Off" - - vm_scale_set_dict.update( - { - "terminate_notification_display": terminate_notification_display - } - ) - - # Convert disks' sku-dict to string display - if ( - vm_scale_set_dict["virtual_machine_profile"].get( - "storage_profile" - ) - is not None - ): - if vm_scale_set_dict["virtual_machine_profile"][ - "storage_profile" - ].get("image_reference"): - image_reference_dict = vm_scale_set_dict[ - "virtual_machine_profile" - ]["storage_profile"]["image_reference"] - image_reference_str = ( - str(image_reference_dict["publisher"]) - + " / " - + str(image_reference_dict["offer"]) - + " / " - + str(image_reference_dict["sku"]) - + " / " - + str(image_reference_dict["version"]) - ) - vm_scale_set_dict["virtual_machine_profile"][ - "storage_profile" - ].update({"image_reference_display": image_reference_str}) - - # switch storage_account_type to storage_account_type for user-friendly words. - # (ex.Premium LRS -> Premium SSD, Standard HDD..) - if vm_scale_set_dict["virtual_machine_profile"][ - "storage_profile" - ].get("data_disks"): - for data_disk in vm_scale_set_dict[ - "virtual_machine_profile" - ]["storage_profile"]["data_disks"]: - data_disk["managed_disk"].update( - { - "storage_type": self.get_disk_storage_type( - data_disk["managed_disk"][ - "storage_account_type" - ] - ) - } - ) - # Get VM Profile's operating_system type (Linux or Windows) - if ( - vm_scale_set_dict["virtual_machine_profile"].get("os_profile") - is not None - ): - vm_scale_set_dict["virtual_machine_profile"][ - "os_profile" - ].update( - { - "operating_system": self.get_operating_system( - vm_scale_set_dict["virtual_machine_profile"][ - "os_profile" - ] - ) - } - ) - - # Get VM Profile's primary Vnet\ - if ( - vm_scale_set_dict["virtual_machine_profile"].get( - "network_profile" - ) - is not None - ): - vmss_vm_network_profile_dict = vm_scale_set_dict[ - "virtual_machine_profile" - ]["network_profile"] - - if primary_vnet := self.get_primary_vnet( - vmss_vm_network_profile_dict[ - "network_interface_configurations" - ] - ): - vmss_vm_network_profile_dict.update( - {"primary_vnet": primary_vnet} - ) - - # Add vm instances list attached to VMSS - vm_instances_list = list() - instance_count = 0 - resource_group = vm_scale_set_dict["resource_group"] - name = vm_scale_set_dict["name"] - - for vm_instance in vm_scale_set_conn.list_vm_scale_set_vms( - resource_group, name - ): - instance_count += 1 - vm_scale_set_dict.update({"instance_count": instance_count}) - - vm_instance_dict = self.get_vm_instance_dict( - vm_instance, vm_scale_set_conn, resource_group, name - ) - vm_instances_list.append(vm_instance_dict) - - vm_scale_set_dict["vm_instances"] = vm_instances_list - - # Get auto scale settings by resource group and vm id - vm_scale_set_dict.update( - { - "autoscale_settings": self.list_auto_scale_settings_obj( - vm_scale_set_conn, resource_group, vm_scale_set_id - ) - } - ) - - # Set virtual_machine_scale_set_power_state information - if vm_scale_set_dict.get("autoscale_settings") is not None: - vm_scale_set_dict.update( - { - "virtual_machine_scale_set_power_state": self.list_virtual_machine_scale_set_power_state( - vm_scale_set_dict["autoscale_settings"] - ), - } - ) - - # update auto_scale_settings to autoscale_setting_resource_collection - auto_scale_setting_resource_col_dict = dict() - auto_scale_setting_resource_col_dict.update( - { - "value": self.list_auto_scale_settings( - vm_scale_set_conn, resource_group, vm_scale_set_id - ) - } - ) - - vm_scale_set_dict.update( - { - "autoscale_setting_resource_collection": auto_scale_setting_resource_col_dict - } - ) - - vm_scale_set_data = VirtualMachineScaleSet( - vm_scale_set_dict, strict=False - ) - vm_scale_set_resource = VmScaleSetResource( - { - "data": vm_scale_set_data, - "region_code": vm_scale_set_data.location, - "reference": ReferenceModel(vm_scale_set_data.reference()), - "tags": vm_scale_set_dict.get("tags", {}), - "name": vm_scale_set_data.name, - "account": vm_scale_set_data.subscription_id, - "instance_type": vm_scale_set_data.sku.name, - } - ) - - # Must set_region_code method for region collection - self.set_region_code(vm_scale_set_data["location"]) - # _LOGGER.debug(f'[VM_SCALE_SET_INFO] {vm_scale_set_resource.to_primitive()}') - vm_scale_set_responses.append( - VmScaleSetResponse({"resource": vm_scale_set_resource}) - ) - - except Exception as e: - _LOGGER.error(f"[list_instances] {vm_scale_set_id} {e}", exc_info=True) - error_resource_response = self.generate_resource_error_response( - e, "Compute", "VMScaleSet", vm_scale_set_id - ) - error_responses.append(error_resource_response) - - _LOGGER.debug(f"** VmScaleSet Finished {time.time() - start_time} Seconds **") - return vm_scale_set_responses, error_responses - - def get_autoscale_rules(self, rules_dict): - rule_list = list() - for rule in rules_dict: - rule_dict = self.convert_nested_dictionary(rule) - rule_list.append(rule_dict) - return rule_list - - # Get instances of a virtual machine from a VM scale set - def get_vm_instance_dict( - self, vm_instance, vm_instance_conn, resource_group, vm_scale_set_name - ): - vm_instance_dict = self.convert_nested_dictionary(vm_instance) - - # Get Instance view of a virtual machine from a VM scale set Instance - # todo : remove - # issue ticket : https://github.com/Azure/azure-sdk-for-python/issues/35789 - # if vm_instance_dict.get("instance_id") is not None: - # vm_instance_dict.update( - # { - # "vm_instance_status_profile": self.get_vm_instance_view_dict( - # vm_instance_conn, - # resource_group, - # vm_scale_set_name, - # "0:", - # ) - # } - # ) - if vm_instance_dict.get("vm_instance_status_profile") is not None: - if ( - vm_instance_dict["vm_instance_status_profile"].get("vm_agent") - is not None - ): - vm_instance_dict.update( - { - "vm_instance_status_display": vm_instance_dict[ - "vm_instance_status_profile" - ]["vm_agent"]["display_status"] - } - ) - - # Get Primary Vnet display - if getattr(vm_instance, "network_profile_configuration") is not None: - if primary_vnet := self.get_primary_vnet( - vm_instance_dict["network_profile_configuration"][ - "network_interface_configurations" - ] - ): - vm_instance_dict.update({"primary_vnet": primary_vnet}) - - return vm_instance_dict - - # Get Instance view of a virtual machine from a VM scale set Instance - def get_vm_instance_view_dict( - self, vm_instance_conn, resource_group, vm_scale_set_name, instance_id - ): - vm_instance_status_profile = vm_instance_conn.get_vm_scale_set_instance_view( - resource_group, vm_scale_set_name, instance_id - ) - vm_instance_status_profile_dict = self.convert_nested_dictionary( - vm_instance_status_profile - ) - - if vm_instance_status_profile.vm_agent is not None: - status_str = None - - for status in vm_instance_status_profile_dict.get("vm_agent").get( - "statuses" - ): - status_str = status["display_status"] - - if status_str: - vm_instance_status_profile_dict["vm_agent"].update( - {"display_status": status_str} - ) - - return vm_instance_status_profile_dict - - def list_auto_scale_settings( - self, vm_scale_set_conn, resource_group_name, vm_scale_set_id - ): - auto_scale_settings_list = list() - auto_scale_settings_obj = vm_scale_set_conn.list_auto_scale_settings( - resource_group=resource_group_name - ) # List all of the Auto scaling Rules in this resource group - - """""" - for auto_scale_setting in auto_scale_settings_obj: - auto_scale_setting_dict = self.convert_nested_dictionary(auto_scale_setting) - auto_scale_setting_dict.update( - { - "profiles_display": self.get_autoscale_profiles_display( - auto_scale_setting_dict["profiles"] - ) - } - ) - if ( - auto_scale_setting_dict["target_resource_uri"].lower() - == vm_scale_set_id.lower() - ): # Compare resources' id - auto_scale_settings_list.append(auto_scale_setting_dict) - - return auto_scale_settings_list - - def get_autoscale_profiles_list(self, autoscale_setting): - profiles_list = list() - for profile in autoscale_setting.profiles: - profile_dict = self.convert_nested_dictionary(profile) - profiles_list.append(profile_dict) - - return profiles_list - - def list_virtual_machine_scale_set_power_state(self, autoscale_obj_list): - power_state_dict = dict() - power_state_list = list() - - for autoscale_setting in autoscale_obj_list: - power_state_dict.update( - { - "location": autoscale_setting.location, - "profiles": self.get_autoscale_profiles_list( - autoscale_setting - ), # profiles_list - "enabled": autoscale_setting.enabled, - "name": autoscale_setting.name, - "notifications": autoscale_setting.notifications, - "target_resource_uri": autoscale_setting.target_resource_uri, - "tags": autoscale_setting.tags, - } - ) - - if power_state_dict.get("profiles") is not None: - power_state_dict.update( - { - "profiles_display": self.get_autoscale_profiles_display( - power_state_dict["profiles"] - ) - } - ) - power_state_list.append(power_state_dict) - return power_state_list - - @staticmethod - def get_proximity_placement_group_name(placement_group_id): - placement_group_name = placement_group_id.split("/")[ - 8 - ] # parse placement_group_name from placement_group_id - return placement_group_name - - @staticmethod - def get_source_disk_name(source_resource_id): - source_disk_name = source_resource_id.split("/")[ - 8 - ] # parse source_disk_name from source_resource_id - return source_disk_name - - @staticmethod - def get_disk_storage_type(sku_tier): - if sku_tier == "Premium_LRS": - sku_name = "Premium SSD" - elif sku_tier == "StandardSSD_LRS": - sku_name = "Standard SSD" - elif sku_tier == "Standard_LRS": - sku_name = "Standard HDD" - else: - sku_name = "Ultra SSD" - return sku_name - - @staticmethod - def get_operating_system(os_profile_dictionary): - if os_profile_dictionary["linux_configuration"] is None: - operating_system = "Windows" - else: - operating_system = "Linux" - return operating_system - - @staticmethod - def get_primary_vnet(network_interface_configurations): - vnet_id = None - - # 1) Find Primary NIC - for nic in network_interface_configurations: - if nic["primary"] is True: - # 2) Find primary ip configurations - for ip_configuration in nic["ip_configurations"]: - if ip_configuration["primary"] is True: - vnet_id = ip_configuration["subnet"]["id"].split("/")[8] - - return vnet_id - - @staticmethod - def list_auto_scale_settings_obj( - vm_scale_set_conn, resource_group_name, vm_scale_set_id - ): - auto_scale_settings_obj_list = list() - # all List of the Auto scaling Rules in this resource group - auto_scale_settings_obj = vm_scale_set_conn.list_auto_scale_settings( - resource_group=resource_group_name - ) - - for auto_scale_setting in auto_scale_settings_obj: - if ( - auto_scale_setting.target_resource_uri.lower() - == vm_scale_set_id.lower() - ): - auto_scale_settings_obj_list.append(auto_scale_setting) - - return auto_scale_settings_obj_list - - @staticmethod - def get_autoscale_profiles_display(power_state_profiles): - profiles_list = list() - for profile in power_state_profiles: - profiles_list.append( - "minimum : " - + str(profile["capacity"]["minimum"]) - + " / " - + "maximum : " - + str( - profile["capacity"]["maximum"] - + " / " - + "default : " - + profile["capacity"]["default"] - ) - ) - - return profiles_list diff --git a/src/spaceone/inventory/manager/web_pubsub_service/__init__.py b/src/spaceone/inventory/manager/web_pubsub_service/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/manager/web_pubsub_service/service_manager.py b/src/spaceone/inventory/manager/web_pubsub_service/service_manager.py deleted file mode 100644 index dd3fc5f2..00000000 --- a/src/spaceone/inventory/manager/web_pubsub_service/service_manager.py +++ /dev/null @@ -1,221 +0,0 @@ -import copy -import time -import logging -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.libs.schema.base import ReferenceModel -from spaceone.core.utils import * -from spaceone.inventory.model.web_pubsub_service.cloud_service_type import ( - CLOUD_SERVICE_TYPES, -) -from spaceone.inventory.connector.web_pubsub_service.connector import ( - WebPubSubServiceConnector, -) -from spaceone.inventory.model.web_pubsub_service.cloud_service import * -from spaceone.inventory.model.web_pubsub_service.data import * - -_LOGGER = logging.getLogger(__name__) - - -class WebPubSubServiceManager(AzureManager): - connector_name = "WebPubSubServiceConnector" - cloud_service_types = CLOUD_SERVICE_TYPES - - def collect_cloud_service(self, params): - """ - Args: - params (dict): - - 'options' : 'dict' - - 'schema' : 'str' - - 'secret_data' : 'dict' - - 'filter' : 'dict' - - 'zones' : 'list' - - 'subscription_info' : 'dict' - - Response: - CloudServiceResponse (list) : list of azure web pubsub service data resource information - ErrorResourceResponse (list) : list of error resource information - """ - - _LOGGER.debug(f"** Web PubSub Service START **") - start_time = time.time() - subscription_info = params["subscription_info"] - web_pubsub_responses = [] - error_responses = [] - - web_pubsub_service_conn: WebPubSubServiceConnector = self.locator.get_connector( - self.connector_name, **params - ) - web_pubsub_services = web_pubsub_service_conn.list_by_subscription() - - for web_pubsub_service in web_pubsub_services: - web_pubsub_service_id = "" - try: - web_pubsub_service_dict = self.convert_nested_dictionary( - web_pubsub_service - ) - web_pubsub_service_id = web_pubsub_service_dict["id"] - resource_group_name = self.get_resource_group_from_id( - web_pubsub_service_id - ) - resource_name = web_pubsub_service_dict["name"] - - # Update data info in Container Instance's Raw Data - - # Make private endpoint name - if private_endpoints := web_pubsub_service_dict.get( - "private_endpoint_connections", [] - ): - for private_endpoint in private_endpoints: - private_endpoint["private_endpoint"][ - "private_endpoint_name_display" - ] = self.get_resource_name_from_id( - private_endpoint["private_endpoint"]["id"] - ) - - # Collect Web PubSub Hub resource - web_pubsub_hubs = web_pubsub_service_conn.list_hubs( - resource_group_name=resource_group_name, resource_name=resource_name - ) - web_pubsub_hubs_dict = [ - self.convert_nested_dictionary(hub) for hub in web_pubsub_hubs - ] - - _hub_responses, _hub_errors = self._collect_web_pubsub_hub( - web_pubsub_hubs_dict, - subscription_info, - web_pubsub_service_dict["location"], - params["secret_data"]["tenant_id"], - ) - web_pubsub_responses.extend(_hub_responses) - error_responses.extend(_hub_errors) - - # Add Web PubSub Hub info in data - web_pubsub_hub_datas = [ - WebPubSubHub(hub_dict, strict=False) - for hub_dict in web_pubsub_hubs_dict - ] - - # Add Web PubSub Key info in data - # web_pubsub_key = web_pubsub_service_conn.list_keys( - # resource_group_name=resource_group_name, resource_name=resource_name - # ) - web_pubsub_key = {} - if web_pubsub_key: - web_pubsub_service_dict["web_pubsub_key"] = ( - WebPubSubKey( - self.convert_nested_dictionary(web_pubsub_key), strict=False - ), - ) - - web_pubsub_service_dict = self.update_tenant_id_from_secret_data( - web_pubsub_service_dict, params["secret_data"] - ) - web_pubsub_service_dict.update( - { - "resource_group": resource_group_name, - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": web_pubsub_service_id}, - "web_pubsub_hubs": web_pubsub_hub_datas, - "web_pubsub_hub_count_display": len(web_pubsub_hub_datas), - } - ) - - web_pubsub_service_data = WebPubSubService( - web_pubsub_service_dict, strict=False - ) - - # Update resource info of Container Instance - web_pubsub_service_resource = WebPubSubServiceResource( - { - "name": resource_name, - "account": web_pubsub_service_dict["subscription_id"], - "data": web_pubsub_service_data, - "tags": web_pubsub_service_dict.get("tags", {}), - "region_code": web_pubsub_service_data.location, - "reference": ReferenceModel( - web_pubsub_service_data.reference() - ), - } - ) - - self.set_region_code(web_pubsub_service_data["location"]) - web_pubsub_responses.append( - WebPubSubServiceResponse({"resource": web_pubsub_service_resource}) - ) - except Exception as e: - _LOGGER.error( - f"[list_instances] {web_pubsub_service_id} {e}", exc_info=True - ) - error_response = self.generate_resource_error_response( - e, "Service", "WebPubSubService", web_pubsub_service_id - ) - error_responses.append(error_response) - - _LOGGER.debug( - f"** Web PubSub Service Finished {time.time() - start_time} Seconds **" - ) - return web_pubsub_responses, error_responses - - def _collect_web_pubsub_hub( - self, web_pubsub_hubs_dict, subscription_info, location, tenant_id - ): - web_pubsub_hub_responses = [] - error_responses = [] - for web_pubsub_hub_dict in web_pubsub_hubs_dict: - web_pubsub_hub_id = "" - try: - web_pubsub_hub_id = web_pubsub_hub_dict["id"] - resource_group_name = self.get_resource_group_from_id(web_pubsub_hub_id) - - web_pubsub_hub_dict.update( - { - "tenant_id": tenant_id, - "location": location, - "resource_group": resource_group_name, - "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], - "azure_monitor": {"resource_id": web_pubsub_hub_id}, - "web_pubsub_svc_name": self.get_web_pubsub_name_from_id( - web_pubsub_hub_id - ), - "web_pubsub_hub_evnet_handler_count_display": len( - web_pubsub_hub_dict.get("properties", {}).get( - "event_handlers", [] - ) - ), - } - ) - web_pubsub_hub_data = WebPubSubHub(web_pubsub_hub_dict, strict=False) - web_pubsub_hub_resource = WebPubSubHubResource( - { - "name": web_pubsub_hub_data.name, - "account": web_pubsub_hub_dict["subscription_id"], - "data": web_pubsub_hub_data, - "tags": web_pubsub_hub_dict.get("tags", {}), - "region_code": web_pubsub_hub_data.location, - "reference": ReferenceModel(web_pubsub_hub_data.reference()), - } - ) - web_pubsub_hub_responses.append( - WebPubSubHubResponse({"resource": web_pubsub_hub_resource}) - ) - except Exception as e: - _LOGGER.error( - f"[list_instances] {web_pubsub_hub_id} {e}", exc_info=True - ) - error_response = self.generate_resource_error_response( - e, "Hub", "WebPubSubService", web_pubsub_hub_id - ) - error_responses.append(error_response) - return web_pubsub_hub_responses, error_responses - - @staticmethod - def get_resource_name_from_id(dict_id): - resource_name = dict_id.split("/")[-1] - return resource_name - - @staticmethod - def get_web_pubsub_name_from_id(dict_id): - svc_name = dict_id.split("/")[-3] - return svc_name diff --git a/src/spaceone/inventory/metrics/ApplicationGateways/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/ApplicationGateways/Instance/instance_count.yaml deleted file mode 100644 index 3bd083ba..00000000 --- a/src/spaceone/inventory/metrics/ApplicationGateways/Instance/instance_count.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -metric_id: metric-azure-ags-instance-count -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.ApplicationGateways.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - default: true - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group.resource_group_name - name: Resource Group - - key: data.operational_state - name: Operational State - default: true - - key: data.subnet - name: Subnet - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-ags-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/ApplicationGateways/Instance/namespace.yaml b/src/spaceone/inventory/metrics/ApplicationGateways/Instance/namespace.yaml deleted file mode 100644 index 3659a5f1..00000000 --- a/src/spaceone/inventory/metrics/ApplicationGateways/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-ags-instance -name: ApplicationGateways/Instance -category: ASSET -resource_type: inventory.CloudService:azure.ApplicationGateways.Instance -group: azure -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-application-gateways.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/ContainerInstances/Container/container_count.yaml b/src/spaceone/inventory/metrics/ContainerInstances/Container/container_count.yaml deleted file mode 100644 index 58dcc669..00000000 --- a/src/spaceone/inventory/metrics/ContainerInstances/Container/container_count.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -metric_id: metric-azure-cis-container-count -name: Container Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.ContainerInstances.Container -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.zones - name: Zone - - key: data.sku - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.os_type - name: OS Type - fields: - value: - key: data.container_count_display - operator: count -unit: Count -namespace_id: ns-azure-cis-container -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/ContainerInstances/Container/gpu_size.yaml b/src/spaceone/inventory/metrics/ContainerInstances/Container/gpu_size.yaml deleted file mode 100644 index 572a4b8d..00000000 --- a/src/spaceone/inventory/metrics/ContainerInstances/Container/gpu_size.yaml +++ /dev/null @@ -1,38 +0,0 @@ ---- -metric_id: metric-azure-cis-container-gpu-size -name: GPU Size -metric_type: GAUGE -resource_type: inventory.CloudService:azure.ContainerInstances.Container -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.zones - name: Zone - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku - name: Sku Tier - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.os_type - name: OS Type - fields: - value: - key: data.gpu_count_display - operator: sum -unit: GB -namespace_id: ns-azure-cis-container -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/ContainerInstances/Container/memory_size.yaml b/src/spaceone/inventory/metrics/ContainerInstances/Container/memory_size.yaml deleted file mode 100644 index 7a7cbe74..00000000 --- a/src/spaceone/inventory/metrics/ContainerInstances/Container/memory_size.yaml +++ /dev/null @@ -1,38 +0,0 @@ ---- -metric_id: metric-azure-cis-container-memory-size -name: Memory Size -metric_type: GAUGE -resource_type: inventory.CloudService:azure.ContainerInstances.Container -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.zones - name: Zone - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku - name: Sku Tier - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.os_type - name: OS Type - fields: - value: - key: data.memory_size_display - operator: sum -unit: GB -namespace_id: ns-azure-cis-container -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/ContainerInstances/Container/namespace.yaml b/src/spaceone/inventory/metrics/ContainerInstances/Container/namespace.yaml deleted file mode 100644 index 1f40fbe2..00000000 --- a/src/spaceone/inventory/metrics/ContainerInstances/Container/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-cis-container -name: ContainerInstances/Container -resource_type: inventory.CloudService:azure.ContainerInstances.Container -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-container-instances.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/ContainerInstances/Container/vcpu_count.yaml b/src/spaceone/inventory/metrics/ContainerInstances/Container/vcpu_count.yaml deleted file mode 100644 index e1481fc9..00000000 --- a/src/spaceone/inventory/metrics/ContainerInstances/Container/vcpu_count.yaml +++ /dev/null @@ -1,38 +0,0 @@ ---- -metric_id: metric-azure-cis-container-vcpu-count -name: vCPU Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.ContainerInstances.Container -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.zones - name: Zone - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku - name: Sku Tier - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.os_type - name: OS Type - fields: - value: - key: data.cpu_count_display - operator: sum -unit: Core -namespace_id: ns-azure-cis-container -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/CosmosDB/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/CosmosDB/Instance/instance_count.yaml deleted file mode 100644 index abf0ea46..00000000 --- a/src/spaceone/inventory/metrics/CosmosDB/Instance/instance_count.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -metric_id: metric-azure-cosmos-db-instance-count -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.CosmosDB.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.kind - name: Kind - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-cosmos-db-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/CosmosDB/Instance/namespace.yaml b/src/spaceone/inventory/metrics/CosmosDB/Instance/namespace.yaml deleted file mode 100644 index 3aa32269..00000000 --- a/src/spaceone/inventory/metrics/CosmosDB/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-cosmos-db-instance -name: CosmosDB/Instance -resource_type: inventory.CloudService:azure.CosmosDB.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-cosmos-db.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/CosmosDB/Instance/sql_database_count.yaml b/src/spaceone/inventory/metrics/CosmosDB/Instance/sql_database_count.yaml deleted file mode 100644 index fa2967bb..00000000 --- a/src/spaceone/inventory/metrics/CosmosDB/Instance/sql_database_count.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -metric_id: metric-azure-cosmos-db-instance-sql-db-count -name: SQL Database Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.CosmosDB.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.instance_type - name: Instance Type - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.kind - name: Kind - fields: - value: - key: data.sql_databases_count_display - operator: sum -unit: Count -namespace_id: ns-azure-cosmos-db-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/Disks/Disk/disk_count.yaml b/src/spaceone/inventory/metrics/Disks/Disk/disk_count.yaml deleted file mode 100644 index 4744998a..00000000 --- a/src/spaceone/inventory/metrics/Disks/Disk/disk_count.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -metric_id: metric-azure-disks-disk-count -name: Disk Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.Disks.Disk -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.zones - name: Zone - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: instance_type - name: Disk Type - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.disk_state - name: Disk State - default: true - - key: data.os_type - name: OS Type - - key: data.managed_by - name: Managed By - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-disks-disk -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/Disks/Disk/disk_size.yaml b/src/spaceone/inventory/metrics/Disks/Disk/disk_size.yaml deleted file mode 100644 index 7b949a25..00000000 --- a/src/spaceone/inventory/metrics/Disks/Disk/disk_size.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -metric_id: metric-azure-disks-disk-size -name: Disk Size -metric_type: GAUGE -resource_type: inventory.CloudService:azure.Disks.Disk -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - - key: data.zones - name: Zone - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: instance_type - name: Disk Type - - key: data.provisioning_state - name: Provisioning State - - default: true - - key: data.disk_state - name: Disk State - default: true - - key: data.os_type - name: OS Type - - key: data.managed_by - name: Managed By - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - fields: - value: - key: data.disk_size_gb - operator: sum -unit: GB -namespace_id: ns-azure-disks-disk -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/Disks/Disk/namespace.yaml b/src/spaceone/inventory/metrics/Disks/Disk/namespace.yaml deleted file mode 100644 index a2c4f412..00000000 --- a/src/spaceone/inventory/metrics/Disks/Disk/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-disks-disk -name: Disks/Disk -resource_type: inventory.CloudService:azure.Disks.Disk -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-disk.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/KeyVaults/Instance/certificates_count.yaml b/src/spaceone/inventory/metrics/KeyVaults/Instance/certificates_count.yaml deleted file mode 100644 index 7a400a02..00000000 --- a/src/spaceone/inventory/metrics/KeyVaults/Instance/certificates_count.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -metric_id: metric-azure-kvs-instance-certificate-count -name: Certificate Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.KeyVaults.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku.name - name: Sku Name - - key: data.properties.provisioning_state - name: Provisioning State - fields: - value: - key: data.certificate_count - operator: sum -unit: Count -namespace_id: ns-azure-key-vaults-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/KeyVaults/Instance/credentials_count.yaml b/src/spaceone/inventory/metrics/KeyVaults/Instance/credentials_count.yaml deleted file mode 100644 index a21492ad..00000000 --- a/src/spaceone/inventory/metrics/KeyVaults/Instance/credentials_count.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -metric_id: metric-azure-kvs-instance-credentials-count -name: Credentials Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.KeyVaults.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku.name - name: Sku Name - - key: data.properties.provisioning_state - name: Provisioning State - fields: - value: - key: data.total_credentials_count - operator: sum -unit: Count -namespace_id: ns-azure-key-vaults-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/KeyVaults/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/KeyVaults/Instance/instance_count.yaml deleted file mode 100644 index 42e987fb..00000000 --- a/src/spaceone/inventory/metrics/KeyVaults/Instance/instance_count.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -metric_id: metric-azure-kvs-instance-count -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.KeyVaults.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku.name - name: Sku Name - - key: data.properties.provisioning_state - name: Provisioning State - - key: data.system_data.created_by - name: Created By - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-key-vaults-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/KeyVaults/Instance/key_count.yaml b/src/spaceone/inventory/metrics/KeyVaults/Instance/key_count.yaml deleted file mode 100644 index 7b547101..00000000 --- a/src/spaceone/inventory/metrics/KeyVaults/Instance/key_count.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -metric_id: metric-azure-kvs-instance-key-count -name: Key Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.KeyVaults.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku.name - name: Sku Name - - key: data.properties.provisioning_state - name: Provisioning State - fields: - value: - key: data.key_count - operator: count -unit: Count -namespace_id: ns-azure-key-vaults-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/KeyVaults/Instance/namespace.yaml b/src/spaceone/inventory/metrics/KeyVaults/Instance/namespace.yaml deleted file mode 100644 index 06748e76..00000000 --- a/src/spaceone/inventory/metrics/KeyVaults/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-key-vaults-instance -name: KeyVaults/Instance -resource_type: inventory.CloudService:azure.KeyVaults.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-key-vault.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/KeyVaults/Instance/secret_count.yaml b/src/spaceone/inventory/metrics/KeyVaults/Instance/secret_count.yaml deleted file mode 100644 index 079a74f9..00000000 --- a/src/spaceone/inventory/metrics/KeyVaults/Instance/secret_count.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -metric_id: metric-azure-kvs-instance-secret-count -name: Secret Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.KeyVaults.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku.name - name: Sku Name - - key: data.properties.provisioning_state - name: Provisioning State - fields: - value: - key: data.secret_count - operator: count -unit: Count -namespace_id: ns-azure-key-vaults-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/LoadBalancers/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/LoadBalancers/Instance/instance_count.yaml deleted file mode 100644 index 61392477..00000000 --- a/src/spaceone/inventory/metrics/LoadBalancers/Instance/instance_count.yaml +++ /dev/null @@ -1,29 +0,0 @@ ---- -metric_id: metric-azure-lbs-instance-count -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.LoadBalancers.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-lbs-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/LoadBalancers/Instance/namespace.yaml b/src/spaceone/inventory/metrics/LoadBalancers/Instance/namespace.yaml deleted file mode 100644 index 66e413dd..00000000 --- a/src/spaceone/inventory/metrics/LoadBalancers/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-lbs-instance -name: LoadBalancers/Instance -resource_type: inventory.CloudService:azure.LoadBalancers.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-loadbalancers.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/MySQLServers/Server/namespace.yaml b/src/spaceone/inventory/metrics/MySQLServers/Server/namespace.yaml deleted file mode 100644 index fc075c5b..00000000 --- a/src/spaceone/inventory/metrics/MySQLServers/Server/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-mysql-servers-server -name: MySQLServers/Server -resource_type: inventory.CloudService:azure.MySQLServers.Server -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-mysql-servers.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/MySQLServers/Server/server_count.yaml b/src/spaceone/inventory/metrics/MySQLServers/Server/server_count.yaml deleted file mode 100644 index 852f3834..00000000 --- a/src/spaceone/inventory/metrics/MySQLServers/Server/server_count.yaml +++ /dev/null @@ -1,29 +0,0 @@ ---- -metric_id: metric-azure-mysql-servers-server-count -name: Server Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.MySQLServers.Server -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-mysql-servers-server -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/NATGateways/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/NATGateways/Instance/instance_count.yaml deleted file mode 100644 index 5f3d533a..00000000 --- a/src/spaceone/inventory/metrics/NATGateways/Instance/instance_count.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -metric_id: metric-azure-nat-gateways-instance -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.NATGateways.Instance -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.zones - name: Zone - - key: data.sku.name - name: SKU Name - - key: data.sku.tier - name: SKU Tier - - key: data.tenant_id - name: Tenant ID - default: true - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-nat-gateways-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/NATGateways/Instance/namespace.yaml b/src/spaceone/inventory/metrics/NATGateways/Instance/namespace.yaml deleted file mode 100644 index dc841110..00000000 --- a/src/spaceone/inventory/metrics/NATGateways/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-nat-gateways-instance -name: NATGateways/Instance -resource_type: inventory.CloudService:azure.NATGateways.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-nat.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/instance_count.yaml deleted file mode 100644 index bcf19aeb..00000000 --- a/src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/instance_count.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -metric_id: metric-azure-network-sgs-instance -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.NetworkSecurityGroups.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - default: true - - key: data.provisioning_state - name: Provisioning State - default: true - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-network-sgs-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/namespace.yaml b/src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/namespace.yaml deleted file mode 100644 index 81a69da7..00000000 --- a/src/spaceone/inventory/metrics/NetworkSecurityGroups/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-network-sgs-instance -name: NetworkSecurityGroups/Instance -resource_type: inventory.CloudService:azure.NetworkSecurityGroups.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-network-security-groups.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/PostgreSQLServers/Server/namespace.yaml b/src/spaceone/inventory/metrics/PostgreSQLServers/Server/namespace.yaml deleted file mode 100644 index cd6ff421..00000000 --- a/src/spaceone/inventory/metrics/PostgreSQLServers/Server/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-postgresql-servers-server -name: PostgreSQL/Server -resource_type: inventory.CloudService:azure.PostgreSQLServers.Server -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-sql-postgresql-server.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/PostgreSQLServers/Server/server_count.yaml b/src/spaceone/inventory/metrics/PostgreSQLServers/Server/server_count.yaml deleted file mode 100644 index 2b3cee47..00000000 --- a/src/spaceone/inventory/metrics/PostgreSQLServers/Server/server_count.yaml +++ /dev/null @@ -1,29 +0,0 @@ ---- -metric_id: metric-azure-postgersql-servers-server-count -name: Server Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.PostgreSQLServers.Server -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-postgresql-servers-server -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml b/src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml deleted file mode 100644 index 9d3d3471..00000000 --- a/src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -metric_id: metric-azure-pubipaddrs-ipaddrs-count -name: IP Address Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.PublicIPAddresses.IPAddress -query_options: - unwind: - path: data.zones - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.zones - name: Zone - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - - key: data.associated_to - name: Associated To - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-pubipaddrs-ipaddrs -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/namespace.yaml b/src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/namespace.yaml deleted file mode 100644 index 54add6ef..00000000 --- a/src/spaceone/inventory/metrics/PublicIPAddresses/IpAddress/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-pubipaddrs-ipaddrs -name: PublicIPAddresses/IPAddresses -resource_type: inventory.CloudService:azure.PublicIPAddresses.IPAddresses -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-public-ip-address.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/SQLDatabases/Database/database_count.yaml b/src/spaceone/inventory/metrics/SQLDatabases/Database/database_count.yaml deleted file mode 100644 index be4494d8..00000000 --- a/src/spaceone/inventory/metrics/SQLDatabases/Database/database_count.yaml +++ /dev/null @@ -1,42 +0,0 @@ ---- -metric_id: metric-azure-sql-databases-database-count -name: Database Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.SQLDatabases.Database -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku Name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.status - name: Status - default: true - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.server_name - name: Server Name - - key: data.compute_tier - name: Compute Tier - - key: data.default_secondary_location - name: Default Secondary Location - - key: data.read_scale - name: Read Scale - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-sql-databases-database -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/SQLDatabases/Database/database_size.yaml b/src/spaceone/inventory/metrics/SQLDatabases/Database/database_size.yaml deleted file mode 100644 index 7a9ef8dd..00000000 --- a/src/spaceone/inventory/metrics/SQLDatabases/Database/database_size.yaml +++ /dev/null @@ -1,43 +0,0 @@ ---- -metric_id: metric-azure-sql-databases-database-size -name: Database Size -metric_type: GAUGE -resource_type: inventory.CloudService:azure.SQLDatabases.Database -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku Name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.status - name: Status - default: true - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.server_name - name: Server Name - - key: data.compute_tier - name: Compute Tier - - key: data.default_secondary_location - name: Default Secondary Location - - key: data.read_scale - name: Read Scale - fields: - value: - key: data.max_size_gb - operator: sum -unit: GB -namespace_id: ns-azure-sql-databases-database -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/SQLDatabases/Database/namespace.yaml b/src/spaceone/inventory/metrics/SQLDatabases/Database/namespace.yaml deleted file mode 100644 index 278f21e6..00000000 --- a/src/spaceone/inventory/metrics/SQLDatabases/Database/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-sql-databases-database -name: SQLDatabases/Database -resource_type: inventory.CloudService:azure.SQLDatabases.Database -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-sql-databases.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/SQLServers/Server/namespace.yaml b/src/spaceone/inventory/metrics/SQLServers/Server/namespace.yaml deleted file mode 100644 index f19ed717..00000000 --- a/src/spaceone/inventory/metrics/SQLServers/Server/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-sql-servers-server -name: SQLServers/Server -resource_type: inventory.CloudService:azure.SQLServers.Server -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-sql-servers.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/SQLServers/Server/server_count.yaml b/src/spaceone/inventory/metrics/SQLServers/Server/server_count.yaml deleted file mode 100644 index 69a632fd..00000000 --- a/src/spaceone/inventory/metrics/SQLServers/Server/server_count.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -metric_id: metric-azure-sql-servers-server-count -name: Server Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.SQLServers.Server -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.state - name: Server State - default: true - - key: data.version - name: Version - - key: data.minimal_tls_version - name: Minimal TLS Version - - key: data.administrators.principal_type - name: Administrator Principal Type - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-sql-servers-server -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/Snapshots/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/Snapshots/Instance/instance_count.yaml deleted file mode 100644 index d774af4c..00000000 --- a/src/spaceone/inventory/metrics/Snapshots/Instance/instance_count.yaml +++ /dev/null @@ -1,47 +0,0 @@ ---- -metric_id: metric-azure-snapshots-instance-count -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.Snapshots.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: instance_type - name: Disk Type - - key: data.provisioning_state - name: Provisioning State - - key: data.os_type - name: OS Type - - key: data.disk_state - name: Disk State - - key: data.source_disk_name - name: Source Disk Name - - key: data.supports_hibernation - name: Supports Hibernation - - key: data.supported_capabilities.architecture - name: Architecture - - key: data.hyper_v_generation - name: Hyper-V Generation - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-snapshots-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/Snapshots/Instance/instance_size.yaml b/src/spaceone/inventory/metrics/Snapshots/Instance/instance_size.yaml deleted file mode 100644 index a9011873..00000000 --- a/src/spaceone/inventory/metrics/Snapshots/Instance/instance_size.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -metric_id: metric-azure-snapshots-instance-size -name: Instance Size -metric_type: GAUGE -resource_type: inventory.CloudService:azure.Snapshots.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: instance_type - name: Disk Type - - key: data.provisioning_state - name: Provisioning State - - key: data.os_type - name: OS Type - - key: data.disk_state - name: Disk State - - key: data.source_disk_name - name: Source Disk Name - - key: data.supports_hibernation - name: Supports Hibernation - - key: data.supported_capabilities.architecture - name: Architecture - - key: data.hyper_v_generation - name: Hyper-V Generation - fields: - value: - key: data.disk_size_gb - operator: sum -unit: GB -namespace_id: ns-azure-snapshots-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/Snapshots/Instance/namespace.yaml b/src/spaceone/inventory/metrics/Snapshots/Instance/namespace.yaml deleted file mode 100644 index 0ad0482b..00000000 --- a/src/spaceone/inventory/metrics/Snapshots/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-snapshots-instance -name: Snapshots/Instance -resource_type: inventory.CloudService:azure.Snapshots.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-disk-snapshot.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_count.yaml b/src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_count.yaml deleted file mode 100644 index bc579c81..00000000 --- a/src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_count.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -metric_id: metric-azure-stg-accounts-instance-blob-count -name: Blob Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.StorageAccounts.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.kind - name: Account Kind - - key: data.access_tier - name: Access Tier - fields: - value: - key: data.blob_count_display - operator: sum -unit: Count -namespace_id: ns-azure-stg-accounts-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_size.yaml b/src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_size.yaml deleted file mode 100644 index ca447be7..00000000 --- a/src/spaceone/inventory/metrics/StorageAccounts/Instance/blob_size.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -metric_id: metric-azure-stg-accounts-instance-blob-size -name: Blob Size -metric_type: GAUGE -resource_type: inventory.CloudService:azure.StorageAccounts.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.kind - name: Account Kind - - key: data.access_tier - name: Access Tier - - fields: - value: - key: data.blob_size_display - operator: sum -unit: Bytes -namespace_id: ns-azure-stg-accounts-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/StorageAccounts/Instance/container_count.yaml b/src/spaceone/inventory/metrics/StorageAccounts/Instance/container_count.yaml deleted file mode 100644 index bea57a8f..00000000 --- a/src/spaceone/inventory/metrics/StorageAccounts/Instance/container_count.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -metric_id: metric-azure-stg-accounts-instance-container-count -name: Container Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.StorageAccounts.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.kind - name: Account Kind - - key: data.access_tier - name: Access Tier - - fields: - value: - key: data.container_count_display - operator: sum -unit: Count -namespace_id: ns-azure-stg-accounts-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/StorageAccounts/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/StorageAccounts/Instance/instance_count.yaml deleted file mode 100644 index cbcef9d6..00000000 --- a/src/spaceone/inventory/metrics/StorageAccounts/Instance/instance_count.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -metric_id: metric-azure-stg-accounts-instance -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.StorageAccounts.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - - key: data.kind - name: Account Kind - - key: data.access_tier - name: Access Tier - - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-stg-accounts-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/StorageAccounts/Instance/namespace.yaml b/src/spaceone/inventory/metrics/StorageAccounts/Instance/namespace.yaml deleted file mode 100644 index bc3fccc7..00000000 --- a/src/spaceone/inventory/metrics/StorageAccounts/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-stg-accounts-instance -name: StorageAccounts/Instance -resource_type: inventory.CloudService:azure.StorageAccounts.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-service-accounts.svg -version: '1.0' diff --git a/src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/namespace.yaml b/src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/namespace.yaml deleted file mode 100644 index b3c6c85e..00000000 --- a/src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-vm-scale-sets-scale-set -name: VMScaleSets/ScaleSet -resource_type: inventory.CloudService:azure.VMScaleSets.ScaleSet -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-vm-scale-set.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml b/src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml deleted file mode 100644 index d607b249..00000000 --- a/src/spaceone/inventory/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -metric_id: metric-azure-vm-scale-sets-scale-set-count -name: Scale Set Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.VMScaleSets.ScaleSet -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku Name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.sku - name: Sku Tier - - key: data.provisioning_state - name: Provisioning State - - key: instance_type - name: Instance Type - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-vm-scale-sets-scale-set -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/VirtualMachines/Instance/instance_count.yaml b/src/spaceone/inventory/metrics/VirtualMachines/Instance/instance_count.yaml deleted file mode 100644 index 5b0a284b..00000000 --- a/src/spaceone/inventory/metrics/VirtualMachines/Instance/instance_count.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -metric_id: metric-azure-vms-instance-count -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.VirtualMachines.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.subscription.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group.resource_group_name - name: Resource Group - - key: instance_type - name: Instance Type - default: true - - key: data.compute.instance_state - name: Instance State - default: true - - key: data.os.os_type - name: OS Type - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-vms-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/VirtualMachines/Instance/memory_size.yaml b/src/spaceone/inventory/metrics/VirtualMachines/Instance/memory_size.yaml deleted file mode 100644 index 76c3ee9c..00000000 --- a/src/spaceone/inventory/metrics/VirtualMachines/Instance/memory_size.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -metric_id: metric-azure-vms-Instance-memory-size -name: Memory Size -metric_type: GAUGE -resource_type: inventory.CloudService:azure.VirtualMachines.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.subscription.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group.resource_group_name - name: Resource Group - - key: instance_type - name: Instance Type - default: true - - key: data.compute.instance_state - name: Instance State - default: true - - key: data.os.os_type - name: OS Type - fields: - value: - key: data.hardware.memory - operator: sum -unit: GB -namespace_id: ns-azure-vms-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/VirtualMachines/Instance/namespace.yaml b/src/spaceone/inventory/metrics/VirtualMachines/Instance/namespace.yaml deleted file mode 100644 index ffe23faa..00000000 --- a/src/spaceone/inventory/metrics/VirtualMachines/Instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-vms-instance -name: VirtualMachines/Instance -resource_type: inventory.CloudService:azure.VirtualMachines.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-vm.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/VirtualMachines/Instance/vcpu_count.yaml b/src/spaceone/inventory/metrics/VirtualMachines/Instance/vcpu_count.yaml deleted file mode 100644 index e16207f1..00000000 --- a/src/spaceone/inventory/metrics/VirtualMachines/Instance/vcpu_count.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -metric_id: metric-azure-vms-instance-vcpu-count -name: vCPU Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.VirtualMachines.Instance -query_options: - group_by: - - key: data.subscription.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - - key: account - name: Subscription ID - - key: data.resource_group.resource_group_name - name: Resource Group - - key: instance_type - name: Instance Type - default: true - - key: data.compute.instance_state - name: Instance State - default: true - - key: data.os.os_type - name: OS Type - fields: - value: - key: data.hardware.core - operator: sum -unit: Core -namespace_id: ns-azure-vms-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/VirtualNetworks/instance/instance_count.yaml b/src/spaceone/inventory/metrics/VirtualNetworks/instance/instance_count.yaml deleted file mode 100644 index bcc9923e..00000000 --- a/src/spaceone/inventory/metrics/VirtualNetworks/instance/instance_count.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -metric_id: metric-azure-vnets-instance-count -name: Instance Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.VirtualNetworks.Instance -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-vnets-instance -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/VirtualNetworks/instance/namespace.yaml b/src/spaceone/inventory/metrics/VirtualNetworks/instance/namespace.yaml deleted file mode 100644 index 181f1e29..00000000 --- a/src/spaceone/inventory/metrics/VirtualNetworks/instance/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-vnets-instance -name: VirtualNetworks/Instance -resource_type: inventory.CloudService:azure.VirtualNetworks.Instance -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-virtual-networks.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/WebPubSubService/Hub/hub_count.yaml b/src/spaceone/inventory/metrics/WebPubSubService/Hub/hub_count.yaml deleted file mode 100644 index 197bde1d..00000000 --- a/src/spaceone/inventory/metrics/WebPubSubService/Hub/hub_count.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -metric_id: metric-azure-web-pub-sub-service-hub -name: Hub Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.WebPubSubService.Hub -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-web-pub-sub-service-hub -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/WebPubSubService/Hub/namespace.yaml b/src/spaceone/inventory/metrics/WebPubSubService/Hub/namespace.yaml deleted file mode 100644 index 52dfc59a..00000000 --- a/src/spaceone/inventory/metrics/WebPubSubService/Hub/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-web-pub-sub-service-hub -name: WebPubSubService/Hub -resource_type: inventory.CloudService:azure.WebPubSubService.Hub -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-web-pubsub-service.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/WebPubSubService/Service/namespace.yaml b/src/spaceone/inventory/metrics/WebPubSubService/Service/namespace.yaml deleted file mode 100644 index c4465194..00000000 --- a/src/spaceone/inventory/metrics/WebPubSubService/Service/namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -namespace_id: ns-azure-web-pub-sub-service-service -name: WebPubSubService/Service -resource_type: inventory.CloudService:azure.WebPubSubService.Service -group: azure -category: ASSET -icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-web-pubsub-service.svg -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/metrics/WebPubSubService/Service/service_count.yaml b/src/spaceone/inventory/metrics/WebPubSubService/Service/service_count.yaml deleted file mode 100644 index 77dada5f..00000000 --- a/src/spaceone/inventory/metrics/WebPubSubService/Service/service_count.yaml +++ /dev/null @@ -1,34 +0,0 @@ ---- -metric_id: metric-azure-web-pub-sub-service-service -name: Service Count -metric_type: GAUGE -resource_type: inventory.CloudService:azure.WebPubSubService.Service -query_options: - group_by: - - key: region_code - name: Region - reference: - resource_type: inventory.Region - reference_key: region_code - - key: data.sku.name - name: Sku name - - key: data.sku.tier - name: Sku Tier - - key: data.tenant_id - name: Tenant ID - - key: data.subscription_name - name: Subscription Name - default: true - - key: account - name: Subscription ID - - key: data.resource_group - name: Resource Group - - key: data.provisioning_state - name: Provisioning State - default: true - fields: - value: - operator: count -unit: Count -namespace_id: ns-azure-web-pub-sub-service-service -version: '1.0' \ No newline at end of file diff --git a/src/spaceone/inventory/model/__init__.py b/src/spaceone/inventory/model/__init__.py deleted file mode 100644 index 567780d7..00000000 --- a/src/spaceone/inventory/model/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from spaceone.inventory.model.disks import * -from spaceone.inventory.model.snapshots import * -from spaceone.inventory.model.vm_scale_sets import * - diff --git a/src/spaceone/inventory/model/application_gateways/__init__.py b/src/spaceone/inventory/model/application_gateways/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/application_gateways/cloud_service.py b/src/spaceone/inventory/model/application_gateways/cloud_service.py deleted file mode 100644 index e41315e6..00000000 --- a/src/spaceone/inventory/model/application_gateways/cloud_service.py +++ /dev/null @@ -1,197 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField, MoreField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.application_gateways.data import ApplicationGateway - -''' -APPLICATION_GATEWAY -''' -# TAB - Default -application_gateway_info_meta = ItemDynamicLayout.set_fields('Application Gateway', fields=[ - TextDyField.data_source('Name', 'name', options={ - 'is_optional': True - }), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'data.subscription_id'), - TextDyField.data_source('Virtual Network', 'data.virtual_network'), - TextDyField.data_source('Subnet', 'data.subnet'), - TextDyField.data_source('Frontend public IP Address', 'data.public_ip_address.ip_address'), - TextDyField.data_source('Frontend private IP Address', 'data.private_ip_address'), - TextDyField.data_source('Tier', 'data.sku.tier') -]) - -# TAB - Configuration -application_gateway_configuration = ItemDynamicLayout.set_fields('Configuration', fields=[ - TextDyField.data_source('Capacity ', 'data.sku.tier'), - # TextDyField.data_source('Capacity Type', ''), - TextDyField.data_source('Minimum Instance Count', 'data.autoscale_configuration.min_capacity'), - TextDyField.data_source('Maximum Instance Count', 'data.autoscale_configuration.max_capacity'), - TextDyField.data_source('Enable HTTP2', 'data.enable_http2') -]) - -# TAB - Subnets -# Name, IPv4, IPv6, Available Ips, Delegated To, Security Group -application_gateway_web_app_firewall = ItemDynamicLayout.set_fields('Web Application Firewall', 'data.web_application_firewall_configuration', fields=[ - EnumDyField.data_source('Firewall Status Enabled', 'enabled', default_state={ - 'safe': [True], - 'warning': [False] - }), - TextDyField.data_source('Firewall Mode', 'firewall_mode'), - EnumDyField.data_source('Inspect Request Body', 'request_body_check', default_state={ - 'safe': [True], - 'warning':[False] - }), - TextDyField.data_source('Max Request Body Size(KB)', 'max_request_body_size_in_kb'), - TextDyField.data_source('File Upload Limit(MB)', 'file_upload_limit_in_mb'), - TextDyField.data_source('Rule Set Type', 'rule_set_type'), - TextDyField.data_source('Rule Set Version', 'rule_set_version') - # TextDyField.data_source('Advanced Rule Configuration', ''), - -]) - -application_gateway_web_app_firewall_exclusions = SimpleTableDynamicLayout.set_fields('Exclusions', 'data.web_application_firewall_configuration.exclusions', fields=[ - TextDyField.data_source('Field', 'match_variable'), - TextDyField.data_source('Operator', 'selector_match_operator'), - TextDyField.data_source('Selector', 'selector') -]) - -application_gateway_web_app_firewall_meta = ListDynamicLayout.set_layouts('Web Application Firewall', layouts=[ - application_gateway_web_app_firewall, - application_gateway_web_app_firewall_exclusions - ]) - -# TAB - Backend Pools -# Name,Rule Associated, Targets -application_gateway_backend_pools = SimpleTableDynamicLayout.set_fields('Backend Pools', 'data.backend_address_pools', fields=[ - TextDyField.data_source('Name', 'name'), - ListDyField.data_source('Rule Associated', 'associated_rules'), - ListDyField.data_source('Targets', 'backend_addresses_display', ) -]) - -# TAB - Backend HTTP Settings -application_gateway_http_settings = SimpleTableDynamicLayout.set_fields('Backend HTTP Settings', 'data.backend_http_settings_collection', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Port', 'port'), - TextDyField.data_source('Protocol', 'protocol'), - EnumDyField.data_source('Cookie Based Affinity', 'cookie_based_affinity', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - TextDyField.data_source('Custom Probe', 'custom_probe'), - TextDyField.data_source('Connection draining', 'connection_draining.enabled'), - TextDyField.data_source('Request time-out', 'request_timeout'), - TextDyField.data_source('Override backend path', 'path'), - TextDyField.data_source('Override with new host name', 'pick_host_name_from_backend_address'), - TextDyField.data_source('Host name', 'host_name') -]) - -# TAB - SSL Settings -application_gateway_ssl_settings = SimpleTableDynamicLayout.set_fields('SSL Settings', 'data.ssl_profiles', fields=[ - TextDyField.data_source('Name', 'name'), - ListDyField.data_source('Client Certificates', 'trusted_client_certificates.id'), - TextDyField.data_source('SSL Policy Type', 'ssl_policy.policy_type', options={ - 'is_optional': True - }), -]) - -# TAB - Frontend IP Configurations -application_gateway_frontend_ip_configurations = SimpleTableDynamicLayout.set_fields('Frontend IP Configurations', 'data.frontend_ip_configurations', fields=[ - TextDyField.data_source('Type', 'ip_type'), - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('IP Address', 'ip_address'), - ListDyField.data_source('Associated Listeners', 'associated_listener') -]) - -# TAB - Listeners -application_gateway_listeners = SimpleTableDynamicLayout.set_fields('Listeners', 'data.http_listeners', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Protocol', 'protocol'), - TextDyField.data_source('Port', 'port'), - TextDyField.data_source('Associated Rule', 'associated_rules'), - TextDyField.data_source('Host name', 'host_name') -]) - -application_gateway_listeners_custom = SimpleTableDynamicLayout.set_fields('Custom Error Configurations', 'data.custom_error_configurations', fields=[ - TextDyField.data_source('Listener Name', 'listener_name'), - TextDyField.data_source('Status Code', 'status_code'), - TextDyField.data_source('Custom Error Page URL', 'custom_error_page_url') -]) - -# 1 + 2) TAB - Listeners -application_gateway_listeners_info = ListDynamicLayout.set_layouts('Listeners', layouts=[ - application_gateway_listeners, - application_gateway_listeners_custom]) - -# TAB - Rules -application_gateway_rules = SimpleTableDynamicLayout.set_fields('Rules', 'data.request_routing_rules', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Type', 'rule_type'), - TextDyField.data_source('Listener', 'http_listener_name'), - TextDyField.data_source('Priority', 'priority') -]) - -# TAB - Rewrites -application_gateway_rewrites = SimpleTableDynamicLayout.set_fields('Rewrites', 'data.rewrite_rule_sets', fields=[ - TextDyField.data_source('Rewrite Sets', 'name'), - TextDyField.data_source('Rules Applied', 'rules_applied'), - ListDyField.data_source('Rewrite Rule Configuration', 'rewrite_rules_display') -]) - -# TAB - Health Probes -application_gateway_health_probes = SimpleTableDynamicLayout.set_fields('Health Probes', 'data.probes', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Protocol', 'protocol'), - TextDyField.data_source('Host', 'host'), - TextDyField.data_source('Path', 'path'), - TextDyField.data_source('Timeout(Seconds)', 'timeout') -]) - -# TAB - Managed Identity -application_gateway_managed_identity = ItemDynamicLayout.set_fields('Managed Identity', 'data.identity', fields=[ - TextDyField.data_source('Type', 'type'), - TextDyField.data_source('Principal ID', 'principal_id'), - TextDyField.data_source('Tenant ID', 'tenant_id'), - MoreField.data_source('User Assigned Identities', 'output_display', options={ - 'sub_key': 'user_assigned_identities', - 'layout': { - 'name': 'User Assigned Identities', - 'type': 'popup', - 'options': { - 'layout': { - 'type': 'raw' - } - } - } - }) -]) - -application_gateway_meta = CloudServiceMeta.set_layouts( - [application_gateway_info_meta, application_gateway_configuration, - application_gateway_web_app_firewall_meta, application_gateway_backend_pools, application_gateway_http_settings, - application_gateway_frontend_ip_configurations, application_gateway_listeners_info, application_gateway_rules, - application_gateway_rewrites, application_gateway_health_probes, application_gateway_managed_identity]) - - -class NetworkResource(CloudServiceResource): - cloud_service_group = StringType(default='ApplicationGateways') - - -class ApplicationGatewayResource(NetworkResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(ApplicationGateway) - _metadata = ModelType(CloudServiceMeta, default=application_gateway_meta, serialized_name='metadata') - name = StringType() - account = StringType() - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class ApplicationGatewayResponse(CloudServiceResponse): - resource = PolyModelType(ApplicationGatewayResource) diff --git a/src/spaceone/inventory/model/application_gateways/cloud_service_type.py b/src/spaceone/inventory/model/application_gateways/cloud_service_type.py deleted file mode 100644 index 67e4cad0..00000000 --- a/src/spaceone/inventory/model/application_gateways/cloud_service_type.py +++ /dev/null @@ -1,237 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -ag_count_by_account_conf = os.path.join(current_dir, 'widget/application_gateways_count_by_account.yaml') -ag_count_by_subscription_conf = os.path.join(current_dir, 'widget/application_gateways_count_by_subscription.yaml') -ag_count_by_location_conf = os.path.join(current_dir, 'widget/application_gateways_count_by_region.yaml') -ag_total_count_conf = os.path.join(current_dir, 'widget/application_gateways_total_count.yaml') - -cst_application_gateways = CloudServiceTypeResource() -cst_application_gateways.name = 'Instance' -cst_application_gateways.group = 'ApplicationGateways' -cst_application_gateways.service_code = 'Microsoft.Network/applicationGateways' -cst_application_gateways.labels = ['Networking'] -cst_application_gateways.is_major = True -cst_application_gateways.is_primary = True -cst_application_gateways.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-application-gateways.svg', -} - -cst_application_gateways._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Public IP Address', 'data.public_ip_address.ip_address'), - TextDyField.data_source('Private IP Address', 'data.private_ip_address'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'data.subscription_id', options={ - 'is_optional': True - }), - # is_optional fields - Configuration - TextDyField.data_source('Capacity', 'data.sku.tier', options={ - 'is_optional': True - }), - TextDyField.data_source('Minimum Instance Count', 'data.autoscale_configuration.min_capacity', options={ - 'is_optional': True - }), - TextDyField.data_source('Maximum Instance Count', 'data.autoscale_configuration.max_capacity', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable HTTP2', 'data.enable_http2', options={ - 'is_optional': True - }), - # is_optional fields - Firewall - TextDyField.data_source('Firewall Mode', 'data.web_application_firewall_configuration.firewall_mode', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall Max Request Body Size(KB)', - 'data.web_application_firewall_configuration.max_request_body_size_in_kb', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall File Upload Limit(MB)', 'data.web_application_firewall_configuration.file_upload_limit_in_mb', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall Rule Set Type', 'data.web_application_firewall_configuration.rule_set_type', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall Rule Set Version', 'data.web_application_firewall_configuration.rule_set_version', options={ - 'is_optional': True - }), - # is_optional fields - Firewall - TextDyField.data_source('Backend Address Pool Name', 'data.backend_address_pools.name', options={ - 'is_optional': True - }), - ListDyField.data_source('Backend Address Rule Associated', 'data.backend_address_pools.associated_rules', options={ - 'is_optional': True - }), - # is_optional fields - HTTP Settings - TextDyField.data_source('HTTP Backend Name', 'data.backend_http_settings_collection.name', options={ - 'is_optional': True - }), - TextDyField.data_source('HTTP Backend Port', 'data.backend_http_settings_collection.port', options={ - 'is_optional': True - }), - TextDyField.data_source('HTTP Backend Protocol', 'data.backend_http_settings_collection.protocol', options={ - 'is_optional': True - }), - # is_optional fields - SSL settings - TextDyField.data_source('SSL Profile Name', 'data.ssl_profiles.name', options={ - 'is_optional': True - }), - ListDyField.data_source('SSL Client Certificates', 'data.ssl_profiles.trusted_client_certificates.id', options={ - 'is_optional': True - }), - TextDyField.data_source('SSL Policy Type', 'data.ssl_profiles.ssl_policy.policy_type', options={ - 'is_optional': True - }), - # is_optional fields - Frontend IP Configurations - TextDyField.data_source('Frontend IP Type', 'data.frontend_ip_configurations.ip_type', options={ - 'is_optional': True - }), - TextDyField.data_source('Frontend IP Configuration Name', 'data.frontend_ip_configurations.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Frontend IP Address', 'data.frontend_ip_configurations.ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('Frontend Associated Listeners', 'data.frontend_ip_configurations.associated_listeners', options={ - 'is_optional': True - }), - # is_optional fields - Listeners - TextDyField.data_source('HTTP Listener Name', 'data.http_listeners.name', options={ - 'is_optional': True - }), - TextDyField.data_source('HTTP Listener Protocol', 'data.http_listeners.protocol', options={ - 'is_optional': True - }), - TextDyField.data_source('HTTP Listener Port', 'data.http_listeners.port', options={ - 'is_optional': True - }), - TextDyField.data_source('HTTP Listener Associated Rule', 'data.http_listeners.associated_rules', options={ - 'is_optional': True - }), - TextDyField.data_source('HTTP Listener Host name', 'data.http_listeners.host_name', options={ - 'is_optional': True - }), - # is_optional fields - Rules - TextDyField.data_source('Request Routing Rule Name', 'data.request_routing_rules.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Request Routing Rule Type', 'data.request_routing_rules.rule_type', options={ - 'is_optional': True - }), - TextDyField.data_source('Request Routing Rule Listener', 'data.request_routing_rules.http_listener_name', options={ - 'is_optional': True - }), - # is_optional fields - Health Probes - TextDyField.data_source('Health Probes Name', 'data.probes.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Protocol', 'data.probes.protocol', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Host', 'data.probes.host', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Path', 'data.probes.path', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Timeout(Seconds)', 'data.probes.timeout', options={ - 'is_optional': True - }) - - ], - search=[ - SearchField.set(name='Subscription ID', key='data.subscription_id'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Public IP Address', key='data.public_ip_address.ip_address'), - SearchField.set(name='Private IP Address', key='data.private_ip_address'), - SearchField.set(name='Capacity', key='data.sku.tier'), - SearchField.set(name='Minimum Instance Count', - key='data.autoscale_configuration.min_capacity', - data_type='integer'), - SearchField.set(name='Maximum Instance Count', - key='data.autoscale_configuration.max_capacity', - data_type='integer'), - SearchField.set(name='Enable HTTP2', - key='data.enable_http2', - data_type='boolean'), - SearchField.set(name='Firewall Mode', - key='data.web_application_firewall_configuration.firewall_mode'), - SearchField.set(name='Firewall Rule Set Type', - key='data.web_application_firewall_configuration.rule_set_type'), - SearchField.set(name='Firewall Rule Set Version', - key='data.web_application_firewall_configuration.rule_set_version'), - SearchField.set(name='Backend Address Pool Name', - key='data.backend_address_pools.name'), - SearchField.set(name='Backend Address Rule Associated', - key='data.backend_address_pools.associated_rules'), - SearchField.set(name='HTTP Backend Name', - key='data.backend_http_settings_collection.name'), - SearchField.set(name='HTTP Backend Port', - key='data.backend_http_settings_collection.port'), - SearchField.set(name='HTTP Backend Protocol', - key='data.backend_http_settings_collection.protocol'), - SearchField.set(name='SSL Profile Name', - key='data.ssl_profiles.name'), - SearchField.set(name='SSL Client Certificates', - key='data.ssl_profiles.trusted_client_certificates.id'), - SearchField.set(name='SSL Policy Type', - key='data.ssl_profiles.ssl_policy.policy_type'), - SearchField.set(name='Frontend IP Type', - key='data.frontend_ip_configurations.ip_type'), - SearchField.set(name='Frontend IP Configuration Name', - key='data.frontend_ip_configurations.name'), - SearchField.set(name='Frontend IP Address', - key='data.frontend_ip_configurations.ip_address'), - SearchField.set(name='Frontend Associated Listeners', - key='data.frontend_ip_configurations.associated_listeners'), - SearchField.set(name='HTTP Listener Name', - key='data.http_listeners.name'), - SearchField.set(name='HTTP Listener Protocol', - key='data.http_listeners.protocol'), - SearchField.set(name='HTTP Listener Port', - key='data.http_listeners.port'), - SearchField.set(name='HTTP Listener Associated Rule', - key='data.http_listeners.associated_rules'), - SearchField.set(name='HTTP Listener Host name', - key='data.http_listeners.host_name'), - SearchField.set(name='Request Routing Rule Name', - key='data.request_routing_rules.name'), - SearchField.set(name='Request Routing Rule Type', - key='data.request_routing_rules.rule_type'), - SearchField.set(name='Request Routing Rule Listener', - key='data.request_routing_rules.http_listener_name'), - SearchField.set(name='Health Probes Name', - key='data.probes.name'), - SearchField.set(name='Health Probes Protocol', - key='data.probes.protocol'), - SearchField.set(name='Health Probes Host', - key='data.probes.host'), - SearchField.set(name='Health Probes Path', - key='data.probes.path'), - SearchField.set(name='Health Probes Timeout(Seconds)', - key='data.probes.timeout', - data_type='integer'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(ag_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(ag_count_by_location_conf)), - ChartWidget.set(**get_data_from_yaml(ag_count_by_account_conf)), - CardWidget.set(**get_data_from_yaml(ag_total_count_conf)) - ] -) - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_application_gateways}), -] diff --git a/src/spaceone/inventory/model/application_gateways/data.py b/src/spaceone/inventory/model/application_gateways/data.py deleted file mode 100644 index 0de3e05f..00000000 --- a/src/spaceone/inventory/model/application_gateways/data.py +++ /dev/null @@ -1,983 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType, DateTimeType, FloatType, DictType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Tags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class SubResource(Model): - id = StringType() - - -class ApplicationGatewayAuthenticationCertificate(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - data = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayAutoscaleConfiguration(Model): - max_capacity = IntType(serialize_when_none=False) - min_capacity = IntType(serialize_when_none=False) - - -class Components1Jq1T4ISchemasManagedserviceidentityPropertiesUserassignedidentitiesAdditionalproperties(Model): - client_id = StringType(serialize_when_none=False) - principal_id = StringType(serialize_when_none=False) - - -class ManagedServiceIdentity(Model): - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType(choices=('None', 'SystemAssigned', 'SystemAssigned, UserAssigned', 'UserAssigned'), - serialize_when_none=False) - user_assigned_identities = DictType(ModelType(Components1Jq1T4ISchemasManagedserviceidentityPropertiesUserassignedidentitiesAdditionalproperties)) - output_display = StringType(default='show', serialize_when_none=False) - - -class ApplicationGatewayBackendAddress(Model): - fqdn = StringType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - -###### Firewall Classes ###### -class AzureFirewallRCAction(Model): - type = StringType(choices=('Allow', 'Deny'), serialize_when_none=False) - - -class AzureFirewallApplicationRuleProtocol(Model): - port = IntType(serialize_when_none=False) - protocol_type = StringType(choices=('Http', 'Https', 'Mssql'), serialize_when_none=False) - - -class AzureFirewallApplicationRule(Model): - description = StringType(serialize_when_none=False) - fqdn_tags = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(ModelType(AzureFirewallApplicationRuleProtocol), serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - target_fqdns = ListType(StringType, serialize_when_none=False) - - -class AzureFirewallApplicationRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - rules = ListType(ModelType(AzureFirewallApplicationRule), serialize_when_none=False) - - -class AzureFirewallIPConfiguration(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(SubResource, serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class AzureFirewallPublicIPAddress(Model): - address = StringType(serialize_when_none=False) - - -class HubPublicIPAddresses(Model): - address = ListType(ModelType(AzureFirewallPublicIPAddress), serialize_when_none=False) - count = IntType(serialize_when_none=False) - - -class HubIPAddresses(Model): - private_ip_address = StringType(serialize_when_none=False) - public_ips = ModelType(HubPublicIPAddresses, serialize_when_none=False) - - -class AzureFirewallIpGroups(Model): - change_number = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - - -class AzureFirewallNatRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNetworkRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - destination_fqdns = ListType(StringType, serialize_when_none=False) - destination_ip_groups = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNatRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = StringType(choices=('Dnat', 'Snat'), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - rules = ListType(ModelType(AzureFirewallNatRule), serialize_when_none=False) - - -class AzureFirewallNetworkRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - rules = ListType(ModelType(AzureFirewallNetworkRule), serialize_when_none=False) - - -class AzureFirewallSku(Model): - name = StringType(choices=('AZFW_Hub', 'AZFW_VNet'), serialize_when_none=False) - tier = StringType(choices=('Premium', 'Standard'), serialize_when_none=False) - - -class AzureFirewall(Model): - etag = StringType() - id = StringType() - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - application_rule_collections = ListType(ModelType(AzureFirewallApplicationRuleCollection), serialize_when_none=False) - firewall_policy = ModelType(SubResource, serialize_when_none=False) - hub_ip_addresses = ModelType(HubIPAddresses, serialize_when_none=False) - ip_configurations = ListType(ModelType(AzureFirewallIPConfiguration), serialize_when_none=False) - ip_groups = ListType(ModelType(AzureFirewallIpGroups), serialize_when_none=False) - management_ip_configuration = ModelType(AzureFirewallIPConfiguration, serialize_when_none=False) - nat_rule_collections = ListType(ModelType(AzureFirewallNatRuleCollection), serialize_when_none=False) - network_rule_collections = ListType(ModelType(AzureFirewallNetworkRuleCollection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - sku = ModelType(AzureFirewallSku, serialize_when_none=False) - threat_intel_mode = StringType(choices=('Alert', 'Deny', 'Off'), serialize_when_none=False) - virtual_hub = ModelType(SubResource, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class ExtendedLocation(Model): - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties(Model): - fqdns = ListType(StringType, serialize_when_none=False) - group_id = StringType(serialize_when_none=False) - required_member_name = StringType(serialize_when_none=False) - - -class DdosSettings(Model): - ddos_custom_policy = ModelType(SubResource, serialize_when_none=False) - protected_ip = BooleanType(serialize_when_none=False) - protection_coverage = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - - -class PublicIPAddressDnsSettings(Model): - domain_name_label = StringType(serialize_when_none=False) - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class IPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = StringType(serialize_when_none=False) # Change to PublicIPAddress ID - subnet = StringType(serialize_when_none=False) - - -class IpTag(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class NatGatewaySku(Model): - name = StringType(choices=('Standard', None), serialize_when_none=False) - - -class NatGateway(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_addresses = ListType(ModelType(SubResource), serialize_when_none=False) - public_ip_prefixes = ListType(ModelType(SubResource), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - subnets = ListType(ModelType(SubResource), serialize_when_none=False) - sku = ModelType(NatGatewaySku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PublicIPAddressSku(Model): - name = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - tier = StringType(choices=('Global', 'Regional'), serialize_when_none=False) - - -class PublicIPAddress(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettings, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = ModelType(IPConfiguration, serialize_when_none=False) - ip_tags = ListType(ModelType(IpTag), serialize_when_none=False) - migration_phase = StringType(choices=('Abort', 'Commit', 'Committed', 'None', 'Prepare'), serialize_when_none=False) - nat_gateway = ModelType(NatGateway, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class Delegation(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(default='-', serialize_when_none=False) - actions = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service_name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class IPConfigurationProfile(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - - -class SecurityRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - access = StringType(choices=('Allow', 'Deny'), serialize_when_none=False) - description = StringType(serialize_when_none=False) - destination_address_prefix = StringType(serialize_when_none=False) - destination_address_prefixes = ListType(StringType, serialize_when_none=False) - destination_application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - destination_port_range = StringType(serialize_when_none=False) - destination_port_ranges = ListType(StringType, serialize_when_none=False) - direction = StringType(choices=('Inbound', 'Outbound'), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - protocol = StringType(choices=('*', 'Ah', 'Esp', 'Icmp', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - source_address_prefix = StringType(serialize_when_none=False) - source_address_prefixes = ListType(StringType, serialize_when_none=False) - source_application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - source_port_range = StringType(serialize_when_none=False) - source_port_ranges = ListType(StringType, serialize_when_none=False) - - -class RetentionPolicyParameters(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class TrafficAnalyticsConfigurationProperties(Model): - enabled = BooleanType(serialize_when_none=False) - traffic_analytics_interval = IntType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - workspace_region = StringType(serialize_when_none=False) - workspace_resource_id = StringType(serialize_when_none=False) - - -class TrafficAnalyticsProperties(Model): - network_watcher_flow_analytics_configuration = ModelType(TrafficAnalyticsConfigurationProperties, - serialize_when_none=False) - - -class FlowLogFormatType(Model): - json = StringType(serialize_when_none=False) - - -class FlowLogFormatParameters(Model): - type = ModelType(FlowLogFormatType, serialize_when_none=False) - version = IntType(serialize_when_none=False) - - -class FlowLog(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - enable = BooleanType(serialize_when_none=False) - flow_analytics_configuration = ModelType(TrafficAnalyticsProperties, serialize_when_none=False) - format = ModelType(FlowLogFormatParameters, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - retention_policy = ModelType(RetentionPolicyParameters, serialize_when_none=False) - storage_id = StringType(serialize_when_none=False) - target_resource_guid = StringType(serialize_when_none=False) - target_resource_id = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(default='-', serialize_when_none=False) - default_security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - flow_logs = ListType(ModelType(FlowLog), serialize_when_none=False) - network_interfaces = StringType(serialize_when_none=False) # Change to Network interfaces' Id - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - subnets = ListType(StringType, serialize_when_none=False) # Change to Subnet IDs - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class CustomDnsConfigPropertiesFormat(Model): - fqdn = StringType(serialize_when_none=False) - ip_addresses = ListType(StringType, serialize_when_none=False) - - -class PrivateLinkServiceConnectionState(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - group_ids = ListType(StringType, serialize_when_none=False) - private_link_service_connection_state = ModelType(PrivateLinkServiceConnectionState, serialize_when_none=False) - private_link_service_id = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - request_message = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateEndpoint(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType(ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False) - manual_private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), - serialize_when_none=False) - network_interfaces = ListType(StringType, serialize_when_none=False) # Change to network interface ids - private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ResourceNavigationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Route(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - next_hop_ip_address = StringType(serialize_when_none=False) - next_hop_type = StringType(choices=('Internet', 'None', 'VirtualAppliance', 'VirtualNetworkGateway', 'VnetLocal'), - serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - - -class RouteTable(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - disable_bgp_route_propagation = BooleanType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - routes = ListType(ModelType(Route), serialize_when_none=False) - subnets = ListType(StringType, default=[], serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceAssociationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allow_delete = BooleanType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - locations = ListType(ModelType(ExtendedLocation), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPolicyDefinition(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service = StringType(serialize_when_none=False) - service_resources = ListType(StringType) - - -class ServiceEndpointPolicy(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - service_endpoint_policy_definitions = ListType(ModelType(ServiceEndpointPolicyDefinition), - serialize_when_none=False) - subnets = ListType(StringType, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPropertiesFormat(Model): - locations = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - - -class Subnet(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - address_prefixes = ListType(StringType, serialize_when_none=False) - application_gateway_ip_configurations = ListType(StringType, serialize_when_none=False) # Change to ip configurations id - delegations = ListType(ModelType(Delegation), serialize_when_none=False) - ip_allocations = ListType(ModelType(SubResource), serialize_when_none=False) - ip_configuration_profiles = ListType(ModelType(IPConfigurationProfile), serialize_when_none=False) - ip_configurations = ListType(ModelType(IPConfiguration), serialize_when_none=False) - azure_firewall = ListType(ModelType(AzureFirewall), serialize_when_none=False) - nat_gateway = ModelType(SubResource, serialize_when_none=False) - network_security_group = ModelType(NetworkSecurityGroup, serialize_when_none=False) - private_endpoint_network_policies = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - private_endpoints = ListType(ModelType(PrivateEndpoint), serialize_when_none=False) - private_link_service_network_policies = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - purpose = StringType(serialize_when_none=False) - resource_navigation_links = ListType(ModelType(ResourceNavigationLink, serialize_when_none=False)) - route_table = ModelType(RouteTable, serialize_when_none=False) - service_association_links = ListType(ModelType(ServiceAssociationLink), serialize_when_none=False) - service_endpoint_policies = ListType(ModelType(ServiceEndpointPolicy), serialize_when_none=False) - service_endpoints = ListType(ModelType(ServiceEndpointPropertiesFormat), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class FrontendIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - inbound_nat_pools = ListType(ModelType(SubResource), serialize_when_none=False) - inbound_nat_rules = ListType(ModelType(SubResource), serialize_when_none=False) - load_balancing_rules = ListType(ModelType(SubResource), serialize_when_none=False) - outbound_rules = ListType(ModelType(SubResource), serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class VirtualNetworkTap(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - destination_load_balancer_front_end_ip_configuration = ModelType(FrontendIPConfiguration, serialize_when_none=False) - destination_network_interface_ip_configuration = StringType(serialize_when_none=False) # Change to networkinterface ip configuration - destination_port = IntType(serialize_when_none=False) - network_interface_tap_configurations = ListType(StringType,serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tags = ListType(ModelType(Tags)) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfiguration(Model): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_gateway_backend_address_pools = ListType(StringType, serialize_when_none=False) # Change to ApplicationGatewayBackendAddressPool's ID - application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - load_balancer_backend_address_pools = ListType(StringType, serialize_when_none=False) # Change to backend address pools id - load_balancer_inbound_nat_rules = ListType(StringType, serialize_when_none=False) # Change to inbound NAT rules id - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - private_link_connection_properties = ModelType(NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - subnet = ModelType(Subnet, serialize_when_none=False) - virtual_network_taps = ListType(ModelType(VirtualNetworkTap), serialize_when_none=False) - - -class ApplicationGatewayBackendAddressPool(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_addresses = ListType(ModelType(ApplicationGatewayBackendAddress), serialize_when_none=False) - backend_addresses_display = ListType(StringType, serialize_when_none=False) - backend_ip_configurations = ListType(ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - associated_rules = ListType(StringType, serialize_when_none=False) - - -class ApplicationGatewayConnectionDraining(Model): - drain_timeout_in_sec = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class ApplicationGatewayBackendHttpSettings(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - affinity_cookie_name = StringType(serialize_when_none=False) - authentication_certificates = ListType(ModelType(SubResource), serialize_when_none=False) - connection_draining = ModelType(ApplicationGatewayConnectionDraining, serialize_when_none=False) - cookie_based_affinity = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - host_name = StringType(serialize_when_none=False) - path = StringType(serialize_when_none=False) - pick_host_name_from_backend_address = BooleanType(serialize_when_none=False) - port = IntType(serialize_when_none=False) - probe = ModelType(SubResource, serialize_when_none=False) - probe_enabled = BooleanType(serialize_when_none=False) - custom_probe = StringType(serialize_when_none=False) - protocol = StringType(choices=('Http', 'Https'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - request_timeout = IntType(serialize_when_none=False) - trusted_root_certificates = ListType(ModelType(SubResource), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayCustomError(Model): - listener_name = StringType(serialize_when_none=False) - custom_error_page_url = StringType(serialize_when_none=False) - status_code = StringType(choices=('HttpStatus403', 'HttpStatus502')) - - -class ApplicationGatewayFrontendIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(default='-', serialize_when_none=False) - type = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - private_link_configuration = ModelType(SubResource, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(SubResource, serialize_when_none=False) - ip_type = StringType(choices=('Public', 'Private'), serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - associated_listener = ListType(StringType, serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - - -class ApplicationGatewayFrontendPort(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - port = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayHttpListener(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_error_configurations = ListType(ModelType(ApplicationGatewayCustomError), serialize_when_none=False) - firewall_policy = ModelType(SubResource) - frontend_ip_configuration = ModelType(SubResource) - frontend_port = ModelType(SubResource) - port = IntType(serialize_when_none=False) - host_name = StringType(default='-') - host_names = ListType(StringType, serialize_when_none=False) - protocol = StringType(choices=('Http', 'Https'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - require_server_name_indication = BooleanType(serialize_when_none=False) - ssl_certificate = ModelType(SubResource, serialize_when_none=False) - ssl_profile = ModelType(SubResource, serialize_when_none=False) - associated_rules = ListType(StringType, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayPrivateEndpointConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - link_identifier = StringType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpoint, serialize_when_none=False) - private_link_service_connection_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayPrivateLinkIpConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayPrivateLinkConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - ip_configurations = ListType(ModelType(ApplicationGatewayPrivateLinkIpConfiguration), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayProbeHealthResponseMatch(Model): - body = StringType(serialize_when_none=False) - status_codes = ListType(StringType, serialize_when_none=False) - - -class ApplicationGatewayProbe(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - host = StringType(serialize_when_none=False) - interval = IntType(serialize_when_none=False) - match = ModelType(ApplicationGatewayProbeHealthResponseMatch, serialize_when_none=False) - min_servers = IntType(serialize_when_none=False) - path = StringType(serialize_when_none=False) - pick_host_name_from_backend_http_settings = BooleanType(serialize_when_none=False) - port = IntType(serialize_when_none=False) - protocol = StringType(choices=('Http', 'Https'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - timeout = IntType(serialize_when_none=False) - unhealthy_threshold = IntType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayRedirectConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(default='-', serialize_when_none=False) - include_path = BooleanType(serialize_when_none=False) - include_query_string = BooleanType(serialize_when_none=False) - path_rules = ListType(ModelType(SubResource), serialize_when_none=False) - redirect_type = StringType(choices=('Found', 'Permanent', 'SeeOther', 'Temporary'), serialize_when_none=False) - request_routing_rules = ListType(ModelType(SubResource), serialize_when_none=False) - target_listener = ModelType(SubResource, serialize_when_none=False) - target_url = StringType(serialize_when_none=False) - url_path_maps = ListType(ModelType(SubResource), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayRequestRoutingRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - backend_http_settings = ModelType(SubResource, serialize_when_none=False) - http_listener = ModelType(SubResource, serialize_when_none=False) - http_listener_name = StringType(default='-') - priority = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - redirect_configuration = ModelType(SubResource, serialize_when_none=False) - rewrite_rule_set = ModelType(SubResource, serialize_when_none=False) - rule_type = StringType(choices=('Basic', 'PathBasedRouting'), serialize_when_none=False) - url_path_map = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayHeaderConfiguration(Model): - header_name = StringType(serialize_when_none=False) - header_value = StringType(serialize_when_none=False) - - -class ApplicationGatewayUrlConfiguration(Model): - modified_path = StringType(serialize_when_none=False) - modified_query_string = StringType(serialize_when_none=False) - reroute = BooleanType(serialize_when_none=False) - - -class ApplicationGatewayRewriteRuleActionSet(Model): - request_header_configurations = ListType(ModelType(ApplicationGatewayHeaderConfiguration), serialize_when_none=False) - response_header_configurations = ListType(ModelType(ApplicationGatewayHeaderConfiguration), serialize_when_none=False) - url_configuration = ModelType(ApplicationGatewayUrlConfiguration, serialize_when_none=False) - - -class ApplicationGatewayRewriteRuleCondition(Model): - ignore_case = BooleanType(serialize_when_none=False) - negate = BooleanType(serialize_when_none=False) - pattern = StringType(serialize_when_none=False) - variable = StringType(serialize_when_none=False) - - -class ApplicationGatewayRewriteRule(Model): - action_set = ModelType(ApplicationGatewayRewriteRuleActionSet, serialize_when_none=False) - conditions = ListType(ModelType(ApplicationGatewayRewriteRuleCondition), serialize_when_none=False) - name = StringType(serialize_when_none=False) - rule_sequence = IntType(serialize_when_none=False) - - -class ApplicationGatewayRewriteRuleSet(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - rewrite_rules = ListType(ModelType(ApplicationGatewayRewriteRule), serialize_when_none=False) - rewrite_rules_display = ListType(StringType, serialize_when_none=False) - rules_applied = ListType(StringType, serialize_when_none=False) - - -class ApplicationGatewaySku(Model): - capacity = IntType(serialize_when_none=False) - name = StringType(choices=('Standard_Large', 'Standard_Medium', 'Standard_Small', 'Standard_v2', - 'WAF_Large', 'WAF_Medium', 'WAF_v2'), serialize_when_none=False) - tier = StringType(choices=('Standard', 'Standard_v2', 'WAF', 'WAF_v2'), serialize_when_none=False) - - -class ApplicationGatewaySslCertificate(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - data = StringType(serialize_when_none=False) - key_vault_secret_id = StringType(serialize_when_none=False) - password = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_cert_data = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewaySslPolicy(Model): - cipher_suites = ListType(StringType, serialize_when_none=False) - disabled_ssl_protocols = ListType(StringType, serialize_when_none=False) - min_protocol_version = StringType(choices=('TLSv1_0', 'TLSv1_1', 'TLSv1_2'), serialize_when_none=False) - policy_name = StringType(choices=('AppGwSslPolicy20150501', 'AppGwSslPolicy20170401', 'AppGwSslPolicy20170401S'), - serialize_when_none=False) - policy_type = StringType(choices=('Custom', 'Predefined'), serialize_when_none=False) - - -class ApplicationGatewayClientAuthConfiguration(Model): - verify_client_cert_issuer_dn = BooleanType(serialize_when_none=False) - - -class ApplicationGatewaySslProfile(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - client_auth_configuration = ModelType(ApplicationGatewayClientAuthConfiguration, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - ssl_policy = ModelType(ApplicationGatewaySslPolicy, serialize_when_none=False) - trusted_client_certificates = ListType(ModelType(SubResource), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayTrustedClientCertificate(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - data = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayTrustedRootCertificate(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - data = StringType(serialize_when_none=False) - key_vault_secret_id = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayPathRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - backend_http_settings = ModelType(SubResource, serialize_when_none=False) - firewall_policy = ModelType(SubResource, serialize_when_none=False) - paths = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - redirect_configuration = ModelType(SubResource, serialize_when_none=False) - rewrite_rule_set = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayUrlPathMap(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - default_backend_address_pool = ModelType(SubResource, serialize_when_none=False) - default_backend_http_settings = ModelType(SubResource, serialize_when_none=False) - default_redirect_configuration = ModelType(SubResource, serialize_when_none=False) - default_rewrite_rule_set = ModelType(SubResource, serialize_when_none=False) - path_rules = ListType(ModelType(ApplicationGatewayPathRule), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayFirewallExclusion(Model): - match_variable = StringType(serialize_when_none=False) - selector = StringType(serialize_when_none=False) - selector_match_operator = StringType(serialize_when_none=False) - - -class ApplicationGatewayFirewallDisabledRuleGroup(Model): - rule_group_name = StringType(serialize_when_none=False) - rules = ListType(IntType, serialize_when_none=False) - - -class ApplicationGatewayWebApplicationFirewallConfiguration(Model): - disabled_rule_groups = ListType(ModelType(ApplicationGatewayFirewallDisabledRuleGroup), serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - exclusions = ListType(ModelType(ApplicationGatewayFirewallExclusion), serialize_when_none=False) - file_upload_limit_in_mb = IntType(serialize_when_none=False) - firewall_mode = StringType(choices=('Detection', 'Prevention'), serialize_when_none=False) - max_request_body_size = IntType(serialize_when_none=False) - max_request_body_size_in_kb = IntType(serialize_when_none=False) - request_body_check = BooleanType(serialize_when_none=False) - rule_set_type = StringType(serialize_when_none=False) - rule_set_version = StringType(serialize_when_none=False) - - -class ApplicationGateway(AzureCloudService): # Main Class - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - identity = ModelType(ManagedServiceIdentity, serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(default='-', serialize_when_none=False) - authentication_certificates = ListType(ModelType(ApplicationGatewayAuthenticationCertificate), - serialize_when_none=False) - autoscale_configuration = ModelType(ApplicationGatewayAutoscaleConfiguration, serialize_when_none=False) - backend_address_pools = ListType(ModelType(ApplicationGatewayBackendAddressPool), serialize_when_none=False) - backend_http_settings_collection = ListType(ModelType(ApplicationGatewayBackendHttpSettings), - serialize_when_none=False) - custom_error_configurations = ListType(ModelType(ApplicationGatewayCustomError), serialize_when_none=False) - enable_fips = BooleanType(serialize_when_none=False) - enable_http2 = BooleanType(serialize_when_none=False) - firewall_policy = ModelType(SubResource, serialize_when_none=False) - force_firewall_policy_association = BooleanType(serialize_when_none=False) - frontend_ip_configurations = ListType(ModelType(ApplicationGatewayFrontendIPConfiguration), - serialize_when_none=False) - frontend_ports = ListType(ModelType(ApplicationGatewayFrontendPort), serialize_when_none=False) - gateway_ip_configurations = ListType(ModelType(ApplicationGatewayIPConfiguration), serialize_when_none=False) - http_listeners = ListType(ModelType(ApplicationGatewayHttpListener), serialize_when_none=False) - operational_state = StringType(choices=('Running', 'Starting', 'Stopped', 'Stopping'), serialize_when_none=False) - private_endpoint_connections = ListType(ModelType(ApplicationGatewayPrivateEndpointConnection), - serialize_when_none=False) - private_link_configurations = ListType(ModelType(ApplicationGatewayPrivateLinkConfiguration), - serialize_when_none=False) - probes = ListType(ModelType(ApplicationGatewayProbe), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), - serialize_when_none=False) - redirect_configurations = ListType(ModelType(ApplicationGatewayRedirectConfiguration), - serialize_when_none=False) - request_routing_rules = ListType(ModelType(ApplicationGatewayRequestRoutingRule), - serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - rewrite_rule_sets = ListType(ModelType(ApplicationGatewayRewriteRuleSet), serialize_when_none=False) - sku = ModelType(ApplicationGatewaySku, serialize_when_none=False) - ssl_certificates = ListType(ModelType(ApplicationGatewaySslCertificate), serialize_when_none=False) - ssl_policy = ModelType(ApplicationGatewaySslPolicy, serialize_when_none=False) - ssl_profiles = ListType(ModelType(ApplicationGatewaySslProfile), serialize_when_none=False) - trusted_client_certificates = ListType(ModelType(ApplicationGatewayTrustedClientCertificate), - serialize_when_none=False) - trusted_root_certificates = ListType(ModelType(ApplicationGatewayTrustedRootCertificate), serialize_when_none=False) - url_path_maps = ListType(ModelType(ApplicationGatewayUrlPathMap), serialize_when_none=False) - web_application_firewall_configuration = ModelType(ApplicationGatewayWebApplicationFirewallConfiguration, - serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - virtual_network = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_account.yaml b/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_account.yaml deleted file mode 100644 index cc39f16c..00000000 --- a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: ApplicationGateways -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_region.yaml b/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_region.yaml deleted file mode 100644 index 8f045b76..00000000 --- a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: ApplicationGateways -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_subscription.yaml b/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_subscription.yaml deleted file mode 100644 index 40184c03..00000000 --- a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: ApplicationGateways -cloud_service_type: Instance -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_total_count.yaml b/src/spaceone/inventory/model/application_gateways/widget/application_gateways_total_count.yaml deleted file mode 100644 index 267c4805..00000000 --- a/src/spaceone/inventory/model/application_gateways/widget/application_gateways_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: ApplicationGateways -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/container_instances/__init__.py b/src/spaceone/inventory/model/container_instances/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/container_instances/cloud_service.py b/src/spaceone/inventory/model/container_instances/cloud_service.py deleted file mode 100644 index da09e6e0..00000000 --- a/src/spaceone/inventory/model/container_instances/cloud_service.py +++ /dev/null @@ -1,95 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType -from spaceone.inventory.model.container_instances.data import ContainerInstance -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, ListDyField - -''' -CONTAINER_INSTANCES -''' - -# TAB - Default -container_instances_info_meta = ItemDynamicLayout.set_fields('Container Instances', fields=[ - TextDyField.data_source('Name', 'name'), - EnumDyField.data_source('State', 'data.instance_view.state', default_state={ - 'safe': ['Running', 'Succeeded'], - 'warning': ['Pending'], - 'alert': ['Stopped', 'Failed'], - 'disable': []}), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Region', 'region_code'), - TextDyField.data_source('SKU', 'data.sku'), - TextDyField.data_source('OS type', 'data.os_type'), - TextDyField.data_source('Container count', 'data.container_count_display'), - TextDyField.data_source('vCPU count', 'data.container_count_display'), - TextDyField.data_source('Memory size(GB)', 'data.memory_size_display'), - TextDyField.data_source('GPU count', 'data.gpu_count_display'), - TextDyField.data_source('Volume count', 'data.volume_count_display'), - TextDyField.data_source('IP Address', 'data.ip_address.ip'), - TextDyField.data_source('IP Address Type', 'data.ip_address.type'), - TextDyField.data_source('FQDN', 'data.ip_address.fqdn'), - TextDyField.data_source('DNS name label', 'data.ip_address.dns_name_label'), - TextDyField.data_source('DNS name label scope reuse', 'data.ip_address.auto_generated_domain_name_label_scope'), - ListDyField.data_source('Ports', 'data.ip_address.ports.port', options={'delimiter': '
'}), -]) - -# TAB -Container -container_instances_info_container = TableDynamicLayout.set_fields('Containers', root_path='data.containers', fields=[ - TextDyField.data_source('Name', 'name'), - EnumDyField.data_source('State', 'instance_view.current_state.state', default_state={ - 'safe': ['Running'], - 'warning': ['Waiting'], - 'alert': ['Terminated'], - 'disable': []}), - TextDyField.data_source('Previous state', 'instance_view.previous_state.state'), - TextDyField.data_source('Restart count', 'instance_view.restart_count'), - TextDyField.data_source('Volume count', 'volume_mount_count_display'), - TextDyField.data_source('CPU cores', 'resources.requests.cpu', options={ - 'translation_id': 'PAGE_SCHEMA.CPU_CORE', - }), - TextDyField.data_source('Memory(GB)', 'resources.requests.memory_in_gb', options={ - 'translation_id': 'PAGE_SCHEMA.MEMORY', - }), - TextDyField.data_source('Image', 'image'), - DateTimeDyField.data_source('Start time', 'instance_view.current_state.start_time'), - DateTimeDyField.data_source('Finish time', 'instance_view.current_state.finish'), - TextDyField.data_source('GPU SKU', 'resources.requests.gpu.sku'), - TextDyField.data_source('GPU count', 'resources.requests.gpu.count'), - ListDyField.data_source('Ports', 'ports.port', options={'delimiter': '
'}), - ListDyField.data_source('Commands', 'command', options={'delimiter': '
'}), - -]) - -# TAB - Volume -container_instances_info_volumes = TableDynamicLayout.set_fields('Volumes', root_path='data.volumes', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Volume type', 'volume_type'), - TextDyField.data_source('Mount path', 'mount_path'), - TextDyField.data_source('Git repository', 'git_repo.repository'), - TextDyField.data_source('Container name', 'container_name') -]) - -container_instances_meta = CloudServiceMeta.set_layouts( - [container_instances_info_meta, container_instances_info_container, container_instances_info_volumes] -) - - -class ContainerResource(CloudServiceResource): - cloud_service_group = StringType(default='ContainerInstances') - - -class ContainerInstanceResource(ContainerResource): - cloud_service_type = StringType(default='Container') - data = ModelType(ContainerInstance) - _metadata = ModelType(CloudServiceMeta, default=container_instances_meta, serialized_name='metadata') - name = StringType(serialize_when_none=False) - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class ContainerInstanceResponse(CloudServiceResponse): - resource = PolyModelType(ContainerInstanceResource) diff --git a/src/spaceone/inventory/model/container_instances/cloud_service_type.py b/src/spaceone/inventory/model/container_instances/cloud_service_type.py deleted file mode 100644 index 8b313c6e..00000000 --- a/src/spaceone/inventory/model/container_instances/cloud_service_type.py +++ /dev/null @@ -1,105 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -container_instances_count_by_account_conf = os.path.join(current_dir, 'widget/container_instances_count_by_account.yaml') -container_instances_count_by_region_conf = os.path.join(current_dir, 'widget/container_instances_count_by_region.yaml') -container_instances_count_by_subscription_conf = os.path.join(current_dir, 'widget/container_Instances_count_by_subscription.yaml') -container_instances_total_container_conf = os.path.join(current_dir, 'widget/container_instances_total_container_count.yaml') -container_instances_total_count_conf = os.path.join(current_dir, 'widget/container_instances_total_count.yaml') -container_instances_total_gpu_conf = os.path.join(current_dir, 'widget/container_instances_total_gpu_count.yaml') -container_instances_total_memory_conf = os.path.join(current_dir, 'widget/container_instances_total_memory_size.yaml') -container_instances_total_vcpu_conf = os.path.join(current_dir, 'widget/container_instances_total_vcpu_count.yaml') - -cst_container_instances = CloudServiceTypeResource() -cst_container_instances.name = 'Container' -cst_container_instances.group = 'ContainerInstances' -cst_container_instances.service_code = 'Microsoft.ContainerInstance/containerGroups' -cst_container_instances.labels = ['Container'] -cst_container_instances.is_major = True -cst_container_instances.is_primary = True -cst_container_instances.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-container-instances.svg', -} -cst_container_instances._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - EnumDyField.data_source('State', 'data.instance_view.state', default_state={ - 'safe': ['Running', 'Succeeded'], - 'warning': ['Pending'], - 'alert': ['Stopped', 'Failed'], - 'disable': []}), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account', options={ - 'is_optional': True - }), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('OS type', 'data.os_type'), - TextDyField.data_source('Container count', 'data.container_count_display'), - TextDyField.data_source('vCPU count', 'data.container_count_display'), - TextDyField.data_source('Memory size(GB)', 'data.memory_size_display'), - TextDyField.data_source('Volume count', 'data.volume_count_display'), - TextDyField.data_source('GPU count', 'data.gpu_count_display'), - TextDyField.data_source('Provisioning State', 'data.provisioning_state', options={ - 'is_optional': True - }), - TextDyField.data_source('Restart Policy', 'data.restart_policy', options={ - 'is_optional': True - }), - TextDyField.data_source('IP Address', 'data.ip_address.ip', options={ - 'is_optional': True - }), - TextDyField.data_source('IP Address Type', 'data.ip_address.type', options={ - 'is_optional': True - }), - TextDyField.data_source('FQDN', 'data.ip_address.fqdn', options={ - 'is_optional': True - }), - TextDyField.data_source('DNS name label', 'data.ip_address.dns_name_label', options={ - 'is_optional': True}), - TextDyField.data_source('DNS name label scope reuse', 'data.ip_address.auto_generated_domain_name_label_scope', - options={'is_optional': True}), - - ], - search=[ - SearchField.set(name='Status', key='data.instance_view.state'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='OS type', key='data.os_type'), - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Provisioning State', key='data.provisioning_state'), - SearchField.set(name='Restart Policy', key='data.restart_policy'), - SearchField.set(name='IP Address', key='data.ip_address.ip'), - SearchField.set(name='FQDN', key='data.ip_address.fqdn'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='SKU', key='data.sku'), - SearchField.set(name='Container count', key='data.container_count_display', data_type='integer'), - SearchField.set(name='vCPU', key='data.cpu_count_display', data_type='integer'), - SearchField.set(name='Memory size(GB)', key='data.memory_size_display', data_type='float'), - SearchField.set(name='GPU count', key='data.gpu_count_display', data_type='integer'), - SearchField.set(name='Volume count', key='data.volume_count_display', data_type='integer'), - SearchField.set(name='DNS name label', key='data.ip_address.dns_name_label'), - SearchField.set(name='DNS name label scope reuse', key='data.ip_address.auto_generated_domain_name_label_scope') - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(container_instances_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(container_instances_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(container_instances_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(container_instances_total_count_conf)), - CardWidget.set(**get_data_from_yaml(container_instances_total_container_conf)), - CardWidget.set(**get_data_from_yaml(container_instances_total_vcpu_conf)), - CardWidget.set(**get_data_from_yaml(container_instances_total_memory_conf)), - CardWidget.set(**get_data_from_yaml(container_instances_total_gpu_conf)) - ] -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_container_instances}), -] \ No newline at end of file diff --git a/src/spaceone/inventory/model/container_instances/data.py b/src/spaceone/inventory/model/container_instances/data.py deleted file mode 100644 index a8028515..00000000 --- a/src/spaceone/inventory/model/container_instances/data.py +++ /dev/null @@ -1,268 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, DictType, StringType, ListType, IntType, BooleanType, DateTimeType, FloatType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -# ContainerGroupIdentity -class UserAssignedIdentity(Model): - client_id = StringType(serialize_when_none=False) - principal_id = StringType(serialize_when_none=False) - - -class ContainerGroupIdentity(Model): - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType(choices=('NONE', 'SYSTEM_ASSIGNED', 'SYSTEM_ASSIGNED_USER_ASSIGNED', 'USER_ASSIGNED'), - serialize_when_none=False) - user_assigned_identities = DictType(StringType(), ModelType(UserAssignedIdentity), serialize_when_none=False) - - -# Container -class ContainerPort(Model): - protocol = StringType(choices=('TCP', 'UDP'), default='TCP') - port = StringType(serialize_when_none=False) - - -class EnvironmentVariable(Model): - name = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - secure_value = StringType(serialize_when_none=False) - - -# Container - ContainerPropertiesInstanceView -class ContainerState(Model): - state = StringType(serialize_when_none=False) - start_time = DateTimeType(serialize_when_none=False) - exit_code = IntType(serialize_when_none=False) - finish_time = DateTimeType(serialize_when_none=False) - detail_status = StringType(serialize_when_none=False) - - -class Event(Model): - count = IntType(serialize_when_none=False) - first_timestamp = DateTimeType(serialize_when_none=False) - last_timestamp = DateTimeType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - message = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ContainerPropertiesInstanceView(Model): - restart_count = IntType(serialize_when_none=False) - current_state = ModelType(ContainerState, serialize_when_none=False) - previous_state = ModelType(ContainerState, serialize_when_none=False) - events = ListType(ModelType(Event), serialize_when_none=False) - - -# Container - ResourceRequirements -class GpuResource(Model): - count = IntType(serialize_when_none=False) - sku = StringType(choices=('K80', 'P100', 'V100'), serialize_when_none=False) - - -class ResourceRequests(Model): - memory_in_gb = FloatType(serialize_when_none=False) - cpu = FloatType(serialize_when_none=False) - gpu = ModelType(GpuResource, serialize_when_none=False) - - -class ResourceLimits(Model): - memory_in_gb = FloatType(serialize_when_none=False) - cpu = FloatType(serialize_when_none=False) - gpu = ModelType(GpuResource, serialize_when_none=False) - - -class ResourceRequirements(Model): - requests = ModelType(ResourceRequests, serialize_when_none=False) - limits = ModelType(ResourceLimits, serialize_when_none=False) - - -# Container - VolumeMount -class VolumeMount(Model): - name = StringType(serialize_when_none=False) - mount_path = StringType(serialize_when_none=False) - read_only = BooleanType(serialize_when_none=False) - - -# Container - ContainerProbe -class ContainerExec(Model): - command = ListType(StringType(serialize_when_none=False)) - - -class HttpHeader(Model): - name = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class ContainerHttpGet(Model): - path = StringType(serialize_when_none=False) - port = IntType(serialize_when_none=False) - scheme = StringType(choices=('HTTP', 'HTTPS'), serialize_when_none=False) - http_headers = ListType(ModelType(HttpHeader), serialize_when_none=False) - - -class ContainerProbe(Model): - exec_property = ModelType(ContainerExec, serialize_when_none=False) - http_get = ModelType(ContainerHttpGet, serialize_when_none=False) - initial_delay_seconds = IntType(serialize_when_none=False) - period_seconds = IntType(serialize_when_none=False) - failure_threshold = IntType(serialize_when_none=False) - success_threshold = IntType(serialize_when_none=False) - timeout_seconds = IntType(serialize_when_none=False) - - -class Container(Model): - name = StringType(serialize_when_none=False) - image = StringType(serialize_when_none=False) - command = ListType(StringType, serialize_when_none=False) - ports = ListType(ModelType(ContainerPort), serialize_when_none=False) - environment_variables = ListType(ModelType(EnvironmentVariable), serialize_when_none=False) - instance_view = ModelType(ContainerPropertiesInstanceView) - resources = ModelType(ResourceRequirements, serialize_when_none=False) - volume_mounts = ListType(ModelType(VolumeMount), serialize_when_none=None) - volume_mount_count_display = IntType(default=0) - liveness_probe = ModelType(ContainerProbe, serialize_when_none=False) - readiness_probe = ModelType(ContainerProbe, serialize_when_none=False) - - -# ImageRegistryCredential -class ImageRegistryCredential(Model): - server = StringType(serialize_when_none=False) - username = StringType(serialize_when_none=False) - password = StringType(serialize_when_none=False) - identity = StringType(serialize_when_none=False) - identity_url = StringType(serialize_when_none=False) - - -# IpAddress -class Port(ContainerPort): - pass - - -class IpAddress(Model): - ports = ListType(ModelType(Port), serialize_when_none=False) - type = StringType(choices=('PRIVATE', 'PUBLIC')) - ip = StringType(serialize_when_none=False) - dns_name_label = StringType(serialize_when_none=False) - auto_generated_domain_name_label_scope = StringType(choices=('NOREUSE', 'RESOURCE_GROUP_REUSE', 'SUBSCRIPTION_REUSE', - 'TENANT_REUSE', 'UNSECURE')) - fqdn = StringType(serialize_when_none=False) - - -# Volume - -# Volume - AzureFileVolume -class AzureFileVolume(Model): - share_name = StringType(serialize_when_none=False) - read_only = BooleanType(serialize_when_none=False) - storage_account_name = StringType(serialize_when_none=False) - storage_account_key = StringType(serialize_when_none=False) - - -# Volume - GitRepoVolume -class GitRepoVolume(Model): - directory = StringType(serialize_when_none=False) - repository = StringType(serialize_when_none=False) - revision = StringType(serialize_when_none=False) - - -class Volume(Model): - name = StringType(serialize_when_none=False) - azure_file = ModelType(AzureFileVolume, serialize_when_none=False) - empty_dir = DictType(StringType, serialize_when_none=False) - secret = DictType(StringType, serialize_when_none=False) - git_repo = ModelType(GitRepoVolume, serialize_when_none=False) - volume_type = StringType(serialize_when_none=False) - mount_path = StringType(serialize_when_none=False) - container_name = StringType(serialize_when_none=False) - - -# ContainerGroupPropertiesInstanceView -class ContainerGroupPropertiesInstanceView(Model): - events = ListType(ModelType(Event)) - state = StringType(serialize_when_none=False) - -# ContainerGroupDiagnostics - - -# ContainerGroupDiagnostics LogAnalytics -class LogAnalytics(Model): - workspace_id = StringType(serialize_when_none=False) - workspace_key = StringType(serialize_when_none=False) - log_type = StringType(choices=('CONTAINER_INSIGHTS', 'CONTAINER_INSTANCE_LOGS')) - metadata = DictType(StringType(), StringType(), serialize_when_none=False) - workspace_resource_id = StringType(serialize_when_none=False) - - -class ContainerGroupDiagnostics(Model): - log_analytics = ModelType(LogAnalytics, serialize_when_none=False) - - -# ContainerGroupSubnetId -class ContainerGroupSubnetId(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - - -# DnsConfiguration -class DnsConfiguration(Model): - name_servers = ListType(StringType, serialize_when_none=False) - search_domains = StringType(serialize_when_none=False) - options = StringType(serialize_when_none=False) - - -# EncryptionProperties -class EncryptionProperties(Model): - vault_base_url = StringType(serialize_when_none=False) - key_name = StringType(serialize_when_none=False) - key_version = StringType(serialize_when_none=False) - -# InitContainerDefinition - - -# InitContainerDefinition - InitContainerPropertiesDefinitionInstanceView -class InitContainerPropertiesDefinitionInstanceView(ContainerPropertiesInstanceView): - pass - - -class InitContainerDefinition(Model): - name = StringType(serialize_when_none=False) - image = StringType(serialize_when_none=False) - command = ListType(StringType, serialize_when_none=False) - environment_variables = ListType(ModelType(EnvironmentVariable), serialize_when_none=False) - instance_view = ModelType(InitContainerPropertiesDefinitionInstanceView, serialize_when_none=False) - volume_mounts = ListType(ModelType(VolumeMount), serialize_when_none=False) - - -class ContainerInstance(AzureCloudService): # Main Class - id = StringType() - location = StringType() - identity = ModelType(ContainerGroupIdentity, serialize_when_none=False) - provisioning_state = StringType(serialize_when_none=False) - containers = ListType(ModelType(Container), serialize_when_none=False) - image_registry_credentials = ListType(ModelType(ImageRegistryCredential), serialize_when_none=False) - restart_policy = StringType(choices=('ALWAYS', 'NEVER', 'ON_FAILURE'), serialize_when_none=False) - ip_address = ModelType(IpAddress, serialize_when_none=False) - os_type = StringType(choices=('LINUX', 'WINDOWS')) - volumes = ListType(ModelType(Volume), serialize_when_none=False) - instance_view = ModelType(ContainerGroupPropertiesInstanceView, serialize_when_none=False) - diagnostics = ModelType(ContainerGroupDiagnostics, serialize_when_none=False) - subnet_ids = ListType(ModelType(ContainerGroupSubnetId), serialize_when_none=False) - dns_config = ModelType(DnsConfiguration, serialize_when_none=False) - sku = StringType(choices=('DEDICATED', 'STANDARD'), serialize_when_none=False) - encryption_properties = ModelType(EncryptionProperties, serialize_when_none=False) - init_containers = ListType(ModelType(InitContainerDefinition), serialize_when_none=False) - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - container_count_display = IntType(default=0) - volume_count_display = IntType(default=0) - cpu_count_display = IntType(default=0) - memory_size_display = FloatType(default=0.0) - gpu_count_display = IntType(default=0) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/container_instances/widget/container_Instances_count_by_subscription.yaml b/src/spaceone/inventory/model/container_instances/widget/container_Instances_count_by_subscription.yaml deleted file mode 100644 index 9b7cd263..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_Instances_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_account.yaml b/src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_account.yaml deleted file mode 100644 index a865425e..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_region.yaml b/src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_region.yaml deleted file mode 100644 index efef2e2c..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_instances_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_container_count.yaml b/src/spaceone/inventory/model/container_instances/widget/container_instances_total_container_count.yaml deleted file mode 100644 index 0429b35d..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_container_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Total Container Count -query: - aggregate: - - group: - fields: - - name: value - key: data.container_count_display - operator: sum -options: - value_options: - key: value - options: - default: 0 diff --git a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_count.yaml b/src/spaceone/inventory/model/container_instances/widget/container_instances_total_count.yaml deleted file mode 100644 index 766ad55e..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_gpu_count.yaml b/src/spaceone/inventory/model/container_instances/widget/container_instances_total_gpu_count.yaml deleted file mode 100644 index 60c216ca..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_gpu_count.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Total GPU Count -query: - aggregate: - - unwind: - path: data.containers - - group: - fields: - - name: value - key: data.containers.resources.requests.gpu.count - operator: sum -options: - value_options: - key: value - options: - default: 0 diff --git a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_memory_size.yaml b/src/spaceone/inventory/model/container_instances/widget/container_instances_total_memory_size.yaml deleted file mode 100644 index 246e65d2..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_memory_size.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Total Memory Size -query: - aggregate: - - unwind: - path: data.containers - - group: - fields: - - name: value - key: data.containers.resources.requests.memory_in_gb - operator: sum -options: - value_options: - key: value - type: size - options: - default: 0 - source_unit: GB diff --git a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_vcpu_count.yaml b/src/spaceone/inventory/model/container_instances/widget/container_instances_total_vcpu_count.yaml deleted file mode 100644 index 7e51c7c6..00000000 --- a/src/spaceone/inventory/model/container_instances/widget/container_instances_total_vcpu_count.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: ContainerInstances -cloud_service_type: Container -name: Total vCPU Count -query: - aggregate: - - unwind: - path: data.containers - - group: - fields: - - name: value - key: data.containers.resources.requests.cpu - operator: sum -options: - value_options: - key: value - options: - default: 0 diff --git a/src/spaceone/inventory/model/cosmos_db/__init__.py b/src/spaceone/inventory/model/cosmos_db/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/cosmos_db/cloud_service.py b/src/spaceone/inventory/model/cosmos_db/cloud_service.py deleted file mode 100644 index abf6cac8..00000000 --- a/src/spaceone/inventory/model/cosmos_db/cloud_service.py +++ /dev/null @@ -1,119 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.cosmos_db.data import DatabaseAccountGetResults - -''' -COSMOS DB -''' -# TAB - Default -cosmos_db_info_meta = ItemDynamicLayout.set_fields('Cosmos DB', fields=[ - TextDyField.data_source('Name', 'data.name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'data.subscription_id'), - TextDyField.data_source('Backup Policy', 'data.backup_policy.type'), - ListDyField.data_source('Read Locations', 'data.read_locations.location_name'), - ListDyField.data_source('Write Locations', 'data.write_locations.location_name'), - TextDyField.data_source('URI', 'data.document_endpoint'), - EnumDyField.data_source('Public Network Access', 'data.public_network_access', default_state={ - 'safe': ['Enabled'], - 'warning':['Disabled'] - }), - TextDyField.data_source('Capacity Mode', 'data.capability_display'), -]) - -# TAB - Features -cosmos_db_features = ItemDynamicLayout.set_fields('Features', fields=[ - EnumDyField.data_source('Enable Automatic Failover', 'data.enable_automatic_failover', default_state={ - 'safe': [True], - 'warning':[False] - }), - EnumDyField.data_source('Enable Free Tier', 'data.enable_free_tier', default_state={ - 'safe': [True], - 'warning':[False] - }), - EnumDyField.data_source('Enable Analytical Storage', 'data.enable_analytical_storage', default_state={ - 'safe': [True], - 'warning':[False] - }), - TextDyField.data_source('Backup Policy', 'data.backup_policy.type'), - ListDyField.data_source('CORS', 'data.cors_display') -]) - -# TAB - Default Consistency -cosmos_db_default_consistency = ItemDynamicLayout.set_fields('Default Consistency', fields=[ - TextDyField.data_source('Default Consistency', 'data.consistency_policy.default_consistency_level') -]) - -# TAB - Features -cosmos_db_backup = ItemDynamicLayout.set_fields('Backup & Restore', fields=[ - TextDyField.data_source('Backup Interval (Minutes)', 'data.backup_policy.periodic_mode_properties.backup_interval_in_minutes'), - TextDyField.data_source('Backup Retention (Hours)', 'data.backup_policy.periodic_mode_properties.backup_retention_interval_in_hours'), - TextDyField.data_source('Backup storage redundancy', 'data.backup_policy.periodic_mode_properties.additional_properties.backupStorageRedundancy'), -]) - -# TAB - Firewall and Virtual Networks -cosmos_db_virtual_network = ItemDynamicLayout.set_fields('Firewall and Virtual Networks', fields=[ - TextDyField.data_source('Enable Public Network Access', 'data.public_network_access'), - ListDyField.data_source('Virtual Networks', 'data.virtual_network_display') -]) - -# TAB - Private Endpoint Connections -cosmos_db_private_endpoint = TableDynamicLayout.set_fields('Private Endpoint Connections', 'data.private_endpoint_connections', fields=[ - TextDyField.data_source('Connection Name', 'name'), - TextDyField.data_source('Connection State', 'private_link_service_connection_state.status'), - TextDyField.data_source('Private Endpoint', 'private_endpoint.name'), - TextDyField.data_source('Description', 'private_link_service_connection_state.description') -]) - -# TAB - Cors -cosmos_db_cors = TableDynamicLayout.set_fields('Cors', 'data.cors', fields=[ - TextDyField.data_source('Connection Name', 'name'), - TextDyField.data_source('Connection State', 'private_link_service_connection_state.status'), - TextDyField.data_source('Private Endpoint', 'private_endpoint.name'), - TextDyField.data_source('Description', 'private_link_service_connection_state.description') -]) - -# TAB - Keys -cosmos_db_keys = ItemDynamicLayout.set_fields('Keys', 'data.keys', fields=[ - TextDyField.data_source('Primary Readonly Master Key', 'primary_readonly_master_key'), - TextDyField.data_source('Secondary Readonly Master Key', 'secondary_readonly_master_key'), - TextDyField.data_source('Primary Master Key', 'primary_master_key'), - TextDyField.data_source('Primary Master Key', 'secondary_master_key') -]) - -# TAB - Database -cosmos_db_database = SimpleTableDynamicLayout.set_fields('Database', 'data.sql_databases', fields=[ - TextDyField.data_source('Database', 'name'), - TextDyField.data_source('ID', 'id') -]) - -cosmos_db_meta = CloudServiceMeta.set_layouts( - [cosmos_db_info_meta, cosmos_db_features, cosmos_db_default_consistency, cosmos_db_backup, - cosmos_db_virtual_network, cosmos_db_private_endpoint, cosmos_db_cors, cosmos_db_database]) - - -class DatabaseResource(CloudServiceResource): - cloud_service_group = StringType(default='CosmosDB') - - -class CosmosDBResource(DatabaseResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(DatabaseAccountGetResults) - _metadata = ModelType(CloudServiceMeta, default=cosmos_db_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class CosmosDBResponse(CloudServiceResponse): - resource = PolyModelType(CosmosDBResource) diff --git a/src/spaceone/inventory/model/cosmos_db/cloud_service_type.py b/src/spaceone/inventory/model/cosmos_db/cloud_service_type.py deleted file mode 100644 index eed37a1e..00000000 --- a/src/spaceone/inventory/model/cosmos_db/cloud_service_type.py +++ /dev/null @@ -1,165 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -cosmosdb_count_by_account_conf = os.path.join(current_dir, 'widget/cosmosdb_count_by_account.yaml') -cosmosdb_count_by_region_conf = os.path.join(current_dir, 'widget/cosmosdb_count_by_region.yaml') -cosmosdb_count_by_subscription_conf = os.path.join(current_dir, 'widget/cosmosdb_count_by_subscription.yaml') -cosmosdb_databases_count_by_subscription_conf = os.path.join(current_dir, - 'widget/cosmosdb_databases_count_by_subscription.yaml') -cosmosdb_total_count_conf = os.path.join(current_dir, 'widget/cosmosdb_total_count.yaml') - -cst_cosmos_db = CloudServiceTypeResource() -cst_cosmos_db.name = 'Instance' -cst_cosmos_db.group = 'CosmosDB' -cst_cosmos_db.service_code = 'Microsoft.DocumentDB/databaseAccounts' -cst_cosmos_db.labels = ['Database'] -cst_cosmos_db.is_major = True -cst_cosmos_db.is_primary = True -cst_cosmos_db.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-cosmos-db.svg', -} - -cst_cosmos_db._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Subscription ID', 'data.subscription_id'), - - # is_optional field - TextDyField.data_source('Backup Policy', 'data.backup_policy.type', options={ - 'is_optional': True - }), - ListDyField.data_source('Read Locations', 'data.read_locations.location_name', options={ - 'is_optional': True - }), - ListDyField.data_source('Write Locations', 'data.write_locations.location_name', options={ - 'is_optional': True - }), - TextDyField.data_source('Document Endpoint', 'data.document_endpoint', options={ - 'is_optional': True - }), - TextDyField.data_source('Capacity Mode', 'data.capability_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable Automatic Failover', 'data.enable_automatic_failover',options={ - 'is_optional': True - }), - TextDyField.data_source('Enable Free Tier', 'data.enable_free_tier', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable Analytical Storage', 'data.enable_analytical_storage', options={ - 'is_optional': True - }), - TextDyField.data_source('Backup Policy', 'data.backup_policy.type', options={ - 'is_optional': True - }), - ListDyField.data_source('CORS', 'data.cors_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Default Consistency', 'data.consistency_policy.default_consistency_level', options={ - 'is_optional': True - }), - TextDyField.data_source('Backup Interval (Minutes)', - 'data.backup_policy.periodic_mode_properties.backup_interval_in_minutes', options={ - 'is_optional': True - }), - TextDyField.data_source('Backup Retention (Hours)', 'data.backup_policy.periodic_mode_properties.backup_retention_interval_in_hours', options={ - 'is_optional': True - }), - TextDyField.data_source('Backup storage redundancy', 'data.backup_policy.periodic_mode_properties.additional_properties.backupStorageRedundancy', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable Public Network Access', 'data.public_network_access', options={ - 'is_optional': True - }), - ListDyField.data_source('Virtual Networks', 'data.virtual_network_display', options={ - 'is_optional': True - }), - # is_optional - private endpoint connections - TextDyField.data_source('Connection Name', 'data.private_endpoint_connections.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Connection State', 'data.private_endpoint_connections.private_link_service_connection_state.status', options={ - 'is_optional': True - }), - TextDyField.data_source('Private Endpoint', 'data.private_endpoint_connections.private_endpoint.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Description', 'data.private_endpoint_connections.private_link_service_connection_state.description', options={ - 'is_optional': True - }), - # is_optional - cors - TextDyField.data_source('Private Endpoint Connection Name', 'data.cors.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Private Endpoint State', 'data.cors.private_link_service_connection_state.status', options={ - 'is_optional': True - }), - TextDyField.data_source('Private Endpoint', 'data.cors.private_endpoint.name', options={ - 'is_optional': True - }), - TextDyField.data_source('COR Private Link Description', 'data.cors.private_link_service_connection_state.description', options={ - 'is_optional': True - }), - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Backup Policy', key='data.backup_policy.type'), - SearchField.set(name='Read Locations', key='data.read_locations.location_name'), - SearchField.set(name='Write Locations', key='data.write_locations.location_name'), - SearchField.set(name='Document Endpoint', key='data.document_endpoint'), - SearchField.set(name='Capacity Mode', key='data.capability_display'), - SearchField.set(name='Enable Automatic Failover', key='data.enable_automatic_failover', data_type='boolean'), - SearchField.set(name='Enable Free Tier', key='data.enable_free_tier', data_type='boolean'), - SearchField.set(name='Enable Analytical Storage', key='data.enable_analytical_storage', data_type='boolean'), - SearchField.set(name='Backup Policy', key='data.backup_policy.type'), - SearchField.set(name='CORS', key='data.cors_display'), - SearchField.set(name='Default Consistency', - key='data.consistency_policy.default_consistency_level'), - SearchField.set(name='Backup Interval (Minutes)', - key='data.backup_policy.periodic_mode_properties.backup_interval_in_minutes', - data_type='integer'), - SearchField.set(name='Backup Retention (Hours)', - key='data.backup_policy.periodic_mode_properties.backup_retention_interval_in_hours'), - SearchField.set(name='Backup storage redundancy', - key='data.backup_policy.periodic_mode_properties.additional_properties.backupStorageRedundancy'), - SearchField.set(name='Enable Public Network Access', - key='data.public_network_access'), - SearchField.set(name='Virtual Networks', - key='data.virtual_network_display'), - SearchField.set(name='Private Endpoint Connection Name', - key='data.private_endpoint_connections.name'), - SearchField.set(name='Private Endpoint State', - key='data.private_endpoint_connections.private_link_service_connection_state.status'), - SearchField.set(name='Private Endpoint Name', - key='data.private_endpoint_connections.name'), - SearchField.set(name='Private Endpoint', - key='data.private_endpoint_connections.name'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(cosmosdb_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(cosmosdb_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(cosmosdb_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(cosmosdb_databases_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(cosmosdb_total_count_conf)), - ] - -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_cosmos_db}), -] diff --git a/src/spaceone/inventory/model/cosmos_db/data.py b/src/spaceone/inventory/model/cosmos_db/data.py deleted file mode 100644 index e325137c..00000000 --- a/src/spaceone/inventory/model/cosmos_db/data.py +++ /dev/null @@ -1,245 +0,0 @@ -from schematics import Model -from schematics.types import ( - ModelType, - ListType, - StringType, - IntType, - BooleanType, - DateTimeType, - UTCDateTimeType, - FloatType, -) -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Tags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class SubResource(Model): - id = StringType() - - -class ApiProperties(Model): - server_version = StringType(serialize_when_none=False) - - -class ManagedServiceIdentity(Model): - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType( - choices=( - "None", - "SystemAssigned", - "SystemAssigned, UserAssigned", - "UserAssigned", - ), - serialize_when_none=False, - ) - user_assigned_identities = StringType(serialize_when_none=False) - - -class PeriodicModeProperties(Model): - backup_interval_in_minutes = IntType(serialize_when_none=False) - backup_retention_interval_in_hours = IntType(serialize_when_none=False) - backup_storage_redundancy = StringType( - choices=("Geo", "Local", "Zone"), serialize_when_none=False - ) - - -class PeriodicModeBackupPolicy(Model): - periodic_mode_properties = ModelType( - PeriodicModeProperties, serialize_when_none=False - ) - type = StringType(serialize_when_none=False) - - -class Capability(Model): - name = StringType(serialize_when_none=False) - - -class ConsistencyPolicy(Model): - default_consistency_level = StringType( - choices=( - "BoundedStaleness", - "ConsistentPrefix", - "Eventual", - "Session", - "Strong", - ), - serialize_when_none=False, - ) - max_interval_in_seconds = IntType(serialize_when_none=False) - max_staleness_prefix = IntType(serialize_when_none=False) - - -class CorsPolicy(Model): - allowed_headers = StringType(serialize_when_none=False) - allowed_methods = StringType(serialize_when_none=False) - allowed_origins = StringType(serialize_when_none=False) - exposed_headers = StringType(serialize_when_none=False) - max_age_in_seconds = IntType(serialize_when_none=False) - - -class FailoverPolicy(Model): - failover_priority = IntType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location_name = StringType(serialize_when_none=False) - - -class IpAddressOrRange(Model): - ip_address_or_range = StringType(serialize_when_none=False) - - -class Location(Model): - document_endpoint = StringType(serialize_when_none=False) - failover_priority = IntType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - is_zone_redundant = BooleanType(serialize_when_none=False) - location_name = StringType(serialize_when_none=False) - provisioning_state = StringType(serialize_when_none=False) - - -class PrivateEndpointProperty(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnectionStateProperty(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - - -class PrivateEndpointConnection(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - group_id = StringType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointProperty, serialize_when_none=False) - private_link_service_connection_state = ModelType( - PrivateLinkServiceConnectionStateProperty, serialize_when_none=False - ) - provisioning_state = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class DatabaseRestoreResource(Model): - collection_names = ListType(StringType, serialize_when_none=False) - database_name = StringType(serialize_when_none=False) - - -class RestoreMode(Model): - point_in_time = StringType(serialize_when_none=False) - - -class RestoreParameters(Model): - databases_to_restore = ListType( - ModelType(DatabaseRestoreResource), serialize_when_none=False - ) - restore_mode = ModelType(RestoreMode, serialize_when_none=False) - restore_source = StringType(serialize_when_none=False) - restore_timestamp_in_utc = UTCDateTimeType(serialize_when_none=False) - - -class VirtualNetworkRule(Model): - id = StringType(serialize_when_none=False) - ignore_missing_v_net_service_endpoint = BooleanType(serialize_when_none=False) - - -class SystemData(Model): - created_at = DateTimeType(serialize_when_none=False) - created_by = StringType(serialize_when_none=False) - created_by_type = StringType( - choices=("Application", "Key", "ManagedIdentity", "User"), - serialize_when_none=False, - ) - last_modified_at = DateTimeType(serialize_when_none=False) - last_modified_by = StringType(serialize_when_none=False) - last_modified_by_type = StringType( - choices=("Application", "Key", "ManagedIdentity", "User"), - serialize_when_none=False, - ) - - -class DatabaseAccountListKeysResult(Model): - primary_master_key = StringType(serialize_when_none=False) - primary_readonly_master_key = StringType(serialize_when_none=False) - secondary_master_key = StringType(serialize_when_none=False) - secondary_readonly_master_key = StringType(serialize_when_none=False) - - -class SqlDatabaseGetResults(Model): - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class DatabaseAccountGetResults(AzureCloudService): # Main Class - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - identity = ModelType(ManagedServiceIdentity, serialize_when_none=False) - location = StringType(serialize_when_none=False) - kind = StringType( - choices=("GlobalDocumentDB", "MongoDB", "Parse"), serialize_when_none=False - ) - name = StringType(default="-", serialize_when_none=False) - api_properties = ModelType(ApiProperties, serialize_when_none=False) - backup_policy = ModelType(PeriodicModeBackupPolicy, serialize_when_none=False) - capabilities = ListType(ModelType(Capability), serialize_when_none=False) - capability_display = StringType(serialize_when_none=False) - connector_offer = StringType(serialize_when_none=False) - consistency_policy = ModelType(ConsistencyPolicy, serialize_when_none=False) - cors = ListType(ModelType(CorsPolicy), serialize_when_none=False) - cors_display = ListType(StringType, serialize_when_none=False) - create_mode = StringType(choices=("Default", "Restore"), serialize_when_none=False) - database_account_offer_type = StringType(serialize_when_none=False) - default_identity = StringType(serialize_when_none=False) - disable_key_based_metadata_write_access = BooleanType(serialize_when_none=False) - document_endpoint = StringType(serialize_when_none=False) - enable_analytical_storage = BooleanType(serialize_when_none=False) - enable_automatic_failover = BooleanType(serialize_when_none=False) - enable_cassandra_connector = BooleanType(serialize_when_none=False) - enable_free_tier = BooleanType(serialize_when_none=False) - enable_multiple_write_locations = BooleanType(serialize_when_none=False) - failover_policies = ListType(ModelType(FailoverPolicy), serialize_when_none=False) - instance_id = StringType(serialize_when_none=False) - ip_rules = ListType(ModelType(IpAddressOrRange), serialize_when_none=False) - is_virtual_network_filter_enabled = BooleanType(serialize_when_none=False) - key_vault_key_uri = BooleanType(serialize_when_none=False) - keys = ModelType(DatabaseAccountListKeysResult, serialize_when_none=False) - locations = ListType(ModelType(Location), serialize_when_none=False) - network_acl_bypass = StringType( - choices=("AzureServices", "None"), serialize_when_none=False - ) - network_acl_bypass_resource_ids = ListType(StringType, serialize_when_none=False) - private_endpoint_connections = ListType( - ModelType(PrivateEndpointConnection), serialize_when_none=False - ) - provisioning_state = StringType(serialize_when_none=False) - public_network_access = StringType( - choices=("Disabled", "Enabled"), serialize_when_none=False - ) - read_locations = ListType(ModelType(Location), serialize_when_none=False) - restore_parameters = ModelType(RestoreParameters, serialize_when_none=False) - virtual_network_rules = ListType( - ModelType(VirtualNetworkRule), serialize_when_none=False - ) - virtual_network_display = ListType(StringType, serialize_when_none=False) - sql_databases = ListType( - ModelType(SqlDatabaseGetResults), serialize_when_none=False - ) - sql_databases_count_display = IntType(serialize_when_none=False) - write_locations = ListType(ModelType(Location), serialize_when_none=False) - system_data = ModelType(SystemData, serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_account.yaml b/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_account.yaml deleted file mode 100644 index 8e35d419..00000000 --- a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: CosmosDB -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_region.yaml b/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_region.yaml deleted file mode 100644 index 91e6a419..00000000 --- a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: CosmosDB -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_subscription.yaml b/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_subscription.yaml deleted file mode 100644 index d34683fe..00000000 --- a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: CosmosDB -cloud_service_type: Instance -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_databases_count_by_subscription.yaml b/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_databases_count_by_subscription.yaml deleted file mode 100644 index 0a802fb0..00000000 --- a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_databases_count_by_subscription.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: CosmosDB -cloud_service_type: Instance -name: Databases Count by Region -query: - aggregate: - - unwind: - path: data.sql_databases - - group: - keys: - - name: name - key: data.name - fields: - - name: count - key: data.sql_databases - operator: count -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_total_count.yaml b/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_total_count.yaml deleted file mode 100644 index 2549036c..00000000 --- a/src/spaceone/inventory/model/cosmos_db/widget/cosmosdb_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: CosmosDB -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/disks/__init__.py b/src/spaceone/inventory/model/disks/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/disks/cloud_service.py b/src/spaceone/inventory/model/disks/cloud_service.py deleted file mode 100644 index e3281ae1..00000000 --- a/src/spaceone/inventory/model/disks/cloud_service.py +++ /dev/null @@ -1,77 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.model.disks.data import Disk -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, ListDyField, SizeField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout,ListDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta - -disk_info_meta = ItemDynamicLayout.set_fields('Disks', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Storage Account Type', 'instance_type'), - SizeField.data_source('Size', 'instance_size'), - EnumDyField.data_source('Disk State', 'data.disk_state', default_state={ - 'safe': ['ActiveSAS', 'ActiveUpload', 'Attached', 'Reserved'], - 'warning':['ReadyToUpload'], - 'available': ['Unattached'] - }), - TextDyField.data_source('Attached VM', 'data.managed_by'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Resource ID', 'data.id'), - ListDyField.data_source('Zones', 'data.zones', options={ - 'delimiter': '
' - }), - TextDyField.data_source('Subscription ID', 'data.subscription_id'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Encryption Type', 'data.encryption.type'), - TextDyField.data_source('Networking', 'data.network_access_policy_display'), - TextDyField.data_source('Os Type', 'data.os_type'), - TextDyField.data_source('Max Shares', 'data.max_shares'), - TextDyField.data_source('VM Generation', 'data.hyper_v_generation'), - TextDyField.data_source('VM architecture', 'data.supported_capabilities.architecture'), - DateTimeDyField.data_source('Time Created', 'data.time_created') - - -]) -''' -DISK -''' -# TAB - Networking -disk_networking_info = ItemDynamicLayout.set_fields('Networking', fields=[ - TextDyField.data_source('Network access', 'data.network_access_policy_display') -]) - -# TAB - Configuration - -shared_disk = ItemDynamicLayout.set_fields('Shared Disk', fields=[ - TextDyField.data_source('Enable shared disk', 'data.enable_shared_disk_display'), - TextDyField.data_source('Max shares', 'data.max_shares'), -]) - -on_demand_bursting = ItemDynamicLayout.set_fields('On-demand bursting', fields=[ - TextDyField.data_source('Enable bursting', 'data.bursting_enabled'), - DateTimeDyField.data_source('Enable bursting time', 'data.bursting_enabled_time'), -]) - -disk_configure_info = ListDynamicLayout.set_layouts('Configuration', layouts=[shared_disk, on_demand_bursting]) - -# TAB - Default -disk_meta = CloudServiceMeta.set_layouts([disk_info_meta, disk_configure_info, disk_networking_info]) - - -class ComputeResource(CloudServiceResource): - cloud_service_group = StringType(default='Disks') - - -class DiskResource(ComputeResource): - cloud_service_type = StringType(default='Disk') - data = ModelType(Disk) - _metadata = ModelType(CloudServiceMeta, default=disk_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class DiskResponse(CloudServiceResponse): - resource = PolyModelType(DiskResource) diff --git a/src/spaceone/inventory/model/disks/cloud_service_type.py b/src/spaceone/inventory/model/disks/cloud_service_type.py deleted file mode 100644 index b78e27aa..00000000 --- a/src/spaceone/inventory/model/disks/cloud_service_type.py +++ /dev/null @@ -1,147 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import ( - CardWidget, - ChartWidget, -) -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - TextDyField, - SearchField, - DateTimeDyField, - ListDyField, - EnumDyField, - SizeField, -) -from spaceone.inventory.libs.schema.cloud_service_type import ( - CloudServiceTypeResource, - CloudServiceTypeResponse, - CloudServiceTypeMeta, -) -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -""" -DISK -""" -disks_count_by_account_conf = os.path.join( - current_dir, "widget/disks_count_by_account.yaml" -) -disks_count_by_region_conf = os.path.join( - current_dir, "widget/disks_count_by_region.yaml" -) -disks_count_by_resource_group_conf = os.path.join( - current_dir, "widget/disks_count_by_resource_group.yaml" -) -disks_size_by_region_conf = os.path.join( - current_dir, "widget/disks_size_by_region.yaml" -) -disks_size_by_status_conf = os.path.join( - current_dir, "widget/disks_size_by_status.yaml" -) -disks_size_by_subscription_conf = os.path.join( - current_dir, "widget/disks_size_by_subscription.yaml" -) -disks_size_by_type_conf = os.path.join(current_dir, "widget/disks_size_by_type.yaml") -disks_total_size_conf = os.path.join(current_dir, "widget/disks_total_size.yaml") -disks_total_count_conf = os.path.join(current_dir, "widget/disks_total_count.yaml") - -cst_disks = CloudServiceTypeResource() -cst_disks.group = "Disks" -cst_disks.name = "Disk" -cst_disks.provider = "azure" -cst_disks.labels = ["Compute", "Storage"] -cst_disks.service_code = "Microsoft.Compute/disks" -cst_disks.is_major = True -cst_disks.is_primary = True -cst_disks.tags = { - "spaceone:icon": f"{ASSET_URL}/azure-disk.svg", - "spaceone:display_name": "Disk", -} - -cst_disks._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source("Storage Account Type", "data.sku.name"), - SizeField.data_source("Size", "data.size"), - EnumDyField.data_source( - "Disk State", - "data.disk_state", - default_state={ - "safe": ["ActiveSAS", "ActiveUpload", "Attached", "Reserved"], - "warning": ["ReadyToUpload"], - "available": ["Unattached"], - }, - ), - TextDyField.data_source("Owner", "data.managed_by"), - TextDyField.data_source("Resource Group", "data.resource_group"), - TextDyField.data_source("Location", "data.location"), - TextDyField.data_source("Subscription Name", "data.subscription_name"), - # is_optional - Default - TextDyField.data_source( - "Subscription ID", "data.subscription_id", options={"is_optional": True} - ), - ListDyField.data_source( - "Zone", "data.zones", options={"delimiter": "
", "is_optional": True} - ), - TextDyField.data_source( - "Encryption Type", "data.encryption.type", options={"is_optional": True} - ), - TextDyField.data_source( - "Networking", - "data.network_access_policy_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Max Shares", "data.max_shares", options={"is_optional": True} - ), - TextDyField.data_source( - "Time Created", "data.time_created", options={"is_optional": True} - ), - ], - search=[ - SearchField.set(name="Tier", key="data.tier", data_type="string"), - SearchField.set( - name="Subscription ID", key="data.subscription_id", data_type="string" - ), - SearchField.set( - name="Subscription Name", key="data.subscription_name", data_type="string" - ), - SearchField.set( - name="Resource Group", key="data.resource_group", data_type="string" - ), - SearchField.set(name="Location", key="data.location", data_type="string"), - SearchField.set(name="Zone", key="data.zones", data_type="string"), - SearchField.set( - name="Storage Account Type", key="data.sku.name", data_type="string" - ), - SearchField.set( - name="Disk Size (Bytes)", key="data.disk_size_bytes", data_type="integer" - ), - SearchField.set( - name="Disk Size (GB)", key="data.disk_size_gb", data_type="integer" - ), - SearchField.set( - name="Disk IOPS", key="data.disk_iops_read_write", data_type="integer" - ), - SearchField.set(name="OS Type", key="data.os_type", data_type="string"), - SearchField.set( - name="Provisioning State", key="data.provisioning_state", data_type="string" - ), - SearchField.set( - name="Time Created", key="data.time_created", data_type="datetime" - ), - ], - widget=[ - CardWidget.set(**get_data_from_yaml(disks_total_count_conf)), - CardWidget.set(**get_data_from_yaml(disks_total_size_conf)), - ChartWidget.set(**get_data_from_yaml(disks_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(disks_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(disks_count_by_resource_group_conf)), - ChartWidget.set(**get_data_from_yaml(disks_size_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(disks_size_by_status_conf)), - ChartWidget.set(**get_data_from_yaml(disks_size_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(disks_size_by_type_conf)), - ], -) - -CLOUD_SERVICE_TYPES = [CloudServiceTypeResponse({"resource": cst_disks})] diff --git a/src/spaceone/inventory/model/disks/data.py b/src/spaceone/inventory/model/disks/data.py deleted file mode 100644 index 7f2ac888..00000000 --- a/src/spaceone/inventory/model/disks/data.py +++ /dev/null @@ -1,104 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, FloatType, DateTimeType, IntType, BooleanType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Sku(Model): - name = StringType(choices=('Standard_LRS', 'Premium_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS'), - serialize_when_none=False) - tier = StringType(choices=('Premium', 'Standard'), serialize_when_none=False) - - -class ImageDiskReference(Model): - id = StringType(serialize_when_none=False) - lun = IntType(serialize_when_none=False) - - -class CreationData(Model): - creation_option = StringType(choices=('Attach', 'Copy', 'Empty', 'FromImage', 'Import', 'Restore', 'Upload'), serialize_when_none=False) - gallery_image_reference = ModelType(ImageDiskReference, serialize_when_none=False) - image_reference = ModelType(ImageDiskReference, serialize_when_none=False) - logical_sector_size = IntType(serialize_when_none=False) - source_resource_id = StringType(serialize_when_none=False) - source_unique_id = StringType(serialize_when_none=False) - source_uri = StringType(serialize_when_none=False) - storage_account_id = StringType(serialize_when_none=False) - upload_size_bytes = IntType(serialize_when_none=False) - - -class SourceVault(Model): - id = StringType(serialize_when_none=False) - - -class DiskEncryptionKey(Model): - source_vault = ModelType(SourceVault, serialize_when_none=False) - secret_url = StringType(serialize_when_none=False) - - -class KeyEncryptionKey(Model): - source_vault = ModelType(SourceVault) - key_url = StringType() - - -class EncryptionSettingsCollection(Model): - disk_encryption_key = ModelType(DiskEncryptionKey, serialize_when_none=False) - key_encryption_key = ModelType(KeyEncryptionKey, serialize_when_none=False) - - -class Encryption(Model): - disk_encryption_set_id = StringType(default='', serialize_when_none=False) - type = StringType(choices=('EncryptionAtRestWithCustomerKey', 'EncryptionAtRestWithPlatformAndCustomerKeys', - 'EncryptionAtRestWithPlatformKey'), - default='EncryptionAtRestWithPlatformKey', serialize_when_none=False) - - -class ShareInfoElement(Model): - vm_uri = StringType(serialize_when_none=False) - - -class SupportedCapabilities(Model): - disk_controller_types = StringType(serialize_when_none=False) - accelerated_network = BooleanType(serialize_when_none=False) - architecture = StringType(serialize_when_none=False) - - -class Disk(AzureCloudService): - name = StringType() - id = StringType() - type = StringType() - location = StringType() - managed_by = StringType(default='') - managed_by_extended = ListType(StringType, serialize_when_none=False) - max_shares = IntType(default=0) - enable_shared_disk_display = BooleanType(default=False) - sku = ModelType(Sku) - zones = ListType(StringType(), serialize_when_none=False) - disk_size_gb = IntType() - disk_iops_read_write = IntType() - disk_iops_read_only = IntType(serialize_when_none=False) - disk_size_bytes = IntType() - size = IntType() # disk size for statistics - encryption_settings_collection = ModelType(EncryptionSettingsCollection, serialize_when_none=False) - encryption = ModelType(Encryption) - hyper_v_generation = StringType(serialize_when_none=False) - time_created = DateTimeType() - creation_data = ModelType(CreationData) - os_type = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Failed', 'Succeeded'), serialize_when_none=False) - share_info = ModelType(ShareInfoElement, serialize_when_none=False) - unique_id = StringType() - disk_m_bps_read_write = IntType() - disk_m_bps_read_only = IntType(serialize_when_none=False) - disk_state = StringType(choices=('ActiveSAS', 'ActiveUpload', 'Attached', 'ReadyToUpload', 'Reserved', 'Unattached')) - network_access_policy = StringType(choices=('AllowAll', 'AllowPrivate', 'DenyAll'), serialize_when_none=False) - network_access_policy_display = StringType() - tier_display = StringType(default='') - supported_capabilities = ModelType(SupportedCapabilities, serialize_when_none=False) - bursting_enabled = BooleanType(default=False) - bursting_enabled_time = DateTimeType() - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } \ No newline at end of file diff --git a/src/spaceone/inventory/model/disks/widget/disks_count_by_account.yaml b/src/spaceone/inventory/model/disks/widget/disks_count_by_account.yaml deleted file mode 100644 index 584c3b2d..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/disks/widget/disks_count_by_region.yaml b/src/spaceone/inventory/model/disks/widget/disks_count_by_region.yaml deleted file mode 100644 index 949795e0..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/disks/widget/disks_count_by_resource_group.yaml b/src/spaceone/inventory/model/disks/widget/disks_count_by_resource_group.yaml deleted file mode 100644 index aeda0959..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_count_by_resource_group.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Count by Resource Group -query: - aggregate: - - group: - keys: - - name: name - key: data.resource_group - fields: - - name: value - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/disks/widget/disks_size_by_region.yaml b/src/spaceone/inventory/model/disks/widget/disks_size_by_region.yaml deleted file mode 100644 index 077d5fac..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_size_by_region.yaml +++ /dev/null @@ -1,26 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Size by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - key: instance_size - operator: sum -options: - chart_type: COLUMN - value_options: - key: value - type: size - options: - default: 0 - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/disks/widget/disks_size_by_status.yaml b/src/spaceone/inventory/model/disks/widget/disks_size_by_status.yaml deleted file mode 100644 index 87033655..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_size_by_status.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Size by Status -query: - aggregate: - - group: - keys: - - name: name - key: data.disk_state - fields: - - name: value - key: instance_size - operator: sum -options: - chart_type: DONUT - value_options: - key: value - type: size - options: - default: 0 diff --git a/src/spaceone/inventory/model/disks/widget/disks_size_by_subscription.yaml b/src/spaceone/inventory/model/disks/widget/disks_size_by_subscription.yaml deleted file mode 100644 index 1d8703d5..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_size_by_subscription.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Size by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: instance_size - operator: sum -options: - chart_type: COLUMN - value_options: - key: value - type: size - options: - default: 0 diff --git a/src/spaceone/inventory/model/disks/widget/disks_size_by_type.yaml b/src/spaceone/inventory/model/disks/widget/disks_size_by_type.yaml deleted file mode 100644 index e8155364..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_size_by_type.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Size by Type -query: - aggregate: - - group: - keys: - - name: name - key: instance_type - fields: - - name: value - key: instance_size - operator: sum -options: - chart_type: TREEMAP diff --git a/src/spaceone/inventory/model/disks/widget/disks_total_count.yaml b/src/spaceone/inventory/model/disks/widget/disks_total_count.yaml deleted file mode 100644 index 61461cd7..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/disks/widget/disks_total_size.yaml b/src/spaceone/inventory/model/disks/widget/disks_total_size.yaml deleted file mode 100644 index 01141302..00000000 --- a/src/spaceone/inventory/model/disks/widget/disks_total_size.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -cloud_service_group: Disks -cloud_service_type: Disk -name: Total Size -query: - aggregate: - - group: - fields: - - name: value - key: instance_size - operator: sum -options: - value_options: - key: value - type: size - options: - default: 0 \ No newline at end of file diff --git a/src/spaceone/inventory/model/job_model.py b/src/spaceone/inventory/model/job_model.py deleted file mode 100644 index 9ed2ccb7..00000000 --- a/src/spaceone/inventory/model/job_model.py +++ /dev/null @@ -1,18 +0,0 @@ -from schematics.models import Model -from schematics.types import ListType, StringType -from schematics.types.compound import ModelType - -__all__ = ["Tasks"] - - -class TaskOptions(Model): - resource_type = StringType(serialize_when_none=False) - cloud_service_types = ListType(StringType, serialize_when_none=False) - - -class Task(Model): - task_options = ModelType(TaskOptions, required=True) - - -class Tasks(Model): - tasks = ListType(ModelType(Task), required=True) diff --git a/src/spaceone/inventory/model/key_vaults/__init__.py b/src/spaceone/inventory/model/key_vaults/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/key_vaults/cloud_service.py b/src/spaceone/inventory/model/key_vaults/cloud_service.py deleted file mode 100644 index 56add802..00000000 --- a/src/spaceone/inventory/model/key_vaults/cloud_service.py +++ /dev/null @@ -1,182 +0,0 @@ -from schematics.types import ( - ModelType, - StringType, - PolyModelType, - FloatType, - DateTimeType, -) - -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - TextDyField, - DateTimeDyField, - EnumDyField, - ListDyField, - SizeField, - StateItemDyField, -) -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ( - ItemDynamicLayout, - TableDynamicLayout, - ListDynamicLayout, - SimpleTableDynamicLayout, - QuerySearchTableDynamicLayout, -) -from spaceone.inventory.libs.schema.cloud_service import ( - CloudServiceResource, - CloudServiceResponse, - CloudServiceMeta, -) -from spaceone.inventory.model.key_vaults.data import KeyVault - -""" -KEY_VAULT -""" -# TAB - Default -key_vault_info_meta = ItemDynamicLayout.set_fields( - "Key Vault", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Resource ID", "data.id"), - TextDyField.data_source("Resource Group", "data.resource_group"), - TextDyField.data_source("Location", "data.location"), - TextDyField.data_source("Subscription", "data.subscription_name"), - TextDyField.data_source("Subscription ID", "account"), - TextDyField.data_source("Vault URI", "data.properties.vault_uri"), - TextDyField.data_source("Sku (Pricing Tier)", "instance_type"), - TextDyField.data_source("Directory ID", "data.properties.tenant_id"), - # TextDyField.data_source('Directory Name', 'data.'), - TextDyField.data_source("Soft-delete", "data.properties.enable_soft_delete"), - TextDyField.data_source( - "Purge Protection", "data.properties.enable_purge_protection_str" - ), - TextDyField.data_source( - "Total Credentials Count", "data.total_credentials_count" - ), - TextDyField.data_source("Keys Count", "data.key_count"), - TextDyField.data_source("Secrets Count", "data.secret_count"), - TextDyField.data_source("Certificates Count", "data.certificate_count"), - ], -) - -# TAB - KeyVaults Permissions -key_vault_permissions = ItemDynamicLayout.set_fields( - "Permissions description", - fields=[ - TextDyField.data_source("Keys", "data.keys_permissions_description_display"), - TextDyField.data_source( - "Secrets", "data.secrets_permissions_description_display" - ), - TextDyField.data_source( - "Certificates", "data.certificates_permissions_description_display" - ), - ], -) -# TAB - Keys -key_vault_keys = QuerySearchTableDynamicLayout.set_fields( - "Keys", - root_path="data.keys", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Type", "instance_type"), - TextDyField.data_source("Location", "location"), - TextDyField.data_source("Status", "attributes.enabled"), - DateTimeDyField.data_source("Expiration Date", "attributes.expires"), - DateTimeDyField.data_source("Creation Date", "attributes.created"), - TextDyField.data_source("Key URI", "key_uri"), - ], -) - -# TAB - Secrets -key_vault_secrets = QuerySearchTableDynamicLayout.set_fields( - "Secrets", - root_path="data.secrets", - fields=[ - TextDyField.data_source("ID", "_id"), - TextDyField.data_source("Type", "_content_type"), - TextDyField.data_source("Status", "_attributes.enabled"), - DateTimeDyField.data_source("Updated Date", "_attributes.updated"), - DateTimeDyField.data_source("Creation Date", "_attributes.created"), - TextDyField.data_source("Recoverable Days", "_attributes.recoverable_days"), - ], -) - -# TAB - Certificates -key_vault_certificates = QuerySearchTableDynamicLayout.set_fields( - "Certificates", - root_path="data.certificates", - fields=[ - TextDyField.data_source("ID", "_id"), - TextDyField.data_source("Status", "_attributes.enabled"), - DateTimeDyField.data_source("Updated Date", "_attributes.updated"), - DateTimeDyField.data_source("Creation Date", "_attributes.created"), - TextDyField.data_source("Recoverable Days", "_attributes.recoverable_days"), - ], -) - -# TAB - Access Policies -key_vault_access_policies = ItemDynamicLayout.set_fields( - "Access Policies", - fields=[ - TextDyField.data_source( - "Enable for Azure VM Deployment", "data.properties.enabled_for_deployment" - ), - TextDyField.data_source( - "Enable for Disk Encryption", "data.properties.enabled_for_disk_encryption" - ), - TextDyField.data_source( - "Enable for Template Deployment", - "data.properties.enabled_for_template_deployment", - ), - TextDyField.data_source( - "Enable RBAC Authorization", "data.properties.enable_rbac_authorization" - ), - ], -) - -# TAB - Networking -key_vault_networking = QuerySearchTableDynamicLayout.set_fields( - "Private Endpoint Connections", - root_path="data.properties.private_endpoint_connections", - fields=[ - TextDyField.data_source("Connection Name", "name"), - TextDyField.data_source( - "Connection State", "private_link_service_connection_state.status" - ), - EnumDyField.data_source( - "Provisioning State", - "provisioning_state", - default_state={"safe": ["Succeeded", "RegisteringDns"]}, - ), - TextDyField.data_source("Private Endpoint", "private_endpoint.id"), - ], -) - -key_vault_meta = CloudServiceMeta.set_layouts( - [ - key_vault_info_meta, - key_vault_permissions, - key_vault_keys, - key_vault_secrets, - key_vault_certificates, - key_vault_access_policies, - key_vault_networking, - ] -) - - -class KeyVaultResource(CloudServiceResource): - cloud_service_group = StringType(default="KeyVaults") - cloud_service_type = StringType(default="Instance") - data = ModelType(KeyVault) - _metadata = ModelType( - CloudServiceMeta, default=key_vault_meta, serialized_name="metadata" - ) - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class KeyVaultResponse(CloudServiceResponse): - resource = PolyModelType(KeyVaultResource) diff --git a/src/spaceone/inventory/model/key_vaults/cloud_service_type.py b/src/spaceone/inventory/model/key_vaults/cloud_service_type.py deleted file mode 100644 index e882b494..00000000 --- a/src/spaceone/inventory/model/key_vaults/cloud_service_type.py +++ /dev/null @@ -1,150 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -key_vaults_count_by_account_conf = os.path.join(current_dir, 'widget/key_vaults_count_by_account.yaml') -key_vaults_count_by_region_conf = os.path.join(current_dir, 'widget/key_vaults_count_by_region.yaml') -key_vaults_count_per_subscription_conf = os.path.join(current_dir, 'widget/key_vaults_count_by_subscription.yaml') -key_vaults_total_count_conf = os.path.join(current_dir, 'widget/key_vaults_total_count.yaml') - -cst_key_vaults = CloudServiceTypeResource() -cst_key_vaults.name = 'Instance' -cst_key_vaults.group = 'KeyVaults' -cst_key_vaults.service_code = 'Microsoft.KeyVault/vaults' -cst_key_vaults.labels = ['Security'] -cst_key_vaults.is_major = True -cst_key_vaults.is_primary = True -cst_key_vaults.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-key-vault.svg', -} - -cst_key_vaults._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Type', 'instance_type'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - - # is_optional fields - Public IP Addresses - TextDyField.data_source('Public IP Address', 'data.public_ip_addresses.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Vault URI', 'data.properties.vault_uri', options={ - 'is_optional': True - }), - TextDyField.data_source('SKU (Pricing Tier)', 'data.sku.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Directory ID', 'data.properties.tenant_id', options={ - 'is_optional': True - }), - TextDyField.data_source('Soft-delete', 'data.properties.enable_soft_delete', options={ - 'is_optional': True - }), - TextDyField.data_source('Purge Protection', 'data.properties.enable_purge_protection', options={ - 'is_optional': True - }), - TextDyField.data_source('Key Name', 'data.keys.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Key Type', 'data.keys.type', options={ - 'is_optional': True - }), - TextDyField.data_source('Key Location', 'data.keys.location', options={ - 'is_optional': True - }), - TextDyField.data_source('Key Status', 'data.keys.attributes.enabled', options={ - 'is_optional': True - }), - DateTimeDyField.data_source('Key Expiration Date', 'data.keys.attributes.expires', options={ - 'is_optional': True - }), - DateTimeDyField.data_source('Key Creation Date', 'data.keys.attributes.created', options={ - 'is_optional': True - }), - TextDyField.data_source('Key URI', 'data.keys.key_uri', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable for Azure VM Deployment', 'data.properties.enabled_for_deployment', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable for Disk Encryption', 'data.properties.enabled_for_disk_encryption', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable for Template Deployment', 'data.properties.enabled_for_template_deployment', options={ - 'is_optional': True - }), - TextDyField.data_source('Enable RBAC Authorization', 'data.properties.enable_rbac_authorization', options={ - 'is_optional': True - }), - - TextDyField.data_source('Private Connection Name', 'data.properties.private_endpoint_connections.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Private Connection State', 'data.properties.private_endpoint_connections.private_link_service_connection_state.status', options={ - 'is_optional': True - }), - TextDyField.data_source('Private Endpoint ID', 'data.properties.private_endpoint_connections.private_endpoint.id', options={ - 'is_optional': True - }), - ], - search=[ - SearchField.set(name='Type', key='instance_type'), - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Public IP Address', key='data.public_ip_addresses.name'), - SearchField.set(name='Vault URI', key='data.properties.vault_uri'), - SearchField.set(name='SKU (Pricing Tier)', key='data.sku.name'), - SearchField.set(name='Directory ID', key='data.properties.tenant_id'), - SearchField.set(name='Soft-delete', key='data.properties.enable_soft_delete'), - SearchField.set(name='Purge Protection', key='data.properties.enable_purge_protection'), - SearchField.set(name='Key Name', key='data.keys.name'), - SearchField.set(name='Key Type', key='data.keys.type'), - SearchField.set(name='Key Location', key='data.keys.location'), - SearchField.set(name='Key Status', key='data.keys.attributes.enabled'), - SearchField.set(name='Key Expiration Date', key='data.keys.attributes.expires'), - SearchField.set(name='Key Creation Date', key='data.keys.attributes.created'), - SearchField.set(name='Key URI', key='data.keys.key_uri'), - SearchField.set(name='Enable for Azure VM Deployment', - key='data.properties.enabled_for_deployment', - data_type='boolean'), - SearchField.set(name='Enable for Disk Encryption', - key='data.properties.enabled_for_disk_encryption', - data_type='boolean'), - SearchField.set(name='Enable for Template Deployment', - key='data.properties.enabled_for_template_deployment', - data_type='boolean'), - SearchField.set(name='Enable RBAC Authorization', - key='data.properties.enable_rbac_authorization', - data_type='boolean'), - SearchField.set(name='Private Endpoint Connection Name', - key='data.properties.private_endpoint_connections.name'), - SearchField.set(name='Private Endpoint Connection State', - key='data.properties.private_endpoint_connections.private_link_service_connection_state.status'), - SearchField.set(name='Private Endpoint ID', - key='data.properties.private_endpoint_connections.private_endpoint.id'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(key_vaults_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(key_vaults_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(key_vaults_count_per_subscription_conf)), - CardWidget.set(**get_data_from_yaml(key_vaults_total_count_conf)), - - ] - -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_key_vaults}), -] diff --git a/src/spaceone/inventory/model/key_vaults/data.py b/src/spaceone/inventory/model/key_vaults/data.py deleted file mode 100644 index cdddfc1d..00000000 --- a/src/spaceone/inventory/model/key_vaults/data.py +++ /dev/null @@ -1,257 +0,0 @@ -from schematics import Model -from schematics.types import ( - ModelType, - ListType, - StringType, - IntType, - BooleanType, - DateTimeType, - DictType, -) -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Tags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class SubResource(Model): - id = StringType() - - -class Permissions(Model): - certificates = ListType(StringType, serialize_when_none=False) - keys = ListType(StringType, serialize_when_none=False) - secrets = ListType(StringType, serialize_when_none=False) - storage = ListType(StringType, serialize_when_none=False) - - -class AccessPolicyEntry(Model): - application_id = StringType(serialize_when_none=False) - object_id = StringType(serialize_when_none=False) - permissions = ModelType(Permissions, serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - - -class IPRule(Model): - value = StringType(serialize_when_none=False) - - -class VirtualNetworkRule(Model): - ip = StringType(serialize_when_none=False) - ignore_missing_vnet_service_endpoint = BooleanType(serialize_when_none=False) - - -class NetworkRuleSet(Model): - bypass = StringType(choices=("AzureServices", "None"), serialize_when_none=False) - default_action = StringType(choices=("Allow", "Deny"), serialize_when_none=False) - ip_rules = ListType(ModelType(IPRule), serialize_when_none=False) - virtual_network_rules = ListType( - ModelType(VirtualNetworkRule), serialize_when_none=False - ) - - -class PrivateEndpoint(Model): - id = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnectionState(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType( - choices=("Approved", "Disconnected", "Pending", "Rejected"), - serialize_when_none=False, - ) - - -class PrivateEndpointConnectionItem(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpoint, serialize_when_none=False) - private_link_service_connection_state = ModelType( - PrivateLinkServiceConnectionState, serialize_when_none=False - ) - provisioning_state = StringType( - choices=( - "Creating", - "Deleting", - "Disconnected", - "Failed", - "Succeeded", - "Updating", - ), - serialize_when_none=False, - ) - - -class Sku(Model): - family = StringType(serialize_when_none=False) - name = StringType(choices=("premium", "standard"), serialize_when_none=False) - - -class SecretAttributes(Model): - created = DateTimeType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - exp = DateTimeType(serialize_when_none=False) - nbf = DateTimeType(serialize_when_none=False) - recoverable_days = IntType(serialize_when_none=False) - recovery_level = StringType( - choices=( - "CustomizedRecoverable", - "CustomizedRecoverable+ProtectedSubscription", - "CustomizedRecoverable+Purgeable", - "Purgeable", - "Recoverable", - "Recoverable+ProtectedSubscription", - "Recoverable+Purgeable", - ), - serialize_when_none=False, - ) - updated = DateTimeType(serialize_when_none=False) - - -class ResourceId(Model): - source_id = StringType(serialize_when_none=False) - vault_url = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - - -class VaultId(Model): - resource_id = ModelType(ResourceId, serialize_when_none=False) - - -class SecretItem(Model): - _attributes = ModelType(SecretAttributes, serialize_when_none=False) - _content_type = StringType(serialize_when_none=False) - _id = StringType(serialize_when_none=False) - _managed = BooleanType(serialize_when_none=False) - _tags = ModelType(Tags, serialize_when_none=False) - _vault_id = ModelType(VaultId, serialize_when_none=False) - - -class CertificateAttributes(Model): - created = DateTimeType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - exp = DateTimeType(serialize_when_none=False) - nbf = DateTimeType(serialize_when_none=False) - recoverable_days = IntType(serialize_when_none=False) - recovery_level = StringType( - choices=( - "CustomizedRecoverable", - "CustomizedRecoverable+ProtectedSubscription", - "CustomizedRecoverable+Purgeable", - "Purgeable", - "Recoverable", - "Recoverable+ProtectedSubscription", - "Recoverable+Purgeable", - ), - serialize_when_none=False, - ) - updated = DateTimeType(serialize_when_none=False) - - -class CertificateItem(Model): - _attributes = ModelType(CertificateAttributes, serialize_when_none=False) - _id = StringType(serialize_when_none=False) - _content_type = StringType(serialize_when_none=False) - _tags = ModelType(Tags, serialize_when_none=False) - _vault_id = ModelType(VaultId, serialize_when_none=False) - - -class VaultProperties(Model): - access_policies = ListType(ModelType(AccessPolicyEntry), serialize_when_none=False) - create_mode = StringType(choices=("default", "recover"), serialize_when_none=False) - enable_purge_protection = BooleanType(default=False, serialize_when_none=False) - enable_purge_protection_str = StringType( - serialize_when_none=False, default="Disabled" - ) - enable_rbac_authorization = BooleanType(serialize_when_none=False) - enable_soft_delete = BooleanType(serialize_when_none=False) - enabled_for_deployment = BooleanType(serialize_when_none=False) - enabled_for_disk_encryption = BooleanType(serialize_when_none=False) - enabled_for_template_deployment = BooleanType(serialize_when_none=False) - hsm_pool_resource_id = StringType(serialize_when_none=False) - network_acls = ModelType(NetworkRuleSet, serialize_when_none=False) - private_endpoint_connections = ListType( - ModelType(PrivateEndpointConnectionItem), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("RegisteringDns", "Succeeded"), serialize_when_none=False - ) - sku = ModelType(Sku, serialize_when_none=False) - soft_delete_retention_in_days = IntType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - vault_uri = StringType(serialize_when_none=False) - - -class KeyAttributes(Model): - created = DateTimeType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - exp = DateTimeType(serialize_when_none=False) - nbf = DateTimeType(serialize_when_none=False) - recoverable_days = IntType(serialize_when_none=False) - recovery_level = StringType( - choices=( - "CustomizedRecoverable", - "CustomizedRecoverable+ProtectedSubscription", - "CustomizedRecoverable+Purgeable", - "Purgeable", - "Recoverable", - "Recoverable+ProtectedSubscription", - "Recoverable+Purgeable", - ), - serialize_when_none=False, - ) - updated = DateTimeType(serialize_when_none=False) - - -class KeyItem(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - key_uri = StringType(serialize_when_none=False) - attributes = ModelType(KeyAttributes, serialize_when_none=False) - kid = StringType(serialize_when_none=False) - managed = BooleanType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - - -class SystemData(Model): - created_at = DateTimeType(serialize_when_none=False) - created_by = StringType(serialize_when_none=False) - created_by_type = StringType(serialize_when_none=False) - last_modified_at = DateTimeType(serialize_when_none=False) - last_modified_by = StringType(serialize_when_none=False) - last_modified_by_type = StringType(serialize_when_none=False) - - -class KeyVault(AzureCloudService): # Main class - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - properties = ModelType(VaultProperties, serialize_when_none=False) - keys = ListType(ModelType(KeyItem), serialize_when_none=False) - secrets = ListType(ModelType(SecretItem), serialize_when_none=False) - certificates = ListType(ModelType(CertificateItem), serialize_when_none=False) - key_count = IntType(serialize_when_none=False) - secret_count = IntType(serialize_when_none=False) - certificate_count = IntType(serialize_when_none=False) - total_credentials_count = IntType(serialize_when_none=False) - system_data = ModelType(SystemData, serialize_when_none=False) - type = StringType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - keys_permissions_description_display = StringType(serialize_when_none=False) - secrets_permissions_description_display = StringType(serialize_when_none=False) - certificates_permissions_description_display = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_account.yaml b/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_account.yaml deleted file mode 100644 index 61e406b2..00000000 --- a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: KeyVaults -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_region.yaml b/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_region.yaml deleted file mode 100644 index d11b1a17..00000000 --- a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: KeyVaults -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_subscription.yaml b/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_subscription.yaml deleted file mode 100644 index 13d7fa38..00000000 --- a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: KeyVaults -cloud_service_type: Instance -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_total_count.yaml b/src/spaceone/inventory/model/key_vaults/widget/key_vaults_total_count.yaml deleted file mode 100644 index cc4b214e..00000000 --- a/src/spaceone/inventory/model/key_vaults/widget/key_vaults_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: KeyVaults -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/load_balancers/__init__.py b/src/spaceone/inventory/model/load_balancers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/load_balancers/cloud_service.py b/src/spaceone/inventory/model/load_balancers/cloud_service.py deleted file mode 100644 index 7fd9d5d6..00000000 --- a/src/spaceone/inventory/model/load_balancers/cloud_service.py +++ /dev/null @@ -1,163 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.model.load_balancers.data import LoadBalancer -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta - -''' -LOAD_BALANCER -''' - -# TAB - Default -# Resource Group, Location, Subscription, Subscription ID, SKU, Backend pool, Health probe, -# Load balancing rule, NAT Rules, Public IP Addresses, Load Balancing Type -load_balancer_info_meta = ItemDynamicLayout.set_fields('LoadBalancers', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'account'), - TextDyField.data_source('SKU', 'type'), - TextDyField.data_source('Backend pools', 'data.backend_address_pools_count_display'), - ListDyField.data_source('Health Probe', 'data.probes_display', options={ - 'delimiter': '
' - }), - ListDyField.data_source('Load Balancing Rule', 'data.load_balancing_rules_display', options={ - 'delimiter': '
' - }), - ListDyField.data_source('NAT Rules', 'data.inbound_nat_rules_display', options={ - 'delimiter': '
' - }), - ListDyField.data_source('Private IP Address', 'data.private_ip_address_display', options={ - 'delimiter': '
' - }), -]) - -# TAB - Frontend IP Configurations -# 1) Name, IP Address, Rules Count, Type, Public IP Address -load_balancer_info_frontend_ip_config = SimpleTableDynamicLayout.set_fields('Frontend IP Configurations', - 'data.frontend_ip_configurations', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('IP Address', 'private_ip_address'), - TextDyField.data_source('IP Version', 'private_ip_address_version'), - ]) - - -# 2) Used By -load_balancer_info_frontend_ip_config_rules = ItemDynamicLayout.set_fields('Used By', fields=[ - ListDyField.data_source('Used By', 'data.frontend_ip_configurations_used_by_display', options={ - 'delimiter': '
' - }) -]) - -# 1 + 2) TAB - Frontend IP Configurations Meta -load_balancer_info_frontend_ip_config_meta = ListDynamicLayout.set_layouts('Frontend IP Configurations', - layouts=[ - load_balancer_info_frontend_ip_config, - load_balancer_info_frontend_ip_config_rules]) - -# TAB - Backend Pools -# 3) Backend pool name, Virtual Network, Private IP Address Version -load_balancer_info_backend_pools = SimpleTableDynamicLayout.set_fields('Backend Pools', 'data.backend_address_pools', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('ID', 'id') -]) - -# 4) Virtual machine, Load Balancer, Network interface, private IP address -load_balancer_info_backend_pools_vms = SimpleTableDynamicLayout.set_fields('Backend Pools VM information', - 'data.network_interfaces', fields=[ - TextDyField.data_source('Backend Pool', 'load_balancer_backend_address_pools_name_display'), - TextDyField.data_source('VM Name', 'virtual_machine_name_display'), - TextDyField.data_source('Network Interface', 'name'), - ListDyField.data_source('Private IP Address', 'private_ip_display', options={ - 'delimiter': '
' - }) - ]) - -# 3 + 4) TAB - Backend Pools -load_balancer_info_backend_pools_meta = ListDynamicLayout.set_layouts('Backend Pools', - layouts=[ - load_balancer_info_backend_pools, - load_balancer_info_backend_pools_vms]) -# TAB - Health Probes -# Name, Protocol, Port -load_balancer_info_health_probes = TableDynamicLayout.set_fields('Health Probes', 'data.probes', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Protocol', 'protocol'), - TextDyField.data_source('Port', 'port'), - TextDyField.data_source('Interval', 'interval_in_seconds'), - TextDyField.data_source('Unhealthy Threshold', 'number_of_probes') -]) - -# TAB _ Load Balancing Rules -# LB rules Name, Load balancing rule, Health probe -> skip -load_balancer_info_load_balancing_rules = TableDynamicLayout.set_fields('Load Balancing Rules', - 'data.load_balancing_rules', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Frontend IP Address', 'frontend_ip_configuration_display'), - TextDyField.data_source('Protocol', 'protocol'), - TextDyField.data_source('Frontend Port', 'frontend_port'), - TextDyField.data_source('Backend Port', 'backend_port'), - ListDyField.data_source('Backend Pool', 'backend_address_pool_display'), - TextDyField.data_source('Session Persistence', 'load_distribution_display'), - TextDyField.data_source('Idle Timeout (minutes)', 'idle_timeout_in_minutes'), - TextDyField.data_source('Floating IP', 'enable_floating_ip'), - TextDyField.data_source('TCP Reset', 'enable_tcp_reset'), - - ]) - -# TAB - Inbound NAT Rules -# Forwards incoming traffic sent to a selected IP address and port combination to a specific virtual machine -# NAT rule Name, IP version, destination, target, service -load_balancer_info_inbound_nat_rules = TableDynamicLayout.set_fields('Inbound NAT Rules', 'data.inbound_nat_rules', - fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Protocol', - 'protocol'), - TextDyField.data_source( - 'Idle timeout (minutes)', - 'idle_timeout_in_minutes'), - TextDyField.data_source('TCP Reset', - 'enable_tcp_reset'), - TextDyField.data_source('Port', - 'frontend_port'), - ListDyField.data_source( - 'Target Virtual Machine', 'target_virtual_machine'), # ***** - TextDyField.data_source( - 'Network IP Configuration', - 'frontend_ip_configuration_display'), - TextDyField.data_source('Port mapping', - 'port_mapping_display'), - TextDyField.data_source('Floating IP', - 'enable_floating_ip'), - TextDyField.data_source('Target Port', - 'backend_port') - ]) -# TextDyField.data_source('IP Version', 'frontend_ip_configurations...private_ip_address_version'), -# TextDyField.data_source('Destination', 'private_ip_address'), - -load_balancer_meta = CloudServiceMeta.set_layouts( - [load_balancer_info_meta, load_balancer_info_frontend_ip_config_meta, load_balancer_info_backend_pools_meta, - load_balancer_info_health_probes, load_balancer_info_inbound_nat_rules, load_balancer_info_load_balancing_rules]) - - -class NetworkResource(CloudServiceResource): - cloud_service_group = StringType(default='LoadBalancers') - - -class LoadBalancerResource(NetworkResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(LoadBalancer) - _metadata = ModelType(CloudServiceMeta, default=load_balancer_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class LoadBalancerResponse(CloudServiceResponse): - resource = PolyModelType(LoadBalancerResource) diff --git a/src/spaceone/inventory/model/load_balancers/cloud_service_type.py b/src/spaceone/inventory/model/load_balancers/cloud_service_type.py deleted file mode 100644 index 6c2cba9e..00000000 --- a/src/spaceone/inventory/model/load_balancers/cloud_service_type.py +++ /dev/null @@ -1,210 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) -load_balancers_backendpool_vm_count_by_region_conf = os.path.join(current_dir, 'widget/load_balancers_backendpool_vm_count_by_region.yaml') -load_balancers_count_by_account_conf = os.path.join(current_dir, 'widget/load_balancers_count_by_account.yaml') -load_balancers_count_by_region_conf = os.path.join(current_dir, 'widget/load_balancers_count_by_region.yaml') -load_balancers_count_by_subscription_conf = os.path.join(current_dir, 'widget/load_balancers_count_by_subscription.yaml') -load_balancers_total_count_conf = os.path.join(current_dir, 'widget/load_balancers_total_count.yaml') - -cst_load_balancers = CloudServiceTypeResource() -cst_load_balancers.name = 'Instance' -cst_load_balancers.group = 'LoadBalancers' -cst_load_balancers.service_code = 'Microsoft.Network/loadBalancers' -cst_load_balancers.labels = ['Networking'] -cst_load_balancers.is_major = True -cst_load_balancers.is_primary = True -cst_load_balancers.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-loadbalancers.svg', -} - -cst_load_balancers._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'data.subscription_id', options={ - 'is_optional': True - }), - TextDyField.data_source('SKU', 'instance_type', options={ - 'is_optional': True - }), - ListDyField.data_source('Health Probe', 'data.probes_display', options={ - 'delimiter': '
', - 'is_optional': True - }), - ListDyField.data_source('Load Balancing Rule', 'data.load_balancing_rules_display', options={ - 'delimiter': '
', - 'is_optional': True - }), - ListDyField.data_source('NAT Rules', 'data.inbound_nat_rules_display', options={ - 'delimiter': '
', - 'is_optional': True - }), - ListDyField.data_source('Private IP Address', 'data.private_ip_address_display', options={ - 'delimiter': '
', - 'is_optional': True - }), - # is_optional fields- Frontend IP Configurations - TextDyField.data_source('Frontend Name', 'data.frontend_ip_configurations.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Frontend IP Address', 'data.frontend_ip_configurations.private_ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('Frontend IP Version', 'data.frontend_ip_configurations.private_ip_address_version', options={ - 'is_optional': True - }), - ListDyField.data_source('Frontend IP Used By', 'data.frontend_ip_configurations_used_by_display', options={ - 'delimiter': '
', - 'is_optional': True - }), - # is_optional fields- Backend Pools - TextDyField.data_source('Backend Pool Name', 'data.backend_address_pools.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Backend Pool ID', 'data.backend_address_pools.id', options={ - 'is_optional': True - }), - # is_optional fields - Health Probes - TextDyField.data_source('Health Probe Name', 'data.probes.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Protocol', 'data.probes.protocol', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Port', 'data.probes.port', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Interval', 'data.probes.interval_in_seconds', options={ - 'is_optional': True - }), - TextDyField.data_source('Health Probes Unhealthy Threshold', 'data.probes.number_of_probes', options={ - 'is_optional': True - }), - # is_optional fields - Load Balancing Rules - TextDyField.data_source('LB Rule Name', 'data.load_balancing_rules.name', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule Frontend IP Address', 'data.load_balancing_rules.frontend_ip_configuration_display', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule Protocol', 'data.load_balancing_rules.protocol', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule Frontend Port', 'data.load_balancing_rules.frontend_port', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule Backend Port', 'data.load_balancing_rules.backend_port', options={ - 'is_optional': True - }), - ListDyField.data_source('LB Rule Backend Pool', 'data.load_balancing_rules.backend_address_pool_display', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule Session Persistence', 'data.load_balancing_rules.load_distribution_display', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule Idle Timeout (minutes)', 'data.load_balancing_rules.idle_timeout_in_minutes', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule Floating IP', 'data.load_balancing_rules.enable_floating_ip', options={ - 'is_optional': True - }), - TextDyField.data_source('LB Rule TCP Reset', 'data.load_balancing_rules.enable_tcp_reset', options={ - 'is_optional': True - }), - # is_optional fields - Inbound NAT Rules - TextDyField.data_source('Inbound NAT Rules Name', 'data.inbound_nat_rules.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule Protocol', 'data.inbound_nat_rules.protocol', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule Idle timeout (minutes)', 'data.inbound_nat_rules.idle_timeout_in_minutes', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule TCP Reset', 'data.inbound_nat_rules.enable_tcp_reset', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule Port', 'data.inbound_nat_rules.frontend_port', options={ - 'is_optional': True - }), - ListDyField.data_source('Inbound NAT Rule Target Virtual Machine', 'data.inbound_nat_rules.target_virtual_machine', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule Network IP Configuration', 'data.inbound_nat_rules.frontend_ip_configuration_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule Port mapping', 'data.inbound_nat_rules.port_mapping_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule Floating IP', 'data.inbound_nat_rules.enable_floating_ip', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound NAT Rule Target Port', 'data.inbound_nat_rules.backend_port', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Load Balancer Type', key='instance_type'), - SearchField.set(name='SKU', key='instance_type'), - SearchField.set(name='Health Probe', key='data.probes_display'), - SearchField.set(name='Load Balancing Rule', key='data.load_balancing_rules_display'), - SearchField.set(name='NAT Rules', key='data.inbound_nat_rules_display'), - SearchField.set(name='Private IP Address', key='data.private_ip_address_display'), - SearchField.set(name='Frontend Name', key='data.frontend_ip_configurations.name'), - SearchField.set(name='Frontend IP Address', key='data.frontend_ip_configurations.private_ip_address'), - SearchField.set(name='Frontend IP Version', key='data.frontend_ip_configurations.private_ip_address_version'), - SearchField.set(name='Frontend IP Used By', key='data.frontend_ip_configurations_used_by_display'), - SearchField.set(name='Backend Pool Name', key='data.backend_address_pools.name'), - SearchField.set(name='Backend Pool ID', key='data.backend_address_pools.id'), - SearchField.set(name='Health Probe Name', key='data.probes.name'), - SearchField.set(name='Health Probes Protocol', key='data.probes.protocol'), - SearchField.set(name='Health Probes Port', key='data.probes.port', data_type='integer'), - SearchField.set(name='Health Probes Interval', key='data.probes.interval_in_seconds', data_type='integer'), - SearchField.set(name='Health Probes Unhealthy Threshold', key='data.probes.number_of_probes'), - SearchField.set(name='LB Rule Name', key='data.load_balancing_rules.name'), - SearchField.set(name='LB Rule Frontend IP Address', key='data.load_balancing_rules.frontend_ip_configuration_display'), - SearchField.set(name='LB Rule Protocol', key='data.load_balancing_rules.protocol'), - SearchField.set(name='LB Rule Frontend Port', key='data.load_balancing_rules.frontend_port', data_type='integer'), - SearchField.set(name='LB Rule Backend Port', key='data.load_balancing_rules.backend_port', data_type='integer'), - SearchField.set(name='LB Rule Backend Pool', key='data.load_balancing_rules.backend_address_pool_display'), - SearchField.set(name='LB Rule Session Persistence', key='data.load_balancing_rules.load_distribution_display'), - SearchField.set(name='LB Rule Idle Timeout (minutes)', key='data.load_balancing_rules.idle_timeout_in_minutes', data_type='integer'), - SearchField.set(name='LB Rule Floating IP', key='data.load_balancing_rules.enable_floating_ip'), - SearchField.set(name='LB Rule TCP Reset', key='data.load_balancing_rules.enable_tcp_reset'), - SearchField.set(name='Inbound NAT Rules Name', key='data.inbound_nat_rules.name'), - SearchField.set(name='Inbound NAT Rule Protocol', key='data.inbound_nat_rules.protocol'), - SearchField.set(name='Inbound NAT Rule Idle timeout (minutes)', key='data.inbound_nat_rules.idle_timeout_in_minutes', data_type='integer'), - SearchField.set(name='Inbound NAT Rule TCP Reset', key='data.load_balancing_rules.enable_tcp_reset'), - SearchField.set(name='Inbound NAT Rule Port', key='data.inbound_nat_rules.frontend_port', data_type='integer'), - SearchField.set(name='Inbound NAT Rule Target Virtual Machine', key='data.inbound_nat_rules.target_virtual_machine'), - SearchField.set(name='Inbound NAT Rule Network IP Configuration', key='data.inbound_nat_rules.frontend_ip_configuration_display'), - SearchField.set(name='Inbound NAT Rule Port mapping', key='data.inbound_nat_rules.port_mapping_display'), - SearchField.set(name='Inbound NAT Rule Floating IP', key='data.inbound_nat_rules.enable_floating_ip'), - SearchField.set(name='Inbound NAT Rule Target Port', key='data.inbound_nat_rules.backend_port', data_type='integer'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(load_balancers_backendpool_vm_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(load_balancers_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(load_balancers_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(load_balancers_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(load_balancers_total_count_conf)), - ] -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_load_balancers}), -] diff --git a/src/spaceone/inventory/model/load_balancers/data.py b/src/spaceone/inventory/model/load_balancers/data.py deleted file mode 100644 index 1b2aa6e1..00000000 --- a/src/spaceone/inventory/model/load_balancers/data.py +++ /dev/null @@ -1,653 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType -from spaceone.inventory.libs.schema.resource import AzureCloudService - -class Tags(Model): - key = StringType() - value = StringType() - - -class SubResource(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - - -class DdosSettings(Model): - ddos_custom_policy = ModelType(SubResource, serialize_when_none=False) - protected_ip = BooleanType(serialize_when_none=False) - protection_coverage = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - - -class ExtendedLocationTypes(Model): - edge_zone = StringType(serialize_when_none=False) - - -class ExtendedLocation(Model): - name = StringType(serialize_when_none=False) - type = ModelType(ExtendedLocationTypes, serialize_when_none=False) - - -class TrafficAnalyticsConfigurationProperties(Model): - enabled = BooleanType(serialize_when_none=False) - traffic_analytics_interval = IntType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - workspace_region = StringType(serialize_when_none=False) - workspace_resource_id = StringType(serialize_when_none=False) - - -class NetworkInterfaceDnsSettings(Model): - applied_dns_servers = ListType(StringType, serialize_when_none=False) - dns_servers = ListType(StringType, serialize_when_none=False) - internal_dns_name_label= StringType(serialize_when_none=False) - internal_domain_name_suffix = StringType(serialize_when_none=False) - internal_fqdn = StringType(serialize_when_none=False) - - -class PublicIPAddressDnsSettings(Model): - domain_name_label = StringType(serialize_when_none=False) - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class PublicIPAddressSku(Model): - name = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - tier = StringType(choices=('Global', 'Regional'), serialize_when_none=False) - - -class IpTag(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class TrafficAnalyticsProperties(Model): - network_watcher_flow_analytics_configuration = ModelType(TrafficAnalyticsConfigurationProperties, serialize_when_none=False) - - -class FlowLogFormatType(Model): - json = StringType(serialize_when_none=False) - - -class FlowLogFormatParameters(Model): - type = ModelType(FlowLogFormatType, serialize_when_none=False) - version = IntType(serialize_when_none=False) - - -class RetentionPolicyParameters(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class FlowLog(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - enable = BooleanType(serialize_when_none=False) - flow_analytics_configuration = ModelType(TrafficAnalyticsProperties, serialize_when_none=False) - format = ModelType(FlowLogFormatParameters, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - retention_policy = ModelType(RetentionPolicyParameters, serialize_when_none=False) - storage_id = StringType(serialize_when_none=False) - target_resource_guid = StringType(serialize_when_none=False) - target_resource_id = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceTapConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class CustomDnsConfigPropertiesFormat(Model): - fqdn = StringType(serialize_when_none=False) - ip_addresses = ListType(StringType, serialize_when_none=False) - - -class NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties(Model): # belongs to NetworkInterfaceIPConfiguration - fqdns = ListType(StringType, serialize_when_none=False) - group_id = StringType(serialize_when_none=False) - required_member_name = StringType(serialize_when_none=False) - - -class ApplicationSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class IPConfigurationProfileRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = ListType(StringType(), default=[], serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnectionState(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - - -class ServiceAssociationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allow_delete = BooleanType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - locations = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPolicyDefinition(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service = StringType(serialize_when_none=False) - service_resources = ListType(StringType) - - -class PrivateLinkServiceConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - group_ids = ListType(StringType, serialize_when_none=False) - private_link_service_connection_state = ModelType(PrivateLinkServiceConnectionState, serialize_when_none=False) - private_link_service_id = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - request_message = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class SecurityRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - access = StringType(choices=('Allow', 'Deny'), serialize_when_none=False) - description = StringType(serialize_when_none=False) - destination_address_prefix = StringType(serialize_when_none=False) - destination_address_prefixes = ListType(StringType, serialize_when_none=False) - destination_application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - destination_port_range = StringType(serialize_when_none=False) - destination_port_ranges = ListType(StringType, serialize_when_none=False) - direction = StringType(choices=('Inbound', 'Outbound'), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - protocol = StringType(choices=('*', 'Ah', 'Esp', 'Icmp', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - source_address_prefix = StringType(serialize_when_none=False) - source_address_prefixes = ListType(StringType, serialize_when_none=False) - source_application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - source_port_range = StringType(serialize_when_none=False) - source_port_ranges = ListType(StringType, serialize_when_none=False) - - -class IPConfigurationRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = ListType(StringType(), default=[], serialize_when_none=False) - - -class Delegation(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - actions = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service_name = StringType(serialize_when_none=False) - - -class ResourceNavigationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Route(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - next_hop_ip_address = StringType(serialize_when_none=False) - next_hop_type = StringType(choices=('Internet', 'None', 'VirtualAppliance', 'VirtualNetworkGateway', 'VnetLocal'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - - -class RouteTable(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - disable_bgp_route_propagation = BooleanType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - routes = ListType(ModelType(Route), serialize_when_none=False) - subnets = ListType(StringType, default=[], serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPolicy(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - service_endpoint_policy_definitions = ListType(ModelType(ServiceEndpointPolicyDefinition), serialize_when_none=False) - subnets = ListType(StringType, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPropertiesFormat(Model): - locations = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service = StringType(serialize_when_none=False) - - -class NetworkSecurityGroupRef(Model): - id = StringType() - name = StringType() - - -class PrivateEndpointRef(Model): - id = StringType() - name = StringType() - - -class IPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - - -class PublicIPAddress(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettings, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = ModelType(IPConfiguration, serialize_when_none=False) - ip_tags = ListType(ModelType(IpTag), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class Subnet(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - address_prefixes = ListType(StringType, serialize_when_none=False) - ip_allocations = ListType(ModelType(SubResource, serialize_when_none=False)) - nat_gateway = ModelType(SubResource, serialize_when_none=False) - private_endpoint_network_policies = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - purpose = StringType(serialize_when_none=False) - delegations = ListType(ModelType(Delegation), serialize_when_none=False) - ip_configuration_profiles = ListType(ModelType(IPConfigurationProfileRef), serialize_when_none=False) - ip_configurations = ListType(ModelType(IPConfigurationRef), serialize_when_none=False) - network_security_group = ModelType(NetworkSecurityGroupRef, serialize_when_none=False) - private_endpoints = ListType(ModelType(PrivateEndpointRef), serialize_when_none=False) - private_link_service_network_policies = StringType(serialize_when_none=False) - resource_navigation_links = ListType(ModelType(ResourceNavigationLink, serialize_when_none=False)) - route_table = ModelType(RouteTable, serialize_when_none=False) - service_association_links = ListType(ModelType(ServiceAssociationLink), serialize_when_none=False) - service_endpoint_policies = ListType(ModelType(ServiceEndpointPolicy), serialize_when_none=False) - service_endpoints = ListType(ModelType(ServiceEndpointPropertiesFormat), serialize_when_none=False) - - -class PrivateEndpoint(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType(ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False) - manual_private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), - serialize_when_none=False) - network_interfaces = ListType(ModelType(SubResource), serialize_when_none=False) # 아래에 있음 - private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = ModelType(Subnet, serialize_when_none=False) # 아래에 있음 - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfiguration(Model): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - private_link_connection_properties = ModelType(NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - subnet = ModelType(Subnet, serialize_when_none=False) - virtual_network_taps = ListType(ModelType(SubResource), serialize_when_none=False) - - -class NetworkInterface(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - dns_settings = ModelType(NetworkInterfaceDnsSettings, serialize_when_none=False) - dscp_configuration = ModelType(SubResource, serialize_when_none=False) - enable_accelerated_networking = BooleanType(serialize_when_none=False) - enable_ip_forwarding = BooleanType(serialize_when_none=False) - hosted_workloads = ListType(StringType, serialize_when_none=False) - ip_configurations = ListType(ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False) # 아래에 있음 - mac_address = StringType(serialize_when_none=False) - network_security_group = ModelType(SubResource) - load_balancer_backend_address_pools_name_display = StringType(serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpoint, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tap_configurations = ListType(ModelType(NetworkInterfaceTapConfiguration), serialize_when_none=False) - virtual_machine = ModelType(SubResource, serialize_when_none=False) - virtual_machine_name_display = StringType(serialize_when_none=False, default='-') - private_ip_display = ListType(StringType, default=[], serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -# class NetworkSecurityGroupRef(Model): -# etag = StringType(serialize_when_none=False) -# id = StringType(serialize_when_none=False) -# location = StringType(serialize_when_none=False) -# name = StringType(serialize_when_none=False) -# default_security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) -# flow_logs = ListType(ModelType(FlowLog), serialize_when_none=False) -# network_interfaces = ListType(ModelType(NetworkInterface), serialize_when_none=False) -# provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) -# resource_guid = StringType(serialize_when_none=False) -# security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) -# subnet = ListType(StringType(), default=[], serialize_when_none=False) -# tags = ModelType(Tags, serialize_when_none=False) -# type = StringType(serialize_when_none=False) - - -# class PrivateEndpointRef(Model): -# etag = StringType(serialize_when_none=False) -# id = StringType(serialize_when_none=False) -# location = StringType(serialize_when_none=False) -# name = StringType(serialize_when_none=False) -# custom_dns_configs = ListType(ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False) -# manual_private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), serialize_when_none=False) -# network_interfaces = ListType(ModelType(NetworkInterface), serialize_when_none=False) # 아래에 있음 -# private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), serialize_when_none=False) -# provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) -# subnet = ListType(StringType(), default=[], serialize_when_none=False) -# tags = ModelType(Tags, serialize_when_none=False) -# type = StringType(serialize_when_none=False) - - -class IPConfigurationProfile(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = ModelType(Subnet, serialize_when_none=False) # 아래에 있음.. 흠 - type = StringType(serialize_when_none=False) - - -class ApplicationGatewayBackendAddress(Model): - fqdn = StringType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - - -class InboundNatPool(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_port_range_end = IntType(serialize_when_none=False) - frontend_port_range_start = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - -################################################################################ -################################################################################ - - -class InboundNatRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_ip_configurations = ListType(ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False) - target_virtual_machine = ListType(StringType, serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - port_mapping_display = StringType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class LoadBalancingRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - backend_address_pool_display = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - disable_outbound_s_nat = BooleanType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - load_distribution = StringType(choices=('Default', 'SourceIP', 'SourceIPProtocol'), serialize_when_none=False) - load_distribution_display = StringType(serialize_when_none=False) - probe = ModelType(SubResource, serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class OutboundRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allocated_outbound_ports = IntType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configurations = ListType(ModelType(SubResource), serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Probe(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - interval_in_seconds = IntType(serialize_when_none=False) - load_balancing_rules = ListType(ModelType(SubResource), serialize_when_none=False) - number_of_probes = IntType(serialize_when_none=False) - port = IntType(serialize_when_none=False) - protocol = StringType(choices=('Http', 'Tcp', 'Https'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - request_path = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - default_security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - flow_logs = ListType(ModelType(FlowLog), serialize_when_none=False) - network_interfaces = ListType(ModelType(NetworkInterface), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - subnets = ListType(ModelType(Subnet), serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class FrontendIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - inbound_nat_pools = ListType(ModelType(InboundNatPool), serialize_when_none=False) - inbound_nat_rules = ListType(ModelType(InboundNatRule), serialize_when_none=False) - load_balancing_rules = ListType(ModelType(LoadBalancingRule), serialize_when_none=False) - outbound_rules = ListType(ModelType(OutboundRule), serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) # 아래에 있음..힝 - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - subnet = ModelType(Subnet, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class VirtualNetworkTap(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - destination_load_balancer_front_end_ip_configuration = ModelType(FrontendIPConfiguration, - serialize_when_none=False) - destination_network_interface_ip_configuration = ModelType(NetworkInterfaceIPConfiguration, - serialize_when_none=False) - destination_port = IntType(serialize_when_none=False) - network_interface_tap_configurations = ListType(ModelType(NetworkInterfaceTapConfiguration)) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), - serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class LoadBalancerBackendAddress(Model): - name = StringType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - load_balancer_frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - network_interface_ip_configuration = ModelType(SubResource, serialize_when_none=False) - virtual_network = ModelType(SubResource, serialize_when_none=False) - - -class BackendAddressPoolRef(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - etag = StringType(serialize_when_none=False) - - -class ApplicationGatewayBackendAddressPool(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_addresses = ListType(ModelType(ApplicationGatewayBackendAddress), serialize_when_none=False) - backend_ip_configurations = ListType(ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class BackendAddressPool(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_ip_configurations = ListType(ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False) - load_balancer_backend_addresses = ListType(ModelType(LoadBalancerBackendAddress), serialize_when_none=False) - load_balancing_rules = ListType(ModelType(SubResource), serialize_when_none=False) - outbound_rule = ModelType(SubResource, serialize_when_none=False) - outbound_rules = ListType(ModelType(SubResource), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - vm_ids = ListType(StringType, serialize_when_none=False) - - -class LoadBalancerSku(Model): - tier = StringType(choices=('Global', 'Regional'), serialize_when_none=False) - name = StringType(choices=('Standard', 'Basic'), serialize_when_none=False) - - -class LoadBalancer(AzureCloudService): - name = StringType() - id = StringType() - location = StringType() - sku = ModelType(LoadBalancerSku, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - backend_address_pools = ListType(ModelType(BackendAddressPool), serialize_when_none=False) - backend_address_pools_count_display = StringType(serialize_when_none=False, default='') - network_interfaces = ListType(ModelType(NetworkInterface), serialize_when_none=False) - frontend_ip_configurations = ListType(ModelType(FrontendIPConfiguration), serialize_when_none=False) - frontend_ip_configurations_used_by_display = ListType(StringType, serialize_when_none=False) - private_ip_address_display = ListType(StringType, serialize_when_none=False) - inbound_nat_pools = ListType(ModelType(InboundNatPool), serialize_when_none=False) - inbound_nat_rules = ListType(ModelType(InboundNatRule), serialize_when_none=False) - inbound_nat_rules_display = ListType(StringType, serialize_when_none=False) - load_balancing_rules = ListType(ModelType(LoadBalancingRule), serialize_when_none=False) - load_balancing_rules_display = ListType(StringType, serialize_when_none=False) - outbound_rules = ListType(ModelType(OutboundRule), serialize_when_none=False) - probes = ListType(ModelType(Probe), serialize_when_none=False) - probes_display = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } \ No newline at end of file diff --git a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_backendpool_vm_count_by_region.yaml b/src/spaceone/inventory/model/load_balancers/widget/load_balancers_backendpool_vm_count_by_region.yaml deleted file mode 100644 index 55dfc5d4..00000000 --- a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_backendpool_vm_count_by_region.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: LoadBalancers -cloud_service_type: Instance -name: Backend Pool VM Count by Region -query: - aggregate: - - unwind: - path: data.network_interfaces - - group: - keys: - - name: name - key: data.network_interfaces.location - fields: - - name: value - key: data.network_interfaces.location - operator: count -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_account.yaml b/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_account.yaml deleted file mode 100644 index dda270eb..00000000 --- a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: LoadBalancers -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_region.yaml b/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_region.yaml deleted file mode 100644 index 2b250668..00000000 --- a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: LoadBalancers -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_subscription.yaml b/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_subscription.yaml deleted file mode 100644 index f382b446..00000000 --- a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: LoadBalancers -cloud_service_type: Instance -name: Total Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_total_count.yaml b/src/spaceone/inventory/model/load_balancers/widget/load_balancers_total_count.yaml deleted file mode 100644 index 7d2cce27..00000000 --- a/src/spaceone/inventory/model/load_balancers/widget/load_balancers_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: LoadBalancers -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/mysql_servers/__init__.py b/src/spaceone/inventory/model/mysql_servers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/mysql_servers/cloud_service.py b/src/spaceone/inventory/model/mysql_servers/cloud_service.py deleted file mode 100644 index 62081355..00000000 --- a/src/spaceone/inventory/model/mysql_servers/cloud_service.py +++ /dev/null @@ -1,93 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField, SizeField, StateItemDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.mysql_servers.data import MySQLServer -''' -MYSQL SERVERS -''' - -# TAB - Default -mysql_servers_info_meta = ItemDynamicLayout.set_fields('MySQL Server', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Server Name', 'data.fully_qualified_domain_name'), - TextDyField.data_source('Type', 'instance_type'), - EnumDyField.data_source('Status', 'data.user_visible_state', default_state={ - 'safe': ['Ready'], - 'warning': ['Dropping'], - 'disable': ['Disabled', 'Inaccessible'] - }), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Server Admin Login Name', 'data.administrator_login'), - TextDyField.data_source('MySQL Version', 'data.version'), - TextDyField.data_source('Performance Configuration (Tier)', 'data.sku.tier'), - TextDyField.data_source('Performance Configuration (Name)', 'data.sku.name'), - TextDyField.data_source('SSL Enforce Status', 'data.ssl_enforcement'), -]) - - -# TAB - Connection Security -mysql_servers_firewall_rules = TableDynamicLayout.set_fields('Firewall Rules', 'data.firewall_rules', fields=[ - TextDyField.data_source('Firewall Rule Name', 'name'), - TextDyField.data_source('Start IP', 'start_ip_address'), - TextDyField.data_source('End IP', 'end_ip_address') -]) -mysql_servers_ssl_tls = ItemDynamicLayout.set_fields('MySQL Server', fields=[ - TextDyField.data_source('Allow Access To Azure Services', 'data.allow_azure_services_access'), - TextDyField.data_source('Enforce SSL Connection', 'data.ssl_enforcement'), - TextDyField.data_source('Minimum TLS Version', 'data.minimal_tls_version') -]) -# 1 + 2) TAB - Connection Security Meta -mysql_servers_connection_security = ListDynamicLayout.set_layouts('Connection Security', layouts=[ - mysql_servers_firewall_rules, - mysql_servers_ssl_tls]) - - -mysql_servers_parameters = TableDynamicLayout.set_fields('MySQL Parameters', fields=[ - TextDyField.data_source('Allow Access To Azure Services', 'data.allow_azure_services_access'), - TextDyField.data_source('Enforce SSL Connection', 'data.ssl_enforcement'), - TextDyField.data_source('Minimum TLS Version', 'data.minimal_tls_version') -]) - -mysql_servers_pricing_tiers = ItemDynamicLayout.set_fields('Pricing Tier', fields=[ - TextDyField.data_source('Tier', 'data.sku.tier'), - TextDyField.data_source('Compute Generation', 'data.sku.family'), - TextDyField.data_source('vCore', 'data.sku.capacity'), - TextDyField.data_source('Storage', 'data.storage_profile.storage_gb'), - EnumDyField.data_source('Storage Auto-Growth', 'data.storage_profile.storage_autogrow', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - EnumDyField.data_source('Geo Redundant Backup', 'data.storage_profile.geo_redundant_backup', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - TextDyField.data_source('Backup Retention Period', 'data.storage_profile.backup_retention_days'), -]) - -mysql_servers_meta = CloudServiceMeta.set_layouts( - [mysql_servers_info_meta, mysql_servers_connection_security, mysql_servers_parameters, mysql_servers_pricing_tiers]) - - -class DatabaseResource(CloudServiceResource): - cloud_service_group = StringType(default='MySQLServers') - - -class MySQLServerResource(DatabaseResource): - cloud_service_type = StringType(default='Server') - data = ModelType(MySQLServer) - _metadata = ModelType(CloudServiceMeta, default=mysql_servers_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class MySQLServerResponse(CloudServiceResponse): - resource = PolyModelType(MySQLServerResource) diff --git a/src/spaceone/inventory/model/mysql_servers/cloud_service_type.py b/src/spaceone/inventory/model/mysql_servers/cloud_service_type.py deleted file mode 100644 index d25bcc8d..00000000 --- a/src/spaceone/inventory/model/mysql_servers/cloud_service_type.py +++ /dev/null @@ -1,123 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -mysql_servers_count_by_account_conf = os.path.join(current_dir, 'widget/mysql_servers_count_by_account.yaml') -mysql_servers_count_by_region_conf = os.path.join(current_dir, 'widget/mysql_servers_count_by_region.yaml') -mysql_servers_count_by_subscription_conf = os.path.join(current_dir, 'widget/mysql_servers_count_by_subscription.yaml') -mysql_servers_count_by_tier_conf = os.path.join(current_dir, 'widget/mysql_servers_count_by_tier.yaml') -mysql_servers_total_count_conf = os.path.join(current_dir, 'widget/mysql_servers_total_count.yaml') - - -cst_mysql_servers = CloudServiceTypeResource() -cst_mysql_servers.name = 'Server' -cst_mysql_servers.group = 'MySQLServers' -cst_mysql_servers.service_code = 'Microsoft.DBforMySQL/servers' -cst_mysql_servers.labels = ['Database'] -cst_mysql_servers.is_major = True -cst_mysql_servers.is_primary = True -cst_mysql_servers.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-mysql-servers.svg', -} - -cst_mysql_servers._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Type', 'instance_type'), - EnumDyField.data_source('Status', 'data.user_visible_state', default_state={ - 'safe': ['Ready'], - 'warning': ['Dropping'], - 'disable': ['Disabled', 'Inaccessible'] - }), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Server Admin Login Name', 'data.administrator_login', options={ - 'is_optional': True - }), - TextDyField.data_source('MySQL Version', 'data.version', options={ - 'is_optional': True - }), - TextDyField.data_source('Performance Configuration (Tier)', 'instance_type', options={ - 'is_optional': True - }), - TextDyField.data_source('Performance Configuration (Name)', 'data.sku.name', options={ - 'is_optional': True - }), - TextDyField.data_source('SSL Enforce Status', 'data.ssl_enforcement', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall Rule Name', 'data.firewall_rules.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall Rule Start IP', 'data.firewall_rules.start_ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall Rule End IP', 'data.firewall_rules.end_ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('Allow Access To Azure Services', 'data.allow_azure_services_access', options={ - 'is_optional': True - }), - TextDyField.data_source('Enforce SSL Connection', 'data.ssl_enforcement', options={ - 'is_optional': True - }), - TextDyField.data_source('Minimum TLS Version', 'data.minimal_tls_version', options={ - 'is_optional': True - }), - TextDyField.data_source('Compute Generation', 'data.sku.family', options={ - 'is_optional': True - }), - TextDyField.data_source('vCore', 'data.sku.capacity', options={ - 'is_optional': True - }), - TextDyField.data_source('Storage', 'data.storage_profile.storage_gb', options={ - 'is_optional': True - }), - TextDyField.data_source('Backup Retention Period', 'data.storage_profile.backup_retention_days', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Type', key='instance_type'), - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Server Admin Login Name', key='data.administrator_login'), - SearchField.set(name='MySQL Version', key='data.version'), - SearchField.set(name='Performance Configuration (Tier)', key='instance_type'), - SearchField.set(name='Performance Configuration (Name)', key='data.sku.name'), - SearchField.set(name='SSL Enforce Status', key='data.ssl_enforcement'), - SearchField.set(name='Firewall Rule Name', key='data.firewall_rules.name'), - SearchField.set(name='Firewall Rule Start IP', key='data.firewall_rules.start_ip_address'), - SearchField.set(name='Firewall Rule End IP', key='data.firewall_rules.end_ip_address'), - SearchField.set(name='Allow Access To Azure Services', key='data.allow_azure_services_access'), - SearchField.set(name='Enforce SSL Connection', key='data.ssl_enforcement'), - SearchField.set(name='Minimum TLS Version', key='data.minimal_tls_version'), - SearchField.set(name='Compute Generation', key='data.sku.family'), - SearchField.set(name='vCore', key='data.sku.capacity', data_type='integer'), - SearchField.set(name='Storage', key='data.storage_profile.storage_gb', data_type='integer'), - SearchField.set(name='Backup Retention Period', key='data.storage_profile.backup_retention_days'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(mysql_servers_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(mysql_servers_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(mysql_servers_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(mysql_servers_count_by_tier_conf)), - CardWidget.set(**get_data_from_yaml(mysql_servers_total_count_conf)), - - ] -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_mysql_servers}), -] diff --git a/src/spaceone/inventory/model/mysql_servers/data.py b/src/spaceone/inventory/model/mysql_servers/data.py deleted file mode 100644 index 96170eb0..00000000 --- a/src/spaceone/inventory/model/mysql_servers/data.py +++ /dev/null @@ -1,95 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, DateTimeType, BooleanType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Tags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class SubResource(Model): - id = StringType() - - -class ResourceIdentity(Model): - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateEndpointProperty(Model): - id = StringType(serialize_when_none=False) - - -class ServerPrivateLinkServiceConnectionStateProperty(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(choices=('Approved', 'Disconnected', 'Pending', 'Rejected'), serialize_when_none=False) - - -class ServerPrivateEndpointConnectionProperties(Model): - private_endpoint = ModelType(PrivateEndpointProperty, serialize_when_none=False) - private_link_service_connection_state = ModelType(ServerPrivateLinkServiceConnectionStateProperty, serialize_when_none=False) - provisioning_state = StringType(choices=('Approving', 'Dropping', 'Failed', 'Ready', 'Rejecting'), serialize_when_none=False) - - -class ServerPrivateEndpointConnection(Model): - id = StringType(serialize_when_none=False) - properties = ModelType(ServerPrivateEndpointConnectionProperties, serialize_when_none=False) - - -class StorageProfile(Model): - backup_retention_days = IntType(serialize_when_none=False) - geo_redundant_backup = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_autogrow = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_mb = IntType(serialize_when_none=False) - storage_gb = IntType(serialize_when_none=False) - - -class Sku(Model): - capacity = IntType(serialize_when_none=False) - family = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - size = StringType(serialize_when_none=False) - tier = StringType(choices=('Basic', 'GeneralPurpose', 'MemoryOptimized'), serialize_when_none=False) - - -class FirewallRule(Model): - id = StringType() - name = StringType(serialize_when_none=False) - end_ip_address = StringType(serialize_when_none=False) - start_ip_address = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class MySQLServer(AzureCloudService): # Main class - id = StringType() - identity = ModelType(ResourceIdentity, serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - administrator_login = StringType(serialize_when_none=False) - byok_enforcement = StringType(serialize_when_none=False) - earliest_restore_date = DateTimeType(serialize_when_none=False) - firewall_rules = ListType(ModelType(FirewallRule), serialize_when_none=False) - allow_azure_services_access = BooleanType(default=True, serialize_when_none=False) - fully_qualified_domain_name = StringType(serialize_when_none=False) - infrastructure_encryption = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - master_server_id = StringType(serialize_when_none=False) - minimal_tls_version = StringType(choices=('TLS1_0', 'TLS1_1', 'TLS1_2', 'TLSEnforcementDisabled'), serialize_when_none=False) - private_endpoint_connections = ListType(ModelType(ServerPrivateEndpointConnection), serialize_when_none=False) - public_network_access = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - replica_capacity = IntType(serialize_when_none=False) - replication_role = StringType(serialize_when_none=False) - ssl_enforcement = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_profile = ModelType(StorageProfile, serialize_when_none=False) - user_visible_state = StringType(choices=('Disabled', 'Dropping', 'Inaccessible', 'Ready'), serialize_when_none=False) - version = StringType(serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_account.yaml b/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_account.yaml deleted file mode 100644 index e90ea2c3..00000000 --- a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: MySQLServers -cloud_service_type: Server -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_region.yaml b/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_region.yaml deleted file mode 100644 index a0fd3377..00000000 --- a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: MySQLServers -cloud_service_type: Server -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_ code \ No newline at end of file diff --git a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_subscription.yaml b/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_subscription.yaml deleted file mode 100644 index c79735c3..00000000 --- a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: MySQLServers -cloud_service_type: Server -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_tier.yaml b/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_tier.yaml deleted file mode 100644 index 93933777..00000000 --- a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_count_by_tier.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: MySQLServers -cloud_service_type: Server -name: Count by Tier -query: - aggregate: - - group: - keys: - - name: name - key: data.sku.tier - fields: - - name: value - key: data.sku.tier - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_total_count.yaml b/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_total_count.yaml deleted file mode 100644 index e86e704e..00000000 --- a/src/spaceone/inventory/model/mysql_servers/widget/mysql_servers_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: MySQLServers -cloud_service_type: Server -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/nat_gateways/__init__.py b/src/spaceone/inventory/model/nat_gateways/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/nat_gateways/cloud_service.py b/src/spaceone/inventory/model/nat_gateways/cloud_service.py deleted file mode 100644 index b0c2b03d..00000000 --- a/src/spaceone/inventory/model/nat_gateways/cloud_service.py +++ /dev/null @@ -1,75 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField, SizeField, StateItemDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.nat_gateways.data import NatGateway - -''' -NAT GATEWAY -''' -# TAB - Default -nat_gateway_info_meta = ItemDynamicLayout.set_fields('NAT Gateway', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Subnets', 'data.subnets_count'), - TextDyField.data_source('Public IP Addresses', 'data.public_ip_addresses_count'), - TextDyField.data_source('Public IP Prefixes', 'data.public_ip_prefixes_count'), - TextDyField.data_source('Idle Timeout (minutes)', 'data.idle_timeout_in_minutes'), -]) - -# TAB - Outbound IP -nat_gateway_outbound_ip_public_ip_addresses = SimpleTableDynamicLayout.set_fields('Public IP Addresses', 'data.public_ip_addresses', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('IP Address', 'ip_address'), - TextDyField.data_source('DNS Name', 'dns_settings.domain_name_label') -]) - -nat_gateway_outbound_ip_public_ip_prefixes = SimpleTableDynamicLayout.set_fields('Public IP Prefixes', 'data.public_ip_prefixes', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('IP Prefix', 'ip_prefix') -]) -nat_gateway_outbound_ip_info = ListDynamicLayout.set_layouts('Outbound IP', layouts=[nat_gateway_outbound_ip_public_ip_addresses, nat_gateway_outbound_ip_public_ip_prefixes]) - -nat_gateway_subnets = SimpleTableDynamicLayout.set_fields('Subnets', 'data.subnets', fields=[ - TextDyField.data_source('Subnet Name', 'name'), - TextDyField.data_source('Subnet Address ', 'address_prefix'), - TextDyField.data_source('Subnet Addresses', 'address_prefixes'), - TextDyField.data_source('Virtual Network', 'virtual_network'), - EnumDyField.data_source('Private Endpoint Network Policies', 'private_endpoint_network_policies', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - EnumDyField.data_source('Private Link Service Network Policies', 'private_link_service_network_policies', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }) -]) - -nat_gateway_meta = CloudServiceMeta.set_layouts( - [nat_gateway_info_meta, nat_gateway_outbound_ip_info, nat_gateway_subnets]) - - -class NetworkResource(CloudServiceResource): - cloud_service_group = StringType(default='NATGateways') - - -class NatGatewayResource(NetworkResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(NatGateway) - _metadata = ModelType(CloudServiceMeta, default=nat_gateway_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class NatGatewayResponse(CloudServiceResponse): - resource = PolyModelType(NatGatewayResource) diff --git a/src/spaceone/inventory/model/nat_gateways/cloud_service_type.py b/src/spaceone/inventory/model/nat_gateways/cloud_service_type.py deleted file mode 100644 index 7a11f290..00000000 --- a/src/spaceone/inventory/model/nat_gateways/cloud_service_type.py +++ /dev/null @@ -1,91 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -nat_gateways_count_by_account_conf = os.path.join(current_dir, 'widget/nat_gateways_count_by_account.yaml') -nat_gateways_count_by_region_conf = os.path.join(current_dir, 'widget/nat_gateways_count_by_region.yaml') -nat_gateways_count_by_subscription_conf = os.path.join(current_dir, 'widget/nat_gateways_count_by_subscription.yaml') -nat_gateways_total_count_conf = os.path.join(current_dir, 'widget/nat_gateways_total_count.yaml') - -cst_nat_gateways = CloudServiceTypeResource() -cst_nat_gateways.name = 'Instance' -cst_nat_gateways.group = 'NATGateways' -cst_nat_gateways.service_code = 'Microsoft.Network/natGateways' -cst_nat_gateways.labels = ['Networking'] -cst_nat_gateways.is_major = True -cst_nat_gateways.is_primary = True -cst_nat_gateways.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-nat.svg', -} - -cst_nat_gateways._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Subnets (count)', 'data.subnets_count'), - TextDyField.data_source('Public IP Addresses (count)', 'data.public_ip_prefixes_count'), - TextDyField.data_source('Public IP Prefixes (count)', 'data.public_ip_prefixes_count'), - # is_optional fields - Public IP Addresses - TextDyField.data_source('Public IP Name', 'data.public_ip_addresses.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Public IP Address', 'data.public_ip_addresses.ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('Public DNS Name', 'data.public_ip_addresses.dns_settings.domain_name_label', options={ - 'is_optional': True - }), - # is_optional fields - Public IP Prefixes - TextDyField.data_source('Public IP Prefix Name', 'data.public_ip_prefixes.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Public IP Prefix', 'data.public_ip_prefixes.ip_prefix', options={ - 'is_optional': True - }), - # is_optional fields - Subnets - TextDyField.data_source('Subnet Name', 'data.subnets.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Subnet Addresses', 'data.subnets.address_prefixes', options={ - 'is_optional': True - }), - TextDyField.data_source('Virtual Network', 'data.subnets.virtual_network', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Public IP Name', key='data.public_ip_addresses.name'), - SearchField.set(name='Public IP Address', key='data.public_ip_addresses.ip_address'), - SearchField.set(name='Public DNS Name', key='data.public_ip_addresses.dns_settings.domain_name_label'), - SearchField.set(name='Public IP Prefix Name', key='data.public_ip_prefixes.name'), - SearchField.set(name='Public IP Prefix', key='data.public_ip_prefixes.ip_prefix'), - SearchField.set(name='Subnet Name', key='data.subnets.name'), - SearchField.set(name='Subnet Addresses', key='data.subnets.address_prefixes'), - SearchField.set(name='Virtual Network', key='data.subnets.virtual_network') - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(nat_gateways_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(nat_gateways_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(nat_gateways_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(nat_gateways_total_count_conf)) - ] - -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_nat_gateways}), -] diff --git a/src/spaceone/inventory/model/nat_gateways/data.py b/src/spaceone/inventory/model/nat_gateways/data.py deleted file mode 100644 index 8cb55dcd..00000000 --- a/src/spaceone/inventory/model/nat_gateways/data.py +++ /dev/null @@ -1,1193 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Tags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class SubResource(Model): - id = StringType() - - -""" -START OF REF CLASSES -""" - - -class NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties(Model): - fqdns = ListType(StringType, serialize_when_none=False) - group_id = StringType(serialize_when_none=False) - required_member_name = StringType(serialize_when_none=False) - - -class ExtendedLocation(Model): - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationSecurityGroupRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfigurationRef( - Model -): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_security_groups = ListType( - ModelType(ApplicationSecurityGroupRef), serialize_when_none=False - ) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - private_link_connection_properties = ModelType( - NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False, - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = StringType( - default="", serialize_when_none=False - ) # Change Public IP Address to id - subnet = StringType(default="", serialize_when_none=False) # Change Subnet to id - virtual_network_taps = ListType(ModelType(SubResource), serialize_when_none=False) - - -""" -END OF REF CLASSES -""" - - -class AddressSpace(Model): - address_count = IntType(serialize_when_none=False, default=0) - address_prefixes = ListType(StringType, default=["-"]) - - -class AutoApproval(Model): - subscriptions = ListType(StringType, serialize_when_none=False) - - -class ApplicationGatewayIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ConnectedDevice( - Model -): # Customized class, model for connected device lists attached to this virtual network - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - device = StringType(serialize_when_none=False) - - -class CustomDnsConfigPropertiesFormat(Model): - fqdn = StringType(serialize_when_none=False) - ip_addresses = ListType(StringType, serialize_when_none=False) - - -class DdosSettings(Model): - ddos_custom_policy = ModelType(SubResource, serialize_when_none=False) - protected_ip = BooleanType(serialize_when_none=False) - protection_coverage = StringType( - choices=("Basic", "Standard"), serialize_when_none=False - ) - - -class DhcpOptions(Model): - dns_servers = ListType(StringType, default=["Azure provided DNS service"]) - - -class Delegation(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(default="-", serialize_when_none=False) - actions = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - service_name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class FlowLogFormatType(Model): - json = StringType(serialize_when_none=False) - - -class FlowLogFormatParameters(Model): - type = ModelType(FlowLogFormatType, serialize_when_none=False) - version = IntType(serialize_when_none=False) - - -class InboundNatPool(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_port_range_end = IntType(serialize_when_none=False) - frontend_port_range_start = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class InboundNatRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_ip_configurations = ListType( - ModelType(NetworkInterfaceIPConfigurationRef), serialize_when_none=False - ) - target_virtual_machine = ListType(StringType, serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - port_mapping_display = StringType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class LoadBalancingRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - backend_address_pool_display = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - disable_outbound_s_nat = BooleanType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - load_distribution = StringType( - choices=("Default", "SourceIP", "SourceIPProtocol"), serialize_when_none=False - ) - load_distribution_display = StringType(serialize_when_none=False) - probe = ModelType(SubResource, serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class OutboundRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allocated_outbound_ports = IntType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configurations = ListType( - ModelType(SubResource), serialize_when_none=False - ) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class PublicIPAddressDnsSettingsRef(Model): - domain_name_label = StringType(serialize_when_none=False) - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class IpTagRef(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class NatGatewaySkuRef(Model): - name = StringType(choices=("Standard", None), serialize_when_none=False) - - -class NatGatewayRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_addresses = ListType(ModelType(SubResource), serialize_when_none=False) - public_ip_prefixes = ListType(ModelType(SubResource), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - subnets = ListType(ModelType(SubResource), serialize_when_none=False) - sku = ModelType(NatGatewaySkuRef, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PublicIPAddressSkuRef(Model): - name = StringType(choices=("Basic", "Standard"), serialize_when_none=False) - tier = StringType(choices=("Global", "Regional"), serialize_when_none=False) - - -class PublicIPAddressRef(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettingsRef, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = StringType( - serialize_when_none=False - ) # Change to IP Configuration id - ip_tags = ListType(ModelType(IpTagRef), serialize_when_none=False) - # linked_public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - migration_phase = StringType( - choices=("Abort", "Commit", "Committed", "None", "Prepare"), - serialize_when_none=False, - ) - nat_gateway = ModelType(NatGatewayRef, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - public_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSkuRef, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class FrontendIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - inbound_nat_pools = ListType(ModelType(InboundNatPool), serialize_when_none=False) - inbound_nat_rules = ListType(ModelType(InboundNatRule), serialize_when_none=False) - load_balancing_rules = ListType( - ModelType(LoadBalancingRule), serialize_when_none=False - ) - outbound_rules = ListType(ModelType(OutboundRule), serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = ModelType(PublicIPAddressRef, serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class RetentionPolicyParameters(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class TrafficAnalyticsConfigurationProperties(Model): - enabled = BooleanType(serialize_when_none=False) - traffic_analytics_interval = IntType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - workspace_region = StringType(serialize_when_none=False) - workspace_resource_id = StringType(serialize_when_none=False) - - -class TrafficAnalyticsProperties(Model): - network_watcher_flow_analytics_configuration = ModelType( - TrafficAnalyticsConfigurationProperties, serialize_when_none=False - ) - - -class FlowLog(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - enable = BooleanType(serialize_when_none=False) - flow_analytics_configuration = ModelType( - TrafficAnalyticsProperties, serialize_when_none=False - ) - format = ModelType(FlowLogFormatParameters, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - retention_policy = ModelType(RetentionPolicyParameters, serialize_when_none=False) - storage_id = StringType(serialize_when_none=False) - target_resource_guid = StringType(serialize_when_none=False) - target_resource_id = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class IPConfigurationProfile(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - - -class IPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - public_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = StringType( - serialize_when_none=False - ) # Change to PublicIPAddress ID - subnet = StringType(serialize_when_none=False) - - -class IpTag(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class ServiceAssociationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allow_delete = BooleanType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - locations = ListType(ModelType(ExtendedLocation), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPolicyDefinition(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - service = StringType(serialize_when_none=False) - service_resources = ListType(StringType) - - -class ServiceEndpointPolicy(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - service_endpoint_policy_definitions = ListType( - ModelType(ServiceEndpointPolicyDefinition), serialize_when_none=False - ) - subnets = ListType(StringType, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPropertiesFormat(Model): - locations = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - service = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - - -class ResourceNavigationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class Route(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - next_hop_ip_address = StringType(serialize_when_none=False) - next_hop_type = StringType( - choices=( - "Internet", - "None", - "VirtualAppliance", - "VirtualNetworkGateway", - "VnetLocal", - ), - serialize_when_none=False, - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - - -class RouteTable(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - disable_bgp_route_propagation = BooleanType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - routes = ListType(ModelType(Route), serialize_when_none=False) - subnets = ListType(StringType, default=[], serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NatGatewaySku(Model): - name = StringType(choices=("Standard", None), serialize_when_none=False) - tier = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnectionState(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - group_ids = ListType(StringType, serialize_when_none=False) - private_link_service_connection_state = ModelType( - PrivateLinkServiceConnectionState, serialize_when_none=False - ) - private_link_service_id = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - request_message = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateLinkServiceIpConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - - -class Visibility(Model): - subscriptions = ListType(StringType, serialize_when_none=False) - - -class PrivateEndpointRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType( - ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False - ) - manual_private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - network_interfaces = ListType( - StringType(), serialize_when_none=False - ) # Change to network interfaces id - private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) # Change to subnet ID - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateEndpointConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - link_identifier = StringType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointRef) - private_link_service_connection_state = ModelType( - PrivateLinkServiceConnectionState, serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class PrivateLinkService(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - alias = StringType(serialize_when_none=False) - auto_approval = ModelType(AutoApproval, serialize_when_none=False) - enable_proxy_protocol = BooleanType(serialize_when_none=False) - fqdns = ListType(StringType, serialize_when_none=False) - ip_configurations = ListType( - ModelType(PrivateLinkServiceIpConfiguration), serialize_when_none=False - ) - loadBalancer_frontend_ip_configurations = ListType( - ModelType(FrontendIPConfiguration), serialize_when_none=False - ) - network_interfaces = ListType( - StringType, serialize_when_none=False - ) # Change to network interfaces' id - private_endpoint_connections = ListType( - ModelType(PrivateEndpointConnection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - visibility = ModelType(Visibility, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PublicIPAddressDnsSettings(Model): - domain_name_label = StringType(serialize_when_none=False) - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class PublicIPAddressSku(Model): - name = StringType(choices=("Basic", "Standard"), serialize_when_none=False) - tier = StringType(choices=("Global", "Regional"), serialize_when_none=False) - - -class ReferencedPublicIPAddress(Model): - id = StringType(serialize_when_none=False) - - -class PublicIPPrefix(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - custom_ip_prefix = ModelType(SubResource) - ip_prefix = StringType(serialize_when_none=False) - ip_tags = ListType(ModelType(IpTag), serialize_when_none=False) - load_balancer_frontend_ip_configuration = ModelType(SubResource) - nat_gateway = (StringType(serialize_when_none=False),) # Change to NAT id - prefix_length = (IntType(serialize_when_none=False),) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - public_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - public_ip_addresses = ListType( - ModelType(ReferencedPublicIPAddress), serialize_when_none=False - ) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PublicIPPrefixSku(Model): - name = StringType(serialize_when_none=False) - tier = StringType(choices=("Global", "Regional"), serialize_when_none=False) - - -class PublicIPAddress(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettings, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = ModelType(IPConfiguration, serialize_when_none=False) - ip_tags = ListType(ModelType(IpTag), serialize_when_none=False) - # linked_public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - migration_phase = StringType( - choices=("Abort", "Commit", "Committed", "None", "Prepare"), - serialize_when_none=False, - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - public_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPPrefixSku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class ApplicationSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class SecurityRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - access = StringType(choices=("Allow", "Deny"), serialize_when_none=False) - description = StringType(serialize_when_none=False) - destination_address_prefix = StringType(serialize_when_none=False) - destination_address_prefixes = ListType(StringType, serialize_when_none=False) - destination_application_security_groups = ListType( - ModelType(ApplicationSecurityGroup), serialize_when_none=False - ) - destination_port_range = StringType(serialize_when_none=False) - destination_port_ranges = ListType(StringType, serialize_when_none=False) - direction = StringType(choices=("Inbound", "Outbound"), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - protocol = StringType( - choices=("*", "Ah", "Esp", "Icmp", "Tcp", "Udp"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - source_address_prefix = StringType(serialize_when_none=False) - source_address_prefixes = ListType(StringType, serialize_when_none=False) - source_application_security_groups = ListType( - ModelType(ApplicationSecurityGroup), serialize_when_none=False - ) - source_port_range = StringType(serialize_when_none=False) - source_port_ranges = ListType(StringType, serialize_when_none=False) - - -class NetworkInterfaceDnsSettings(Model): - applied_dns_servers = ListType(StringType, serialize_when_none=False) - dns_servers = ListType(StringType, serialize_when_none=False) - internal_dns_name_label = StringType(serialize_when_none=False) - internal_domain_name_suffix = StringType(serialize_when_none=False) - internal_fqdn = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfiguration(Model): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_security_groups = ListType( - ModelType(ApplicationSecurityGroup), serialize_when_none=False - ) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - private_link_connection_properties = ModelType( - NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False, - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - virtual_network_taps = ListType(ModelType(SubResource), serialize_when_none=False) - - -class NetworkInterfaceTapConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class NetworkSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(default="-", serialize_when_none=False) - default_security_rules = ListType( - ModelType(SecurityRule), serialize_when_none=False - ) - flow_logs = ListType(ModelType(FlowLog), serialize_when_none=False) - network_interfaces = StringType( - serialize_when_none=False - ) # Change to Network interfaces' Id - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - subnets = ListType(StringType, serialize_when_none=False) # Change to Subnet IDs - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterface(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - dns_settings = ModelType(NetworkInterfaceDnsSettings, serialize_when_none=False) - dscp_configuration = ModelType(SubResource, serialize_when_none=False) - enable_accelerated_networking = BooleanType(serialize_when_none=False) - enable_ip_forwarding = BooleanType(serialize_when_none=False) - hosted_workloads = ListType(StringType, serialize_when_none=False) - ip_configurations = ListType( - ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False - ) - mac_address = StringType(serialize_when_none=False) - migration_phase = StringType( - choices=("Abort", "Commit", "Committed", "None", "Prepare"), - serialize_when_none=False, - ) - nic_type = StringType(choices=("Elastic", "Standard"), serialize_when_none=False) - network_security_group = ModelType(NetworkSecurityGroup, serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointRef, serialize_when_none=False) - private_link_service = ModelType(PrivateLinkService, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - tap_configurations = ListType( - ModelType(NetworkInterfaceTapConfiguration), serialize_when_none=False - ) - virtual_machine = ModelType(SubResource, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateEndpoint(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType( - ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False - ) - manual_private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - network_interfaces = ListType( - ModelType(NetworkInterface), serialize_when_none=False - ) - private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -###### Firewall Classes ###### -class AzureFirewallRCAction(Model): - type = StringType(choices=("Allow", "Deny"), serialize_when_none=False) - - -class AzureFirewallApplicationRuleProtocol(Model): - port = IntType(serialize_when_none=False) - protocol_type = StringType( - choices=("Http", "Https", "Mssql"), serialize_when_none=False - ) - - -class AzureFirewallApplicationRule(Model): - description = StringType(serialize_when_none=False) - fqdn_tags = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType( - ModelType(AzureFirewallApplicationRuleProtocol), serialize_when_none=False - ) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - target_fqdns = ListType(StringType, serialize_when_none=False) - - -class AzureFirewallApplicationRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - rules = ListType(ModelType(AzureFirewallApplicationRule), serialize_when_none=False) - - -class AzureFirewallIPConfiguration(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = ModelType(SubResource, serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class AzureFirewallPublicIPAddress(Model): - address = StringType(serialize_when_none=False) - - -class HubPublicIPAddresses(Model): - address = ListType( - ModelType(AzureFirewallPublicIPAddress), serialize_when_none=False - ) - count = IntType(serialize_when_none=False) - - -class HubIPAddresses(Model): - private_ip_address = StringType(serialize_when_none=False) - public_ips = ModelType(HubPublicIPAddresses, serialize_when_none=False) - - -class AzureFirewallIpGroups(Model): - change_number = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - - -class AzureFirewallNatRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNetworkRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - destination_fqdns = ListType(StringType, serialize_when_none=False) - destination_ip_groups = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNatRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = StringType(choices=("Dnat", "Snat"), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - rules = ListType(ModelType(AzureFirewallNatRule), serialize_when_none=False) - - -class AzureFirewallNetworkRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - rules = ListType(ModelType(AzureFirewallNetworkRule), serialize_when_none=False) - - -class AzureFirewallSku(Model): - name = StringType(choices=("AZFW_Hub", "AZFW_VNet"), serialize_when_none=False) - tier = StringType(choices=("Premium", "Standard"), serialize_when_none=False) - - -class AzureFirewall(Model): - etag = StringType() - id = StringType() - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - application_rule_collections = ListType( - ModelType(AzureFirewallApplicationRuleCollection), serialize_when_none=False - ) - firewall_policy = ModelType(SubResource, serialize_when_none=False) - hub_ip_addresses = ModelType(HubIPAddresses, serialize_when_none=False) - ip_configurations = ListType( - ModelType(AzureFirewallIPConfiguration), serialize_when_none=False - ) - ip_groups = ListType(ModelType(AzureFirewallIpGroups), serialize_when_none=False) - management_ip_configuration = ModelType( - AzureFirewallIPConfiguration, serialize_when_none=False - ) - nat_rule_collections = ListType( - ModelType(AzureFirewallNatRuleCollection), serialize_when_none=False - ) - network_rule_collections = ListType( - ModelType(AzureFirewallNetworkRuleCollection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - sku = ModelType(AzureFirewallSku, serialize_when_none=False) - threat_intel_mode = StringType( - choices=("Alert", "Deny", "Off"), serialize_when_none=False - ) - virtual_hub = ModelType(SubResource, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class Subnet(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - virtual_network = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - address_prefixes = ListType(StringType, serialize_when_none=False) - application_gateway_ip_configurations = ModelType( - ApplicationGatewayIPConfiguration, serialize_when_none=False - ) - delegations = ListType(ModelType(Delegation), serialize_when_none=False) - ip_allocations = ListType(ModelType(SubResource), serialize_when_none=False) - ip_configuration_profiles = ListType( - ModelType(IPConfigurationProfile), serialize_when_none=False - ) - ip_configurations = ListType(ModelType(IPConfiguration), serialize_when_none=False) - azure_firewall = ListType(ModelType(AzureFirewall), serialize_when_none=False) - nat_gateway = ModelType(SubResource, serialize_when_none=False) - network_security_group = ModelType(NetworkSecurityGroup, serialize_when_none=False) - private_endpoint_network_policies = StringType( - choices=("Disabled", "Enabled"), serialize_when_none=False - ) - private_endpoints = ListType(ModelType(PrivateEndpoint), serialize_when_none=False) - private_link_service_network_policies = StringType( - choices=("Disabled", "Enabled"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - purpose = StringType(serialize_when_none=False) - resource_navigation_links = ListType( - ModelType(ResourceNavigationLink, serialize_when_none=False) - ) - route_table = ModelType(RouteTable, serialize_when_none=False) - service_association_links = ListType( - ModelType(ServiceAssociationLink), serialize_when_none=False - ) - service_endpoint_policies = ListType( - ModelType(ServiceEndpointPolicy), serialize_when_none=False - ) - service_endpoints = ListType( - ModelType(ServiceEndpointPropertiesFormat), serialize_when_none=False - ) - type = StringType(serialize_when_none=False) - - -class VirtualNetworkBgpCommunities(Model): - regional_community = StringType(serialize_when_none=False) - virtual_network_community = StringType(serialize_when_none=False) - - -class VirtualNetworkPeering(Model): - id = StringType(serialize_when_none=False) - etag = StringType(serialize_when_none=False) - name = StringType() - allow_forwarded_traffic = BooleanType(serialize_when_none=False) - allow_gateway_transit = BooleanType(serialize_when_none=False) - allow_virtual_network_access = BooleanType(serialize_when_none=False) - do_not_verify_remote_gateways = BooleanType(serialize_when_none=False) - peering_state = StringType( - choices=("Connected", "Disconnected", "Initiated"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - remote_address_space = ModelType(AddressSpace, serialize_when_none=False) - remote_bgp_communities = ModelType( - VirtualNetworkBgpCommunities, serialize_when_none=False - ) - remote_virtual_network = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - use_remote_gateways = BooleanType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NatGateway(AzureCloudService): # Main class - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_addresses = ListType( - ModelType(PublicIPAddress), serialize_when_none=False - ) - public_ip_addresses_count = IntType(default=0) - public_ip_prefixes = ListType(ModelType(PublicIPPrefix), serialize_when_none=False) - public_ip_prefixes_count = IntType(default=0) - resource_guid = StringType(serialize_when_none=False) - subnets = ListType(ModelType(Subnet), serialize_when_none=False) - subnets_count = IntType(default=0) - sku = ModelType(NatGatewaySku, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_account.yaml b/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_account.yaml deleted file mode 100644 index 3fb9a4ec..00000000 --- a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: NATGateways -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_region.yaml b/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_region.yaml deleted file mode 100644 index 60fa33f7..00000000 --- a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: NATGateways -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_subscription.yaml b/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_subscription.yaml deleted file mode 100644 index 810a3c64..00000000 --- a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: NATGateways -cloud_service_type: Instance -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_total_count.yaml b/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_total_count.yaml deleted file mode 100644 index a41f2062..00000000 --- a/src/spaceone/inventory/model/nat_gateways/widget/nat_gateways_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: NATGateways -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: count - options: - default: 0 diff --git a/src/spaceone/inventory/model/network_security_groups/__init__.py b/src/spaceone/inventory/model/network_security_groups/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/network_security_groups/cloud_service.py b/src/spaceone/inventory/model/network_security_groups/cloud_service.py deleted file mode 100644 index 0248fb2a..00000000 --- a/src/spaceone/inventory/model/network_security_groups/cloud_service.py +++ /dev/null @@ -1,80 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField, SizeField, StateItemDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.network_security_groups.data import NetworkSecurityGroup - -''' -NETWORK_SECURITY_GROUP -''' -# TAB - Default -network_security_group_info_meta = ItemDynamicLayout.set_fields('Network Security Group', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account') -]) - -# TAB - Inbound Security Rules -network_security_group_inbound_security_rules = TableDynamicLayout.set_fields('Inbound Security Rules', 'data.inbound_security_rules', fields=[ - TextDyField.data_source('Priority', 'priority'), - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Port', 'destination_port_range'), - TextDyField.data_source('Protocol', 'protocol'), - TextDyField.data_source('Source', 'source_address_prefix'), - TextDyField.data_source('Destination', 'destination_address_prefix'), - TextDyField.data_source('Action', 'access') -]) - -# TAB - Outbound Security Rules -network_security_group_outbound_security_rules = TableDynamicLayout.set_fields('Outbound Security Rules', 'data.outbound_security_rules', fields=[ - TextDyField.data_source('Priority', 'priority'), - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Port', 'destination_port_range'), - TextDyField.data_source('Protocol', 'protocol'), - TextDyField.data_source('Source', 'source_address_prefix'), - TextDyField.data_source('Destination', 'destination_address_prefix'), - TextDyField.data_source('Action', 'access') -]) - -# TAB - Network Interfaces -network_security_group_network_interfaces = TableDynamicLayout.set_fields('Network Interfaces', 'data.network_interfaces', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Public IP Address', 'public_ip_address'), - TextDyField.data_source('Private IP Address', 'private_ip_address'), - TextDyField.data_source('Virtual Machine', 'virtual_machine_display') -]) - -# TAB - Subnets -network_subnets = TableDynamicLayout.set_fields('Subnets', 'data.subnets', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Address Range', 'address_prefix'), - TextDyField.data_source('Virtual Network', 'virtual_network') -]) - -network_security_group_meta = CloudServiceMeta.set_layouts( - [network_security_group_info_meta, network_security_group_inbound_security_rules, network_subnets, - network_security_group_outbound_security_rules, network_security_group_network_interfaces]) - - -class NetworkResource(CloudServiceResource): - cloud_service_group = StringType(default='NetworkSecurityGroups') - - -class NetworkSecurityGroupResource(NetworkResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(NetworkSecurityGroup) - _metadata = ModelType(CloudServiceMeta, default=network_security_group_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class NetworkSecurityGroupResponse(CloudServiceResponse): - resource = PolyModelType(NetworkSecurityGroupResource) diff --git a/src/spaceone/inventory/model/network_security_groups/cloud_service_type.py b/src/spaceone/inventory/model/network_security_groups/cloud_service_type.py deleted file mode 100644 index 53aef9f1..00000000 --- a/src/spaceone/inventory/model/network_security_groups/cloud_service_type.py +++ /dev/null @@ -1,142 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -nsg_count_by_account_conf = os.path.join(current_dir, 'widget/nsg_count_by_account.yaml') -nsg_count_by_region_conf = os.path.join(current_dir, 'widget/nsg_count_by_region.yaml') -nsg_count_by_subscription_conf = os.path.join(current_dir, 'widget/nsg_count_by_subscription.yaml') -nsg_inbound_count_by_subscription_conf = os.path.join(current_dir, 'widget/nsg_inbound_count_by_subscription.yaml') -nsg_outbound_count_by_subscription_conf = os.path.join(current_dir, 'widget/nsg_outbound_count_by_subscription.yaml') -nsg_total_count_conf = os.path.join(current_dir, 'widget/nsg_total_count.yaml') - -cst_network_security_groups = CloudServiceTypeResource() -cst_network_security_groups.name = 'Instance' -cst_network_security_groups.group = 'NetworkSecurityGroups' -cst_network_security_groups.service_code = 'Microsoft.Network/networkSecurityGroups' -cst_network_security_groups.labels = ['Networking'] -cst_network_security_groups.is_major = True -cst_network_security_groups.is_primary = True -cst_network_security_groups.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-network-security-groups.svg', -} - -cst_network_security_groups._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Virtual Machines', 'data.virtual_machines_display'), - # is_optional fields - Inbound Security Rules - TextDyField.data_source('Inbound Rule Priority', 'data.inbound_security_rules.priority', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound Rule Name', 'data.inbound_security_rules.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound Rule Port', 'data.inbound_security_rules.destination_port_range', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound Rule Protocol', 'data.inbound_security_rules.protocol', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound Rule Source', 'data.inbound_security_rules.source_address_prefix', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound Rule Destination', 'data.inbound_security_rules.destination_address_prefix', options={ - 'is_optional': True - }), - TextDyField.data_source('Inbound Rule Action', 'data.inbound_security_rules.access', options={ - 'is_optional': True - }), - # is_optional fields - Outbound Security Rules - TextDyField.data_source('Outbound Rule Priority', 'data.outbound_security_rules.priority', options={ - 'is_optional': True - }), - TextDyField.data_source('Outbound Rule Name', 'data.outbound_security_rules.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Outbound Rule Port', 'data.outbound_security_rules.destination_port_range', options={ - 'is_optional': True - }), - TextDyField.data_source('Outbound Rule Protocol', 'data.outbound_security_rules.protocol', options={ - 'is_optional': True - }), - TextDyField.data_source('Outbound Rule Source', 'data.outbound_security_rules.source_address_prefix', options={ - 'is_optional': True - }), - TextDyField.data_source('Outbound Rule Destination', 'data.outbound_security_rules.destination_address_prefix', options={ - 'is_optional': True - }), - TextDyField.data_source('Outbound Rule Action', 'data.outbound_security_rules.access', options={ - 'is_optional': True - }), - # is_optional_field - Network Interfaces - TextDyField.data_source('Network Interface Name', 'data.network_interfaces.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Network Interface Public IP Address', 'data.network_interfaces.public_ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('Network Interface Private IP Address', 'data.network_interfaces.private_ip_address', options={ - 'is_optional': True - }), - # is_optional field - Subnets - TextDyField.data_source('Subnet Name', 'data.subnets.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Subnet Address Range', 'data.subnets.address_prefix', options={ - 'is_optional': True - }), - TextDyField.data_source('Virtual Network', 'data.subnets.virtual_network', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Virtual Machines', key='data.virtual_machines_display'), - SearchField.set(name='Inbound Rule Priority', key='data.inbound_security_rules.priority', data_type='integer'), - SearchField.set(name='Inbound Rule Name', key='data.inbound_security_rules.name'), - SearchField.set(name='Inbound Rule Port', key='data.inbound_security_rules.destination_port_range'), - SearchField.set(name='Inbound Rule Protocol', key='data.inbound_security_rules.protocol'), - SearchField.set(name='Inbound Rule Source', key='data.inbound_security_rules.source_address_prefix'), - SearchField.set(name='Inbound Rule Destination', key='data.inbound_security_rules.destination_address_prefix'), - SearchField.set(name='Inbound Rule Action', key='data.inbound_security_rules.access'), - SearchField.set(name='Outbound Rule Priority', key='data.outbound_security_rules.priority', data_type='integer'), - SearchField.set(name='Outbound Rule Name', key='data.outbound_security_rules.name'), - SearchField.set(name='Outbound Rule Port', key='data.outbound_security_rules.destination_port_range'), - SearchField.set(name='Outbound Rule Protocol', key='data.outbound_security_rules.protocol'), - SearchField.set(name='Outbound Rule Source', key='data.outbound_security_rules.source_address_prefix'), - SearchField.set(name='Outbound Rule Destination', key='data.outbound_security_rules.destination_address_prefix'), - SearchField.set(name='Outbound Rule Action', key='data.outbound_security_rules.access'), - SearchField.set(name='Network Interface Name', key='data.network_interfaces.name'), - SearchField.set(name='Network Interface Public IP Address', key='data.network_interfaces.public_ip_address'), - SearchField.set(name='Network Interface Private IP Address', key='data.network_interfaces.private_ip_address'), - SearchField.set(name='Subnet Name', key='data.subnets.name'), - SearchField.set(name='Subnet Address Range', key='data.subnets.address_prefix'), - SearchField.set(name='Virtual Network', key='data.subnets.virtual_network'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(nsg_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(nsg_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(nsg_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(nsg_inbound_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(nsg_outbound_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(nsg_total_count_conf)) - ] -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_network_security_groups}), -] diff --git a/src/spaceone/inventory/model/network_security_groups/data.py b/src/spaceone/inventory/model/network_security_groups/data.py deleted file mode 100644 index 792b1841..00000000 --- a/src/spaceone/inventory/model/network_security_groups/data.py +++ /dev/null @@ -1,1049 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Tags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class SubResource(Model): - id = StringType() - - -class ExtendedLocation(Model): - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class SecurityRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - access = StringType(choices=("Allow", "Deny"), serialize_when_none=False) - description = StringType(serialize_when_none=False) - destination_address_prefix = StringType(serialize_when_none=False) - destination_address_prefixes = ListType(StringType, serialize_when_none=False) - destination_application_security_groups = ListType( - ModelType(ApplicationSecurityGroup), serialize_when_none=False - ) - destination_port_range = StringType(serialize_when_none=False) - destination_port_ranges = ListType(StringType, serialize_when_none=False) - direction = StringType(choices=("Inbound", "Outbound"), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - protocol = StringType( - choices=("*", "Ah", "Esp", "Icmp", "Tcp", "Udp"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - source_address_prefix = StringType(serialize_when_none=False) - source_address_prefixes = ListType(StringType, serialize_when_none=False) - source_application_security_groups = ListType( - ModelType(ApplicationSecurityGroup), serialize_when_none=False - ) - source_port_range = StringType(serialize_when_none=False) - source_port_ranges = ListType(StringType, serialize_when_none=False) - - -class TrafficAnalyticsConfigurationProperties(Model): - enabled = BooleanType(serialize_when_none=False) - traffic_analytics_interval = IntType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - workspace_region = StringType(serialize_when_none=False) - workspace_resource_id = StringType(serialize_when_none=False) - - -class TrafficAnalyticsProperties(Model): - network_watcher_flow_analytics_configuration = ModelType( - TrafficAnalyticsConfigurationProperties, serialize_when_none=False - ) - - -class FlowLogFormatType(Model): - json = StringType(serialize_when_none=False) - - -class FlowLogFormatParameters(Model): - type = ModelType(FlowLogFormatType, serialize_when_none=False) - version = IntType(serialize_when_none=False) - - -class RetentionPolicyParameters(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class FlowLog(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - enable = BooleanType(serialize_when_none=False) - flow_analytics_configuration = ModelType( - TrafficAnalyticsProperties, serialize_when_none=False - ) - format = ModelType(FlowLogFormatParameters, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - retention_policy = ModelType(RetentionPolicyParameters, serialize_when_none=False) - storage_id = StringType(serialize_when_none=False) - target_resource_guid = StringType(serialize_when_none=False) - target_resource_id = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceDnsSettings(Model): - applied_dns_servers = ListType(StringType, serialize_when_none=False) - dns_servers = ListType(StringType, serialize_when_none=False) - internal_dns_name_label = StringType(serialize_when_none=False) - internal_domain_name_suffix = StringType(serialize_when_none=False) - internal_fqdn = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties(Model): - fqdns = ListType(StringType, serialize_when_none=False) - group_id = StringType(serialize_when_none=False) - required_member_name = StringType(serialize_when_none=False) - - -class PublicIPAddressSku(Model): - name = StringType(choices=("Basic", "Standard"), serialize_when_none=False) - tier = StringType(choices=("Global", "Regional"), serialize_when_none=False) - - -class IpTag(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class DdosSettings(Model): - ddos_custom_policy = ModelType(SubResource, serialize_when_none=False) - protected_ip = BooleanType(serialize_when_none=False) - protection_coverage = StringType( - choices=("Basic", "Standard"), serialize_when_none=False - ) - - -class PublicIPAddressDnsSettings(Model): - domain_name_label = StringType(serialize_when_none=False) - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class IPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = StringType( - serialize_when_none=False - ) # Change to Public IP Address's ID - subnet = StringType(serialize_when_none=False) - - -class NatGatewaySku(Model): - name = StringType(choices=("Standard", None), serialize_when_none=False) - - -class NatGateway(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_addresses = ListType(ModelType(SubResource), serialize_when_none=False) - public_ip_prefixes = ListType(ModelType(SubResource), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - subnets = ListType(ModelType(SubResource), serialize_when_none=False) - sku = ModelType(NatGatewaySku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PublicIPAddress(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettings, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = ModelType(IPConfiguration, serialize_when_none=False) - ip_tags = ListType(ModelType(IpTag), serialize_when_none=False) - # linked_public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - migration_phase = StringType( - choices=("Abort", "Commit", "Committed", "None", "Prepare"), - serialize_when_none=False, - ) - nat_gateway = ModelType(NatGateway, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - public_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class NetworkInterfaceIPConfiguration(Model): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_security_groups = ListType( - ModelType(ApplicationSecurityGroup), serialize_when_none=False - ) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - private_link_connection_properties = ModelType( - NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False, - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - virtual_network_taps = ListType(ModelType(SubResource), serialize_when_none=False) - - -class NetworkSecurityGroupRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(default="-", serialize_when_none=False) - default_security_rules = ListType( - ModelType(SecurityRule), serialize_when_none=False - ) - flow_logs = ListType(ModelType(FlowLog), serialize_when_none=False) - network_interfaces = StringType( - serialize_when_none=False - ) # Change to Network interfaces' Id - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - subnets = ListType(StringType, serialize_when_none=False) # Change to Subnet IDs - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnectionState(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - group_ids = ListType(StringType, serialize_when_none=False) - private_link_service_connection_state = ModelType( - PrivateLinkServiceConnectionState, serialize_when_none=False - ) - private_link_service_id = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - request_message = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class CustomDnsConfigPropertiesFormat(Model): - fqdn = StringType(serialize_when_none=False) - ip_addresses = ListType(StringType, serialize_when_none=False) - - -class PrivateEndpointRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType( - ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False - ) - manual_private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - network_interfaces = ListType( - StringType(), serialize_when_none=False - ) # Change to network interfaces id - private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) # Change to subnet ID - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class AutoApproval(Model): - subscriptions = ListType(StringType, serialize_when_none=False) - - -class PrivateLinkServiceIpConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - - -class InboundNatPool(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_port_range_end = IntType(serialize_when_none=False) - frontend_port_range_start = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class ApplicationSecurityGroupRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfigurationRef( - Model -): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_security_groups = ListType( - ModelType(ApplicationSecurityGroupRef), serialize_when_none=False - ) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - private_link_connection_properties = ModelType( - NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False, - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = StringType( - default="", serialize_when_none=False - ) # Change Public IP Address to id - subnet = StringType(default="", serialize_when_none=False) # Change Subnet to id - virtual_network_taps = ListType(ModelType(SubResource), serialize_when_none=False) - - -class InboundNatRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_ip_configurations = ListType( - ModelType(NetworkInterfaceIPConfigurationRef), serialize_when_none=False - ) - target_virtual_machine = ListType(StringType, serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - port_mapping_display = StringType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class LoadBalancingRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - backend_address_pool_display = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - disable_outbound_s_nat = BooleanType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - load_distribution = StringType( - choices=("Default", "SourceIP", "SourceIPProtocol"), serialize_when_none=False - ) - load_distribution_display = StringType(serialize_when_none=False) - probe = ModelType(SubResource, serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class OutboundRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allocated_outbound_ports = IntType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configurations = ListType( - ModelType(SubResource), serialize_when_none=False - ) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=("All", "Tcp", "Udp"), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class FrontendIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - inbound_nat_pools = ListType(ModelType(InboundNatPool), serialize_when_none=False) - inbound_nat_rules = ListType(ModelType(InboundNatRule), serialize_when_none=False) - load_balancing_rules = ListType( - ModelType(LoadBalancingRule), serialize_when_none=False - ) - outbound_rules = ListType(ModelType(OutboundRule), serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), serialize_when_none=False - ) - private_ip_allocation_method = StringType( - choices=("Dynamic", "Static"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = StringType(serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PrivateEndpointConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - link_identifier = StringType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointRef) - private_link_service_connection_state = ModelType( - PrivateLinkServiceConnectionState, serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class Visibility(Model): - subscriptions = ListType(StringType, serialize_when_none=False) - - -class PrivateLinkService(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - alias = StringType(serialize_when_none=False) - auto_approval = ModelType(AutoApproval, serialize_when_none=False) - enable_proxy_protocol = BooleanType(serialize_when_none=False) - fqdns = ListType(StringType, serialize_when_none=False) - ip_configurations = ListType( - ModelType(PrivateLinkServiceIpConfiguration), serialize_when_none=False - ) - loadBalancer_frontend_ip_configurations = ListType( - ModelType(FrontendIPConfiguration), serialize_when_none=False - ) - network_interfaces = ListType( - StringType, serialize_when_none=False - ) # Change to network interfaces' id - private_endpoint_connections = ListType( - ModelType(PrivateEndpointConnection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - visibility = ModelType(Visibility, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceTapConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class NetworkInterface(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - dns_settings = ModelType(NetworkInterfaceDnsSettings, serialize_when_none=False) - dscp_configuration = ModelType(SubResource, serialize_when_none=False) - enable_accelerated_networking = BooleanType(serialize_when_none=False) - enable_ip_forwarding = BooleanType(serialize_when_none=False) - hosted_workloads = ListType(StringType, serialize_when_none=False) - ip_configurations = ListType( - ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False - ) - private_ip_address = StringType(serialize_when_none=False) - public_ip_address = StringType(serialize_when_none=False) - mac_address = StringType(serialize_when_none=False) - migration_phase = StringType( - choices=("Abort", "Commit", "Committed", "None", "Prepare"), - serialize_when_none=False, - ) - nic_type = StringType(choices=("Elastic", "Standard"), serialize_when_none=False) - network_security_group = ModelType( - NetworkSecurityGroupRef, serialize_when_none=False - ) - primary = BooleanType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointRef, serialize_when_none=False) - private_link_service = ModelType(PrivateLinkService, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - tap_configurations = ListType( - ModelType(NetworkInterfaceTapConfiguration), serialize_when_none=False - ) - virtual_machine = ModelType(SubResource, serialize_when_none=False) - virtual_machine_display = StringType(default="-") - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -### Subnet Class ### -class ServiceEndpointPropertiesFormat(Model): - locations = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - service = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - - -class ApplicationGatewayIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Delegation(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(default="-", serialize_when_none=False) - actions = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - service_name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class IPConfigurationProfile(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - - -class AzureFirewallRCAction(Model): - type = StringType(choices=("Allow", "Deny"), serialize_when_none=False) - - -class AzureFirewallApplicationRuleProtocol(Model): - port = IntType(serialize_when_none=False) - protocol_type = StringType( - choices=("Http", "Https", "Mssql"), serialize_when_none=False - ) - - -class AzureFirewallApplicationRule(Model): - description = StringType(serialize_when_none=False) - fqdn_tags = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType( - ModelType(AzureFirewallApplicationRuleProtocol), serialize_when_none=False - ) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - target_fqdns = ListType(StringType, serialize_when_none=False) - - -class AzureFirewallApplicationRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - rules = ListType(ModelType(AzureFirewallApplicationRule), serialize_when_none=False) - - -class AzureFirewallPublicIPAddress(Model): - address = StringType(serialize_when_none=False) - - -class HubPublicIPAddresses(Model): - address = ListType( - ModelType(AzureFirewallPublicIPAddress), serialize_when_none=False - ) - count = IntType(serialize_when_none=False) - - -class HubIPAddresses(Model): - private_ip_address = StringType(serialize_when_none=False) - public_ips = ModelType(HubPublicIPAddresses, serialize_when_none=False) - - -class AzureFirewallIPConfiguration(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - public_ip_address = ModelType(SubResource, serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class AzureFirewallIpGroups(Model): - change_number = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - - -class AzureFirewallNatRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNatRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = StringType(choices=("Dnat", "Snat"), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - rules = ListType(ModelType(AzureFirewallNatRule), serialize_when_none=False) - - -class AzureFirewallNetworkRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - destination_fqdns = ListType(StringType, serialize_when_none=False) - destination_ip_groups = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNetworkRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - rules = ListType(ModelType(AzureFirewallNetworkRule), serialize_when_none=False) - - -class AzureFirewallSku(Model): - name = StringType(choices=("AZFW_Hub", "AZFW_VNet"), serialize_when_none=False) - tier = StringType(choices=("Premium", "Standard"), serialize_when_none=False) - - -class AzureFirewall(Model): - etag = StringType() - id = StringType() - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - application_rule_collections = ListType( - ModelType(AzureFirewallApplicationRuleCollection), serialize_when_none=False - ) - firewall_policy = ModelType(SubResource, serialize_when_none=False) - hub_ip_addresses = ModelType(HubIPAddresses, serialize_when_none=False) - ip_configurations = ListType( - ModelType(AzureFirewallIPConfiguration), serialize_when_none=False - ) - ip_groups = ListType(ModelType(AzureFirewallIpGroups), serialize_when_none=False) - management_ip_configuration = ModelType( - AzureFirewallIPConfiguration, serialize_when_none=False - ) - nat_rule_collections = ListType( - ModelType(AzureFirewallNatRuleCollection), serialize_when_none=False - ) - network_rule_collections = ListType( - ModelType(AzureFirewallNetworkRuleCollection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - sku = ModelType(AzureFirewallSku, serialize_when_none=False) - threat_intel_mode = StringType( - choices=("Alert", "Deny", "Off"), serialize_when_none=False - ) - virtual_hub = ModelType(SubResource, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class ResourceNavigationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class Route(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - next_hop_ip_address = StringType(serialize_when_none=False) - next_hop_type = StringType( - choices=( - "Internet", - "None", - "VirtualAppliance", - "VirtualNetworkGateway", - "VnetLocal", - ), - serialize_when_none=False, - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - - -class RouteTable(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - disable_bgp_route_propagation = BooleanType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - routes = ListType(ModelType(Route), serialize_when_none=False) - subnets = ListType(StringType, default=[], serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateEndpoint(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType( - ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False - ) - manual_private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - network_interfaces = ListType( - ModelType(NetworkInterface), serialize_when_none=False - ) - private_link_service_connections = ListType( - ModelType(PrivateLinkServiceConnection), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - subnet = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceAssociationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allow_delete = BooleanType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - locations = ListType(ModelType(ExtendedLocation), serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPolicyDefinition(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - service = StringType(serialize_when_none=False) - service_resources = ListType(StringType) - - -class ServiceEndpointPolicy(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - service_endpoint_policy_definitions = ListType( - ModelType(ServiceEndpointPolicyDefinition), serialize_when_none=False - ) - subnets = ListType(StringType, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Subnet(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - virtual_network = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - address_prefixes = ListType(StringType, serialize_when_none=False) - application_gateway_ip_configurations = ListType( - ModelType(ApplicationGatewayIPConfiguration, serialize_when_none=False) - ) - delegations = ListType(ModelType(Delegation), serialize_when_none=False) - ip_allocations = ListType(ModelType(SubResource), serialize_when_none=False) - ip_configuration_profiles = ListType( - ModelType(IPConfigurationProfile), serialize_when_none=False - ) - ip_configurations = ListType(ModelType(IPConfiguration), serialize_when_none=False) - azure_firewall = ListType(ModelType(AzureFirewall), serialize_when_none=False) - nat_gateway = ModelType(SubResource, serialize_when_none=False) - network_security_group = ModelType( - NetworkSecurityGroupRef, serialize_when_none=False - ) - private_endpoint_network_policies = StringType( - choices=("Disabled", "Enabled"), serialize_when_none=False - ) - private_endpoints = ListType(ModelType(PrivateEndpoint), serialize_when_none=False) - private_link_service_network_policies = StringType( - choices=("Disabled", "Enabled"), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - purpose = StringType(serialize_when_none=False) - resource_navigation_links = ListType( - ModelType(ResourceNavigationLink, serialize_when_none=False) - ) - route_table = ModelType(RouteTable, serialize_when_none=False) - service_association_links = ListType( - ModelType(ServiceAssociationLink), serialize_when_none=False - ) - service_endpoint_policies = ListType( - ModelType(ServiceEndpointPolicy), serialize_when_none=False - ) - service_endpoints = ListType( - ModelType(ServiceEndpointPropertiesFormat), serialize_when_none=False - ) - type = StringType(serialize_when_none=False) - - -class NetworkSecurityGroup(AzureCloudService): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(default="-", serialize_when_none=False) - default_security_rules = ListType( - ModelType(SecurityRule), serialize_when_none=False - ) - inbound_security_rules = ListType( - ModelType(SecurityRule), serialize_when_none=False - ) - outbound_security_rules = ListType( - ModelType(SecurityRule), serialize_when_none=False - ) - flow_logs = ListType(ModelType(FlowLog), serialize_when_none=False) - network_interfaces = ListType( - ModelType(NetworkInterface), serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Deleting", "Failed", "Succeeded", "Updating"), - serialize_when_none=False, - ) - resource_guid = StringType(serialize_when_none=False) - security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - subnets = ListType(ModelType(Subnet), serialize_when_none=False) - virtual_machines_display = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_account.yaml b/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_account.yaml deleted file mode 100644 index 9c071834..00000000 --- a/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: NetworkSecurityGroups -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_region.yaml b/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_region.yaml deleted file mode 100644 index a9f9d06c..00000000 --- a/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: NetworkSecurityGroups -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_subscription.yaml b/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_subscription.yaml deleted file mode 100644 index 1e28d560..00000000 --- a/src/spaceone/inventory/model/network_security_groups/widget/nsg_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: NetworkSecurityGroups -cloud_service_type: Instance -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/network_security_groups/widget/nsg_inbound_count_by_subscription.yaml b/src/spaceone/inventory/model/network_security_groups/widget/nsg_inbound_count_by_subscription.yaml deleted file mode 100644 index c12e6064..00000000 --- a/src/spaceone/inventory/model/network_security_groups/widget/nsg_inbound_count_by_subscription.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: NetworkSecurityGroups -cloud_service_type: Instance -name: Inbound Rule Count by Subscription -query: - aggregate: - - unwind: - path: data.inbound_security_rules - - group: - keys: - - name: name - key: account - fields: - - name: value - key: data.inbound_security_rules - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/network_security_groups/widget/nsg_outbound_count_by_subscription.yaml b/src/spaceone/inventory/model/network_security_groups/widget/nsg_outbound_count_by_subscription.yaml deleted file mode 100644 index 587ab324..00000000 --- a/src/spaceone/inventory/model/network_security_groups/widget/nsg_outbound_count_by_subscription.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: NetworkSecurityGroups -cloud_service_type: Instance -name: Outbound Rule Count by Subscription -query: - aggregate: - - unwind: - path: data.outbound_security_rules - - group: - keys: - - name: name - key: account - fields: - - name: value - key: data.outbound_security_rules - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/network_security_groups/widget/nsg_total_count.yaml b/src/spaceone/inventory/model/network_security_groups/widget/nsg_total_count.yaml deleted file mode 100644 index 9773f85d..00000000 --- a/src/spaceone/inventory/model/network_security_groups/widget/nsg_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: NetworkSecurityGroups -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/postgresql_servers/__init__.py b/src/spaceone/inventory/model/postgresql_servers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/postgresql_servers/cloud_service.py b/src/spaceone/inventory/model/postgresql_servers/cloud_service.py deleted file mode 100644 index c578e544..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/cloud_service.py +++ /dev/null @@ -1,124 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.model.postgresql_servers.data import PostgreSQLServer -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, EnumDyField, \ - ListDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta - -''' -POSTGRESQL SERVERS -''' - -# TAB - Default -postgresql_servers_info_meta = ItemDynamicLayout.set_fields('PostgreSQL Servers', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Resource ID', 'data.id'), - EnumDyField.data_source('Status', 'data.user_visible_state', default_state={ - 'safe': ['Ready'], - 'warning': ['Disabled', 'Dropping', 'Inaccessible'] - }), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Server Name', 'data.fully_qualified_domain_name'), - TextDyField.data_source('Admin Username', 'data.administrator_login'), - TextDyField.data_source('PostgreSQL Version', 'data.version'), - TextDyField.data_source('Performance Configuration Tier', 'data.sku.tier'), - TextDyField.data_source('Performance Configuration Name', 'data.sku.name'), - TextDyField.data_source('Performance Configuration Capacity', 'data.sku.capacity'), - EnumDyField.data_source('SSL Enforce Status', 'data.ssl_enforcement', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }) -]) - -# TAB - Connection Security -postgresql_server_connection_security_default = ItemDynamicLayout.set_fields('Connection Security', fields=[ - EnumDyField.data_source('Public Network Access', 'data.public_network_access', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - EnumDyField.data_source('SSL Enforcement', 'data.ssl_enforcement', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - TextDyField.data_source('TLS Setting', 'data.minimal_tls_version'), - -]) - -postgresql_server_firewall_rules = SimpleTableDynamicLayout.set_fields('Firewall Rules', 'data.firewall_rules', fields=[ - TextDyField.data_source('Firewall Rule Name', 'name'), - TextDyField.data_source('Start IP', 'start_ip_address'), - TextDyField.data_source('End IP', 'end_ip_address') -]) - -# TAB - VNet Rules -postgresql_server_vnet_rules = SimpleTableDynamicLayout.set_fields('VNET Rules', 'data.virtual_network_rules', fields=[ - TextDyField.data_source('Rule Name', 'name'), - TextDyField.data_source('Virtual Network', 'virtual_network_name_display'), - TextDyField.data_source('Subnet', 'subnet_name'), - EnumDyField.data_source('Endpoint Status', 'state', default_state={ - 'safe': ['Ready', 'InProgress'], - 'warning': ['Deleting', 'Initializing', 'Unknown'] - }) -]) - -# 1 + 2 + 3) TAB - Connection Security Meta -postgresql_servers_connection_security = ListDynamicLayout.set_layouts('Connection Security', layouts=[ - postgresql_server_connection_security_default, - postgresql_server_firewall_rules, postgresql_server_vnet_rules]) - -# TAB - Replicas -postgresql_servers_replication = SimpleTableDynamicLayout.set_fields('Replicas', 'data.replicas', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Location', 'location'), - EnumDyField.data_source('Status', 'user_visible_state', default_state={ - 'safe': ['Ready'], - 'warning': ['Disabled', 'Dropping', 'Inaccessible'] - }), - TextDyField.data_source('Master Server Name', 'master_server_name') -]) - -# TAB - Server Admin -postgresql_servers_server_admin = SimpleTableDynamicLayout.set_fields('Active Directory Admin', 'data.server_administrators', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Login', 'login'), - TextDyField.data_source('SID', 'sid'), - TextDyField.data_source('Tenant ID', 'tenant_id') -]) - -# TAB - Pricing Tier -postgresql_servers_pricing_tier = ItemDynamicLayout.set_fields('Pricing Tier', fields=[ - TextDyField.data_source('Compute Generation', 'data.sku.name'), - TextDyField.data_source('vCore', 'data.sku.capacity'), - EnumDyField.data_source('Storage Auto Grow', 'data.storage_profile.storage_autogrow', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - TextDyField.data_source('Backup Retention Period (Days)', 'data.storage_profile.backup_retention_days') -]) - -postgresql_servers_meta = CloudServiceMeta.set_layouts( - [postgresql_servers_info_meta, postgresql_servers_connection_security, postgresql_servers_replication, - postgresql_servers_server_admin, postgresql_servers_pricing_tier]) - - -class DatabaseResource(CloudServiceResource): - cloud_service_group = StringType(default='PostgreSQLServers') - - -class PostgreSQLServerResource(DatabaseResource): - cloud_service_type = StringType(default='Server') - data = ModelType(PostgreSQLServer) - _metadata = ModelType(CloudServiceMeta, default=postgresql_servers_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class PostgreSQLServerResponse(CloudServiceResponse): - resource = PolyModelType(PostgreSQLServerResource) diff --git a/src/spaceone/inventory/model/postgresql_servers/cloud_service_type.py b/src/spaceone/inventory/model/postgresql_servers/cloud_service_type.py deleted file mode 100644 index f9dc2a08..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/cloud_service_type.py +++ /dev/null @@ -1,226 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import ( - CardWidget, - ChartWidget, -) -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - TextDyField, - SearchField, - DateTimeDyField, - ListDyField, - EnumDyField, - SizeField, -) -from spaceone.inventory.libs.schema.cloud_service_type import ( - CloudServiceTypeResource, - CloudServiceTypeResponse, - CloudServiceTypeMeta, -) -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -postgresql_count_by_account_conf = os.path.join( - current_dir, "widget/postgresql_count_by_account.yaml" -) -postgresql_count_by_region_conf = os.path.join( - current_dir, "widget/postgresql_count_by_region.yaml" -) -postgresql_count_by_subscription_conf = os.path.join( - current_dir, "widget/postgresql_count_by_subscription.yaml" -) -postgresql_count_by_tier_conf = os.path.join( - current_dir, "widget/postgresql_count_by_tier.yaml" -) -postgresql_total_count_conf = os.path.join( - current_dir, "widget/postgresql_total_count.yaml" -) - -cst_postgre_sql_servers = CloudServiceTypeResource() -cst_postgre_sql_servers.name = "Server" -cst_postgre_sql_servers.group = "PostgreSQLServers" -cst_postgre_sql_servers.service_code = "Microsoft.DBforPostgreSQL/servers" -cst_postgre_sql_servers.labels = ["Database"] -cst_postgre_sql_servers.is_primary = True -cst_postgre_sql_servers.is_major = True -cst_postgre_sql_servers.tags = { - "spaceone:icon": f"{ASSET_URL}/azure-sql-postgresql-server.svg", -} - -cst_postgre_sql_servers._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source("Type", "instance_type"), - EnumDyField.data_source( - "Status", - "data.user_visible_state", - default_state={ - "safe": ["Ready"], - "warning": ["Disabled", "Dropping", "Inaccessible"], - }, - ), - TextDyField.data_source( - "Resource Group", "data.resource_group", options={"is_optional": True} - ), - TextDyField.data_source( - "Location", "data.location", options={"is_optional": True} - ), - TextDyField.data_source( - "Subscription Name", "data.subscription_name", options={"is_optional": True} - ), - TextDyField.data_source( - "Subscription ID", "account", options={"is_optional": True} - ), - TextDyField.data_source( - "Server Name", - "data.fully_qualified_domain_name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Admin Username", "data.administrator_login", options={"is_optional": True} - ), - TextDyField.data_source( - "PostgreSQL Version", "data.version", options={"is_optional": True} - ), - TextDyField.data_source( - "Performance Configuration Tier", - "instance_type", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Performance Configuration Name", - "data.sku.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Performance Configuration Capacity", - "data.sku.capacity", - options={"is_optional": True}, - ), - TextDyField.data_source( - "SSL Enforce Status", "data.ssl_enforcement", options={"is_optional": True} - ), - TextDyField.data_source( - "Public Network Access", - "data.public_network_access", - options={"is_optional": True}, - ), - TextDyField.data_source( - "SSL Enforcement", "data.ssl_enforcement", options={"is_optional": True} - ), - TextDyField.data_source( - "TLS Setting", "data.minimal_tls_version", options={"is_optional": True} - ), - TextDyField.data_source( - "Firewall Rule Name", - "data.firewall_rules.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Start IP", - "data.firewall_rules.start_ip_address", - options={"is_optional": True}, - ), - TextDyField.data_source( - "End IP", - "data.firewall_rules.end_ip_address", - options={"is_optional": True}, - ), - # VNet Rules - TextDyField.data_source( - "Virtual Network Rule Name", - "data.virtual_network_rules.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Virtual Network", - "data.virtual_network_rules.virtual_network_name_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Subnet", - "data.virtual_network_rules.subnet_name", - options={"is_optional": True}, - ), - # Replicas - TextDyField.data_source( - "Replicas Name", "data.replicas.name", options={"is_optional": True} - ), - TextDyField.data_source( - "Replicas Location", "data.replicas.location", options={"is_optional": True} - ), - TextDyField.data_source( - "Replicas Master Server Name", - "data.replicas.master_server_name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Active Directory Name", - "data.server_administrators.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Login", "data.server_administrators.login", options={"is_optional": True} - ), - TextDyField.data_source( - "SID", "data.server_administrators.sid", options={"is_optional": True} - ), - TextDyField.data_source( - "Tenant ID", - "data.server_administrators.tenant_id", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Compute Generation", "data.sku.name", options={"is_optional": True} - ), - TextDyField.data_source( - "Compute Tier", "instance_type", options={"is_optional": True} - ), - TextDyField.data_source( - "vCore", "data.sku.capacity", options={"is_optional": True} - ), - TextDyField.data_source( - "Backup Retention Period (Days)", - "data.storage_profile.backup_retention_days", - options={"is_optional": True}, - ), - ], - search=[ - SearchField.set(name="Subscription ID", key="account"), - SearchField.set(name="Subscription Name", key="data.subscription_name"), - SearchField.set(name="Resource Group", key="data.resource_group"), - SearchField.set(name="Location", key="data.location"), - SearchField.set(name="Server Name", key="data.fully_qualified_domain_name"), - SearchField.set(name="Admin Username", key="data.administrator_login"), - SearchField.set(name="PostgreSQL Version", key="data.version"), - SearchField.set(name="Performance Configuration Tier", key="instance_type"), - SearchField.set(name="Performance Configuration Name", key="data.sku.name"), - SearchField.set( - name="Performance Configuration Capacity", - key="data.sku.capacity", - data_type="integer", - ), - SearchField.set(name="SSL Enforce Status", key="data.ssl_enforcement"), - SearchField.set(name="SSL Enforcement", key="data.ssl_enforcement"), - SearchField.set(name="Public Network Access", key="data.public_network_access"), - SearchField.set(name="TLS Setting", key="data.minimal_tls_version"), - SearchField.set(name="Firewall Rule Name", key="data.firewall_rules.name"), - SearchField.set( - name="Firewall Rule Start IP", key="data.firewall_rules.start_ip_address" - ), - SearchField.set( - name="Firewall Rule End IP", key="data.firewall_rules.end_ip_address" - ), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(postgresql_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(postgresql_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(postgresql_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(postgresql_count_by_tier_conf)), - CardWidget.set(**get_data_from_yaml(postgresql_total_count_conf)), - ], -) - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({"resource": cst_postgre_sql_servers}), -] diff --git a/src/spaceone/inventory/model/postgresql_servers/data.py b/src/spaceone/inventory/model/postgresql_servers/data.py deleted file mode 100644 index f3b89c69..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/data.py +++ /dev/null @@ -1,409 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType, FloatType, DateTimeType -from spaceone.inventory.libs.schema.resource import AzureCloudService, AzureTags - - -class ResourceIdentity(Model): - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType(choices=('SystemAssigned', ''), serialize_when_none=False) - - -class PrivateEndpointProperty(Model): - id = StringType() - - -class PrivateLinkServiceConnectionStateProperty(Model): - actions_required = StringType(choices=('None', ''), serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(choices=('Approved', 'Disconnected', 'Pending', 'Rejected'), serialize_when_none=False) - - -class PrivateEndpointConnectionProperties(Model): - private_endpoint = ModelType(PrivateEndpointProperty, serialize_when_none=False) - private_link_service_connection_state = ModelType(PrivateLinkServiceConnectionStateProperty, - serialize_when_none=False) - provisioning_state = StringType(choices=('Approving', 'Dropping', 'Failed', 'Ready', 'Rejecting')) - - -class ServerPrivateEndpointConnection(Model): - id = StringType(serialize_when_none=False) - properties = ModelType(PrivateEndpointConnectionProperties) - - -class ServerAzureADAdministrator(Model): - id = StringType() - name = StringType(serialize_when_none=False) - administrator_type = StringType(choices=('ActiveDirectory', ''), serialize_when_none=False) - login = StringType(serialize_when_none=False) - sid = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - - -class AutomaticTuningServerOptions(Model): - actual_state = StringType(choices=('Off', 'On'), serialize_when_none=False) - desired_state = StringType(choices=('Default', 'Off', 'On'), serialize_when_none=False) - reason_code = IntType(serialize_when_none=False) - reason_desc = StringType(choices=('AutoConfigured', 'Default', 'Disabled'), serialize_when_none=False) - tuning_type = StringType(choices=('createIndex', 'dropIndex', 'forceLastGoodPlan'), serialize_when_none=False) - - -class ServerAutomaticTuning(Model): - name = StringType() - id = StringType() - actual_state = StringType(choices=('Auto', 'Custom', 'Unspecified'), serialize_when_none=False) - desired_state = StringType(choices=('Default', 'Off', 'On'), serialize_when_none=False) - options = ListType(ModelType(AutomaticTuningServerOptions, serialize_when_none=False)) - type = StringType(serialize_when_none=False) - - -class ServerBlobAuditingPolicy(Model): - name = StringType() - id = StringType() - audit_actions_and_groups = ListType(StringType, serialize_when_none=False) - is_azure_monitor_target_enabled = BooleanType(serialize_when_none=False) - is_storage_secondary_key_in_use = BooleanType(serialize_when_none=False) - queue_delay_ms = IntType(serialize_when_none=False) - retention_days = IntType(serialize_when_none=False) - state = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_account_access_key = StringType(serialize_when_none=False) - storage_account_subscription_id = StringType(serialize_when_none=False) - storage_endpoint = StringType(default='-') - type = StringType(serialize_when_none=False) - - -class PartnerInfo(Model): - id = StringType() - location = StringType() - replication_role = StringType(choices=('Primary', 'Secondary'), serialize_when_none=False) - - -class FailoverGroupReadOnlyEndpoint(Model): - failover_policy = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - - -class FailoverGroupReadWriteEndpoint(Model): - failover_policy = StringType(choices=('Automatic', 'Manual'), serialize_when_none=False) - failover_with_data_loss_grace_period_minutes = IntType(serialize_when_none=False) - - -class FailoverGroup(Model): - name = StringType(serialize_when_none=False) - id = StringType() - location = StringType() - databases = ListType(StringType, serialize_when_none=False) - partner_servers = ListType(ModelType(PartnerInfo), serialize_when_none=False) - primary_server = StringType(serialize_when_none=False) - secondary_server = StringType(serialize_when_none=False) - read_only_endpoint = ModelType(FailoverGroupReadOnlyEndpoint, serialize_when_none=False) - read_write_endpoint = ModelType(FailoverGroupReadWriteEndpoint, serialize_when_none=False) - replication_role = StringType(choices=('Primary', 'Secondary'), serialize_when_none=False) - replication_state = StringType(serialize_when_none=False) - failover_policy_display = StringType(serialize_when_none=False) - grace_period_display = StringType(serialize_when_none=False) - tags = ListType(ModelType(AzureTags)) - type = StringType(serialize_when_none=False) - - -class SyncGroupSchemaColumn(Model): - data_size = StringType(serialize_when_none=False) - data_type = StringType(serialize_when_none=False) - quoted_name = StringType(serialize_when_none=False) - - -class SyncGroupSchemaTable(Model): - columns = ListType(ModelType(SyncGroupSchemaColumn), serialize_when_none=False) - quoted_name = StringType(serialize_when_none=False) - - -class SyncGroupSchema(Model): - master_sync_member_name = StringType(serialize_when_none=False) - tables = ListType(ModelType(SyncGroupSchemaTable), serialize_when_none=False) - - -class SyncGroup(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - conflict_resolution_policy = StringType(choices=('HubWin', 'MemberWin'), serialize_when_none=False) - hub_database_password = StringType(serialize_when_none=False) - hub_database_user_name = StringType(serialize_when_none=False) - interval = IntType(serialize_when_none=False) - last_sync_time = DateTimeType(serialize_when_none=False) - schema = ModelType(SyncGroupSchema, serialize_when_none=False) - sync_database_id = StringType(serialize_when_none=False) - sync_state = StringType(choices=('Error', 'Good', 'NotReady', 'Progressing', 'Warning'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class SyncAgent(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - expiry_time = StringType(serialize_when_none=False) - is_up_to_date = BooleanType(serialize_when_none=False) - last_alive_time = StringType(serialize_when_none=False) - state = StringType(choices=('NeverConnected', 'Offline', 'Online'), serialize_when_none=False) - sync_database_id = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class RetentionPolicy(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class LogSettings(Model): - category = StringType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - retention_policy = ModelType(RetentionPolicy) - - -class MetricSettings(Model): - category = StringType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - retention_policy = ModelType(RetentionPolicy) - time_grain = StringType(serialize_when_none=False) - - -class DiagnosticSettingsResource(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - event_hub_authorization_rule_id = StringType(serialize_when_none=False) - event_hub_name = StringType(serialize_when_none=False) - log_analytics_destination_type = StringType(serialize_when_none=False) - logs = ListType(ModelType(LogSettings), serialize_when_none=False) - metrics = ListType(ModelType(MetricSettings), serialize_when_none=False) - service_bus_rule_id = StringType(serialize_when_none=False) - storage_account_id = StringType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ReplicationLink(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - is_termination_allowed = BooleanType(serialize_when_none=False) - partner_database = StringType(serialize_when_none=False) - partner_location = StringType(serialize_when_none=False) - partner_role = StringType(choices=('Copy', 'NonReadableSecondary', 'Primary', 'Secondary', 'Source'), serialize_when_none=False) - partner_server = StringType(default='-') - percent_complete = IntType(serialize_when_none=False) - replication_mode = StringType(serialize_when_none=False) - replication_state = StringType(choices=('CATCH_UP', 'PENDING', 'SEEDING', 'SUSPENDED'), serialize_when_none=False) - role = StringType(choices=('Copy', 'NonReadableSecondary', 'Primary', 'Secondary', 'Source'), serialize_when_none=False) - start_time = DateTimeType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Sku(Model): - capacity = IntType(serialize_when_none=False) - family = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - size = StringType(serialize_when_none=False) - tier = StringType(serialize_when_none=False) - - -class Database(Model): - name = StringType(serialize_when_none=False) - id = StringType() - kind = StringType(serialize_when_none=False) - location = StringType() - managed_by = StringType(serialize_when_none=False) - server_name = StringType(serialize_when_none=False) - subscription_id = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - - administrator_login = StringType(default='-') - auto_pause_delay = IntType(serialize_when_none=False) - catalog_collation = StringType(choices=('DATABASE_DEFAULT', 'SQL_Latin1_General_CP1_CI_AS'), - serialize_when_none=False) - collation = StringType(serialize_when_none=False) - create_mode = StringType(choices=( - 'Copy', 'Default', 'OnlineSecondary', 'PointInTimeRestore', 'Recovery', 'Restore', 'RestoreExternalBackup', - 'RestoreExternalBackupSecondary', 'RestoreLongTermRetentionBackup', 'Secondary'), serialize_when_none=False) - creation_date = DateTimeType(serialize_when_none=False) - current_service_objective_name = StringType(serialize_when_none=False) - current_sku = ModelType(Sku, serialize_when_none=False) - database_id = StringType(serialize_when_none=False) - default_secondary_location = StringType(serialize_when_none=False) - earliest_restore_date = DateTimeType(serialize_when_none=False) - elastic_pool_id = StringType(serialize_when_none=False) - failover_group_id = StringType(serialize_when_none=False) - high_availability_replica_count = IntType(serialize_when_none=False) - license_type = StringType(choices=('BasePrice', 'LicenseIncluded'), serialize_when_none=False) - long_term_retention_backup_resource_id = StringType(default='-') - maintenance_configuration_id = StringType(serialize_when_none=False) - max_log_size_bytes = IntType(serialize_when_none=False) - max_size_bytes = IntType(serialize_when_none=False) - max_size_gb = FloatType(serialize_when_none=False) - min_capacity = FloatType(serialize_when_none=False) - paused_date = DateTimeType(serialize_when_none=False) - read_scale = StringType(choices=('Disabled', 'Enabled'), default='Disabled') - recoverable_database_id = StringType(serialize_when_none=False) - recovery_services_recovery_point_id = StringType(serialize_when_none=False) - requested_service_objective_name = StringType(serialize_when_none=False) - restorable_dropped_database_id = StringType(serialize_when_none=False) - restore_point_in_time = StringType(serialize_when_none=False) - resumed_date = DateTimeType(serialize_when_none=False) - sample_name = StringType(choices=('AdventureWorksLT', 'WideWorldImportersFull', 'WideWorldImportersStd'), - serialize_when_none=False) - secondary_type = StringType(choices=('Geo', 'Named'), serialize_when_none=False) - source_database_deletion_date = StringType(serialize_when_none=False) - source_database_id = StringType(serialize_when_none=False) - status = StringType(choices=( - 'AutoClosed', 'Copying', 'Creating', 'Disabled', 'EmergencyMode', 'Inaccessible', 'Offline', - 'OfflineChangingDwPerformanceTiers', 'OfflineSecondary', 'Online', - 'OnlineChangingDwPerformanceTiers', 'Paused', 'Pausing', 'Recovering', 'RecoveryPending', 'Restoring', - 'Resuming', 'Scaling', 'Shutdown', 'Standby', 'Suspect'), serialize_when_none=False) - storage_account_type = StringType(choices=('GRS', 'LRS', 'ZRS'), serialize_when_none=False) - zone_redundant = BooleanType(serialize_when_none=False) - diagnostic_settings_resource = ListType(ModelType(DiagnosticSettingsResource), serialize_when_none=False) - replication_link = ListType(ModelType(ReplicationLink), serialize_when_none=False) - sync_group = ListType(ModelType(SyncGroup), serialize_when_none=False) - sync_agent = ListType(ModelType(SyncAgent), serialize_when_none=False) - sync_group_display = ListType(StringType, serialize_when_none=False) - sync_agent_display = ListType(StringType, serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - pricing_tier_display = StringType(default='-') - service_tier_display = StringType(default='-') - compute_tier = StringType(serialize_when_none=False) - tags = ListType(ModelType(AzureTags)) - type = StringType(serialize_when_none=False) - - -class ElasticPoolPerDatabaseSettings(Model): - max_capacity = FloatType(serialize_when_none=False) - min_capacity = FloatType(serialize_when_none=False) - - -class ElasticPool(Model): - name = StringType(serialize_when_none=False) - id = StringType() - kind = StringType(serialize_when_none=False) - location = StringType() - creation_date = DateTimeType(serialize_when_none=False) - license_type = StringType(choices=('BasePrice', 'LicenseIncluded'), default='BasePrice') - maintenance_configuration_id = StringType(serialize_when_none=False) - max_size_bytes = IntType(serialize_when_none=False) - max_size_gb = FloatType(serialize_when_none=False, default=0) - per_database_settings = ModelType(ElasticPoolPerDatabaseSettings, serialize_when_none=False) - state = StringType(choices=('Creating', 'Disabled', 'Ready'), serialize_when_none=False) - zone_redundant = BooleanType(serialize_when_none=False) - sku = ModelType(Sku) - per_db_settings_display = StringType(serialize_when_none=False) - pricing_tier_display = StringType(serialize_when_none=False) - databases = ListType(ModelType(Database)) - number_of_databases = IntType(serialize_when_none=False, default=0) - unit_display = StringType(serialize_when_none=False), - server_name_display = StringType(serialize_when_none=False) - resource_group_display = StringType(serialize_when_none=False) - tags = ModelType(AzureTags) - type = StringType(serialize_when_none=False) - - -class EncryptionProtector(Model): - id = StringType() - kind = StringType(serialize_when_none=False) - location = StringType() - name = StringType() - server_key_name = StringType(serialize_when_none=False) - server_key_type = StringType(choices=('AzureKeyVault', 'ServiceManaged'), default='ServiceManaged') - subregion = StringType(serialize_when_none=False) - thumbprint = StringType(serialize_when_none=False) - uri = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class RestorableDroppedDatabase(Model): - name = StringType(serialize_when_none=False) - id = StringType() - location = StringType() - creation_date = DateTimeType(serialize_when_none=False) - database_name = StringType(serialize_when_none=False) - deletion_date = DateTimeType(serialize_when_none=False) - earliest_restore_date = DateTimeType(serialize_when_none=False) - edition = StringType(serialize_when_none=False) - elastic_pool_name = StringType(default='-') - max_size_bytes = StringType(serialize_when_none=False) - service_level_objective = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class VirtualNetworkRule(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - ignore_missing_vnet_service_endpoint = BooleanType(serialize_when_none=False) - state = StringType(choices=('Deleting', 'InProgress', 'Initializing', 'Ready', 'Unknown'), serialize_when_none=False) - virtual_network_subnet_id = StringType(serialize_when_none=False) - subnet_name = StringType(serialize_when_none=False) - virtual_network_name_display = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class FirewallRule(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - end_ip_address = StringType(serialize_when_none=False) - start_ip_address = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class StorageProfile(Model): - backup_retention_days = IntType(serialize_when_none=False) - geo_redundant_backup = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_autogrow = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_mb = IntType(serialize_when_none=False) - - -class ReplicaServer(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - location = StringType(serialize_when_none=False) - user_visible_state = StringType(choices=('Disabled', 'Dropping', 'Inaccessible', 'Ready'), serialize_when_none=False) - master_server_name = StringType(serialize_when_none=False) - - -class ServerAdministratorResource(Model): - id = StringType() - name = StringType() - administrator_type = StringType(serialize_when_none=False) - login = StringType(serialize_when_none=False) - sid = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PostgreSQLServer(AzureCloudService): # Main Class - name = StringType() - id = StringType() - identity = ModelType(ResourceIdentity, serialize_when_none=False) - location = StringType() - administrator_login = StringType(serialize_when_none=False) - byok_enforcement = StringType(serialize_when_none=False) - earliest_restore_date = DateTimeType(serialize_when_none=False) - firewall_rules = ListType(ModelType(FirewallRule), serialize_when_none=False) - fully_qualified_domain_name = StringType(serialize_when_none=False) - infrastructure_encryption = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - master_server_id = StringType(serialize_when_none=False) - minimal_tls_version = StringType(serialize_when_none=False) - private_endpoint_connections = ListType(ModelType(ServerPrivateEndpointConnection)) - public_network_access = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - replica_capacity = IntType(serialize_when_none=False) - replication_role = StringType(serialize_when_none=False) - replicas = ListType(ModelType(ReplicaServer), serialize_when_none=False) - server_administrators = ListType(ModelType(ServerAdministratorResource), serialize_when_none=False) - ssl_enforcement = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_profile = ModelType(StorageProfile, serialize_when_none=False) - user_visible_state = StringType(choices=('Disabled', 'Dropping', 'Inaccessible', 'Ready'), serialize_when_none=False) - version = StringType(serialize_when_none=False) - virtual_network_rules = ListType(ModelType(VirtualNetworkRule), serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_account.yaml b/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_account.yaml deleted file mode 100644 index 6ffda7de..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: PostgreSQLServers -cloud_service_type: Server -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_region.yaml b/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_region.yaml deleted file mode 100644 index 9d01fbf0..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: PostgreSQLServers -cloud_service_type: Server -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_subscription.yaml b/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_subscription.yaml deleted file mode 100644 index ed595b76..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: PostgreSQLServers -cloud_service_type: Server -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_tier.yaml b/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_tier.yaml deleted file mode 100644 index d5d3a630..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_count_by_tier.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: PostgreSQLServers -cloud_service_type: Server -name: Inbound Count by Tier -query: - aggregate: - - group: - keys: - - name: name - key: data.user_visible_state - fields: - - name: value - key: data.user_visible_state - operator: count -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_total_count.yaml b/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_total_count.yaml deleted file mode 100644 index 7424eece..00000000 --- a/src/spaceone/inventory/model/postgresql_servers/widget/postgresql_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: PostgreSQLServers -cloud_service_type: Server -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/public_ip_addresses/__init__.py b/src/spaceone/inventory/model/public_ip_addresses/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/public_ip_addresses/cloud_service.py b/src/spaceone/inventory/model/public_ip_addresses/cloud_service.py deleted file mode 100644 index bd81bd30..00000000 --- a/src/spaceone/inventory/model/public_ip_addresses/cloud_service.py +++ /dev/null @@ -1,64 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, DateTimeType, FloatType - -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField, SizeField, StateItemDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.public_ip_addresses.data import PublicIPAddress - -''' -PUBLIC_IP_ADDRESS -''' -# TAB - Default -public_ip_address_meta = ItemDynamicLayout.set_fields('Public IP Address', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('SKU', 'instance_type'), - TextDyField.data_source('Tier', 'data.sku.tier'), - TextDyField.data_source('IP Address', 'data.ip_address'), - TextDyField.data_source('DNS Name', 'data.dns_settings.fqdn'), - TextDyField.data_source('Associated To', 'data.associated_to') - # TextDyField.data_source('Routing Preference', ''), - -]) - -# TAB - Configuration -public_ip_address_configuration = ItemDynamicLayout.set_fields('Configuration', fields=[ - TextDyField.data_source('IP Address Assignment', 'data.public_ip_allocation_method'), - TextDyField.data_source('Idle Timeout(Minutes)', 'data.idle_timeout_in_minutes'), - TextDyField.data_source('DNS Name Label(Optional)', 'data.dns_settings.domain_name_label') -]) - -# TAB - Alias Record Sets TODO: Find Alias information API -public_ip_address_alias_record_sets = TableDynamicLayout.set_fields('Alias Record Sets', fields=[ - TextDyField.data_source('Subscription', ''), - TextDyField.data_source('DNS Zone', ''), - TextDyField.data_source('Name', ''), - TextDyField.data_source('Type', ''), - TextDyField.data_source('TTL', '') -]) - -public_addresses_meta = CloudServiceMeta.set_layouts([public_ip_address_meta, public_ip_address_configuration]) - - -class NetworkResource(CloudServiceResource): - cloud_service_group = StringType(default='PublicIPAddresses') - - -class PublicIPAddressResource(NetworkResource): - cloud_service_type = StringType(default='IPAddress') - data = ModelType(PublicIPAddress) - _metadata = ModelType(CloudServiceMeta, default=public_addresses_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class PublicIPAddressResponse(CloudServiceResponse): - resource = PolyModelType(PublicIPAddressResource) diff --git a/src/spaceone/inventory/model/public_ip_addresses/cloud_service_type.py b/src/spaceone/inventory/model/public_ip_addresses/cloud_service_type.py deleted file mode 100644 index 08cbd2d5..00000000 --- a/src/spaceone/inventory/model/public_ip_addresses/cloud_service_type.py +++ /dev/null @@ -1,90 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -public_ip_address_count_by_account_conf = os.path.join(current_dir, 'widget/public_ip_addresses_count_by_account.yaml') -public_ip_address_count_by_region_conf = os.path.join(current_dir, 'widget/public_ip_addresses_count_by_region.yaml') -public_ip_address_count_by_subscription_conf = os.path.join(current_dir, - 'widget/public_ip_addresses_count_by_subscription.yaml') -public_ip_address_total_count_conf = os.path.join(current_dir, 'widget/public_ip_addresses_total_count.yaml') - - -cst_public_ip_addresses = CloudServiceTypeResource() -cst_public_ip_addresses.name = 'IPAddress' -cst_public_ip_addresses.group = 'PublicIPAddresses' -cst_public_ip_addresses.service_code = 'Microsoft.Network/publicIPAddresses' -cst_public_ip_addresses.labels = ['Networking'] -cst_public_ip_addresses.is_major = True -cst_public_ip_addresses.is_primary = True -cst_public_ip_addresses.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-public-ip-address.svg', -} - -cst_public_ip_addresses._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Associated To', 'data.associated_to'), - - # is_optional fields - Default - TextDyField.data_source('Subscription ID', 'account', options={ - 'is_optional': True - }), - TextDyField.data_source('SKU', 'instance_type', options={ - 'is_optional': True - }), - TextDyField.data_source('Tier', 'data.sku.tier', options={ - 'is_optional': True - }), - TextDyField.data_source('IP Address', 'data.ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('DNS Name', 'data.dns_settings.fqdn', options={ - 'is_optional': True - }), - - # is_optional fields - Configuration - TextDyField.data_source('IP Address Assignment', 'data.public_ip_allocation_method', options={ - 'is_optional': True - }), - TextDyField.data_source('Idle Timeout(Minutes)', 'data.idle_timeout_in_minutes', options={ - 'is_optional': True - }), - TextDyField.data_source('DNS Name Label(Optional)', 'data.dns_settings.domain_name_label', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='SKU', key='instance_type'), - SearchField.set(name='Tier', key='data.sku.tier'), - SearchField.set(name='IP Address', key='data.ip_address'), - SearchField.set(name='DNS Name', key='data.dns_settings.fqdn'), - SearchField.set(name='IP Address Assignment', key='data.public_ip_allocation_method'), - SearchField.set(name='Idle Timeout(Minutes)', key='data.idle_timeout_in_minutes', data_type='integer'), - SearchField.set(name='DNS Name Label(Optional)', key='data.dns_settings.domain_name_label'), - SearchField.set(name='Associated To', key='data.associated_to') - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(public_ip_address_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(public_ip_address_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(public_ip_address_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(public_ip_address_total_count_conf)) - ] -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_public_ip_addresses}), -] diff --git a/src/spaceone/inventory/model/public_ip_addresses/data.py b/src/spaceone/inventory/model/public_ip_addresses/data.py deleted file mode 100644 index 7dc89db3..00000000 --- a/src/spaceone/inventory/model/public_ip_addresses/data.py +++ /dev/null @@ -1,122 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType, DateTimeType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Tags(Model): - key = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class SubResource(Model): - id = StringType() - - -class ExtendedLocation(Model): - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class DdosSettings(Model): - ddos_custom_policy = ModelType(SubResource, serialize_when_none=False) - protected_ip = BooleanType(serialize_when_none=False) - protection_coverage = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - - -class PublicIPAddressDnsSettings(Model): - domain_name_label = StringType(default='-') - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class NetworkInterface(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - dscp_configuration = ModelType(SubResource, serialize_when_none=False) - enable_accelerated_networking = BooleanType(serialize_when_none=False) - enable_ip_forwarding = BooleanType(serialize_when_none=False) - migration_phase = StringType(choices=('Abort', 'Commit', 'Committed', 'None', 'Prepare'), serialize_when_none=False) - nic_type = StringType(choices=('Elastic', 'Standard'), serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - virtual_machine = ModelType(SubResource, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class IPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = StringType(serialize_when_none=False) - network_interface = ModelType(NetworkInterface, serialize_when_none=False) - - -class IpTag(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class NatGatewaySku(Model): - name = StringType(choices=('Standard', None), serialize_when_none=False) - - -class NatGateway(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_addresses = ListType(ModelType(SubResource), serialize_when_none=False) - public_ip_prefixes = ListType(ModelType(SubResource), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - subnets = ListType(ModelType(SubResource), serialize_when_none=False) - sku = ModelType(NatGatewaySku, serialize_when_none=False) - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PublicIPAddressSku(Model): - name = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - tier = StringType(choices=('Global', 'Regional'), serialize_when_none=False) - - -class PublicIPAddress(AzureCloudService): # Main Class - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettings, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = ModelType(IPConfiguration, serialize_when_none=False) - associated_to = StringType(serialize_when_none=False) - ip_tags = ListType(ModelType(IpTag), serialize_when_none=False) - # linked_public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - migration_phase = StringType(choices=('Abort', 'Commit', 'Committed', 'None', 'Prepare'), serialize_when_none=False) - nat_gateway = ModelType(NatGateway, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSku, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_account.yaml b/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_account.yaml deleted file mode 100644 index e1b078fa..00000000 --- a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: PublicIPAddresses -cloud_service_type: IPAddress -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_region.yaml b/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_region.yaml deleted file mode 100644 index 01d9e676..00000000 --- a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: PublicIPAddresses -cloud_service_type: IPAddress -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_subscription.yaml b/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_subscription.yaml deleted file mode 100644 index 8674c7d6..00000000 --- a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: PublicIPAddresses -cloud_service_type: IPAddress -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_total_count.yaml b/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_total_count.yaml deleted file mode 100644 index fef59547..00000000 --- a/src/spaceone/inventory/model/public_ip_addresses/widget/public_ip_addresses_total_count.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -cloud_service_group: PublicIPAddresses -cloud_service_type: IPAddress -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - key: region_code - operator: count diff --git a/src/spaceone/inventory/model/snapshots/__init__.py b/src/spaceone/inventory/model/snapshots/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/snapshots/cloud_service.py b/src/spaceone/inventory/model/snapshots/cloud_service.py deleted file mode 100644 index 5f6dfc3e..00000000 --- a/src/spaceone/inventory/model/snapshots/cloud_service.py +++ /dev/null @@ -1,53 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.model.snapshots.data import Snapshot -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, ListDyField, SizeField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta - -''' -SNAPSHOT -''' -# TAB - Default -snapshot_info_meta = ItemDynamicLayout.set_fields('Snapshots', fields=[ - - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Storage Type', 'instance_type'), - SizeField.data_source('Size', 'data.size'), - TextDyField.data_source('Source Disk', 'data.source_disk_name'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - EnumDyField.data_source('Snapshot state', 'data.disk_state', default_state={ - 'safe': ['ActiveSAS', 'ActiveUpload', 'Attached', 'Reserved'], - 'warning': ['ReadyToUpload'], - 'available': ['Unattached'] - }), - TextDyField.data_source('Snapshot Type', 'data.incremental_display'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Encryption Type', 'data.encryption.type_display'), - TextDyField.data_source('Network Access Policy', 'data.network_access_policy_display'), - DateTimeDyField.data_source('Created Time', 'launched_at') -]) - -snapshot_meta = CloudServiceMeta.set_layouts([snapshot_info_meta]) - - -class ComputeResource(CloudServiceResource): - cloud_service_group = StringType(default='Snapshots') - - -class SnapshotResource(ComputeResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(Snapshot) - _metadata = ModelType(CloudServiceMeta, default=snapshot_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class SnapshotResponse(CloudServiceResponse): - resource = PolyModelType(SnapshotResource) diff --git a/src/spaceone/inventory/model/snapshots/cloud_service_type.py b/src/spaceone/inventory/model/snapshots/cloud_service_type.py deleted file mode 100644 index ed5dac76..00000000 --- a/src/spaceone/inventory/model/snapshots/cloud_service_type.py +++ /dev/null @@ -1,79 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField, SizeField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -snapshots_count_by_account_conf = os.path.join(current_dir, 'widget/snapshots_count_by_account.yaml') -snapshots_count_by_region_conf = os.path.join(current_dir, 'widget/snapshots_count_by_region.yaml') -snapshots_count_by_resource_group_conf = os.path.join(current_dir, 'widget/snapshots_count_by_resource_group.yaml') -snapshots_count_by_subscription_conf = os.path.join(current_dir, 'widget/snapshots_count_by_subscription.yaml') -snapshots_total_count_conf = os.path.join(current_dir, 'widget/snapshots_total_count.yaml') -snapshots_total_size_conf = os.path.join(current_dir, 'widget/snapshots_total_size.yaml') - - -cst_snapshots = CloudServiceTypeResource() -cst_snapshots.name = 'Instance' -cst_snapshots.group = 'Snapshots' -cst_snapshots.service_code = 'Microsoft.Compute/snapshots' -cst_snapshots.labels = ['Compute', 'Storage'] -cst_snapshots.is_primary = True -cst_snapshots.is_major = True -cst_snapshots.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-disk-snapshot.svg', -} - -cst_snapshots._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Source disk', 'data.source_disk_name'), - TextDyField.data_source('Snapshot type', 'data.incremental_display'), - SizeField.data_source('Source disk size', 'data.disk_size_bytes'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - DateTimeDyField.data_source('Launched', 'data.time_created'), - - # is_optional fields - Default - TextDyField.data_source('Subscription ID', 'account', options={ - 'is_optional': True - }), - TextDyField.data_source('Encryption Type', 'data.encryption.type_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Network Access Policy', 'data.network_access_policy_display', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Storage Account Type', key='instance_type'), - SearchField.set(name='Snapshot Type', key='data.incremental_display'), - SearchField.set(name='Disk Size (Bytes)', key='data.disk_size_bytes'), - SearchField.set(name='Disk Size (GB)', key='instance_size', data_type='float'), - SearchField.set(name='Encryption', key='data.encryption.type_display'), - SearchField.set(name='Network Access Policy', key='data.network_access_policy'), - SearchField.set(name='Provisioning State', key='data.provisioning_state'), - SearchField.set(name='Launched', key='data.time_created', data_type='datetime') - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(snapshots_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(snapshots_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(snapshots_count_by_resource_group_conf)), - ChartWidget.set(**get_data_from_yaml(snapshots_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(snapshots_total_count_conf)), - CardWidget.set(**get_data_from_yaml(snapshots_total_size_conf)) - ] -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_snapshots}), -] diff --git a/src/spaceone/inventory/model/snapshots/data.py b/src/spaceone/inventory/model/snapshots/data.py deleted file mode 100644 index a8d352cc..00000000 --- a/src/spaceone/inventory/model/snapshots/data.py +++ /dev/null @@ -1,131 +0,0 @@ -from schematics import Model -from schematics.types import ( - ModelType, - ListType, - StringType, - DateTimeType, - IntType, - BooleanType, -) -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Sku(Model): - name = StringType( - choices=("Standard_LRS", "Premium_LRS", "StandardSSD_LRS", "UltraSSD_LRS"), - serialize_when_none=False, - ) - tier = StringType(choices=("Premium", "Standard"), serialize_when_none=False) - - -class ImageDiskReference(Model): - id = StringType(serialize_when_none=False) - Lun = IntType(serialize_when_none=False) - - -class CreationData(Model): - creation_option = StringType( - choices=("Attach", "Copy", "Empty", "FromImage", "Import", "Restore", "Upload"), - serialize_when_none=False, - ) - image_reference = ModelType(ImageDiskReference, serialize_when_none=False) - gallery_image_reference = ModelType(ImageDiskReference, serialize_when_none=False) - logical_sector_size = IntType(serialize_when_none=False) - source_resource_id = StringType() - source_uri = StringType(serialize_when_none=False) - source_unique_id = StringType(serialize_when_none=False) - storage_account_id = StringType(serialize_when_none=False) - upload_size_bytes = IntType(serialize_when_none=False) - - -class SourceVault(Model): - id = StringType(serialize_when_none=False) - - -class DiskEncryptionKey(Model): - source_vault = ModelType(SourceVault, serialize_when_none=False) - secret_url = StringType(serialize_when_none=False) - - -class KeyEncryptionKey(Model): - source_vault = ModelType(SourceVault) - key_url = StringType() - - -class EncryptionSettingsCollection(Model): - disk_encryption_key = ModelType(DiskEncryptionKey, serialize_when_none=False) - key_encryption_key = ModelType(KeyEncryptionKey, serialize_when_none=False) - - -class Encryption(Model): - disk_encryption_set_id = StringType(default="", serialize_when_none=False) - type = StringType( - choices=( - "EncryptionAtRestWithCustomerKey", - "EncryptionAtRestWithPlatformAndCustomerKeys", - "EncryptionAtRestWithPlatformKey", - ), - default="EncryptionAtRestWithPlatformKey", - serialize_when_none=False, - ) - type_display = StringType() - - -class ShareInfoElement(Model): - vm_uri = StringType(serialize_when_none=False) - - -class SupportedCapabilities(Model): - architecture = StringType(serialize_when_none=False) - - -class Snapshot(AzureCloudService): - id = StringType() - location = StringType() - managed_by = StringType(serialize_when_none=False) - name = StringType() - creation_data = ModelType(CreationData) - disk_access_id = StringType(serialize_when_none=False) - disk_iops_read_write = StringType(serialize_when_none=False) - disk_m_bps_read_write = StringType(serialize_when_none=False) - disk_size_bytes = IntType() - disk_size_gb = IntType() - disk_state = StringType( - choices=( - "ActiveSAS", - "ActiveUpload", - "Attached", - "ReadyToUpload", - "Reserved", - "Unattached", - ) - ) - encryption = ModelType(Encryption) - encryption_settings_collection = ModelType( - EncryptionSettingsCollection, serialize_when_none=False - ) - hyper_v_generation = StringType(serialize_when_none=False) - incremental = BooleanType() - incremental_display = StringType(default="Full", serialize_when_none=False) - network_access_policy = StringType( - choices=("AllowAll", "AllowPrivate", "DenyAll"), serialize_when_none=False - ) - network_access_policy_display = StringType(serialize_when_none=False) - os_type = StringType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Failed", "Succeeded"), serialize_when_none=False - ) - time_created = DateTimeType(serialize_when_none=False) - unique_id = StringType() - size = IntType() - sku = ModelType(Sku) - source_disk_name = StringType() - supported_capabilities = ModelType(SupportedCapabilities, serialize_when_none=False) - tier_display = StringType(default="") - type = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_account.yaml b/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_account.yaml deleted file mode 100644 index d33c035d..00000000 --- a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: Snapshots -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_region.yaml b/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_region.yaml deleted file mode 100644 index ee19971c..00000000 --- a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: Snapshots -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_resource_group.yaml b/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_resource_group.yaml deleted file mode 100644 index 098504b4..00000000 --- a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_resource_group.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: Snapshots -cloud_service_type: Instance -name: Snapshots Count by Resource Group -query: - aggregate: - - group: - keys: - - name: name - key: data.resource_group - fields: - - name: value - key: data.resource_group - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_subscription.yaml b/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_subscription.yaml deleted file mode 100644 index 908e36b1..00000000 --- a/src/spaceone/inventory/model/snapshots/widget/snapshots_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: Snapshots -cloud_service_type: Instance -name: Snapshots Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/snapshots/widget/snapshots_total_count.yaml b/src/spaceone/inventory/model/snapshots/widget/snapshots_total_count.yaml deleted file mode 100644 index b7083bf2..00000000 --- a/src/spaceone/inventory/model/snapshots/widget/snapshots_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: Snapshots -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/snapshots/widget/snapshots_total_size.yaml b/src/spaceone/inventory/model/snapshots/widget/snapshots_total_size.yaml deleted file mode 100644 index a74e7139..00000000 --- a/src/spaceone/inventory/model/snapshots/widget/snapshots_total_size.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: Snapshots -cloud_service_type: Instance -name: Total Size -query: - aggregate: - - group: - fields: - - name: value - key: data.disk_size_gb - operator: sum -options: - value_options: - key: value - type: size - options: - default: 0 - source_unit: GB \ No newline at end of file diff --git a/src/spaceone/inventory/model/sql_databases/__init__.py b/src/spaceone/inventory/model/sql_databases/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/sql_databases/cloud_service.py b/src/spaceone/inventory/model/sql_databases/cloud_service.py deleted file mode 100644 index 497a94eb..00000000 --- a/src/spaceone/inventory/model/sql_databases/cloud_service.py +++ /dev/null @@ -1,142 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.model.sql_databases.data import * -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta - -''' -SQL DATABASES -''' - -# TAB - Default -# Resource Group, Location, Subscription, Subscription ID, SKU, Backend pool, Health probe, -# Load balancing rule, NAT Rules, Public IP Addresses, Load Balancing Type -sql_databases_info_meta = ItemDynamicLayout.set_fields('SQL Databases', fields=[ - TextDyField.data_source('Database Name', 'name'), - EnumDyField.data_source('Status', 'data.status', default_state={ - 'safe': ['Online', 'Creating', 'Copying', 'Creating', 'OnlineChangingDwPerformanceTiers', 'Restoring', - 'Resuming', 'Scaling', 'Standby'], - 'warning': ['AutoClosed', 'Inaccessible', 'Offline', 'OfflineChangingDwPerformanceTiers', 'OfflineSecondary', - 'Pausing', 'Recovering', 'RecoveryPending', 'Suspect'], - 'disable': ['Disabled', 'Paused', 'Shutdown'], - 'alert': ['EmergencyMode'] - }), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Server Name', 'data.server_name'), - TextDyField.data_source('Elastic Pool', 'data.elastic_pool_id'), - TextDyField.data_source('Pricing Tier', 'data.pricing_tier_display'), - DateTimeDyField.data_source('Earliest Restore Point', 'data.earliest_restore_date'), - TextDyField.data_source('Collation', 'data.collation'), - DateTimeDyField.data_source('Creation Date', 'launched_at'), - TextDyField.data_source('Server Admin Login', 'data.administrator_login'), - -]) - -# TAB - Configure -sql_databases_configure = ItemDynamicLayout.set_fields('Configure', fields=[ - TextDyField.data_source('Service Tier', 'data.service_tier_display'), - TextDyField.data_source('Compute Tier', 'data.compute_tier'), - TextDyField.data_source('Compute Hardware', 'data.sku.family'), - TextDyField.data_source('Licence Type', 'data.license_type'), - TextDyField.data_source('vCores', 'data.current_sku.capacity'), - TextDyField.data_source('Data max size', 'instance_size'), - TextDyField.data_source('Zone Redundant', 'data.zone_redundant'), - ListDyField.data_source('Sync Groups', 'data.sync_group_display'), - ListDyField.data_source('Sync Agents', 'data.sync_agent_display'), - TextDyField.data_source('Collation', 'data.collation'), - DateTimeDyField.data_source('Creation Date', 'data.creation_date') -]) - - -# TAB - Backups -# Database, Earliest PITR restore point (UTC), Available LTR backups -sql_databases_backups = TableDynamicLayout.set_fields('Backups', 'data', fields=[ - TextDyField.data_source('Database', 'name'), - TextDyField.data_source('Earliest PITR Restore Point (UTC)', 'earliest_restore_date'), - TextDyField.data_source('Available LTR backups', 'long_term_retention_backup_resource_id'), -]) - -# TAB - Replication -sql_databases_replication = TableDynamicLayout.set_fields('Replicas', 'data.replication_link', fields=[ - TextDyField.data_source('Name', 'partner_database'), - TextDyField.data_source('linkType', 'link_type'), - TextDyField.data_source('Region', 'partner_location'), - TextDyField.data_source('Replica state', 'replica_state'), -]) - -# TAB - Maintenance -sql_databases_maintenance = ItemDynamicLayout.set_fields('Maintenance', 'data', fields=[ - -]) - -# TAB - Sync to other databases - Sync database -sql_databases_sync_to_other_databases_sync_database = TableDynamicLayout.set_fields('Sync Group', 'data.sync_group', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Status', 'sync_state'), - TextDyField.data_source('Use private link', 'use_private_link_connection'), - TextDyField.data_source('Automatic Sync', 'automatic_sync'), - TextDyField.data_source('Conflict Resolution', 'conflict_resolution_policy'), - TextDyField.data_source('Interval', 'interval') - -]) -# TAB - Sync to other databases - Sync Agent -sql_databases_sync_to_other_databases_sync_agent = TableDynamicLayout.set_fields('Sync Agent', 'data.sync_agent', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Status', 'state'), - TextDyField.data_source('version', 'version') -]) - -# TAB - Sync to other databases -sql_databases_sync_to_other_databases_info = ListDynamicLayout.set_layouts('Sync to other databases', layouts=[ - sql_databases_sync_to_other_databases_sync_database, sql_databases_sync_to_other_databases_sync_agent -]) - -# TAB - Auditing -sql_servers_auditing = ItemDynamicLayout.set_fields('Auditing', 'data.database_auditing_settings', fields=[ - EnumDyField.data_source('Enable SQL Auditing', 'state', default_state={ - 'safe': ['Enabled'], - 'warning': ['Disabled'] - }), - TextDyField.data_source('Audit Log Destination', 'storage_endpoint'), - TextDyField.data_source('Storage Account ID', 'storage_account_subscription_id'), - TextDyField.data_source('Retention days', 'retention_days'), - TextDyField.data_source('Secondary Storage access key used', 'is_storage_secondary_key_in_use'), - TextDyField.data_source('Storage Authentication Type', 'storage_account_access_key') -]) - -# TAB - Diagnostic Settings -sql_databases_diagnostic_settings = SimpleTableDynamicLayout.set_fields('Diagnostic Settings', 'data.diagnostic_settings_resource', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Storage Account', 'storage_account_id'), - TextDyField.data_source('Event Hub', 'event_hub_name'), - TextDyField.data_source('Log Analytics Workspace', 'workspace_id'), -]) - -sql_databases_meta = CloudServiceMeta.set_layouts( - [sql_databases_info_meta, sql_databases_configure, sql_databases_diagnostic_settings, sql_databases_backups, - sql_databases_replication, sql_databases_sync_to_other_databases_info]) - - -class DatabaseResource(CloudServiceResource): - cloud_service_group = StringType(default='SQLDatabases') - - -class SQLDatabaseResource(DatabaseResource): - cloud_service_type = StringType(default='Database') - data = ModelType(SQLDatabase) - _metadata = ModelType(CloudServiceMeta, default=sql_databases_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class SQLDatabaseResponse(CloudServiceResponse): - resource = PolyModelType(SQLDatabaseResource) diff --git a/src/spaceone/inventory/model/sql_databases/cloud_service_type.py b/src/spaceone/inventory/model/sql_databases/cloud_service_type.py deleted file mode 100644 index 84893f2c..00000000 --- a/src/spaceone/inventory/model/sql_databases/cloud_service_type.py +++ /dev/null @@ -1,148 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField, SizeField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -sql_databases_count_by_account_conf = os.path.join(current_dir, 'widget/sql_databases_count_by_account.yaml') -sql_databases_count_by_region_conf = os.path.join(current_dir, 'widget/sql_databases_count_by_region.yaml') -sql_databases_count_by_subscription_conf = os.path.join(current_dir, 'widget/sql_databases_count_by_subscription.yaml') -sql_databases_total_count_conf = os.path.join(current_dir, 'widget/sql_databases_total_count.yaml') - -cst_sql_databases = CloudServiceTypeResource() -cst_sql_databases.name = 'Database' -cst_sql_databases.group = 'SQLDatabases' -cst_sql_databases.service_code = 'Microsoft.Sql/servers/databases' -cst_sql_databases.labels = ['Database'] -cst_sql_databases.is_major = True -cst_sql_databases.is_primary = True -cst_sql_databases.service_code = 'Microsoft.Sql/servers/databases' -cst_sql_databases.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-sql-databases.svg', -} - -cst_sql_databases._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - EnumDyField.data_source('Status', 'data.status', default_state={ - 'safe': ['Online', 'Creating', 'Copying', 'Creating', 'OnlineChangingDwPerformanceTiers', 'Restoring', - 'Resuming', 'Scaling', 'Standby'], - 'warning': ['AutoClosed', 'Inaccessible', 'Offline', 'OfflineChangingDwPerformanceTiers', - 'OfflineSecondary', - 'Pausing', 'Recovering', 'RecoveryPending', 'Suspect'], - 'disable': ['Disabled', 'Paused', 'Shutdown'], - 'alert': ['EmergencyMode'] - }), - TextDyField.data_source('Replication Partner Server', 'data.replication_link.partner_server'), - TextDyField.data_source('Server', 'data.server_name'), - TextDyField.data_source('Pricing Tier', 'data.pricing_tier_display'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - - # is_optional fields - Default - TextDyField.data_source('Elastic Pool', 'data.elastic_pool_id', options={ - 'is_optional': True - }), - DateTimeDyField.data_source('Earliest Restore Point', 'data.earliest_restore_date', options={ - 'is_optional': True - }), - TextDyField.data_source('Collation', 'data.collation', options={ - 'is_optional': True - }), - DateTimeDyField.data_source('Creation Date', 'launched_at', options={ - 'is_optional': True - }), - TextDyField.data_source('Server Admin Login', 'data.administrator_login', options={ - 'is_optional': True - }), - - # is_optional fields - Configure - TextDyField.data_source('Service Tier', 'data.service_tier_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Compute Tier', 'data.compute_tier', options={ - 'is_optional': True - }), - TextDyField.data_source('Compute Hardware', 'data.sku.family', options={ - 'is_optional': True - }), - TextDyField.data_source('Licence Type', 'data.license_type', options={ - 'is_optional': True - }), - TextDyField.data_source('vCores', 'data.current_sku.capacity', options={ - 'is_optional': True - }), - TextDyField.data_source('Data max size', 'instance_size', options={ - 'is_optional': True - }), - TextDyField.data_source('Zone Redundant', 'data.zone_redundant', options={ - 'is_optional': True - }), - ListDyField.data_source('Sync Groups', 'data.sync_group_display', options={ - 'is_optional': True - }), - ListDyField.data_source('Sync Agents', 'data.sync_agent_display', options={ - 'is_optional': True - }), - - # is_optional fields - Diagnostic Settings - TextDyField.data_source('Diagnostic Setting Name', 'data.diagnostic_settings_resource.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Diagnostic Setting Storage Account', 'data.diagnostic_settings_resource.storage_account_id', options={ - 'is_optional': True - }), - TextDyField.data_source('Event Hub', 'data.diagnostic_settings_resource.event_hub_name', options={ - 'is_optional': True - }), - TextDyField.data_source('Log Analytics Workspace', 'data.diagnostic_settings_resource.workspace_id', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Database ID', key='data.database_id'), - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Tier', key='instance_type'), - SearchField.set(name='Server Name', key='data.managed_by'), - SearchField.set(name='Status', key='data.status'), - SearchField.set(name='Replication Partner Server', key='data.replication_link.partner_server'), - SearchField.set(name='Pricing Tier', key='data.pricing_tier_display'), - SearchField.set(name='Elastic Pool', key='data.elastic_pool_id'), - SearchField.set(name='Earliest Restore Point', key='data.earliest_restore_date'), - SearchField.set(name='Collation', key='data.collation'), - SearchField.set(name='Server Admin Login', key='data.administrator_login'), - SearchField.set(name='Service Tier', key='data.service_tier_display'), - SearchField.set(name='Compute Tier', key='data.compute_tier'), - SearchField.set(name='Compute Hardware', key='data.sku.family'), - SearchField.set(name='Licence Type', key='data.license_type'), - SearchField.set(name='vCores', key='data.current_sku.capacity', data_type='integer'), - SearchField.set(name='Data max size', key='instance_size', data_type='integer'), - SearchField.set(name='Zone Redundant', key='data.zone_redundant'), - SearchField.set(name='Sync Groups', key='data.sync_group_display'), - SearchField.set(name='Sync Agents', key='data.sync_agent_display'), - SearchField.set(name='Diagnostic Setting Name', key='data.diagnostic_settings_resource.name'), - SearchField.set(name='Diagnostic Setting Storage Account', key='data.diagnostic_settings_resource.storage_account_id'), - SearchField.set(name='Event Hub', key='data.diagnostic_settings_resource.event_hub_name'), - SearchField.set(name='Log Analytics Workspace', key='data.diagnostic_settings_resource.workspace_id'), - SearchField.set(name='Creation Date', key='launched_at', data_type='datetime'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(sql_databases_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(sql_databases_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(sql_databases_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(sql_databases_total_count_conf)) - ] - -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_sql_databases}), -] diff --git a/src/spaceone/inventory/model/sql_databases/data.py b/src/spaceone/inventory/model/sql_databases/data.py deleted file mode 100644 index 1ccb999f..00000000 --- a/src/spaceone/inventory/model/sql_databases/data.py +++ /dev/null @@ -1,196 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType, FloatType, DateTimeType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class Sku(Model): - capacity = IntType(serialize_when_none=False) - family = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - size = StringType(serialize_when_none=False) - tier = StringType(serialize_when_none=False) - - -class SyncGroupSchemaColumn(Model): - data_size = StringType(serialize_when_none=False) - data_type = StringType(serialize_when_none=False) - quoted_name = StringType(serialize_when_none=False) - - -class SyncGroupSchemaTable(Model): - columns = ListType(ModelType(SyncGroupSchemaColumn), serialize_when_none=False) - quoted_name = StringType(serialize_when_none=False) - - -class SyncGroupSchema(Model): - master_sync_member_name = StringType(serialize_when_none=False) - tables = ListType(ModelType(SyncGroupSchemaTable), serialize_when_none=False) - - -class SyncGroup(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - conflict_resolution_policy = StringType(choices=('HubWin', 'MemberWin'), serialize_when_none=False) - hub_database_password = StringType(serialize_when_none=False) - hub_database_user_name = StringType(serialize_when_none=False) - interval = IntType(serialize_when_none=False) - last_sync_time = DateTimeType(serialize_when_none=False) - schema = ModelType(SyncGroupSchema, serialize_when_none=False) - sync_database_id = StringType(serialize_when_none=False) - sync_state = StringType(choices=('Error', 'Good', 'NotReady', 'Progressing', 'Warning'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - user_private_link = BooleanType(serialize_when_none=False) - conflict_logging_retention_in_days = IntType(serialize_when_none=False) - use_private_link_connection = BooleanType(serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - automatic_sync = BooleanType(serialize_when_none=False) - - -class SyncAgent(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - expiry_time = DateTimeType(serialize_when_none=False) - is_up_to_date = BooleanType(serialize_when_none=False) - last_alive_time = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - state = StringType(choices=('NeverConnected', 'Offline', 'Online'), serialize_when_none=False) - sync_database_id = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class RetentionPolicy(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class LogSettings(Model): - category = StringType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - retention_policy = ModelType(RetentionPolicy) - - -class MetricSettings(Model): - category = StringType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - retention_policy = ModelType(RetentionPolicy) - time_grain = StringType(serialize_when_none=False) - - -class DiagnosticSettingsResource(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - event_hub_authorization_rule_id = StringType(serialize_when_none=False) - event_hub_name = StringType(serialize_when_none=False) - log_analytics_destination_type = StringType(serialize_when_none=False) - logs = ListType(ModelType(LogSettings), serialize_when_none=False) - metrics = ListType(ModelType(MetricSettings), serialize_when_none=False) - service_bus_rule_id = StringType(serialize_when_none=False) - storage_account_id = StringType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ReplicationLink(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - is_termination_allowed = BooleanType(serialize_when_none=False) - partner_database = StringType(serialize_when_none=False) - partner_location = StringType(serialize_when_none=False) - partner_role = StringType(choices=('Copy', 'NonReadableSecondary', 'Primary', 'Secondary', 'Source'), serialize_when_none=False) - partner_server = StringType(default='-') - percent_complete = IntType(serialize_when_none=False) - replication_mode = StringType(serialize_when_none=False) - replication_state = StringType(choices=('CATCH_UP', 'PENDING', 'SEEDING', 'SUSPENDED'), serialize_when_none=False) - role = StringType(choices=('Copy', 'NonReadableSecondary', 'Primary', 'Secondary', 'Source'), serialize_when_none=False) - start_time = DateTimeType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - link_type = StringType(choices=('GEO', 'NAMED'), serialize_when_none=False) - replica_state = StringType(serialized_name=False) - - -class DatabaseBlobAuditingPolicy(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - retention_days = IntType(serialize_when_none=False) - audit_actions_and_groups = ListType(StringType, serialize_when_none=False) - is_storage_secondary_key_in_use = BooleanType(serialize_when_none=False) - is_azure_monitor_target_enabled = BooleanType(serialize_when_none=False) - queue_delay_ms = IntType(serialize_when_none=False) - state = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - storage_endpoint = StringType(serialize_when_none=False) - storage_account_access_key = StringType(serialize_when_none=False) - storage_account_subscription_id = StringType(serialize_when_none=False) - - -class SQLDatabase(AzureCloudService): # Main Class - name = StringType(serialize_when_none=False) - id = StringType() - kind = StringType(serialize_when_none=False) - location = StringType() - managed_by = StringType(serialize_when_none=False) - server_name = StringType(serialize_when_none=False) - administrator_login = StringType(default='-') - auto_pause_delay = IntType(serialize_when_none=False) - catalog_collation = StringType(choices=('DATABASE_DEFAULT', 'SQL_Latin1_General_CP1_CI_AS'), - serialize_when_none=False) - collation = StringType(serialize_when_none=False) - create_mode = StringType(choices=( - 'Copy', 'Default', 'OnlineSecondary', 'PointInTimeRestore', 'Recovery', 'Restore', 'RestoreExternalBackup', - 'RestoreExternalBackupSecondary', 'RestoreLongTermRetentionBackup', 'Secondary'), serialize_when_none=False) - creation_date = DateTimeType(serialize_when_none=False) - current_service_objective_name = StringType(serialize_when_none=False) - current_sku = ModelType(Sku, serialize_when_none=False) - database_id = StringType(serialize_when_none=False) - default_secondary_location = StringType(serialize_when_none=False) - earliest_restore_date = DateTimeType(serialize_when_none=False) - elastic_pool_id = StringType(serialize_when_none=False) - failover_group_id = StringType(serialize_when_none=False) - high_availability_replica_count = IntType(serialize_when_none=False) - license_type = StringType(choices=('BasePrice', 'LicenseIncluded'), serialize_when_none=False) - long_term_retention_backup_resource_id = StringType(default='-') - maintenance_configuration_id = StringType(serialize_when_none=False) - max_log_size_bytes = IntType(serialize_when_none=False) - max_size_bytes = IntType(serialize_when_none=False) - max_size_gb = FloatType(serialize_when_none=False) - min_capacity = FloatType(serialize_when_none=False) - paused_date = DateTimeType(serialize_when_none=False) - read_scale = StringType(choices=('Disabled', 'Enabled'), default='Disabled') - recoverable_database_id = StringType(serialize_when_none=False) - recovery_services_recovery_point_id = StringType(serialize_when_none=False) - requested_service_objective_name = StringType(serialize_when_none=False) - restorable_dropped_database_id = StringType(serialize_when_none=False) - restore_point_in_time = StringType(serialize_when_none=False) - resumed_date = DateTimeType(serialize_when_none=False) - sample_name = StringType(choices=('AdventureWorksLT', 'WideWorldImportersFull', 'WideWorldImportersStd'), - serialize_when_none=False) - secondary_type = StringType(choices=('Geo', 'Named'), serialize_when_none=False) - source_database_deletion_date = StringType(serialize_when_none=False) - source_database_id = StringType(serialize_when_none=False) - status = StringType(choices=( - 'AutoClosed', 'Copying', 'Creating', 'Disabled', 'EmergencyMode', 'Inaccessible', 'Offline', - 'OfflineChangingDwPerformanceTiers', 'OfflineSecondary', 'Online', - 'OnlineChangingDwPerformanceTiers', 'Paused', 'Pausing', 'Recovering', 'RecoveryPending', 'Restoring', - 'Resuming', 'Scaling', 'Shutdown', 'Standby', 'Suspect'), serialize_when_none=False) - storage_account_type = StringType(choices=('GRS', 'LRS', 'ZRS'), serialize_when_none=False) - zone_redundant = BooleanType(serialize_when_none=False) - diagnostic_settings_resource = ListType(ModelType(DiagnosticSettingsResource), serialize_when_none=False) - replication_link = ListType(ModelType(ReplicationLink), serialize_when_none=False) - sync_group = ListType(ModelType(SyncGroup), serialize_when_none=False) - sync_agent = ListType(ModelType(SyncAgent), serialize_when_none=False) - sync_group_display = ListType(StringType, serialize_when_none=False) - sync_agent_display = ListType(StringType, serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - pricing_tier_display = StringType(default='-') - service_tier_display = StringType(default='-') - compute_tier = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - database_auditing_settings = ModelType(DatabaseBlobAuditingPolicy, serialize_when_none=False) - - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_account.yaml b/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_account.yaml deleted file mode 100644 index a01706c9..00000000 --- a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: SQLDatabases -cloud_service_type: Database -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_region.yaml b/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_region.yaml deleted file mode 100644 index a829e27a..00000000 --- a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: SQLDatabases -cloud_service_type: Database -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_subscription.yaml b/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_subscription.yaml deleted file mode 100644 index 1704a372..00000000 --- a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: SQLDatabases -cloud_service_type: Database -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_total_count.yaml b/src/spaceone/inventory/model/sql_databases/widget/sql_databases_total_count.yaml deleted file mode 100644 index 6b1d042b..00000000 --- a/src/spaceone/inventory/model/sql_databases/widget/sql_databases_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: SQLDatabases -cloud_service_type: Database -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/sql_servers/__init__.py b/src/spaceone/inventory/model/sql_servers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/sql_servers/cloud_service.py b/src/spaceone/inventory/model/sql_servers/cloud_service.py deleted file mode 100644 index 6d17ac8b..00000000 --- a/src/spaceone/inventory/model/sql_servers/cloud_service.py +++ /dev/null @@ -1,378 +0,0 @@ -from schematics.types import ( - ModelType, - StringType, - PolyModelType, - FloatType, - DateTimeType, -) - -from spaceone.inventory.model.sql_servers.data import SQLServer -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - TextDyField, - DateTimeDyField, - EnumDyField, - ListDyField, -) -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ( - ItemDynamicLayout, - TableDynamicLayout, - ListDynamicLayout, - SimpleTableDynamicLayout, -) -from spaceone.inventory.libs.schema.cloud_service import ( - CloudServiceResource, - CloudServiceResponse, - CloudServiceMeta, -) - -""" -SQL SERVERS - -""" - -# TAB - Default -# Resource Group, Status, Location, Subscription, Subscription ID, Server Admin, Firewalls, Active Directory admin, Server name -sql_servers_info_meta = ItemDynamicLayout.set_fields( - "SQL Servers", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Resource Group", "data.resource_group"), - TextDyField.data_source("Resource ID", "data.id"), - EnumDyField.data_source( - "Status", - "data.state", - default_state={"safe": ["Ready"], "warning": ["Disabled"]}, - ), - TextDyField.data_source("Location", "data.location"), - TextDyField.data_source("Subscription", "data.subscription_name"), - TextDyField.data_source("Subscription ID", "account"), - TextDyField.data_source("Server Admin", "data.administrator_login"), - TextDyField.data_source("Active Directory Admin", "data.azure_ad_admin_name"), - TextDyField.data_source("Server Name", "data.fully_qualified_domain_name"), - ], -) - -# TAB - Failover Groups -# Name, Primary Server, Secondary Server, Read/Write Failover Policy, Grace Period (minutes), Database count -sql_server_failover_group = TableDynamicLayout.set_fields( - "Failover Groups", - "data.failover_groups", - fields=[ - TextDyField.data_source("ID", "id"), - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Primary Server", "primary_server"), - TextDyField.data_source("Secondary Server", "secondary_server"), - TextDyField.data_source( - "Read/Write Failover Policy", "failover_policy_display" - ), - TextDyField.data_source("Grace Period (minutes)", "grace_period_display"), - # TextDyField.data_source('Database count', ''), - ], -) - -# TAB - Backups -# Database, Earliest PITR restore point (UTC), Available LTR backups -sql_server_backups = TableDynamicLayout.set_fields( - "Backups", - "data.databases", - fields=[ - TextDyField.data_source("Database", "name"), - TextDyField.data_source( - "Earliest PITR Restore Point (UTC)", "earliest_restore_date" - ), - TextDyField.data_source( - "Available LTR backups", "long_term_retention_backup_resource_id" - ), - ], -) - -# TAB - Active Directory Admin -# Active Directory Admin -sql_servers_active_directory_admin = ItemDynamicLayout.set_fields( - "Active Directory Admin", - fields=[ - TextDyField.data_source("Active Directory Admin", "data.azure_ad_admin_name") - ], -) - -# TAB - SQL Databases - Default -sql_servers_databases = TableDynamicLayout.set_fields( - "Databases", - "data.databases", - fields=[ - TextDyField.data_source("Database", "name"), - TextDyField.data_source("Resource ID", "id"), - EnumDyField.data_source( - "Status", - "status", - default_state={ - "safe": [ - "Online", - "Creating", - "Copying", - "Creating", - "OnlineChangingDwPerformanceTiers", - "Restoring", - "Resuming", - "Scaling", - "Standby", - ], - "warning": [ - "AutoClosed", - "Inaccessible", - "Offline", - "OfflineChangingDwPerformanceTiers", - "OfflineSecondary", - "Pausing", - "Recovering", - "RecoveryPending", - "Suspect", - ], - "disable": ["Disabled", "Paused", "Shutdown"], - "alert": ["EmergencyMode"], - }, - ), - TextDyField.data_source("Resource Group", "resource_group"), - TextDyField.data_source("Subscription ID", "subscription_id"), - TextDyField.data_source("Location", "location"), - TextDyField.data_source("Server Name", "server_name"), - TextDyField.data_source("Elastic Pool", ""), - # TextDyField.data_source('Connection Strings', ''), - TextDyField.data_source("Pricing Tier", "pricing_tier_display"), - TextDyField.data_source("Earliest Restore Point", "earliest_restore_date"), - ], -) - -# TAB - SQL Databases - Configure -sql_servers_databases_configure = TableDynamicLayout.set_fields( - "Databases Configure", - "data.databases", - fields=[ - TextDyField.data_source("Service Tier", "service_tier_display"), - TextDyField.data_source("Compute Tier", "compute_tier"), - TextDyField.data_source("Compute Hardware", "sku.family"), - TextDyField.data_source("License Type", "license_type"), - TextDyField.data_source("vCores", "sku.capacity"), - TextDyField.data_source("Data Max Size", "max_size_gb"), - TextDyField.data_source("Zone Redundant", "zone_redundant"), - ListDyField.data_source("Sync Groups", "sync_group_display"), - ListDyField.data_source("Sync Agents", "sync_agent_display"), - TextDyField.data_source("Collation", "collation"), - DateTimeDyField.data_source("Creation Date", "creation_date"), - # TextDyField.data_source('Server Admin Login', '') # Remove: DB is already under the specific server - # TextDyField.data_source('Active Directory Login', ''), # Remove: DB is already under the specific server - ], -) - -# TAB - SQL Databases - tags -sql_databases_info_tags = TableDynamicLayout.set_fields( - "Tags", - "data.tags", - fields=[ - TextDyField.data_source("Key", "key"), - TextDyField.data_source("Value", "value"), - ], -) - -# TAB - Dynamic Data Masking : "Masking rules: + Tab "Recommended fields to mask" # TODO: confirm!! -sql_servers_databases_info = ListDynamicLayout.set_layouts( - "SQL Databases", - layouts=[ - sql_servers_databases, - sql_servers_databases_configure, - sql_databases_info_tags, - ], -) - -# TAB - Elastic Pools -# Name, Pricing tier, Per DB settings, of DBs, Storage, unit, avg, peak, average utilization over past hour -sql_servers_elastic_pools = TableDynamicLayout.set_fields( - "Elastic Pools", - "data.elastic_pools", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Resource Group", "resource_group_display"), - TextDyField.data_source("Per DB Settings", "per_db_settings_display"), - TextDyField.data_source("Pricing Tier", "pricing_tier_display"), - TextDyField.data_source("# of DBs", "number_of_databases"), - TextDyField.data_source("Unit", "unit_display"), - EnumDyField.data_source( - "Status", - "state", - default_state={"safe": ["Ready", "Creating"], "warning": ["Disabled"]}, - ), - # TextDyField.data_source('Storage[%]', ''), - # TextDyField.data_source('Avg[%]', ''), - # TextDyField.data_source('Peak[%]', ''), - # TextDyField.data_source('Utilization Over Past Hour[%]', ''), - # TextDyField.data_source('Utilization Over Past Hour[%]', ''), - TextDyField.data_source("Server Name", "server_name_display"), - TextDyField.data_source("Resource Configuration", "pricing_tier_display"), - TextDyField.data_source("Maximum Storage Size", "max_size_gb"), - ListDyField.data_source("Tags", "tags"), - ], -) - -# TAB - Deleted Databases -sql_servers_deleted_databases = TableDynamicLayout.set_fields( - "Deleted Databases", - "data.deleted_databases", - fields=[ - TextDyField.data_source("Database", "database_name"), - DateTimeDyField.data_source("Deletion Time (UTC)", "deletion_date"), - DateTimeDyField.data_source("Creation Time (UTC)", "creation_date"), - TextDyField.data_source("Edition Time (UTC)", "edition"), - ], -) - -# TAB - Auditing -sql_servers_auditing = ItemDynamicLayout.set_fields( - "Auditing", - "data.server_auditing_settings", - fields=[ - EnumDyField.data_source( - "Enable SQL Auditing", - "state", - default_state={"safe": ["Enabled"], "warning": ["Disabled"]}, - ), - TextDyField.data_source("Audit Log Destination", "storage_endpoint"), - TextDyField.data_source( - "Storage Account ID", "storage_account_subscription_id" - ), - ], -) - -# TAB - Firewalls and Virtual Networks -sql_servers_network = ItemDynamicLayout.set_fields( - "Network", - fields=[ - EnumDyField.data_source( - "Public Network access", - "data.public_network_access", - default_state={"safe": ["Enabled"], "warning": ["Disabled"]}, - ), - TextDyField.data_source("Minimum TLS Version", "data.minimal_tls_version"), - TextDyField.data_source( - "Connection Policy", "data.server_auditing_settings.name" - ), - TextDyField.data_source( - "Allow Azure Services and Resources to Access this server", - "data.server_auditing_settings.is_azure_monitor_target_enabled", - ), - ], -) -sql_servers_firewall_rules = TableDynamicLayout.set_fields( - "Firewall Rules", - "data.firewall_rules", - fields=[ - TextDyField.data_source("Rule Name", "name"), - TextDyField.data_source("Start IP", "start_ip_address"), - TextDyField.data_source("End IP", "end_ip_address"), - ], -) - -sql_servers_virtual_network_rules = TableDynamicLayout.set_fields( - "Virtual Network Rules", - "data.virtual_network_rules", - fields=[ - TextDyField.data_source("Rule Name", "name"), - TextDyField.data_source("Virtual Network", "virtual_network_name_display"), - TextDyField.data_source("Subnet ID", "virtual_network_subnet_id"), - # TextDyField.data_source('Address Range', ''), - # TextDyField.data_source('Endpoint Status', ''), - TextDyField.data_source("Resource Group", "resource_group"), - TextDyField.data_source("Subscription", "subscription_id"), - EnumDyField.data_source( - "State", - "state", - default_state={ - "safe": ["Ready", "InProgress", "Initializing"], - "warning": ["Deleting", "Unknown"], - }, - ), - ], -) - -sql_servers_firewalls_and_vn = ListDynamicLayout.set_layouts( - "Firewalls and Network", - layouts=[ - sql_servers_network, - sql_servers_firewall_rules, - sql_servers_virtual_network_rules, - ], -) - -# TAB - Private Endpoint Connections -sql_servers_private_endpoint_connections = TableDynamicLayout.set_fields( - "Private Endpoint Connections", - "data.private_endpoint_connections", - fields=[ - TextDyField.data_source("Connection ID", "connection_id"), - TextDyField.data_source("State", "status"), - TextDyField.data_source("Private Endpoint Name", "private_endpoint_name"), - TextDyField.data_source("Request / Response Message", "description"), - ], -) - -# TAB - Transparent Data Encryption -sql_servers_transparent_data_encryption = TableDynamicLayout.set_fields( - "Transparent Data Encryption", - "data.encryption_protectors", - fields=[ - TextDyField.data_source("Transparent Data Encryption", "kind"), - TextDyField.data_source("Key", "server_key_name"), - TextDyField.data_source("Key Type", "server_key_type"), - TextDyField.data_source("Uri", "uri"), - ], -) - -# TAB - Automatic Tuning -sql_servers_automatic_tuning_options = TableDynamicLayout.set_fields( - "Tuning Options", - "data.server_automatic_tuning.options", - fields=[ - TextDyField.data_source("Tuning Type", "tuning_type"), - TextDyField.data_source("Desired State", "desired_state"), - TextDyField.data_source("Current State", "actual_state"), - ], -) - -# TAB - SQL Databases -sql_servers_meta = CloudServiceMeta.set_layouts( - [ - sql_servers_info_meta, - sql_server_failover_group, - sql_server_backups, - sql_servers_active_directory_admin, - sql_servers_databases_info, - sql_servers_elastic_pools, - sql_servers_deleted_databases, - sql_servers_auditing, - sql_servers_network, - sql_servers_transparent_data_encryption, - sql_servers_automatic_tuning_options, - sql_servers_firewalls_and_vn, - sql_servers_private_endpoint_connections, - ] -) - - -class DatabaseResource(CloudServiceResource): - cloud_service_group = StringType(default="SQLServers") - - -class SQLServerResource(DatabaseResource): - cloud_service_type = StringType(default="Server") - data = ModelType(SQLServer) - _metadata = ModelType( - CloudServiceMeta, default=sql_servers_meta, serialized_name="metadata" - ) - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class SQLServerResponse(CloudServiceResponse): - resource = PolyModelType(SQLServerResource) diff --git a/src/spaceone/inventory/model/sql_servers/cloud_service_type.py b/src/spaceone/inventory/model/sql_servers/cloud_service_type.py deleted file mode 100644 index e195a090..00000000 --- a/src/spaceone/inventory/model/sql_servers/cloud_service_type.py +++ /dev/null @@ -1,477 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import ( - CardWidget, - ChartWidget, -) -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - TextDyField, - SearchField, - DateTimeDyField, - ListDyField, - EnumDyField, - SizeField, -) -from spaceone.inventory.libs.schema.cloud_service_type import ( - CloudServiceTypeResource, - CloudServiceTypeResponse, - CloudServiceTypeMeta, -) -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -sql_databases_count_by_server_conf = os.path.join( - current_dir, "widget/sql_databases_count_by_server.yaml" -) -sql_databases_count_by_subscription_conf = os.path.join( - current_dir, "widget/sql_databases_count_by_subscription.yaml" -) -sql_databases_count_by_tier_conf = os.path.join( - current_dir, "widget/sql_databases_count_by_tier.yaml" -) -sql_servers_count_by_account_conf = os.path.join( - current_dir, "widget/sql_servers_count_by_account.yaml" -) -sql_servers_count_by_region_conf = os.path.join( - current_dir, "widget/sql_servers_count_by_region.yaml" -) -sql_servers_count_by_subscription_conf = os.path.join( - current_dir, "widget/sql_servers_count_by_subscription.yaml" -) -sql_servers_failover_count_by_region_conf = os.path.join( - current_dir, "widget/sql_servers_failover_count_by_region.yaml" -) -sql_servers_failover_count_by_server_conf = os.path.join( - current_dir, "widget/sql_servers_failover_count_by_server.yaml" -) -sql_servers_total_count_conf = os.path.join( - current_dir, "widget/sql_servers_total_count.yaml" -) - -cst_sql_servers = CloudServiceTypeResource() -cst_sql_servers.name = "Server" -cst_sql_servers.group = "SQLServers" -cst_sql_servers.service_code = "Microsoft.Sql/servers" -cst_sql_servers.labels = ["Database"] -cst_sql_servers.is_primary = True -cst_sql_servers.is_major = True -cst_sql_servers.tags = { - "spaceone:icon": f"{ASSET_URL}/azure-sql-servers.svg", -} - -cst_sql_servers._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - EnumDyField.data_source( - "Status", - "data.state", - default_state={"safe": ["Ready"], "warning": ["Disabled"]}, - ), - TextDyField.data_source("Resource Group", "data.resource_group"), - TextDyField.data_source("Location", "data.location"), - TextDyField.data_source("Subscription Name", "data.subscription_name"), - # is_optional fields - Default - TextDyField.data_source( - "Subscription ID", "account", options={"is_optional": True} - ), - TextDyField.data_source( - "Server Admin", "data.administrator_login", options={"is_optional": True} - ), - TextDyField.data_source( - "Active Directory Admin", - "data.azure_ad_admin_name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Server Name", - "data.fully_qualified_domain_name", - options={"is_optional": True}, - ), - # is_optional fields - Failover Groups - TextDyField.data_source( - "Failover Group ID", - "data.failover_groups.id", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Failover Group Name", - "data.failover_groups.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Failover Groups Primary Server", - "data.failover_groups.primary_server", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Failover Groups Secondary Server", - "data.failover_groups.secondary_server", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Read/Write Failover Policy", - "data.failover_groups.failover_policy_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Grace Period (minutes)", - "data.failover_groups.grace_period_display", - options={"is_optional": True}, - ), - # is_optional fields - Backups - TextDyField.data_source( - "Backup Database", "data.databases.name", options={"is_optional": True} - ), - TextDyField.data_source( - "Backup Earliest PITR Restore Point (UTC)", - "data.databases.earliest_restore_date", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Backup Available LTR backups", - "data.databases.long_term_retention_backup_resource_id", - options={"is_optional": True}, - ), - # is_optional fields - Active Directory Admin - TextDyField.data_source( - "Active Directory Admin", - "data.azure_ad_admin_name", - options={"is_optional": True}, - ), - # is_optional fields - Elastic Pools - TextDyField.data_source( - "Elastic Pool Name", - "data.elastic_pools.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Elastic Pool Resource Group", - "data.elastic_pools.resource_group_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Per DB Settings", - "data.elastic_pools.per_db_settings_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Pricing Tier", - "data.elastic_pools.pricing_tier_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "# of DBs", - "data.elastic_pools.number_of_databases", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Elastic Pool Unit", - "data.elastic_pools.unit_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Elastic Pool Server Name", - "data.elastic_pools.server_name_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Elastic Pool Resource Configuration", - "data.elastic_pools.pricing_tier_display", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Elastic Pool Maximum Storage Size", - "data.elastic_pools.max_size_gb", - options={"is_optional": True}, - ), - # is_optional fields - Deleted Databases - TextDyField.data_source( - "Deleted Database", - "data.deleted_databases.database_name", - options={"is_optional": True}, - ), - DateTimeDyField.data_source( - "Deletion Time (UTC)", - "data.deleted_databases.deletion_date", - options={"is_optional": True}, - ), - DateTimeDyField.data_source( - "Deleted Databases Creation Time (UTC)", - "data.deleted_databases.creation_date", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Deleted Databases Edition Time (UTC)", - "data.deleted_databases.edition", - options={"is_optional": True}, - ), - # is_optional fields - Auditing - TextDyField.data_source( - "Audit Log Destination", - "data.server_auditing_settings.storage_endpoint", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Audit Storage Account ID", - "data.server_auditing_settings.storage_account_subscription_id", - options={"is_optional": True}, - ), - # is_optional fields - Firewalls and Vnets - TextDyField.data_source( - "Minimum TLS Version", - "data.minimal_tls_version", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Connection Policy", - "data.server_auditing_settings.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Allow Azure Services and Resources to Access this server", - "data.server_auditing_settings.is_azure_monitor_target_enabled", - options={"is_optional": True}, - ), - # is_optional fields - Firewall Rules - TextDyField.data_source( - "Firewall Rule Name", - "data.firewall_rules.name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Firewall Start IP", - "data.firewall_rules.start_ip_address", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Firewall End IP", - "data.firewall_rules.end_ip_address", - options={"is_optional": True}, - ), - # is_optional fields - Private Endpoint Connections - TextDyField.data_source( - "Private Endpoint Connection ID", - "data.private_endpoint_connections.connection_id", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Private Endpoint State", - "data.private_endpoint_connections.status", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Private Endpoint Name", - "data.private_endpoint_connections.private_endpoint_name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Request / Response Message", - "data.private_endpoint_connections.description", - options={"is_optional": True}, - ), - # is_optional fields - Transparent Data Encryption - TextDyField.data_source( - "Transparent Data Encryption", - "data.encryption_protectors.kind", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Encryption Key", - "data.encryption_protectors.server_key_name", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Encryption Key Type", - "data.encryption_protectors.server_key_type", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Encryption URI", - "data.encryption_protectors.uri", - options={"is_optional": True}, - ), - # is_optional fields - Automatic Tuning - TextDyField.data_source( - "Tuning Type", - "data.server_automatic_tuning.options.tuning_type", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Tuning Desired State", - "data.server_automatic_tuning.options.desired_state", - options={"is_optional": True}, - ), - TextDyField.data_source( - "Tuning Current State", - "data.server_automatic_tuning.options.actual_state", - options={"is_optional": True}, - ), - ], - search=[ - SearchField.set(name="Subscription ID", key="account"), - SearchField.set(name="Subscription Name", key="data.subscription_name"), - SearchField.set(name="Resource Group", key="data.resource_group"), - SearchField.set(name="Location", key="data.location"), - SearchField.set(name="Server Admin", key="data.administrator_login"), - SearchField.set(name="Active Directory Admin", key="data.azure_ad_admin_name"), - SearchField.set(name="Server Name", key="data.fully_qualified_domain_name"), - SearchField.set(name="Failover Group ID", key="data.failover_groups.id"), - SearchField.set(name="Failover Group Name", key="data.failover_groups.name"), - SearchField.set( - name="Failover Groups Primary Server", - key="data.failover_groups.primary_server", - ), - SearchField.set( - name="Failover Groups Secondary Server", - key="data.failover_groups.secondary_server", - ), - SearchField.set( - name="Read/Write Failover Policy", - key="data.failover_groups.failover_policy_display", - ), - SearchField.set( - name="Grace Period (minutes)", - key="data.failover_groups.grace_period_display", - data_type="integer", - ), - SearchField.set(name="Backup Database", key="data.databases.name"), - SearchField.set( - name="Backup Earliest PITR Restore Point (UTC)", - key="data.databases.earliest_restore_date", - data_type="datetime", - ), - SearchField.set( - name="Backup Available LTR backups", - key="data.databases.long_term_retention_backup_resource_id", - ), - SearchField.set(name="Active Directory Admin", key="data.azure_ad_admin_name"), - SearchField.set(name="Elastic Pool Name", key="data.elastic_pools.name"), - SearchField.set( - name="Elastic Pool Resource Group", - key="data.elastic_pools.resource_group_display", - ), - SearchField.set( - name="Per DB Settings", key="data.elastic_pools.per_db_settings_display" - ), - SearchField.set( - name="Pricing Tier", key="data.elastic_pools.pricing_tier_display" - ), - SearchField.set( - name="Number of DBs", - key="data.elastic_pools.number_of_databases", - data_type="integer", - ), - SearchField.set( - name="Elastic Pool Unit", key="data.elastic_pools.unit_display" - ), - SearchField.set( - name="Elastic Pool Server Name", - key="data.elastic_pools.server_name_display", - ), - SearchField.set( - name="Elastic Pool Resource Configuration", - key="data.elastic_pools.pricing_tier_display", - ), - SearchField.set( - name="Elastic Pool Maximum Storage Size", - key="data.elastic_pools.max_size_gb", - ), - SearchField.set( - name="Deleted Database", key="data.deleted_databases.database_name" - ), - SearchField.set( - name="Deletion Time (UTC)", - key="data.deleted_databases.deletion_date", - data_type="datetime", - ), - SearchField.set( - name="Deleted Databases Creation Time (UTC)", - key="data.deleted_databases.creation_date", - data_type="datetime", - ), - SearchField.set( - name="Deleted Databases Edition Time (UTC)", - key="data.deleted_databases.edition", - data_type="datetime", - ), - SearchField.set( - name="Audit Log Destination", - key="data.server_auditing_settings.storage_endpoint", - ), - SearchField.set( - name="Audit Storage Account ID", - key="data.server_auditing_settings.storage_account_subscription_id", - ), - SearchField.set(name="Minimum TLS Version", key="data.minimal_tls_version"), - SearchField.set( - name="Connection Policy", key="data.server_auditing_settings.name" - ), - SearchField.set( - name="Allow Azure Services and Resources to Access this server", - key="data.server_auditing_settings.is_azure_monitor_target_enabled", - ), - SearchField.set(name="Firewall Rule Name", key="data.firewall_rules.name"), - SearchField.set( - name="Firewall Start IP", key="data.firewall_rules.start_ip_address" - ), - SearchField.set( - name="Firewall End IP", key="data.firewall_rules.end_ip_address" - ), - SearchField.set( - name="Private Endpoint Connection ID", - key="data.private_endpoint_connections.connection_id", - ), - SearchField.set( - name="Private Endpoint State", - key="data.private_endpoint_connections.status", - ), - SearchField.set( - name="Private Endpoint Name", - key="data.private_endpoint_connections.private_endpoint_name", - ), - SearchField.set( - name="Request / Response Message", - key="data.private_endpoint_connections.description", - ), - SearchField.set( - name="Transparent Data Encryption", key="data.encryption_protectors.kind" - ), - SearchField.set( - name="Encryption Key", key="data.encryption_protectors.server_key_name" - ), - SearchField.set( - name="Encryption Key Type", key="data.encryption_protectors.server_key_type" - ), - SearchField.set(name="Encryption URI", key="data.encryption_protectors.uri"), - SearchField.set( - name="Tuning Type", key="data.server_automatic_tuning.options.tuning_type" - ), - SearchField.set( - name="Tuning Desired State", - key="data.server_automatic_tuning.options.desired_state", - ), - SearchField.set( - name="Tuning Current State", - key="data.server_automatic_tuning.options.actual_state", - ), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(sql_servers_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(sql_servers_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(sql_servers_count_by_subscription_conf)), - ChartWidget.set( - **get_data_from_yaml(sql_servers_failover_count_by_region_conf) - ), - ChartWidget.set( - **get_data_from_yaml(sql_servers_failover_count_by_server_conf) - ), - ChartWidget.set(**get_data_from_yaml(sql_databases_count_by_server_conf)), - ChartWidget.set(**get_data_from_yaml(sql_databases_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(sql_databases_count_by_tier_conf)), - CardWidget.set(**get_data_from_yaml(sql_servers_total_count_conf)), - ], -) - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({"resource": cst_sql_servers}), -] diff --git a/src/spaceone/inventory/model/sql_servers/data.py b/src/spaceone/inventory/model/sql_servers/data.py deleted file mode 100644 index c674077a..00000000 --- a/src/spaceone/inventory/model/sql_servers/data.py +++ /dev/null @@ -1,517 +0,0 @@ -from schematics import Model -from schematics.types import ( - ModelType, - ListType, - StringType, - IntType, - BooleanType, - FloatType, - DateTimeType, -) -from spaceone.inventory.libs.schema.resource import AzureCloudService, AzureTags - - -class ResourceIdentity(Model): - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType(choices=("None", "SystemAssigned", "UserAssigned")) - - -class PrivateEndpointProperty(Model): - id = StringType() - - -class PrivateLinkServiceConnectionStateProperty(Model): - actions_required = StringType(choices=("None", ""), serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType( - choices=("Approved", "Disconnected", "Pending", "Rejected"), - serialize_when_none=False, - ) - - -class PrivateEndpointConnectionProperties(Model): - private_endpoint = ModelType(PrivateEndpointProperty, serialize_when_none=False) - private_link_service_connection_state = ModelType( - PrivateLinkServiceConnectionStateProperty, serialize_when_none=False - ) - provisioning_state = StringType( - choices=("Approving", "Dropping", "Failed", "Ready", "Rejecting") - ) - - -class ServerPrivateEndpointConnection(Model): - id = StringType(serialize_when_none=False) - connection_id = StringType(serialize_when_none=False) - private_endpoint_name = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - properties = ModelType(PrivateEndpointConnectionProperties) - - -class ServerAzureADAdministrator(Model): - id = StringType() - name = StringType(serialize_when_none=False) - administrator_type = StringType( - choices=("ActiveDirectory", ""), serialize_when_none=False - ) - login = StringType(serialize_when_none=False) - sid = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - - -class AutomaticTuningServerOptions(Model): - actual_state = StringType(choices=("Off", "On"), serialize_when_none=False) - desired_state = StringType( - choices=("Default", "Off", "On"), serialize_when_none=False - ) - reason_code = IntType(serialize_when_none=False) - reason_desc = StringType( - choices=("AutoConfigured", "Default", "Disabled"), serialize_when_none=False - ) - tuning_type = StringType( - choices=("createIndex", "dropIndex", "forceLastGoodPlan"), - serialize_when_none=False, - ) - - -class ServerAutomaticTuning(Model): - name = StringType() - id = StringType() - actual_state = StringType( - choices=("Auto", "Custom", "Unspecified"), serialize_when_none=False - ) - desired_state = StringType( - choices=("Default", "Off", "On"), serialize_when_none=False - ) - options = ListType( - ModelType(AutomaticTuningServerOptions, serialize_when_none=False) - ) - type = StringType(serialize_when_none=False) - - -class ServerBlobAuditingPolicy(Model): - name = StringType() - id = StringType() - audit_actions_and_groups = ListType(StringType, serialize_when_none=False) - is_azure_monitor_target_enabled = BooleanType(serialize_when_none=False) - is_storage_secondary_key_in_use = BooleanType(serialize_when_none=False) - queue_delay_ms = IntType(serialize_when_none=False) - retention_days = IntType(serialize_when_none=False) - state = StringType(choices=("Disabled", "Enabled"), serialize_when_none=False) - storage_account_access_key = StringType(serialize_when_none=False) - storage_account_subscription_id = StringType(serialize_when_none=False) - storage_endpoint = StringType(default="-") - type = StringType(serialize_when_none=False) - - -class PartnerInfo(Model): - id = StringType() - location = StringType() - replication_role = StringType( - choices=("Primary", "Secondary"), serialize_when_none=False - ) - - -class FailoverGroupReadOnlyEndpoint(Model): - failover_policy = StringType( - choices=("Disabled", "Enabled"), serialize_when_none=False - ) - - -class FailoverGroupReadWriteEndpoint(Model): - failover_policy = StringType( - choices=("Automatic", "Manual"), serialize_when_none=False - ) - failover_with_data_loss_grace_period_minutes = IntType(serialize_when_none=False) - - -class FailoverGroup(Model): - name = StringType(serialize_when_none=False) - id = StringType() - location = StringType() - databases = ListType(StringType, serialize_when_none=False) - partner_servers = ListType(ModelType(PartnerInfo), serialize_when_none=False) - primary_server = StringType(serialize_when_none=False) - secondary_server = StringType(serialize_when_none=False) - read_only_endpoint = ModelType( - FailoverGroupReadOnlyEndpoint, serialize_when_none=False - ) - read_write_endpoint = ModelType( - FailoverGroupReadWriteEndpoint, serialize_when_none=False - ) - replication_role = StringType( - choices=("Primary", "Secondary"), serialize_when_none=False - ) - replication_state = StringType(serialize_when_none=False) - failover_policy_display = StringType(serialize_when_none=False) - grace_period_display = StringType(serialize_when_none=False) - tags = ListType(ModelType(AzureTags)) - type = StringType(serialize_when_none=False) - - -class SyncGroupSchemaColumn(Model): - data_size = StringType(serialize_when_none=False) - data_type = StringType(serialize_when_none=False) - quoted_name = StringType(serialize_when_none=False) - - -class SyncGroupSchemaTable(Model): - columns = ListType(ModelType(SyncGroupSchemaColumn), serialize_when_none=False) - quoted_name = StringType(serialize_when_none=False) - - -class SyncGroupSchema(Model): - master_sync_member_name = StringType(serialize_when_none=False) - tables = ListType(ModelType(SyncGroupSchemaTable), serialize_when_none=False) - - -class SyncGroup(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - conflict_resolution_policy = StringType( - choices=("HubWin", "MemberWin"), serialize_when_none=False - ) - hub_database_password = StringType(serialize_when_none=False) - hub_database_user_name = StringType(serialize_when_none=False) - interval = IntType(serialize_when_none=False) - last_sync_time = DateTimeType(serialize_when_none=False) - schema = ModelType(SyncGroupSchema, serialize_when_none=False) - sync_database_id = StringType(serialize_when_none=False) - sync_state = StringType( - choices=("Error", "Good", "NotReady", "Progressing", "Warning"), - serialize_when_none=False, - ) - type = StringType(serialize_when_none=False) - - -class SyncAgent(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - expiry_time = DateTimeType(serialize_when_none=False) - is_up_to_date = BooleanType(serialize_when_none=False) - last_alive_time = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - state = StringType( - choices=("NeverConnected", "Offline", "Online"), serialize_when_none=False - ) - sync_database_id = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class RetentionPolicy(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class LogSettings(Model): - category = StringType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - retention_policy = ModelType(RetentionPolicy) - - -class MetricSettings(Model): - category = StringType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - retention_policy = ModelType(RetentionPolicy) - time_grain = StringType(serialize_when_none=False) - - -class DiagnosticSettingsResource(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - event_hub_authorization_rule_id = StringType(serialize_when_none=False) - event_hub_name = StringType(serialize_when_none=False) - log_analytics_destination_type = StringType(serialize_when_none=False) - logs = ListType(ModelType(LogSettings), serialize_when_none=False) - metrics = ListType(ModelType(MetricSettings), serialize_when_none=False) - service_bus_rule_id = StringType(serialize_when_none=False) - storage_account_id = StringType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ReplicationLink(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - is_termination_allowed = BooleanType(serialize_when_none=False) - partner_database = StringType(serialize_when_none=False) - partner_location = StringType(serialize_when_none=False) - partner_role = StringType( - choices=("Copy", "NonReadableSecondary", "Primary", "Secondary", "Source"), - serialize_when_none=False, - ) - partner_server = StringType(default="-") - percent_complete = IntType(serialize_when_none=False) - replication_mode = StringType(serialize_when_none=False) - replication_state = StringType( - choices=("CATCH_UP", "PENDING", "SEEDING", "SUSPENDED"), - serialize_when_none=False, - ) - role = StringType( - choices=("Copy", "NonReadableSecondary", "Primary", "Secondary", "Source"), - serialize_when_none=False, - ) - start_time = DateTimeType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Sku(Model): - capacity = IntType(serialize_when_none=False) - family = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - size = StringType(serialize_when_none=False) - tier = StringType(serialize_when_none=False) - - -class Database(Model): - name = StringType(serialize_when_none=False) - id = StringType() - kind = StringType(serialize_when_none=False) - location = StringType() - managed_by = StringType(serialize_when_none=False) - server_name = StringType(serialize_when_none=False) - subscription_id = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - - administrator_login = StringType(default="-") - auto_pause_delay = IntType(serialize_when_none=False) - catalog_collation = StringType( - choices=("DATABASE_DEFAULT", "SQL_Latin1_General_CP1_CI_AS"), - serialize_when_none=False, - ) - collation = StringType(serialize_when_none=False) - create_mode = StringType( - choices=( - "Copy", - "Default", - "OnlineSecondary", - "PointInTimeRestore", - "Recovery", - "Restore", - "RestoreExternalBackup", - "RestoreExternalBackupSecondary", - "RestoreLongTermRetentionBackup", - "Secondary", - ), - serialize_when_none=False, - ) - creation_date = DateTimeType(serialize_when_none=False) - current_service_objective_name = StringType(serialize_when_none=False) - current_sku = ModelType(Sku, serialize_when_none=False) - database_id = StringType(serialize_when_none=False) - default_secondary_location = StringType(serialize_when_none=False) - earliest_restore_date = DateTimeType(serialize_when_none=False) - elastic_pool_id = StringType(serialize_when_none=False) - failover_group_id = StringType(serialize_when_none=False) - high_availability_replica_count = IntType(serialize_when_none=False) - license_type = StringType( - choices=("BasePrice", "LicenseIncluded"), serialize_when_none=False - ) - long_term_retention_backup_resource_id = StringType(default="-") - maintenance_configuration_id = StringType(serialize_when_none=False) - max_log_size_bytes = IntType(serialize_when_none=False) - max_size_bytes = IntType(serialize_when_none=False) - max_size_gb = FloatType(serialize_when_none=False) - min_capacity = FloatType(serialize_when_none=False) - paused_date = DateTimeType(serialize_when_none=False) - read_scale = StringType(choices=("Disabled", "Enabled"), default="Disabled") - recoverable_database_id = StringType(serialize_when_none=False) - recovery_services_recovery_point_id = StringType(serialize_when_none=False) - requested_service_objective_name = StringType(serialize_when_none=False) - restorable_dropped_database_id = StringType(serialize_when_none=False) - restore_point_in_time = StringType(serialize_when_none=False) - resumed_date = DateTimeType(serialize_when_none=False) - sample_name = StringType( - choices=("AdventureWorksLT", "WideWorldImportersFull", "WideWorldImportersStd"), - serialize_when_none=False, - ) - secondary_type = StringType(choices=("Geo", "Named"), serialize_when_none=False) - source_database_deletion_date = StringType(serialize_when_none=False) - source_database_id = StringType(serialize_when_none=False) - status = StringType( - choices=( - "AutoClosed", - "Copying", - "Creating", - "Disabled", - "EmergencyMode", - "Inaccessible", - "Offline", - "OfflineChangingDwPerformanceTiers", - "OfflineSecondary", - "Online", - "OnlineChangingDwPerformanceTiers", - "Paused", - "Pausing", - "Recovering", - "RecoveryPending", - "Restoring", - "Resuming", - "Scaling", - "Shutdown", - "Standby", - "Suspect", - ), - serialize_when_none=False, - ) - storage_account_type = StringType( - choices=("GRS", "LRS", "ZRS"), serialize_when_none=False - ) - zone_redundant = BooleanType(serialize_when_none=False) - diagnostic_settings_resource = ListType( - ModelType(DiagnosticSettingsResource), serialize_when_none=False - ) - replication_link = ListType(ModelType(ReplicationLink), serialize_when_none=False) - sync_group = ListType(ModelType(SyncGroup), serialize_when_none=False) - sync_agent = ListType(ModelType(SyncAgent), serialize_when_none=False) - sync_group_display = ListType(StringType, serialize_when_none=False) - sync_agent_display = ListType(StringType, serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - pricing_tier_display = StringType(default="-") - service_tier_display = StringType(default="-") - compute_tier = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ElasticPoolPerDatabaseSettings(Model): - max_capacity = FloatType(serialize_when_none=False) - min_capacity = FloatType(serialize_when_none=False) - - -class ElasticPool(Model): - name = StringType(serialize_when_none=False) - id = StringType() - kind = StringType(serialize_when_none=False) - location = StringType() - creation_date = DateTimeType(serialize_when_none=False) - license_type = StringType( - choices=("BasePrice", "LicenseIncluded"), default="BasePrice" - ) - maintenance_configuration_id = StringType(serialize_when_none=False) - max_size_bytes = IntType(serialize_when_none=False) - max_size_gb = FloatType(serialize_when_none=False, default=0) - per_database_settings = ModelType( - ElasticPoolPerDatabaseSettings, serialize_when_none=False - ) - state = StringType( - choices=("Creating", "Disabled", "Ready"), serialize_when_none=False - ) - zone_redundant = BooleanType(serialize_when_none=False) - sku = ModelType(Sku) - per_db_settings_display = StringType(serialize_when_none=False) - pricing_tier_display = StringType(serialize_when_none=False) - databases = ListType(ModelType(Database)) - number_of_databases = IntType(serialize_when_none=False, default=0) - unit_display = (StringType(serialize_when_none=False),) - server_name_display = StringType(serialize_when_none=False) - resource_group_display = StringType(serialize_when_none=False) - tags = ModelType(AzureTags) - type = StringType(serialize_when_none=False) - - -class EncryptionProtector(Model): - id = StringType() - kind = StringType(serialize_when_none=False) - location = StringType() - name = StringType() - server_key_name = StringType(serialize_when_none=False) - server_key_type = StringType( - choices=("AzureKeyVault", "ServiceManaged"), default="ServiceManaged" - ) - subregion = StringType(serialize_when_none=False) - thumbprint = StringType(serialize_when_none=False) - uri = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class RestorableDroppedDatabase(Model): - name = StringType(serialize_when_none=False) - id = StringType() - location = StringType() - creation_date = DateTimeType(serialize_when_none=False) - database_name = StringType(serialize_when_none=False) - deletion_date = DateTimeType(serialize_when_none=False) - earliest_restore_date = DateTimeType(serialize_when_none=False) - edition = StringType(serialize_when_none=False) - elastic_pool_name = StringType(default="-") - max_size_bytes = StringType(serialize_when_none=False) - service_level_objective = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class VirtualNetworkRule(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - subscription_id = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - ignore_missing_vnet_service_endpoint = BooleanType(serialize_when_none=False) - state = StringType( - choices=("Deleting", "InProgress", "Initializing", "Ready", "Unknown"), - serialize_when_none=False, - ) - virtual_network_subnet_id = StringType(serialize_when_none=False) - virtual_network_name_display = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class FirewallRule(Model): - id = StringType(serialize_when_none=False) - kind = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - end_ip_address = StringType(serialize_when_none=False) - start_ip_address = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class SQLServer(AzureCloudService): - name = StringType() - id = StringType() - identity = ModelType(ResourceIdentity, serialize_when_none=False) - kind = StringType(serialize_when_none=False) - location = StringType() - type = StringType() - administrator_login = StringType(serialize_when_none=False) - azure_ad_admin_name = StringType(default="Not configured") - administrator_login_password = StringType(serialize_when_none=False) - encryption_protectors = ListType( - ModelType(EncryptionProtector), serialize_when_none=False - ) - fully_qualified_domain_name = StringType(serialize_when_none=False) - minimal_tls_version = StringType( - choices=("1.0", "1.1", "1.2"), serialize_when_none=False - ) - private_endpoint_connections = ListType(ModelType(ServerPrivateEndpointConnection)) - public_network_access = StringType(choices=("Disabled", "Enabled")) - state = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - administrators = ModelType(ServerAzureADAdministrator, serialize_when_none=False) - azure_ad_administrators = ListType( - ModelType(ServerAzureADAdministrator, serialize_when_none=False) - ) - server_automatic_tuning = ModelType( - ServerAutomaticTuning, serialize_when_none=False - ) - server_automatic_tuning_display = BooleanType(serialize_when_none=False) - server_auditing_settings = ModelType( - ServerBlobAuditingPolicy, serialize_when_none=False - ) - failover_groups = ListType(ModelType(FailoverGroup), serialize_when_none=False) - databases = ListType(ModelType(Database), serialize_when_none=False) - elastic_pools = ListType(ModelType(ElasticPool), serialize_when_none=False) - deleted_databases = ListType( - ModelType(RestorableDroppedDatabase), serialize_when_none=False - ) - virtual_network_rules = ListType( - ModelType(VirtualNetworkRule), serialize_when_none=False - ) - firewall_rules = ListType(ModelType(FirewallRule), serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_server.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_server.yaml deleted file mode 100644 index 01d49f3c..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_server.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Databases Count by Server -query: - aggregate: - - unwind: - path: data.databases - - group: - keys: - - name: name - key: data.databases.server_name - fields: - - name: value - key: data.databases.server_name - operator: count -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_subscription.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_subscription.yaml deleted file mode 100644 index 33fe4e3b..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Databases Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_tier.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_tier.yaml deleted file mode 100644 index 62af3d2b..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_databases_count_by_tier.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Databases Count by Server -query: - aggregate: - - unwind: - path: data.databases - - group: - keys: - - name: name - key: data.databases.server_name - fields: - - name: value - key: data.databases.server_name - operator: text -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_account.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_account.yaml deleted file mode 100644 index f3e32e66..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_region.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_region.yaml deleted file mode 100644 index 62e79cdc..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_subscription.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_subscription.yaml deleted file mode 100644 index a682ffa0..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_count_by_subscription.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_region.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_region.yaml deleted file mode 100644 index f12cb1c2..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_region.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Failover Count by Region -query: - aggregate: - - unwind: - path: data.failover_groups - - group: - keys: - - name: name - key: data.failover_groups.location - fields: - - name: value - key: data.failover_groups.location - operator: count -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_server.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_server.yaml deleted file mode 100644 index f12cb1c2..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_failover_count_by_server.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Failover Count by Region -query: - aggregate: - - unwind: - path: data.failover_groups - - group: - keys: - - name: name - key: data.failover_groups.location - fields: - - name: value - key: data.failover_groups.location - operator: count -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_total_count.yaml b/src/spaceone/inventory/model/sql_servers/widget/sql_servers_total_count.yaml deleted file mode 100644 index bd9c6503..00000000 --- a/src/spaceone/inventory/model/sql_servers/widget/sql_servers_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: SQLServers -cloud_service_type: Server -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/storage_accounts/__init__.py b/src/spaceone/inventory/model/storage_accounts/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/storage_accounts/cloud_service.py b/src/spaceone/inventory/model/storage_accounts/cloud_service.py deleted file mode 100644 index 30f9d29d..00000000 --- a/src/spaceone/inventory/model/storage_accounts/cloud_service.py +++ /dev/null @@ -1,98 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType - -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField, SizeField, StateItemDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.storage_accounts.data import StorageAccount - -''' -STORAGE_ACCOUNT -''' -# TAB - Default -storage_account_info_meta = ItemDynamicLayout.set_fields('Storage Account', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('State of Primary', 'data.status_of_primary'), - TextDyField.data_source('Performance Tier', 'instance_type'), - TextDyField.data_source('Access Tier', 'data.access_tier'), - TextDyField.data_source('Replication', 'data.sku.name'), - TextDyField.data_source('Account Kind', 'data.kind'), - TextDyField.data_source('Provisioning State', 'data.provisioning_state'), - DateTimeDyField.data_source('Creation Time', 'data.creation_time'), - TextDyField.data_source('Container count', 'data.container_count_display'), - TextDyField.data_source('Blob count', 'data.blob_count_display'), - SizeField.data_source('Blob total size', 'data.blob_size_display') -]) - -# TAB - Networking -storage_group_networking = ItemDynamicLayout.set_fields('Networking', fields=[ - TextDyField.data_source('Is Public', 'data.network_rule_set.is_public_access_allowed'), - TextDyField.data_source('Virtual Network', 'data.network_rule_set.virtual_networks'), - ListDyField.data_source('Firewall Address Range', 'data.network_rule_set.firewall_address_range'), - ListDyField.data_source('Resource Instances', 'data.network_rule_set.resource_access_rules_display'), - TextDyField.data_source('Exceptions', 'data.network_rule_set.bypass'), - TextDyField.data_source('Routing Preference', 'data.routing_preference_display'), - TextDyField.data_source('Publish Microsoft Endpoints', 'data.routing_preference.publish_microsoft_endpoints'), - TextDyField.data_source('Publish Internet Endpoints', 'data.routing_preference.publish_internet_endpoints') -]) - -# TAB - Endpoints -storage_account_primary_endpoints = ItemDynamicLayout.set_fields('Primary Endpoints', fields=[ - TextDyField.data_source('Blob', 'data.primary_endpoints.blob'), - TextDyField.data_source('Queue', 'data.primary_endpoints.queue'), - TextDyField.data_source('Table', 'data.primary_endpoints.table'), - TextDyField.data_source('File', 'data.primary_endpoints.file'), - TextDyField.data_source('Web', 'data.primary_endpoints.web'), - TextDyField.data_source('DFS', 'data.primary_endpoints.dfs'), - TextDyField.data_source('Microsoft Endpoints', 'data.routing_preference.publish_microsoft_endpoints'), - TextDyField.data_source('Internet Endpoints', 'data.routing_preference.publish_internet_endpoints') -]) - -# TAB - Encryption -storage_account_encryption = ItemDynamicLayout.set_fields('Encryption', 'data.encryption', fields=[ - TextDyField.data_source('Key Source', 'key_source'), - TextDyField.data_source('Key Vault URI', 'key_vault_properties.key_vault_uri') -]) - - -# TAB - Geo-Replication -storage_account_geo_replication = TableDynamicLayout.set_fields('Geo-Replication', fields=[ - TextDyField.data_source('Primary Location', 'data.primary_location'), - EnumDyField.data_source('Status of Primary', 'data.status_of_primary', default_state={ - 'safe': ['available'], - 'warning': ['unavailable'] - }), - TextDyField.data_source('Secondary Location', 'data.secondary_location'), - EnumDyField.data_source('Status of Secondary', 'data.status_of_secondary', default_state={ - 'safe': ['available'], - 'warning': ['unavailable'] - }) -]) - -storage_account_meta = CloudServiceMeta.set_layouts( - [storage_account_info_meta, storage_group_networking, storage_account_primary_endpoints, storage_account_encryption, - storage_account_geo_replication]) - - -class StorageResource(CloudServiceResource): - cloud_service_group = StringType(default='StorageAccounts') - - -class StorageAccountResource(StorageResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(StorageAccount) - _metadata = ModelType(CloudServiceMeta, default=storage_account_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class StorageAccountResponse(CloudServiceResponse): - resource = PolyModelType(StorageAccountResource) diff --git a/src/spaceone/inventory/model/storage_accounts/cloud_service_type.py b/src/spaceone/inventory/model/storage_accounts/cloud_service_type.py deleted file mode 100644 index 2b56f574..00000000 --- a/src/spaceone/inventory/model/storage_accounts/cloud_service_type.py +++ /dev/null @@ -1,188 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - SizeField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -storage_accounts_blob_count_by_account_conf = os.path.join(current_dir, 'widget/storage_accounts_blob_count_by_account.yaml') -storage_accounts_blob_count_by_region_conf = os.path.join(current_dir, 'widget/storage_accounts_blob_count_by_region.yaml') -storage_accounts_blob_count_by_resource_group_conf = os.path.join(current_dir, 'widget/storage_accounts_blob_count_by_resource_group.yaml') -storage_accounts_blob_size_by_account_conf = os.path.join(current_dir, 'widget/storage_accounts_blob_size_by_account.yaml') -storage_accounts_blob_size_by_region_conf = os.path.join(current_dir, 'widget/storage_accounts_blob_size_by_region.yaml') -storage_accounts_blob_size_by_resource_group_conf = os.path.join(current_dir, 'widget/storage_accounts_blob_size_by_resource_group.yaml') -storage_accounts_count_by_account_conf = os.path.join(current_dir, 'widget/storage_accounts_count_by_account.yaml') -storage_accounts_count_by_region_conf = os.path.join(current_dir, 'widget/storage_accounts_count_by_region.yaml') -storage_accounts_count_by_resource_group_conf = os.path.join(current_dir, 'widget/storage_accounts_count_by_resource_group.yaml') -storage_accounts_total_blob_count_conf = os.path.join(current_dir, 'widget/storage_accounts_total_blob_count.yaml') -storage_accounts_total_blob_size_conf = os.path.join(current_dir, 'widget/storage_accounts_total_blob_size.yaml') -storage_accounts_total_count_conf = os.path.join(current_dir, 'widget/storage_accounts_total_count.yaml') - -cst_storage_accounts = CloudServiceTypeResource() -cst_storage_accounts.name = 'Instance' -cst_storage_accounts.group = 'StorageAccounts' -cst_storage_accounts.service_code = 'Microsoft.Storage/storageAccounts' -cst_storage_accounts.labels = ['Storage'] -cst_storage_accounts.is_major = True -cst_storage_accounts.is_primary = True -cst_storage_accounts.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-service-accounts.svg', -} -cst_storage_accounts._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Container count', 'data.container_count_display'), - TextDyField.data_source('Blob count', 'data.blob_count_display'), - SizeField.data_source('Blob total size', 'data.blob_size_display'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('SKU', 'data.sku.name'), - TextDyField.data_source('Type', 'data.type'), - TextDyField.data_source('State of Primary', 'data.status_of_primary', options={ - 'is_optional': True - }), - TextDyField.data_source('Performance Tier', 'instance_type', options={ - 'is_optional': True - }), - TextDyField.data_source('Access Tier', 'data.access_tier', options={ - 'is_optional': True - }), - TextDyField.data_source('Replication', 'data.sku.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Kind of Account', 'data.kind', options={ - 'is_optional': True - }), - TextDyField.data_source('Provisioning State', 'data.provisioning_state', options={ - 'is_optional': True - }), - TextDyField.data_source('Is Public', 'data.allow_blob_public_access', options={ - 'is_optional': True - }), - TextDyField.data_source('Virtual Network', 'data.network_acls.virtual_networks', options={ - 'is_optional': True - }), - ListDyField.data_source('Firewall Address Range', 'data.network_acls.firewall_address_range', options={ - 'is_optional': True - }), - ListDyField.data_source('Resource Instances', 'data.network_acls.resource_access_rules_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Exceptions', 'data.network_acls.bypass', options={ - 'is_optional': True - }), - TextDyField.data_source('Routing Preference', 'data.routing_preference_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Publish Microsoft Endpoints', 'data.routing_preference.publish_microsoft_endpoints', options={ - 'is_optional': True - }), - TextDyField.data_source('Publish Internet Endpoints', 'data.routing_preference.publish_internet_endpoints', options={ - 'is_optional': True - }), - TextDyField.data_source('Blob', 'data.primary_endpoints.blob', options={ - 'is_optional': True - }), - TextDyField.data_source('Queue', 'data.primary_endpoints.queue', options={ - 'is_optional': True - }), - TextDyField.data_source('Table', 'data.primary_endpoints.table', options={ - 'is_optional': True - }), - TextDyField.data_source('File', 'data.primary_endpoints.file', options={ - 'is_optional': True - }), - TextDyField.data_source('Web', 'data.primary_endpoints.web', options={ - 'is_optional': True - }), - TextDyField.data_source('DFS', 'data.primary_endpoints.dfs', options={ - 'is_optional': True - }), - TextDyField.data_source('Microsoft Endpoints', 'data.routing_preference.publish_microsoft_endpoints', options={ - 'is_optional': True - }), - TextDyField.data_source('Internet Endpoints', 'data.routing_preference.publish_internet_endpoints', options={ - 'is_optional': True - }), - TextDyField.data_source('Container Name', 'data.container_item.name', options={ - 'is_optional': True - }), - DateTimeDyField.data_source('Container Last Modified', 'data.container_item.last_modified_time', options={ - 'is_optional': True - }), - TextDyField.data_source('Container Public Access Level', 'data.container_item.public_access', options={ - 'is_optional': True - }), - TextDyField.data_source('Container Lease State', 'data.container_item.lease_state', options={ - 'is_optional': True - }), - TextDyField.data_source('Primary Location', 'data.primary_location', options={ - 'is_optional': True - }), - TextDyField.data_source('Secondary Location', 'data.secondary_location', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Container count', key='data.container_count_display', data_type='integer'), - SearchField.set(name='Blob count', key='data.blob_count_display', data_type='integer'), - SearchField.set(name='Blob total size(Bytes)', key='data.blob_size_display', data_type='integer'), - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='SKU', key='data.sku.name'), - SearchField.set(name='Type', key='data.type'), - SearchField.set(name='State of Primary', key='data.status_of_primary'), - SearchField.set(name='Performance Tier', key='instance_type'), - SearchField.set(name='Access Tier', key='data.access_tier'), - SearchField.set(name='Replication', key='data.sku.name'), - SearchField.set(name='Kind of Account', key='data.kind'), - SearchField.set(name='Provisioning State', key='data.provisioning_state'), - SearchField.set(name='Is Public', key='data.allow_blob_public_access', data_type='boolean'), - SearchField.set(name='Virtual Network', key='data.network_acls.virtual_networks'), - SearchField.set(name='Firewall Address Range', key='data.network_acls.firewall_address_range'), - SearchField.set(name='Resource Instances', key='data.network_acls.resource_access_rules_display'), - SearchField.set(name='Exceptions', key='data.network_acls.bypass'), - SearchField.set(name='Routing Preference', key='data.routing_preference_display'), - SearchField.set(name='Publish Microsoft Endpoints', key='data.routing_preference.publish_microsoft_endpoints'), - SearchField.set(name='Publish Internet Endpoints', key='data.routing_preference.publish_internet_endpoints'), - SearchField.set(name='Blob', key='data.primary_endpoints.blob'), - SearchField.set(name='Queue', key='data.primary_endpoints.queue'), - SearchField.set(name='Table', key='data.primary_endpoints.table'), - SearchField.set(name='File', key='data.primary_endpoints.file'), - SearchField.set(name='Web', key='data.primary_endpoints.web'), - SearchField.set(name='DFS', key='data.primary_endpoints.dfs'), - SearchField.set(name='Microsoft Endpoints', key='data.routing_preference.publish_microsoft_endpoints'), - SearchField.set(name='Internet Endpoints', key='data.routing_preference.publish_internet_endpoints'), - SearchField.set(name='Container Name', key='data.container_item.name'), - SearchField.set(name='Container Last Modified', key='data.container_item.last_modified_time', data_type='datetime'), - SearchField.set(name='Container Public Access Level', key='data.container_item.public_access'), - SearchField.set(name='Container Lease State', key='data.container_item.lease_state'), - SearchField.set(name='Primary Location', key='data.primary_location'), - SearchField.set(name='Secondary Location', key='data.secondary_location'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(storage_accounts_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_count_by_resource_group_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_blob_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_blob_count_by_resource_group_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_blob_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_blob_size_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_blob_size_by_resource_group_conf)), - ChartWidget.set(**get_data_from_yaml(storage_accounts_blob_size_by_account_conf)), - CardWidget.set(**get_data_from_yaml(storage_accounts_total_count_conf)), - CardWidget.set(**get_data_from_yaml(storage_accounts_total_blob_count_conf)), - CardWidget.set(**get_data_from_yaml(storage_accounts_total_blob_size_conf)), - ] -) - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_storage_accounts}), -] diff --git a/src/spaceone/inventory/model/storage_accounts/data.py b/src/spaceone/inventory/model/storage_accounts/data.py deleted file mode 100644 index 960cb5a0..00000000 --- a/src/spaceone/inventory/model/storage_accounts/data.py +++ /dev/null @@ -1,300 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType, DateTimeType, DictType, FloatType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -class SubResource(Model): - id = StringType() - - -class ExtendedLocation(Model): - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnectionState(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - - -class PrivateEndpointRef(Model): - id = StringType(serialize_when_none=False) - ''' - etag = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType(ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False) - manual_private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), - serialize_when_none=False) - network_interfaces = ListType(StringType(), serialize_when_none=False) # Change to network interfaces id - private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to subnet ID - tags = ModelType(Tags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - ''' - - -class PrivateEndpointConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - link_identifier = StringType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointRef) - private_link_service_connection_state = ModelType(PrivateLinkServiceConnectionState, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPolicyDefinition(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service = StringType(serialize_when_none=False) - service_resources = ListType(StringType) - - -class UserAssignedIdentity(Model): - client_id = StringType(serialize_when_none=False) - principal_id = StringType(serialize_when_none=False) - - -class Identity(Model): - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType(choices=('None', 'SystemAssigned', 'SystemAssigned,UserAssigned', 'UserAssigned'), serialize_when_none=False) - user_assigned_identities = DictType(StringType, ModelType(UserAssignedIdentity), serialize_when_none=False) - - -class ActiveDirectoryProperties(Model): - azure_storage_s_id = StringType(serialize_when_none=False) - domain_guid = StringType(serialize_when_none=False) - domain_name = StringType(serialize_when_none=False) - domain_s_id = StringType(serialize_when_none=False) - forest_name = StringType(serialize_when_none=False) - net_bios_domain_name = StringType(serialize_when_none=False) - - -class AzureFilesIdentityBasedAuthentication(Model): - active_directory_properties = ModelType(ActiveDirectoryProperties, serialize_when_none=False) - default_share_permission = StringType(choices=('None', 'StorageFileDataSmbShareContributor', 'StorageFileDataSmbShareElevatedContributor', 'StorageFileDataSmbShareOwner', 'StorageFileDataSmbShareReader'), serialize_when_none=False) - directory_service_options = StringType(choices=('AADDS', 'AD', 'None'), serialize_when_none=False) - - -class BlobRestoreRange(Model): - end_range = StringType(serialize_when_none=False) - start_range = StringType(serialize_when_none=False) - - -class BlobRestoreParameters(Model): - blob_ranges = ListType(ModelType(BlobRestoreRange), serialize_when_none=False) - time_to_restore = StringType(serialize_when_none=False) - - -class BlobRestoreStatus(Model): - failure_reason = StringType(serialize_when_none=False) - parameters = ModelType(BlobRestoreParameters, serialize_when_none=False) - restore_id = StringType(serialize_when_none=False) - status = StringType(choices=('Complete', 'Failed', 'InProgress'), serialize_when_none=False) - - -class CustomDomain(Model): - name = StringType(serialize_when_none=False) - use_sub_domain_name = BooleanType(serialize_when_none=False) - - -class EncryptionIdentity(Model): - user_assigned_identity = StringType(serialize_when_none=False) - - -class KeyVaultProperties(Model): - current_versioned_key_identifier = StringType(serialize_when_none=False) - key_name = StringType(serialize_when_none=False) - key_vault_uri = StringType(serialize_when_none=False) - key_version = StringType(serialize_when_none=False) - last_key_rotation_timestamp = DateTimeType(serialize_when_none=False) - - -class EncryptionService(Model): - enabled = BooleanType(serialize_when_none=False) - key_type = StringType(choices=('Account', 'Service'), serialize_when_none=False) - last_enabled_time = DateTimeType(serialize_when_none=False) - - -class EncryptionServices(Model): - blob = ModelType(EncryptionService, serialize_when_none=False) - file = ModelType(EncryptionService, serialize_when_none=False) - queue = ModelType(EncryptionService, serialize_when_none=False) - table = ModelType(EncryptionService, serialize_when_none=False) - - -class Encryption(Model): - identity = ModelType(EncryptionIdentity, serialize_when_none=False) - key_source = StringType(choices=('Microsoft.Keyvault', 'Microsoft.Storage')) - key_vault_properties = ModelType(KeyVaultProperties, serialize_when_none=False) - require_infrastructure_encryption = BooleanType(serialize_when_none=False) - services = ModelType(EncryptionServices, serialize_when_none=False) - - -class GeoReplicationStats(Model): - can_failover = BooleanType(serialize_when_none=False) - last_sync_time = StringType(serialize_when_none=False) - status = StringType(choices=('Bootstrap', 'Live', 'Unavailable'), serialize_when_none=False) - - -class KeyCreationTime(Model): - key1 = DateTimeType(serialize_when_none=False) - key2 = DateTimeType(serialize_when_none=False) - - -class KeyPolicy(Model): - key_expiration_period_in_days = IntType(serialize_when_none=False) - - -class IPRule(Model): - action = StringType(serialize_when_none=False) - value = StringType(serialize_when_none=False) - - -class ResourceAccessRule(Model): - resource_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - - -class VirtualNetworkRule(Model): - action = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - state = StringType(choices=('Deprovisioning', 'Failed', 'NetworkSourceDeleted', 'Provisioning', 'Succeeded'), serialize_when_none=False) - name = StringType(serialize_when_none=False) - - -class NetworkRuleSet(Model): - bypass = StringType(choices=('AzureServices', 'Logging', 'Metrics', 'None'), serialize_when_none=False) - default_action = StringType(choices=('Allow', 'Deny'), serialize_when_none=False) - is_public_access_allowed = BooleanType(serialize_when_none=False) - firewall_address_range = ListType(StringType, serialize_when_none=False) - ip_rules = ListType(ModelType(IPRule), serialize_when_none=False) - resource_access_rules = ListType(ModelType(ResourceAccessRule), serialize_when_none=False) - resource_access_rules_display = ListType(StringType, serialize_when_none=False) - virtual_network_rules = ListType(ModelType(VirtualNetworkRule), serialize_when_none=False) - virtual_networks = ListType(StringType, serialize_when_none=False) - - -class StorageAccountInternetEndpoints(Model): - blob = StringType(serialize_when_none=False) - dfs = StringType(serialize_when_none=False) - file = StringType(serialize_when_none=False) - web = StringType(serialize_when_none=False) - - -class StorageAccountMicrosoftEndpoints(Model): - blob = StringType(serialize_when_none=False) - dfs = StringType(serialize_when_none=False) - file = StringType(serialize_when_none=False) - web = StringType(serialize_when_none=False) - queue = StringType(serialize_when_none=False) - table = StringType(serialize_when_none=False) - - -class Endpoints(Model): - blob = StringType(serialize_when_none=False) - dfs = StringType(serialize_when_none=False) - file = StringType(serialize_when_none=False) - internet_endpoints = ModelType(StorageAccountInternetEndpoints, serialize_when_none=False) - microsoft_endpoints = ModelType(StorageAccountMicrosoftEndpoints, serialize_when_none=False) - queue = StringType(serialize_when_none=False) - table = StringType(serialize_when_none=False) - web = StringType(serialize_when_none=False) - - -class RoutingPreference(Model): - publish_internet_endpoints = BooleanType(serialize_when_none=False) - publish_microsoft_endpoints = BooleanType(serialize_when_none=False) - routing_choice = StringType(choices=('InternetRouting', 'MicrosoftRouting'), serialize_when_none=False) - - -class SasPolicy(Model): - expiration_action = StringType(serialize_when_none=False) - sas_expiration_period = StringType(serialize_when_none=False) - - -class Sku(Model): - name = StringType(choices=('Premium_LRS', 'Premium_ZRS', 'Standard_GRS', 'Standard_GZRS', 'Standard_LRS', - 'Standard_RAGRS', 'Standard_RAGZRS', 'Standard_ZRS'), serialize_when_none=False) - tier = StringType(choices=('Premium', 'Standard'), serialize_when_none=False) - - -class ContainerItem(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - etag = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - deleted = BooleanType(serialize_when_none=False) - deleted_time = DateTimeType(serialize_when_none=False) - remaining_retention_days = IntType(serialize_when_none=False) - public_access = StringType(serialize_when_none=False) - last_modified_time = DateTimeType(serialize_when_none=False) - lease_state = StringType(serialize_when_none=False) - lease_status = StringType(choices=['LOCKED', 'UNLOCKED']) - lease_duration = StringType(choices=['FIXED', 'INFINITE']) - # metadata = DictType(StringType) - default_encryption_scope = StringType(serialize_when_none=False) - - -class StorageAccount(AzureCloudService): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(default='-', serialize_when_none=False) - container_item = ListType(ModelType(ContainerItem), serialize_when_none=False) - identity = ModelType(Identity, serialize_when_none=False) - is_public = StringType(serialize_when_none=False) - access_tier = StringType(choices=('Cool', 'Hot'), serialize_when_none=False) - allow_blob_public_access = BooleanType(serialize_when_none=False) - allow_cross_tenant_replication = BooleanType(serialize_when_none=False) - allow_shared_key_access = BooleanType(serialize_when_none=False) - azure_files_identity_based_authentication = ModelType(AzureFilesIdentityBasedAuthentication, - serialize_when_none=False) - blob_range_status = ModelType(BlobRestoreStatus, serialize_when_none=False) - creation_time = DateTimeType(serialize_when_none=False) - custom_domain = ModelType(CustomDomain, serialize_when_none=False) - encryption = ModelType(Encryption, serialize_when_none=False) - failover_in_progress = BooleanType(serialize_when_none=False) - geo_replication_stats = ModelType(GeoReplicationStats, serialize_when_none=False) - is_hns_enabled = BooleanType(serialize_when_none=False) - is_nfs_v3_enabled = BooleanType(serialize_when_none=False) - key_creation_time = ModelType(KeyCreationTime, serialize_when_none=False) - key_policy = ModelType(KeyPolicy, serialize_when_none=False) - large_file_shares_state = StringType(choices=('Enabled', 'Disabled'), serialize_when_none=False) - last_geo_failover_time = StringType(serialize_when_none=False) - minimum_tls_version = StringType(choices=('TLS1_0', 'TLS1_1', 'TLS1_2'), serialize_when_none=False) - network_rule_set = ModelType(NetworkRuleSet, serialize_when_none=False) - primary_endpoints = ModelType(Endpoints, serialize_when_none=False) - primary_location = StringType(serialize_when_none=False) - private_endpoint_connections = ListType(ModelType(PrivateEndpointConnection), serialize_when_none=False) - provisioning_state = StringType(choices=('Creating', 'ResolvingDNS', 'Succeeded'), serialize_when_none=False) - routing_preference = ModelType(RoutingPreference, serialize_when_none=False) - routing_preference_display = StringType(default='Microsoft network routing') - sas_policy = ModelType(SasPolicy, serialize_when_none=False) - secondary_endpoints = ModelType(Endpoints, serialize_when_none=False) - secondary_location = StringType(default='-') - status_of_primary = StringType(choices=('available', 'unavailable'), serialize_when_none=False) - status_of_secondary = StringType(choices=('available', 'unavailable'), serialize_when_none=False) - supports_https_traffic_only = BooleanType(serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - type = StringType(serialize_when_none=False) - blob_size_display = FloatType(default=0.0) - blob_count_display = IntType(default=0) - container_count_display = IntType(default=0) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_account.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_account.yaml deleted file mode 100644 index 67875926..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_account.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Blob Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: data.blob_count_display - operator: sum - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_region.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_region.yaml deleted file mode 100644 index 048f68e4..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_region.yaml +++ /dev/null @@ -1,26 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Blob Count By Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - key: data.blob_count_display - operator: sum - filter: - - key: account - value: true - operator: exists -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code - diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_resource_group.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_resource_group.yaml deleted file mode 100644 index 6c4ddade..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_count_by_resource_group.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Blob Count by Resource Group -query: - aggregate: - - group: - keys: - - name: name - key: data.resource_group - fields: - - name: value - key: data.blob_count_display - operator: sum -options: - chart_type: DONUT \ No newline at end of file diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_account.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_account.yaml deleted file mode 100644 index 97ad9997..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_account.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Blob Size By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: data.blob_size_display - operator: sum - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT - value_options: - key: value - type: size diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_region.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_region.yaml deleted file mode 100644 index f8e28d1d..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_region.yaml +++ /dev/null @@ -1,24 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Blob Size by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - key: data.blob_size_display - operator: sum -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: "inventory.Region" - reference_key: region_code - value_options: - key: value - type: size \ No newline at end of file diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_resource_group.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_resource_group.yaml deleted file mode 100644 index a59c0051..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_blob_size_by_resource_group.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Blob Size by Resource Group -query: - aggregate: - - group: - keys: - - name: name - key: data.resource_group - fields: - - name: value - key: data.blob_size_display - operator: sum -options: - chart_type: DONUT - value_options: - key: value - type: size diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_account.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_account.yaml deleted file mode 100644 index f4d064a1..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_region.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_region.yaml deleted file mode 100644 index f71045f6..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_resource_group.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_resource_group.yaml deleted file mode 100644 index c1b47c2f..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_count_by_resource_group.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Count by Resource Group -query: - aggregate: - - group: - keys: - - name: name - key: data.resource_group - fields: - - name: value - operator: count -options: - chart_type: DONUT \ No newline at end of file diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_count.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_count.yaml deleted file mode 100644 index 30715273..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Total Blob Count -query: - aggregate: - - group: - fields: - - name: value - key: data.blob_count_display - operator: sum -options: - value_options: - key: value - options: - default: 0 diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_size.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_size.yaml deleted file mode 100644 index ea267919..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_blob_size.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Total Blob Size -query: - aggregate: - - group: - fields: - - name: value - key: data.blob_size_display - operator: sum -options: - value_options: - key: value - type: size - options: - default: 0 diff --git a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_count.yaml b/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_count.yaml deleted file mode 100644 index f990bf8c..00000000 --- a/src/spaceone/inventory/model/storage_accounts/widget/storage_accounts_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: StorageAccounts -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/virtual_machines/__init__.py b/src/spaceone/inventory/model/virtual_machines/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/virtual_machines/cloud_service.py b/src/spaceone/inventory/model/virtual_machines/cloud_service.py deleted file mode 100644 index d37ea67e..00000000 --- a/src/spaceone/inventory/model/virtual_machines/cloud_service.py +++ /dev/null @@ -1,290 +0,0 @@ -from schematics.types import ( - ModelType, - StringType, - PolyModelType, - FloatType, - DateTimeType, - DictType, - ListType, -) -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - TextDyField, - DateTimeDyField, - EnumDyField, - SizeField, - ListDyField, -) -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ( - ItemDynamicLayout, - TableDynamicLayout, - ListDynamicLayout, -) -from spaceone.inventory.libs.schema.cloud_service import ( - CloudServiceResource, - CloudServiceResponse, - CloudServiceMeta, - Tags, -) -from spaceone.inventory.model.virtual_machines.data import VirtualMachine - -""" -Virtual Machine -""" - -# TAB Default -# Instance -virtual_machine = ItemDynamicLayout.set_fields( - "Virtual Machine", - fields=[ - TextDyField.data_source("Resource ID", "data.compute.instance_id"), - TextDyField.data_source("VM ID", "data.compute.tags.vm_id"), - EnumDyField.data_source( - "VM State", - "data.compute.instance_state", - default_state={ - "safe": ["RUNNING"], - "warning": ["STARTING", "DEALLOCATING", "STOPPING", "DEALLOCATING"], - "disable": ["DEALLOCATED"], - "alert": ["STOPPED"], - }, - ), - TextDyField.data_source("Instance Type", "data.compute.instance_type"), - TextDyField.data_source("Image", "data.compute.image"), - EnumDyField.data_source( - "Azure Priority", - "data.azure.priority", - default_badge={ - "indigo.500": ["Regular"], - "coral.600": ["Low"], - "peacock.600": ["Spot"], - }, - ), - TextDyField.data_source("Region", "region_code"), - TextDyField.data_source("Availability Zone", "data.compute.az"), - TextDyField.data_source("Key Pair", "data.compute.keypair"), - EnumDyField.data_source( - "Ultra SSD Enabled", - "data.azure.ultra_ssd_enabled", - default_badge={ - "indigo.500": ["true"], - "coral.600": ["false"], - }, - ), - EnumDyField.data_source( - "Write Accelerator Enabled", - "data.azure.write_accelerator_enabled", - default_badge={"indigo.500": ["true"], "coral.600": ["false"]}, - ), - EnumDyField.data_source( - "Boot Diagnostics", - "data.azure.boot_diagnostics", - default_badge={"indigo.500": ["true"], "coral.600": ["false"]}, - ), - ListDyField.data_source( - "Public IP", - "data.nics", - options={"sub_key": "public_ip_address", "delimiter": "
"}, - ), - ListDyField.data_source( - "Security Groups", - "data.compute.security_groups", - options={"sub_key": "display", "delimiter": "
"}, - ), - DateTimeDyField.data_source("Launched At", "data.compute.launched_at"), - ], -) - -vnet = ItemDynamicLayout.set_fields( - "Virtual Network", - fields=[ - TextDyField.data_source("VNet ID", "data.vnet.vnet_id"), - TextDyField.data_source("VNet Name", "data.vnet.vnet_name"), - TextDyField.data_source("Subnet ID", "data.subnet.subnet_id"), - TextDyField.data_source("Subnet Name", "data.subnet.subnet_name"), - ], -) - -vm_os = ItemDynamicLayout.set_fields( - "Operating System", - fields=[ - TextDyField.data_source( - "OS Type", - "data.os.os_type", - options={"translation_id": "PAGE_SCHEMA.OS_TYPE"}, - ), - TextDyField.data_source( - "OS Distribution", - "data.os.os_distro", - options={ - "translation_id": "PAGE_SCHEMA.OS_DISTRO", - }, - ), - TextDyField.data_source( - "OS Architecture", - "data.os.os_arch", - options={ - "translation_id": "PAGE_SCHEMA.OS_ARCH", - }, - ), - TextDyField.data_source( - "OS Version Details", - "data.os.details", - options={ - "translation_id": "PAGE_SCHEMA.OS_DETAILS", - }, - ), - TextDyField.data_source( - "OS License", - "data.os.os_license", - options={ - "translation_id": "PAGE_SCHEMA.OS_LICENSE", - }, - ), - ], -) - -vm_hw = ItemDynamicLayout.set_fields( - "Hardware", - fields=[ - TextDyField.data_source( - "Core", - "data.hardware.core", - options={ - "translation_id": "PAGE_SCHEMA.CPU_CORE", - }, - ), - TextDyField.data_source( - "Memory", - "data.hardware.memory", - options={ - "translation_id": "PAGE_SCHEMA.MEMORY", - }, - ), - ], -) - -azure_vm = ListDynamicLayout.set_layouts( - "Azure VM", layouts=[virtual_machine, vm_os, vm_hw, vnet] -) - -# Tab Disk -disk = TableDynamicLayout.set_fields( - "Disk", - root_path="data.disks", - fields=[ - TextDyField.data_source("Index", "device_index"), - TextDyField.data_source("Name", "tags.disk_name"), - SizeField.data_source("Size", "size"), - TextDyField.data_source("Disk ID", "tags.disk_id"), - TextDyField.data_source("Storage Account Type", "tags.storage_Account_type"), - TextDyField.data_source("IOPS", "tags.iops"), - TextDyField.data_source("Throughput (mbps)", "tags.throughput_mbps"), - TextDyField.data_source("Encryption Set", "tags.disk_encryption_set"), - TextDyField.data_source("Caching", "tags.caching"), - ], -) - -# Tab - NIC -nic = TableDynamicLayout.set_fields( - "NIC", - root_path="data.nics", - fields=[ - TextDyField.data_source("Index", "device_index"), - TextDyField.data_source("Name", "tags.name"), - ListDyField.data_source( - "IP Addresses", "ip_addresses", options={"delimiter": "
"} - ), - TextDyField.data_source("Public IP", "public_ip_address"), - TextDyField.data_source("MAC Address", "mac_address"), - TextDyField.data_source("CIDR", "cidr"), - TextDyField.data_source("etag", "tags.etag"), - EnumDyField.data_source( - "Enable Accelerated Networking", - "tags.enable_accelerated_networking", - default_badge={"indigo.500": ["true"], "coral.600": ["false"]}, - ), - EnumDyField.data_source( - "Enable IP Forwarding", - "tags.enable_ip_forwarding", - default_badge={"indigo.500": ["true"], "coral.600": ["false"]}, - ), - ], -) - -# Tab - Security Group -security_group = TableDynamicLayout.set_fields( - "Network Security Groups", - root_path="data.security_group", - fields=[ - EnumDyField.data_source( - "Direction", - "direction", - default_badge={"indigo.500": ["inbound"], "coral.600": ["outbound"]}, - ), - TextDyField.data_source("Name", "security_group_name"), - EnumDyField.data_source( - "Protocol", "protocol", default_outline_badge=["ALL", "TCP", "UDP", "ICMP"] - ), - TextDyField.data_source("Port Range", "port"), - TextDyField.data_source("Remote", "remote"), - TextDyField.data_source("Priority", "priority"), - EnumDyField.data_source( - "Action", - "action", - default_badge={"indigo.500": ["allow"], "coral.600": ["deny"]}, - ), - TextDyField.data_source("Description", "description"), - ], -) - -# Tab - Load Balancer -lb = TableDynamicLayout.set_fields( - "Load Balancer", - root_path="data.load_balancer", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Endpoint", "endpoint"), - EnumDyField.data_source( - "Type", - "type", - default_badge={"indigo.500": ["network"], "coral.600": ["application"]}, - ), - ListDyField.data_source("Protocol", "protocol", options={"delimiter": "
"}), - ListDyField.data_source("Port", "port", options={"delimiter": "
"}), - EnumDyField.data_source( - "Scheme", - "scheme", - default_badge={ - "indigo.500": ["internet-facing"], - "coral.600": ["internal"], - }, - ), - ], -) - -virtual_machine_meta = CloudServiceMeta.set_layouts( - [azure_vm, disk, nic, security_group, lb] -) - - -class ComputeResource(CloudServiceResource): - cloud_service_group = StringType(default="VirtualMachines") - - -class VirtualMachineResource(ComputeResource): - cloud_service_type = StringType(default="Instance") - data = ModelType(VirtualMachine) - _metadata = ModelType( - CloudServiceMeta, default=virtual_machine_meta, serialized_name="metadata" - ) - name = StringType() - account = StringType(serialize_when_none=False) - ip_addresses = ListType(StringType()) - server_type = StringType(default="VM") - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class VirtualMachineResponse(CloudServiceResponse): - resource = PolyModelType(VirtualMachineResource) diff --git a/src/spaceone/inventory/model/virtual_machines/cloud_service_type.py b/src/spaceone/inventory/model/virtual_machines/cloud_service_type.py deleted file mode 100644 index 892858ef..00000000 --- a/src/spaceone/inventory/model/virtual_machines/cloud_service_type.py +++ /dev/null @@ -1,269 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, \ - ListDyField, \ - EnumDyField, SizeField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -virtual_machine_total_count_conf = os.path.join(current_dir, 'widget/virtual_machine_total_running_count.yaml') -virtual_machine_total_disk_size_conf = os.path.join(current_dir, 'widget/virtual_machine_total_disk_size.yaml') -virtual_machine_total_memory_size_conf = os.path.join(current_dir, 'widget/virtual_machine_total_memory_size.yaml') -virtual_machine_total_vcpu_count_conf = os.path.join(current_dir, 'widget/virtual_machine_total_vcpu_count.yaml') -virtual_machine_count_by_account_conf = os.path.join(current_dir, 'widget/virtual_machine_count_by_account.yaml') -virtual_machine_count_by_instance_type_conf = os.path.join(current_dir, - 'widget/virtual_machine_count_by_instance_type.yaml') -virtual_machine_count_by_region_conf = os.path.join(current_dir, 'widget/virtual_machine_count_by_region.yaml') - -cst_virtual_machine = CloudServiceTypeResource() -cst_virtual_machine.name = 'Instance' -cst_virtual_machine.group = 'VirtualMachines' -cst_virtual_machine.labels = ['Compute', 'Server'] -cst_virtual_machine.is_major = True -cst_virtual_machine.is_primary = True -cst_virtual_machine.service_code = 'Microsoft.Compute/virtualMachines' -cst_virtual_machine.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-vm.svg', -} - - -cst_virtual_machine._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - EnumDyField.data_source('Instance State', 'data.compute.instance_state', default_state={ - 'safe': ['RUNNING'], - 'warning': ['PENDING', 'REBOOTING', 'SHUTTING-DOWN', 'STOPPING', 'STARTING', - 'PROVISIONING', 'STAGING', 'DEALLOCATING', 'REPAIRING'], - 'alert': ['STOPPED', 'DEALLOCATED', 'SUSPENDED'], - 'disable': ['TERMINATED']} - ), - TextDyField.data_source('Cloud Service ID', 'cloud_service_id', options={ - 'is_optional': True - }), - TextDyField.data_source('Instance Type', 'data.compute.instance_type'), - TextDyField.data_source('Core', 'data.hardware.core'), - TextDyField.data_source('Memory', 'data.hardware.memory'), - TextDyField.data_source('Instance ID', 'data.compute.instance_id', options={ - 'is_optional': True - }), - TextDyField.data_source('Key Pair', 'data.compute.keypair', options={ - 'is_optional': True - }), - TextDyField.data_source('Image', 'data.compute.image', options={ - 'is_optional': True - }), - - TextDyField.data_source('Availability Zone', 'data.compute.az'), - TextDyField.data_source('OS Type', 'data.os.os_type', options={ - 'is_optional': True - }), - TextDyField.data_source('OS', 'data.os.os_distro'), - TextDyField.data_source('OS Architecture', 'data.os.os_arch', options={ - 'is_optional': True - }), - TextDyField.data_source('Primary IP', 'data.primary_ip_address'), - ListDyField.data_source('Public DNS', 'data.nics', options={ - 'sub_key': 'tags.public_dns', - 'is_optional': True - }), - ListDyField.data_source('Public IP', 'data.nics', options={ - 'sub_key': 'public_ip_address', - 'is_optional': True - }), - TextDyField.data_source('All IP', 'ip_addresses', options={ - 'is_optional': True - }), - TextDyField.data_source('MAC Address', 'data.nics.mac_address', options={ - 'is_optional': True - }), - TextDyField.data_source('CIDR', 'data.vnet.cidr', options={ - 'is_optional': True - }), - TextDyField.data_source('VNet ID', 'data.vnet.vnet_id', options={ - 'is_optional': True - }), - TextDyField.data_source('VNet Name', 'data.vnet.vnet_name', options={ - 'is_optional': True - }), - TextDyField.data_source('Subnet ID', 'data.subnet.subnet_id', options={ - 'is_optional': True - }), - TextDyField.data_source('Subnet Name', 'data.subnet.subnet_name', options={ - 'is_optional': True - }), - TextDyField.data_source('Load Balancer Name', 'data.load_balancer.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Load Balancer DNS', 'data.load_balancer.endpoint', options={ - 'is_optional': True - }), - TextDyField.data_source('Ultra SSD Enabled', 'data.azure.ultra_ssd_enabled', options={ - 'is_optional': True - }), - TextDyField.data_source('Write Accelerator Enabled', 'data.azure.write_accelerator_enabled', options={ - 'is_optional': True - }), - TextDyField.data_source('Boot Diagnostics', 'data.azure.boot_diagnostics', options={ - 'is_optional': True - }), - TextDyField.data_source('Priority', 'data.azure.priority', options={ - 'is_optional': True - }), - TextDyField.data_source('Auto Scaling Group', 'data.auto_scaling_group.name', options={ - 'is_optional': True - }), - TextDyField.data_source('CPU Utilization', 'data.monitoring.cpu.utilization.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - TextDyField.data_source('Memory Usage', 'data.monitoring.memory.usage.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - TextDyField.data_source('Disk Read IOPS', 'data.monitoring.disk.read_iops.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - TextDyField.data_source('Disk Write IOPS', 'data.monitoring.disk.write_iops.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - SizeField.data_source('Disk Read Throughput', 'data.monitoring.disk.read_throughput.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - SizeField.data_source('Disk Write Throughput', 'data.monitoring.disk.write_throughput.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - TextDyField.data_source('Network Received PPS', 'data.monitoring.network.received_pps.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - TextDyField.data_source('Network Send PPS', 'data.monitoring.network.sent_pps.avg', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - SizeField.data_source('Network Received Throughput', 'data.monitoring.network.received_throughput.avg', - options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - SizeField.data_source('Network Sent Throughput', 'data.monitoring.network.sent_throughput.avg', - options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Average)' - }), - TextDyField.data_source('CPU Utilization', 'data.monitoring.cpu.utilization.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - TextDyField.data_source('Memory Usage', 'data.monitoring.memory.usage.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - TextDyField.data_source('Disk Read IOPS', 'data.monitoring.disk.read_iops.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - TextDyField.data_source('Disk Write IOPS', 'data.monitoring.disk.write_iops.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - SizeField.data_source('Disk Read Throughput', 'data.monitoring.disk.read_throughput.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - SizeField.data_source('Disk Write Throughput', 'data.monitoring.disk.write_throughput.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - TextDyField.data_source('Network Received PPS', 'data.monitoring.network.received_pps.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - TextDyField.data_source('Network Send PPS', 'data.monitoring.network.sent_pps.max', options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - SizeField.data_source('Network Received Throughput', 'data.monitoring.network.received_throughput.max', - options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - SizeField.data_source('Network Sent Throughput', 'data.monitoring.network.sent_throughput.max', - options={ - 'default': 0, - 'is_optional': True, - 'field_description': '(Daily Max)' - }), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Launched', 'launched_at', options={'is_optional': True}), - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group.resource_group_name'), - SearchField.set(name='IP Address', key='ip_addresses'), - SearchField.set(name='Instance ID', key='data.compute.instance_id'), - SearchField.set(name='Instance State', key='data.compute.instance_state'), - SearchField.set(name='Instance Type', key='data.compute.instance_type'), - SearchField.set(name='Key Pair', key='data.compute.keypair'), - SearchField.set(name='Image', key='data.compute.image'), - SearchField.set(name='Availability Zone', key='data.compute.az'), - SearchField.set(name='OS Type', key='data.os.os_type'), - SearchField.set(name='OS Architecture', key='data.os.os_arch'), - SearchField.set(name='MAC Address', key='data.nics.mac_address'), - SearchField.set(name='Public IP Address', key='data.nics.public_ip_address'), - SearchField.set(name='Public DNS', key='data.nics.tags.public_dns'), - SearchField.set(name='VNet ID', key='data.vnet.vnet_id'), - SearchField.set(name='VNet Name', key='data.vnet.vnet_name'), - SearchField.set(name='Subnet ID', key='data.subnet.subnet_id'), - SearchField.set(name='Subnet Name', key='data.subnet.subnet_name'), - SearchField.set(name='ELB Name', key='data.load_balancer.name'), - SearchField.set(name='ELB DNS', key='data.load_balancer.endpoint'), - SearchField.set(name='Auto Scaling Group', key='data.auto_scaling_group.name'), - SearchField.set(name='Core', key='data.hardware.core', data_type='integer'), - SearchField.set(name='Memory', key='data.hardware.memory', data_type='float'), - SearchField.set(name='Management State', key='state'), - SearchField.set(name='Cloud Service Group', key='cloud_service_group'), - SearchField.set(name='Cloud Service Type', key='cloud_service_type'), - SearchField.set(name='Service Account', key='collection_info.service_accounts', - reference='identity.ServiceAccount'), - SearchField.set(name='Launched', key='data.launched_at'), - ], - widget=[ - CardWidget.set(**get_data_from_yaml(virtual_machine_total_count_conf)), - CardWidget.set(**get_data_from_yaml(virtual_machine_total_vcpu_count_conf)), - CardWidget.set(**get_data_from_yaml(virtual_machine_total_memory_size_conf)), - CardWidget.set(**get_data_from_yaml(virtual_machine_total_disk_size_conf)), - ChartWidget.set(**get_data_from_yaml(virtual_machine_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(virtual_machine_count_by_instance_type_conf)), - ChartWidget.set(**get_data_from_yaml(virtual_machine_count_by_account_conf)), - ] -) -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_virtual_machine}), -] diff --git a/src/spaceone/inventory/model/virtual_machines/data.py b/src/spaceone/inventory/model/virtual_machines/data.py deleted file mode 100644 index 8e9d88d7..00000000 --- a/src/spaceone/inventory/model/virtual_machines/data.py +++ /dev/null @@ -1,209 +0,0 @@ -from schematics import Model -from schematics.types import ( - ModelType, - ListType, - StringType, - FloatType, - DateTimeType, - BooleanType, - IntType, -) -from spaceone.inventory.libs.schema.resource import AzureCloudService, AzureTags -from spaceone.inventory.libs.schema.region import RegionResource - -from pydantic import BaseModel - - -# Activity Log -class ActivityLog(Model): - resource_uri = StringType() - - -# Azure -class Azure(Model): - ultra_ssd_enabled = BooleanType(default=False) - write_accelerator_enabled = BooleanType(default=False) - boot_diagnostics = BooleanType(default=True) - priority = StringType(choices=("Regular", "Low", "Spot"), default="Regular") - tags = ListType(ModelType(AzureTags)) - - -# Compute -class SecurityGroups(Model): - display = StringType() - id = StringType() - name = StringType() - - -class ComputeTags(Model): - vm_id = StringType() - - -class Compute(Model): - keypair = StringType() - az = StringType() - instance_state = StringType( - choices=( - "STARTING", - "RUNNING", - "STOPPING", - "STOPPED", - "DEALLOCATING", - "DEALLOCATED", - ) - ) - instance_type = StringType() - launched_at = DateTimeType() - instance_id = StringType(default="") - instance_name = StringType(default="") - security_groups = ListType(ModelType(SecurityGroups)) - image = StringType() - account = StringType(default="") - tags = ModelType(ComputeTags, default={}) - - -# Disk -class DiskTags(Model): - disk_name = StringType() - caching = StringType(choices=("None", "ReadOnly", "ReadWrite")) - storage_account_type = StringType( - choices=("Standard_LRS", "Premium_LRS", "StandardSSD_LRS", "UltraSSD_LRS") - ) - disk_encryption_set = StringType(choices=("PMK", "CMK"), default="PMK") - iops = IntType() - throughput_mbps = IntType() - disk_id = StringType() - - -class Disk(Model): - device_index = IntType() - device = StringType(default="") - disk_type = StringType(choices=("os_disk", "data_disk")) - size = FloatType() - tags = ModelType(DiskTags, default={}) - - -# Hardware -class Hardware(Model): - core = IntType(default=0) - memory = FloatType(default=0.0) - - -# Load Balancer -class LoadBalancerTags(Model): - lb_id = StringType() - - -class LoadBalancer(Model): - type = StringType(choices=("application", "network")) - endpoint = StringType() - port = ListType(IntType()) - name = StringType() - protocol = ListType(StringType()) - scheme = StringType(choices=("internet-facing", "internal")) - tags = ModelType(LoadBalancerTags, default={}) - - -# Nic -class NICTags(Model): - name = StringType() - etag = StringType() - enable_accelerated_networking = BooleanType(default=False) - enable_ip_forwarding = BooleanType(default=False) - - -class NIC(Model): - device_index = IntType() - device = StringType(default="") - nic_type = StringType(default="") - ip_addresses = ListType(StringType(), default=[]) - cidr = StringType() - mac_address = StringType(default="") - public_ip_address = StringType() - tags = ModelType(NICTags, default={}) - - -# OS -class OS(Model): - os_distro = StringType() - os_arch = StringType(default="x86_64") - details = StringType() - os_type = StringType(choices=("LINUX", "WINDOWS")) - - -# Resource Group -class ResourceGroup(Model): - resource_group_name = StringType() - resource_group_id = StringType() - - -# Security Group -class SecurityGroup(Model): - protocol = StringType() - remote = StringType() - remote_cidr = StringType(serialize_when_none=False) - remote_id = StringType(serialize_when_none=False) - security_group_name = StringType() - security_group_id = StringType() - description = StringType(default="") - direction = StringType(choices=("inbound", "outbound")) - port_range_min = IntType(serialize_when_none=False) - port_range_max = IntType(serialize_when_none=False) - port = StringType(serialize_when_none=False) - priority = IntType(serialize_when_none=False) - action = StringType(choices=("allow", "deny")) - - -# Subnet -class Subnet(Model): - subnet_name = StringType() - subnet_id = StringType() - cidr = StringType() - - -# Subscription -class Subscription(Model): - subscription_id = StringType() - subscription_name = StringType() - tenant_id = StringType() - tenant_name = StringType(serialize_when_none=False) - domain = StringType(serialize_when_none=False) - - -# VMSS -class VMSS(Model): - scale_set_name = StringType() - capacity = IntType() - admin_username = StringType() - unique_id = StringType() - - -# VNet -class VNet(Model): - vnet_id = StringType() - vnet_name = StringType() - cidr = StringType() - - -class VirtualMachine(AzureCloudService): # Main Class - os = ModelType(OS) - azure = ModelType(Azure) - hardware = ModelType(Hardware) - security_group = ListType(ModelType(SecurityGroup)) - compute = ModelType(Compute) - load_balancer = ListType(ModelType(LoadBalancer)) - vnet = ModelType(VNet) - subnet = ModelType(Subnet) - vmss = ModelType(VMSS, serialize_when_none=False) - activity_log = ModelType(ActivityLog, serialize_when_none=False) - primary_ip_address = StringType(default="") - disks = ListType(ModelType(Disk)) - nics = ListType(ModelType(NIC)) - subscription = ModelType(Subscription) - resource_group = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_account.yaml b/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_account.yaml deleted file mode 100644 index f7972deb..00000000 --- a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: VirtualMachines -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_instance_type.yaml b/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_instance_type.yaml deleted file mode 100644 index 04a0f7ac..00000000 --- a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_instance_type.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: VirtualMachines -cloud_service_type: Instance -name: Count By Instance Type -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: TREEMAP - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_region.yaml b/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_region.yaml deleted file mode 100644 index a85bfcd3..00000000 --- a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: VirtualMachines -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_disk_size.yaml b/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_disk_size.yaml deleted file mode 100644 index 9481ddcb..00000000 --- a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_disk_size.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: VirtualMachines -cloud_service_type: Instance -name: Total Disk Size -query: - aggregate: - - unwind: - path: data.disks - - group: - fields: - - name: value - key: data.disks.size - operator: sum -options: - value_options: - key: value - type: size - options: - default: 0 - source_unit: Byte diff --git a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_memory_size.yaml b/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_memory_size.yaml deleted file mode 100644 index 347b008d..00000000 --- a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_memory_size.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: VirtualMachines -cloud_service_type: Instance -name: Total Memory Size -query: - aggregate: - - group: - fields: - - name: value - key: data.hardware.memory - operator: sum -options: - value_options: - key: value - type: size - options: - default: 0 - source_unit: GB diff --git a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_running_count.yaml b/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_running_count.yaml deleted file mode 100644 index 3ba08653..00000000 --- a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_running_count.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -cloud_service_group: VirtualMachines -cloud_service_type: Instance -name: Total Running Count -query: - aggregate: - - count: - name: value - filter: - - key: data.compute.instance_state - value: RUNNING - operator: eq -options: - value_options: - key: value - options: - default: 0 diff --git a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_vcpu_count.yaml b/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_vcpu_count.yaml deleted file mode 100644 index 19a92513..00000000 --- a/src/spaceone/inventory/model/virtual_machines/widget/virtual_machine_total_vcpu_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: VirtualMachines -cloud_service_type: Instance -name: Total vCPU Count -query: - aggregate: - - group: - fields: - - name: value - key: data.hardware.core - operator: sum -options: - value_options: - key: value - options: - default: 0 diff --git a/src/spaceone/inventory/model/virtual_networks/__init__.py b/src/spaceone/inventory/model/virtual_networks/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/virtual_networks/cloud_service.py b/src/spaceone/inventory/model/virtual_networks/cloud_service.py deleted file mode 100644 index 6038d89a..00000000 --- a/src/spaceone/inventory/model/virtual_networks/cloud_service.py +++ /dev/null @@ -1,119 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, DateTimeType, FloatType - -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \ - ListDyField, SizeField, StateItemDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout, SimpleTableDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta -from spaceone.inventory.model.virtual_networks.data import VirtualNetwork - -''' -VIRTUAL_NETWORK -''' -# TAB - Default -virtual_network_info_meta = ItemDynamicLayout.set_fields('Virtual Network', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - ListDyField.data_source('DNS servers', 'data.dhcp_options.dns_servers'), - EnumDyField.data_source('DDoS Protection Standard', 'data.enable_ddos_protection', default_state={ - 'safe': ['True'], - 'warning': ['False'] - }), - TextDyField.data_source('Resource GUID', 'data.resource_guid'), - ListDyField.data_source('Address Space', 'data.address_space.address_prefixes') -]) - - -''' -# TAB - Address Space - -# Address space, Address range, Address count -virtual_network_address_space = ItemDynamicLayout.set_fields('Address Space', 'data.address_space', fields=[ - ListDyField.data_source('Address Space', 'address_prefixes'), - TextDyField.data_source('Address Range', ''), - TextDyField.data_source('Address Count', '') -]) -''' - -# TAB - Connected Devices -virtual_network_connected_devices = SimpleTableDynamicLayout.set_fields('Connected Devices', 'data.connected_devices', fields=[ - TextDyField.data_source('Device', 'device'), - TextDyField.data_source('Type', 'type'), - # TextDyField.data_source('IP Address', ''), - TextDyField.data_source('Subnet', 'name') # TODO : 210713 -]) - -# TAB - Subnets -# Name, IPv4, IPv6, Available Ips, Delegated To, Security Group -virtual_network_subnets = SimpleTableDynamicLayout.set_fields('Subnets', 'data.subnets', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('IP Address Prefix', 'address_prefix'), - ListDyField.data_source('IP Address Prefixes', 'address_prefixes'), - TextDyField.data_source('Delegated To', 'delegations.name'), - TextDyField.data_source('Security Group', 'network_security_group.name') -]) - - -# TAB - Firewall -# Name, IP Address, Subnet -virtual_network_firewall = SimpleTableDynamicLayout.set_fields('Firewall', 'data.azure_firewall', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('IP Address', 'ip_configurations.private_ip_address'), - TextDyField.data_source('Subnet', 'subnet') -]) - -# TAB - Peerings -# Name, Peering Status, Peer, Gateway Transit -virtual_network_peerings = SimpleTableDynamicLayout.set_fields('Peerings', 'data.virtual_network_peerings', fields=[ - TextDyField.data_source('Name', 'name'), - EnumDyField.data_source('Peering Status', 'peering_state', default_state={ - 'safe': ['Connected'], - 'warning': ['Disconnected', 'Initiated'] - }), - TextDyField.data_source('Peer', 'remote_virtual_network.id'), - TextDyField.data_source('Gateway Transit', 'allow_gateway_transit') -]) - -virtual_network_service_endpoints = SimpleTableDynamicLayout.set_fields('Service Endpoints', 'data.service_endpoints', fields=[ - TextDyField.data_source('Service', 'service'), - TextDyField.data_source('Subnet', 'subnet'), - EnumDyField.data_source('Status', 'provisioning_state', default_state={ - 'safe': ['Succeeded'], - 'warning': ['Failed', 'Deleting', 'Updating'] - }), - TextDyField.data_source('Locations', 'locations') -]) - -# TAB - Private Endpoints -virtual_network_private_endpoints = SimpleTableDynamicLayout.set_fields('Private Endpoints', 'data.private_endpoints', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Subnet', 'subnet'), - TextDyField.data_source('Resource Group', 'resource_group') -]) - -virtual_network_meta = CloudServiceMeta.set_layouts( - [virtual_network_info_meta, virtual_network_connected_devices, - virtual_network_subnets, virtual_network_firewall, virtual_network_peerings, virtual_network_service_endpoints, - virtual_network_private_endpoints]) - - -class NetworkResource(CloudServiceResource): - cloud_service_group = StringType(default='VirtualNetworks') - - -class VirtualNetworkResource(NetworkResource): - cloud_service_type = StringType(default='Instance') - data = ModelType(VirtualNetwork) - _metadata = ModelType(CloudServiceMeta, default=virtual_network_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class VirtualNetworkResponse(CloudServiceResponse): - resource = PolyModelType(VirtualNetworkResource) diff --git a/src/spaceone/inventory/model/virtual_networks/cloud_service_type.py b/src/spaceone/inventory/model/virtual_networks/cloud_service_type.py deleted file mode 100644 index e49c6f6d..00000000 --- a/src/spaceone/inventory/model/virtual_networks/cloud_service_type.py +++ /dev/null @@ -1,144 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, ListDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -virtual_networks_count_by_account_conf = os.path.join(current_dir, 'widget/virtual_networks_count_by_account.yaml') -virtual_networks_count_by_region_conf = os.path.join(current_dir, 'widget/virtual_networks_count_by_region.yaml') -virtual_networks_count_by_subscription_conf = os.path.join(current_dir, 'widget/virtual_networks_count_by_subscription.yaml') -virtual_networks_subnet_count_by_region_conf = os.path.join(current_dir, 'widget/virtual_networks_subnet_count_by_region.yaml') -virtual_networks_subnet_count_by_subscription_conf = os.path.join(current_dir, 'widget/virtual_networks_subnet_count_by_subscription.yaml') -virtual_networks_total_count_conf = os.path.join(current_dir, 'widget/virtual_networks_total_count.yaml') - -cst_virtual_network = CloudServiceTypeResource() -cst_virtual_network.name = 'Instance' -cst_virtual_network.group = 'VirtualNetworks' -cst_virtual_network.service_code = 'Microsoft.Network/virtualNetworks' -cst_virtual_network.labels = ['Networking'] -cst_virtual_network.is_major = True -cst_virtual_network.is_primary = True -cst_virtual_network.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-virtual-networks.svg', -} - -cst_virtual_network._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - - # is_optional fields - Default - TextDyField.data_source('Subscription ID', 'account', options={ - 'is_optional': True - }), - ListDyField.data_source('DNS servers', 'data.dhcp_options.dns_servers', options={ - 'is_optional': True - }), - TextDyField.data_source('Resource GUID', 'data.resource_guid', options={ - 'is_optional': True - }), - ListDyField.data_source('Address Space', 'data.address_space.address_prefixes', options={ - 'is_optional': True - }), - - # is_optional fields - Connected Devices - TextDyField.data_source('Connected Device', 'data.connected_devices.device', options={ - 'is_optional': True - }), - TextDyField.data_source('Connected Device Type', 'data.connected_devices.type', options={ - 'is_optional': True - }), - TextDyField.data_source('Connected Subnet', 'data.connected_devices.name', options={ - 'is_optional': True - }), - - # is_optional fields -Subnets - TextDyField.data_source('Subnet Name', 'data.subnets.name', options={ - 'is_optional': True - }), - ListDyField.data_source('Subnet IP Prefixes', 'data.subnets.address_prefixes', options={ - 'is_optional': True - }), - TextDyField.data_source('Subnet Delegated To', 'data.subnets.delegations.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Subnet Network Security Group', 'data.subnets.network_security_group.name', options={ - 'is_optional': True - }), - - # is optional fields - Firewall - TextDyField.data_source('Firewall Name', 'data.azure_firewall.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall IP Address', 'data.azure_firewall.ip_configurations.private_ip_address', options={ - 'is_optional': True - }), - TextDyField.data_source('Firewall Subnet', 'data.azure_firewall.subnet', options={ - 'is_optional': True - }), - - # is_optional fields - Peerings - TextDyField.data_source('Peering Name', 'data.virtual_network_peerings.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Peer', 'data.virtual_network_peerings.remote_virtual_network.id', options={ - 'is_optional': True - }), - TextDyField.data_source('Peer Gateway Transit', 'data.virtual_network_peerings.allow_gateway_transit', options={ - 'is_optional': True - }), - - # is optional fields - Service Endpoints - TextDyField.data_source('Service Endpoint', 'data.service_endpoints.service', options={ - 'is_optional': True - }), - TextDyField.data_source('Service Endpoint Subnet', 'data.service_endpoints.subnet', options={ - 'is_optional': True - }), - TextDyField.data_source('Service Endpoint Locations', 'data.service_endpoints.locations', options={ - 'is_optional': True - }), - - # is optional fields - Private Endpoints - TextDyField.data_source('Private Endpoint', 'data.private_endpoints.name', options={ - 'is_optional': True - }), - TextDyField.data_source('Private Endpoint Subnet', 'data.private_endpoints.subnet', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='DNS servers', key='data.dhcp_options.dns_servers'), - SearchField.set(name='Resource GUID', key='data.resource_guid'), - SearchField.set(name='Address Space', key='data.address_space.address_prefixes'), - SearchField.set(name='Connected Device', key='data.connected_devices.device'), - SearchField.set(name='Connected Device Type', key='data.connected_devices.type'), - SearchField.set(name='Connected Subnet', key='data.connected_devices.name'), - SearchField.set(name='Subnet Name', key='data.subnets.name'), - SearchField.set(name='Subnet IP Prefixes', key='data.subnets.address_prefixes'), - SearchField.set(name='Subnet Delegated To', key='data.subnets.delegations.name'), - SearchField.set(name='Subnet Network Security Group', key='data.subnets.network_security_group.name'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(virtual_networks_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(virtual_networks_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(virtual_networks_count_by_subscription_conf)), - ChartWidget.set(**get_data_from_yaml(virtual_networks_subnet_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(virtual_networks_subnet_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(virtual_networks_total_count_conf)), - ] -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_virtual_network}), -] diff --git a/src/spaceone/inventory/model/virtual_networks/data.py b/src/spaceone/inventory/model/virtual_networks/data.py deleted file mode 100644 index 27926fca..00000000 --- a/src/spaceone/inventory/model/virtual_networks/data.py +++ /dev/null @@ -1,888 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType -from spaceone.inventory.libs.schema.resource import AzureCloudService, AzureTags - - -class SubResource(Model): - id = StringType() - - -''' -START OF REF CLASSES -''' - - -class NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties(Model): - fqdns = ListType(StringType, serialize_when_none=False) - group_id = StringType(serialize_when_none=False) - required_member_name = StringType(serialize_when_none=False) - - -class ExtendedLocation(Model): - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ApplicationSecurityGroupRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfigurationRef(Model): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_security_groups = ListType(ModelType(ApplicationSecurityGroupRef), serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - private_link_connection_properties = ModelType(NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = StringType(default='', serialize_when_none=False) # Change Public IP Address to id - subnet = StringType(default='', serialize_when_none=False) # Change Subnet to id - virtual_network_taps = ListType(ModelType(SubResource), serialize_when_none=False) - - -''' -END OF REF CLASSES -''' - - -class AddressSpace(Model): - address_count = IntType(serialize_when_none=False, default=0) - address_prefixes = ListType(StringType, default=['-']) - - -class AutoApproval(Model): - subscriptions = ListType(StringType, serialize_when_none=False) - - -class ApplicationGatewayIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ConnectedDevice(Model): # Customized class, model for connected device lists attached to this virtual network - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - device = StringType(serialize_when_none=False) - - -class CustomDnsConfigPropertiesFormat(Model): - fqdn = StringType(serialize_when_none=False) - ip_addresses = ListType(StringType, serialize_when_none=False) - - -class DdosSettings(Model): - ddos_custom_policy = ModelType(SubResource, serialize_when_none=False) - protected_ip = BooleanType(serialize_when_none=False) - protection_coverage = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - - -class DhcpOptions(Model): - dns_servers = ListType(StringType, default=['Azure provided DNS service']) - - -class Delegation(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(default='-', serialize_when_none=False) - actions = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service_name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class FlowLogFormatType(Model): - json = StringType(serialize_when_none=False) - - -class FlowLogFormatParameters(Model): - type = ModelType(FlowLogFormatType, serialize_when_none=False) - version = IntType(serialize_when_none=False) - - -class InboundNatPool(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_port_range_end = IntType(serialize_when_none=False) - frontend_port_range_start = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class InboundNatRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_ip_configurations = ListType(ModelType(NetworkInterfaceIPConfigurationRef), serialize_when_none=False) - target_virtual_machine = ListType(StringType, serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - port_mapping_display = StringType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class LoadBalancingRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - backend_address_pool_display = StringType(serialize_when_none=False) - backend_port = IntType(serialize_when_none=False) - disable_outbound_s_nat = BooleanType(serialize_when_none=False) - enable_floating_ip = BooleanType(serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configuration = ModelType(SubResource, serialize_when_none=False) - frontend_ip_configuration_display = StringType(serialize_when_none=False) - frontend_port = IntType(serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - load_distribution = StringType(choices=('Default', 'SourceIP', 'SourceIPProtocol'), serialize_when_none=False) - load_distribution_display = StringType(serialize_when_none=False) - probe = ModelType(SubResource, serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class OutboundRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allocated_outbound_ports = IntType(serialize_when_none=False) - backend_address_pool = ModelType(SubResource, serialize_when_none=False) - enable_tcp_reset = BooleanType(serialize_when_none=False) - frontend_ip_configurations = ListType(ModelType(SubResource), serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - protocol = StringType(choices=('All', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PublicIPAddressDnsSettingsRef(Model): - domain_name_label = StringType(serialize_when_none=False) - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class IpTagRef(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class NatGatewaySkuRef(Model): - name = StringType(choices=('Standard', None), serialize_when_none=False) - - -class NatGatewayRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_addresses = ListType(ModelType(SubResource), serialize_when_none=False) - public_ip_prefixes = ListType(ModelType(SubResource), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - subnets = ListType(ModelType(SubResource), serialize_when_none=False) - sku = ModelType(NatGatewaySkuRef, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PublicIPAddressSkuRef(Model): - name = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - tier = StringType(choices=('Global', 'Regional'), serialize_when_none=False) - - -class PublicIPAddressRef(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettingsRef, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = StringType(serialize_when_none=False) # Change to IP Configuration id - ip_tags = ListType(ModelType(IpTagRef), serialize_when_none=False) - # linked_public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - migration_phase = StringType(choices=('Abort', 'Commit', 'Committed', 'None', 'Prepare'), serialize_when_none=False) - nat_gateway = ModelType(NatGatewayRef, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSkuRef, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class FrontendIPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - inbound_nat_pools = ListType(ModelType(InboundNatPool), serialize_when_none=False) - inbound_nat_rules = ListType(ModelType(InboundNatRule), serialize_when_none=False) - load_balancing_rules = ListType(ModelType(LoadBalancingRule), serialize_when_none=False) - outbound_rules = ListType(ModelType(OutboundRule), serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(PublicIPAddressRef, serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class RetentionPolicyParameters(Model): - days = IntType(serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - - -class TrafficAnalyticsConfigurationProperties(Model): - enabled = BooleanType(serialize_when_none=False) - traffic_analytics_interval = IntType(serialize_when_none=False) - workspace_id = StringType(serialize_when_none=False) - workspace_region = StringType(serialize_when_none=False) - workspace_resource_id = StringType(serialize_when_none=False) - - -class TrafficAnalyticsProperties(Model): - network_watcher_flow_analytics_configuration = ModelType(TrafficAnalyticsConfigurationProperties, - serialize_when_none=False) - - -class FlowLog(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - enable = BooleanType(serialize_when_none=False) - flow_analytics_configuration = ModelType(TrafficAnalyticsProperties, serialize_when_none=False) - format = ModelType(FlowLogFormatParameters, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - retention_policy = ModelType(RetentionPolicyParameters, serialize_when_none=False) - storage_id = StringType(serialize_when_none=False) - target_resource_guid = StringType(serialize_when_none=False) - target_resource_id = StringType(serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class IPConfigurationProfile(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - - -class IPConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = StringType(serialize_when_none=False) # Change to PublicIPAddress ID - subnet = StringType(serialize_when_none=False) - - -class IpTag(Model): - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class ServiceAssociationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - allow_delete = BooleanType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - locations = ListType(ModelType(ExtendedLocation), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPolicyDefinition(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service = StringType(serialize_when_none=False) - service_resources = ListType(StringType) - - -class ServiceEndpointPolicy(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - service_endpoint_policy_definitions = ListType(ModelType(ServiceEndpointPolicyDefinition), - serialize_when_none=False) - subnets = ListType(StringType, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class ServiceEndpointPropertiesFormat(Model): - locations = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - service = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - - -class ResourceNavigationLink(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - link = StringType(serialize_when_none=False) - linked_resource_type = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class Route(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - next_hop_ip_address = StringType(serialize_when_none=False) - next_hop_type = StringType(choices=('Internet', 'None', 'VirtualAppliance', 'VirtualNetworkGateway', 'VnetLocal'), - serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - - -class RouteTable(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - disable_bgp_route_propagation = BooleanType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - routes = ListType(ModelType(Route), serialize_when_none=False) - subnets = ListType(StringType, default=[], serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NatGatewaySku(Model): - name = StringType(choices=('Standard', None), serialize_when_none=False) - - -class NatGateway(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_addresses = ListType(ModelType(SubResource), serialize_when_none=False) - public_ip_prefixes = ListType(ModelType(SubResource), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - subnets = ListType(ModelType(SubResource), serialize_when_none=False) - sku = ModelType(NatGatewaySku, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class PrivateLinkServiceConnectionState(Model): - actions_required = StringType(serialize_when_none=False) - description = StringType(serialize_when_none=False) - status = StringType(serialize_when_none=False) - - -class PrivateLinkServiceConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - group_ids = ListType(StringType, serialize_when_none=False) - private_link_service_connection_state = ModelType(PrivateLinkServiceConnectionState, serialize_when_none=False) - private_link_service_id = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - request_message = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateLinkServiceIpConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - type = StringType(serialize_when_none=False) - - -class Visibility(Model): - subscriptions = ListType(StringType, serialize_when_none=False) - - -class PrivateEndpointRef(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType(ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False) - manual_private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), - serialize_when_none=False) - network_interfaces = ListType(StringType(), serialize_when_none=False) # Change to network interfaces id - private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to subnet ID - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateEndpointConnection(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - link_identifier = StringType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointRef) - private_link_service_connection_state = ModelType(PrivateLinkServiceConnectionState, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateLinkService(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - alias = StringType(serialize_when_none=False) - auto_approval = ModelType(AutoApproval, serialize_when_none=False) - enable_proxy_protocol = BooleanType(serialize_when_none=False) - fqdns = ListType(StringType, serialize_when_none=False) - ip_configurations = ListType(ModelType(PrivateLinkServiceIpConfiguration), serialize_when_none=False) - loadBalancer_frontend_ip_configurations = ListType(ModelType(FrontendIPConfiguration), serialize_when_none=False) - network_interfaces = ListType(StringType, serialize_when_none=False) # Change to network interfaces' id - private_endpoint_connections = ListType(ModelType(PrivateEndpointConnection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - visibility = ModelType(Visibility, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PublicIPAddressDnsSettings(Model): - domain_name_label = StringType(serialize_when_none=False) - fqdn = StringType(serialize_when_none=False) - reverse_fqdn = StringType(serialize_when_none=False) - - -class PublicIPAddressSku(Model): - name = StringType(choices=('Basic', 'Standard'), serialize_when_none=False) - tier = StringType(choices=('Global', 'Regional'), serialize_when_none=False) - - -class PublicIPAddress(Model): - etag = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - ddos_settings = ModelType(DdosSettings, serialize_when_none=False) - dns_settings = ModelType(PublicIPAddressDnsSettings, serialize_when_none=False) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_address = StringType(serialize_when_none=False) - ip_configuration = ModelType(IPConfiguration, serialize_when_none=False) - ip_tags = ListType(ModelType(IpTag), serialize_when_none=False) - # linked_public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - migration_phase = StringType(choices=('Abort', 'Commit', 'Committed', 'None', 'Prepare'), serialize_when_none=False) - nat_gateway = ModelType(NatGateway, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - public_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - sku = ModelType(PublicIPAddressSku, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class ApplicationSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class SecurityRule(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - access = StringType(choices=('Allow', 'Deny'), serialize_when_none=False) - description = StringType(serialize_when_none=False) - destination_address_prefix = StringType(serialize_when_none=False) - destination_address_prefixes = ListType(StringType, serialize_when_none=False) - destination_application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - destination_port_range = StringType(serialize_when_none=False) - destination_port_ranges = ListType(StringType, serialize_when_none=False) - direction = StringType(choices=('Inbound', 'Outbound'), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - protocol = StringType(choices=('*', 'Ah', 'Esp', 'Icmp', 'Tcp', 'Udp'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - source_address_prefix = StringType(serialize_when_none=False) - source_address_prefixes = ListType(StringType, serialize_when_none=False) - source_application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - source_port_range = StringType(serialize_when_none=False) - source_port_ranges = ListType(StringType, serialize_when_none=False) - - -class NetworkInterfaceDnsSettings(Model): - applied_dns_servers = ListType(StringType, serialize_when_none=False) - dns_servers = ListType(StringType, serialize_when_none=False) - internal_dns_name_label = StringType(serialize_when_none=False) - internal_domain_name_suffix = StringType(serialize_when_none=False) - internal_fqdn = StringType(serialize_when_none=False) - - -class NetworkInterfaceIPConfiguration(Model): # ip configuration in a network interface - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_security_groups = ListType(ModelType(ApplicationSecurityGroup), serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - private_ip_address_version = StringType(choices=('IPv4', 'IPv6'), serialize_when_none=False) - private_ip_allocation_method = StringType(choices=('Dynamic', 'Static'), serialize_when_none=False) - private_link_connection_properties = ModelType(NetworkInterfaceIPConfigurationPrivateLinkConnectionProperties, - serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(PublicIPAddress, serialize_when_none=False) - subnet = StringType(serialize_when_none=False) # Change to Subnet ID - virtual_network_taps = ListType(ModelType(SubResource), serialize_when_none=False) - - -class NetworkInterfaceTapConfiguration(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkSecurityGroup(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(default='-', serialize_when_none=False) - default_security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - flow_logs = ListType(ModelType(FlowLog), serialize_when_none=False) - network_interfaces = StringType(serialize_when_none=False) # Change to Network interfaces' Id - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - security_rules = ListType(ModelType(SecurityRule), serialize_when_none=False) - subnets = ListType(StringType, serialize_when_none=False) # Change to Subnet IDs - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class NetworkInterface(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - dns_settings = ModelType(NetworkInterfaceDnsSettings, serialize_when_none=False) - dscp_configuration = ModelType(SubResource, serialize_when_none=False) - enable_accelerated_networking = BooleanType(serialize_when_none=False) - enable_ip_forwarding = BooleanType(serialize_when_none=False) - hosted_workloads = ListType(StringType, serialize_when_none=False) - ip_configurations = ListType(ModelType(NetworkInterfaceIPConfiguration), serialize_when_none=False) - mac_address = StringType(serialize_when_none=False) - migration_phase = StringType(choices=('Abort', 'Commit', 'Committed', 'None', 'Prepare'), serialize_when_none=False) - nic_type = StringType(choices=('Elastic', 'Standard'), serialize_when_none=False) - network_security_group = ModelType(NetworkSecurityGroup, serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - private_endpoint = ModelType(PrivateEndpointRef, serialize_when_none=False) - private_link_service = ModelType(PrivateLinkService, serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - tap_configurations = ListType(ModelType(NetworkInterfaceTapConfiguration), serialize_when_none=False) - virtual_machine = ModelType(SubResource, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class PrivateEndpoint(Model): - etag = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - location = ModelType(ExtendedLocation, serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - name = StringType(serialize_when_none=False) - custom_dns_configs = ListType(ModelType(CustomDnsConfigPropertiesFormat), serialize_when_none=False) - manual_private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), - serialize_when_none=False) - network_interfaces = ListType(ModelType(NetworkInterface), serialize_when_none=False) - private_link_service_connections = ListType(ModelType(PrivateLinkServiceConnection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - resource_group = StringType(serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -###### Firewall Classes ###### -class AzureFirewallRCAction(Model): - type = StringType(choices=('Allow', 'Deny'), serialize_when_none=False) - - -class AzureFirewallApplicationRuleProtocol(Model): - port = IntType(serialize_when_none=False) - protocol_type = StringType(choices=('Http', 'Https', 'Mssql'), serialize_when_none=False) - - -class AzureFirewallApplicationRule(Model): - description = StringType(serialize_when_none=False) - fqdn_tags = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(ModelType(AzureFirewallApplicationRuleProtocol), serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - target_fqdns = ListType(StringType, serialize_when_none=False) - - -class AzureFirewallApplicationRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - rules = ListType(ModelType(AzureFirewallApplicationRule), serialize_when_none=False) - - -class AzureFirewallIPConfiguration(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - private_ip_address = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - public_ip_address = ModelType(SubResource, serialize_when_none=False) - subnet = ModelType(SubResource, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class AzureFirewallPublicIPAddress(Model): - address = StringType(serialize_when_none=False) - - -class HubPublicIPAddresses(Model): - address = ListType(ModelType(AzureFirewallPublicIPAddress), serialize_when_none=False) - count = IntType(serialize_when_none=False) - - -class HubIPAddresses(Model): - private_ip_address = StringType(serialize_when_none=False) - public_ips = ModelType(HubPublicIPAddresses, serialize_when_none=False) - - -class AzureFirewallIpGroups(Model): - change_number = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - - -class AzureFirewallNatRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNetworkRule(Model): - description = StringType(serialize_when_none=False) - destination_addresses = ListType(StringType, serialize_when_none=False) - destination_ports = ListType(StringType, serialize_when_none=False) - destination_fqdns = ListType(StringType, serialize_when_none=False) - destination_ip_groups = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - protocols = ListType(StringType, serialize_when_none=False) - source_addresses = ListType(StringType, serialize_when_none=False) - source_ip_groups = ListType(StringType, serialize_when_none=False) - translated_address = StringType(serialize_when_none=False) - translated_fqdn = StringType(serialize_when_none=False) - translated_port = StringType(serialize_when_none=False) - - -class AzureFirewallNatRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = StringType(choices=('Dnat', 'Snat'), serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - rules = ListType(ModelType(AzureFirewallNatRule), serialize_when_none=False) - - -class AzureFirewallNetworkRuleCollection(Model): - etag = StringType() - id = StringType() - name = StringType(serialize_when_none=False) - action = ModelType(AzureFirewallRCAction, serialize_when_none=False) - priority = IntType(serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - rules = ListType(ModelType(AzureFirewallNetworkRule), serialize_when_none=False) - - -class AzureFirewallSku(Model): - name = StringType(choices=('AZFW_Hub', 'AZFW_VNet'), serialize_when_none=False) - tier = StringType(choices=('Premium', 'Standard'), serialize_when_none=False) - - -class AzureFirewall(Model): - etag = StringType() - id = StringType() - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - subnet = StringType(serialize_when_none=False) - application_rule_collections = ListType(ModelType(AzureFirewallApplicationRuleCollection), - serialize_when_none=False) - firewall_policy = ModelType(SubResource, serialize_when_none=False) - hub_ip_addresses = ModelType(HubIPAddresses, serialize_when_none=False) - ip_configurations = ListType(ModelType(AzureFirewallIPConfiguration), serialize_when_none=False) - ip_groups = ListType(ModelType(AzureFirewallIpGroups), serialize_when_none=False) - management_ip_configuration = ModelType(AzureFirewallIPConfiguration, serialize_when_none=False) - nat_rule_collections = ListType(ModelType(AzureFirewallNatRuleCollection), serialize_when_none=False) - network_rule_collections = ListType(ModelType(AzureFirewallNetworkRuleCollection), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - sku = ModelType(AzureFirewallSku, serialize_when_none=False) - threat_intel_mode = StringType(choices=('Alert', 'Deny', 'Off'), serialize_when_none=False) - virtual_hub = ModelType(SubResource, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class Subnet(Model): - etag = StringType(serialize_when_none=False) - id = StringType() - name = StringType(serialize_when_none=False) - address_prefix = StringType(serialize_when_none=False) - address_prefixes = ListType(StringType, serialize_when_none=False) - application_gateway_ip_configurations = ListType(ModelType(ApplicationGatewayIPConfiguration, serialize_when_none=False)) - delegations = ListType(ModelType(Delegation), serialize_when_none=False) - ip_allocations = ListType(ModelType(SubResource), serialize_when_none=False) - ip_configuration_profiles = ListType(ModelType(IPConfigurationProfile), serialize_when_none=False) - ip_configurations = ListType(ModelType(IPConfiguration), serialize_when_none=False) - azure_firewall = ListType(ModelType(AzureFirewall), serialize_when_none=False) - nat_gateway = ModelType(SubResource, serialize_when_none=False) - network_security_group = ModelType(NetworkSecurityGroup, serialize_when_none=False) - private_endpoint_network_policies = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - private_endpoints = ListType(ModelType(PrivateEndpoint), serialize_when_none=False) - private_link_service_network_policies = StringType(choices=('Disabled', 'Enabled'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - purpose = StringType(serialize_when_none=False) - resource_navigation_links = ListType(ModelType(ResourceNavigationLink, serialize_when_none=False)) - route_table = ModelType(RouteTable, serialize_when_none=False) - service_association_links = ListType(ModelType(ServiceAssociationLink), serialize_when_none=False) - service_endpoint_policies = ListType(ModelType(ServiceEndpointPolicy), serialize_when_none=False) - service_endpoints = ListType(ModelType(ServiceEndpointPropertiesFormat), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class VirtualNetworkBgpCommunities(Model): - regional_community = StringType(serialize_when_none=False) - virtual_network_community = StringType(serialize_when_none=False) - - -class VirtualNetworkPeering(Model): - id = StringType(serialize_when_none=False) - etag = StringType(serialize_when_none=False) - name = StringType() - allow_forwarded_traffic = BooleanType(serialize_when_none=False) - allow_gateway_transit = BooleanType(serialize_when_none=False) - allow_virtual_network_access = BooleanType(serialize_when_none=False) - do_not_verify_remote_gateways = BooleanType(serialize_when_none=False) - peering_state = StringType(choices=('Connected', 'Disconnected', 'Initiated'), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - remote_address_space = ModelType(AddressSpace, serialize_when_none=False) - remote_bgp_communities = ModelType(VirtualNetworkBgpCommunities, serialize_when_none=False) - remote_virtual_network = ModelType(SubResource, serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - use_remote_gateways = BooleanType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class VirtualNetwork(AzureCloudService): # Main Class - id = StringType(serialize_when_none=False) - etag = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(default='-', serialize_when_none=False) - extended_location = ModelType(ExtendedLocation, serialize_when_none=False) - address_space = ModelType(AddressSpace, serialize_when_none=False) - bgp_communities = ModelType(VirtualNetworkBgpCommunities, serialize_when_none=False) - ddos_protection_plan = ModelType(SubResource, serialize_when_none=False) - dhcp_options = ModelType(DhcpOptions, serialize_when_none=False) - enable_ddos_protection = BooleanType(default=False, serialize_when_none=False) - enable_vm_protection = BooleanType(serialize_when_none=False) - ip_allocations = ListType(ModelType(SubResource), serialize_when_none=False) - provisioning_state = StringType(choices=('Deleting', 'Failed', 'Succeeded', 'Updating'), serialize_when_none=False) - resource_guid = StringType(serialize_when_none=False) - service_endpoints = ListType(ModelType(ServiceEndpointPropertiesFormat), serialize_when_none=False) - private_endpoints = ListType(ModelType(PrivateEndpoint), serialize_when_none=False) - connected_devices = ListType(ModelType(ConnectedDevice), serialize_when_none=False) - subnets = ListType(ModelType(Subnet), serialize_when_none=False) - virtual_network_peerings = ListType(ModelType(VirtualNetworkPeering), serialize_when_none=False) - azure_firewall = ListType(ModelType(AzureFirewall), serialize_when_none=False) - type = StringType(serialize_when_none=False) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_account.yaml b/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_account.yaml deleted file mode 100644 index fd31940a..00000000 --- a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_account.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -cloud_service_group: VirtualNetworks -cloud_service_type: Instance -name: Count By Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count - filter: - - key: account - value: true - operator: exists -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_region.yaml b/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_region.yaml deleted file mode 100644 index 72c46b55..00000000 --- a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: VirtualNetworks -cloud_service_type: Instance -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_subscription.yaml b/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_subscription.yaml deleted file mode 100644 index 7d08c5a3..00000000 --- a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_count_by_subscription.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -cloud_service_group: VirtualNetworks -cloud_service_type: Instance -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_region.yaml b/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_region.yaml deleted file mode 100644 index 1a2973c4..00000000 --- a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_region.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: VirtualNetworks -cloud_service_type: Instance -name: Subnet Count by Region -query: - aggregate: - - unwind: - path: data.subnets - - group: - keys: - - name: name - key: region_code - fields: - - name: value - key: region_code - operator: count -options: - chart_type: COLUMN diff --git a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_subscription.yaml b/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_subscription.yaml deleted file mode 100644 index 98df63d4..00000000 --- a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_subnet_count_by_subscription.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -cloud_service_group: VirtualNetworks -cloud_service_type: Instance -name: Subnet Count by Subscription -query: - aggregate: - - unwind: - path: data.subnets - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_total_count.yaml b/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_total_count.yaml deleted file mode 100644 index d02f8e6f..00000000 --- a/src/spaceone/inventory/model/virtual_networks/widget/virtual_networks_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: VirtualNetworks -cloud_service_type: Instance -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/vm_scale_sets/__init__.py b/src/spaceone/inventory/model/vm_scale_sets/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/vm_scale_sets/cloud_service.py b/src/spaceone/inventory/model/vm_scale_sets/cloud_service.py deleted file mode 100644 index d44ed302..00000000 --- a/src/spaceone/inventory/model/vm_scale_sets/cloud_service.py +++ /dev/null @@ -1,296 +0,0 @@ -from schematics.types import ( - ModelType, - StringType, - PolyModelType, - FloatType, - DateTimeType, -) - -from spaceone.inventory.model.vm_scale_sets.data import VirtualMachineScaleSet -from spaceone.inventory.libs.schema.metadata.dynamic_field import ( - TextDyField, - DateTimeDyField, - EnumDyField, - ListDyField, - SizeField, - StateItemDyField, -) -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ( - ItemDynamicLayout, - TableDynamicLayout, - ListDynamicLayout, - SimpleTableDynamicLayout, -) -from spaceone.inventory.libs.schema.cloud_service import ( - CloudServiceResource, - CloudServiceResponse, - CloudServiceMeta, -) - -""" -VM_SCALE_SET -""" -# TAB - Default -# Instance termination notification(Configuration Tab), over provisioning, proximity placement group, Termination Notification -# application health monitoring(Health and repair Tab), Upgrade Policy(Upgrade Policy Tab), -vm_scale_set_info_meta = ItemDynamicLayout.set_fields( - "VmScaleSets", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Resource ID", "data.id"), - TextDyField.data_source("Resource Group", "data.resource_group"), - TextDyField.data_source("Location", "data.location"), - TextDyField.data_source("Subscription", "data.subscription_name"), - TextDyField.data_source("Subscription ID", "account"), - TextDyField.data_source("Instances", "data.instance_count"), - TextDyField.data_source( - "Operating System", - "data.virtual_machine_profile.os_profile.operating_system", - ), - TextDyField.data_source("Size", "instance_type"), - TextDyField.data_source( - "Virtual network/subnet", - "data.virtual_machine_profile.network_profile.primary_vnet", - ), - TextDyField.data_source("Host group", "data.host_group.id"), - TextDyField.data_source( - "Ephemeral OS Disk", - "data.virtual_machine_profile.storage_profile.os_disk.diff_disk_settings.option.local", - ), - TextDyField.data_source( - "Azure Spot Eviction Policy", "data.virtual_machine_profile.eviction_policy" - ), - TextDyField.data_source( - "Azure Spot Max Price", - "data.virtual_machine_profile.billing_profile.max_price", - ), - TextDyField.data_source( - "Termination Notification", "data.terminate_notification_display" - ), - TextDyField.data_source("OverProvisioning", "data.overprovision"), - TextDyField.data_source( - "Proximity Placement Group", "data.proximity_placement_group_display" - ), - TextDyField.data_source( - "Automatic Repairs", "data.automatic_repairs_policy.enabled" - ), - TextDyField.data_source("Upgrade Policy", "data.upgrade_policy.mode"), - TextDyField.data_source("Fault Domains", "data.platform_fault_domain_count"), - ], -) - -# TAB - Instances -# name, computer name, location, status, provisioning state, fault domain, -# protection policy, and latest model -vm_scale_set_instance = TableDynamicLayout.set_fields( - "Instances", - "data.vm_instances", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Computer Name", "os_profile.computer_name"), - TextDyField.data_source("Location", "location"), - EnumDyField.data_source( - "Status", - "vm_instance_status_profile.statuses.code", - default_state={ - "safe": ["PowerState/running", "PowerState/starting"], - "warning": [ - "PowerState/deallocated", - "PowerState/deallocating", - "PowerState/stopped", - "PowerState/stopping", - "PowerState/unknown", - ], - }, - ), - TextDyField.data_source("Provisioning State", "provisioning_state"), - TextDyField.data_source( - "Protection From Scale-in", "protection_policy.protect_from_scale_in" - ), - TextDyField.data_source( - "Protection From Scale-set Actions", - "protection_policy.protect_from_scale_set_actions", - ), - TextDyField.data_source("Latest Model", "latest_model_applied"), - TextDyField.data_source("Virtual Network", "primary_vnet"), - ], -) - -# TAB - Networking -# IP Configuration, Network interface, Virtual Network, Accelerated Networking, -# Inbound /Outbound port rules(x) , Load balancing(x) -vm_scale_set_info_networking = ItemDynamicLayout.set_fields( - "Networking", - "data.virtual_machine_profile.network_profile", - fields=[ - TextDyField.data_source("Virtual Network", "primary_vnet"), - ], -) - -vm_scale_set_info_network_configuration = SimpleTableDynamicLayout.set_fields( - "Network Configuration", - "data.virtual_machine_profile.network_profile.network_interface_configurations", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source( - "Network interface", "enable_accelerated_networking_display" - ), - TextDyField.data_source( - "Accelerated Networking", "enable_accelerated_networking_display" - ), - TextDyField.data_source("Primary", "primary"), - ], -) - -vm_scale_set_info_ip_configurations = SimpleTableDynamicLayout.set_fields( - "IP Configurations", - "data.virtual_machine_profile.network_profile.network_interface_configurations.ip_configurations", - fields=[ - TextDyField.data_source( - "Public Ip Address Configuration", "public_ip_address_configuration" - ), - TextDyField.data_source( - "Private IP Address Version", "private_ip_address_version" - ), - ], -) - -vm_scale_set_info_network = ListDynamicLayout.set_layouts( - "Networking", - layouts=[ - vm_scale_set_info_networking, - vm_scale_set_info_network_configuration, - vm_scale_set_info_ip_configurations, - ], -) - -# TAB - Scaling -# Instance Count, Scale-in policy -vm_scale_set_scaling_info = ItemDynamicLayout.set_fields( - "Scaling", - fields=[ - TextDyField.data_source("Instance Count", "data.instance_count"), - ListDyField.data_source( - "Scale-in Policy", - "data.scale_in_policy.rules", - options={"delimiter": "
"}, - ), - ], -) - -vm_scale_set_scaling_rules = SimpleTableDynamicLayout.set_fields( - "Autoscale Settings", - "data.virtual_machine_scale_set_power_state", - fields=[ - TextDyField.data_source("Name", "name"), - ListDyField.data_source( - "Profiles", "profiles_display", options={"delimiter": "
"} - ), - TextDyField.data_source("Default", "profiles.capacity.default"), - TextDyField.data_source("Max", "profiles.capacity.maximum"), - TextDyField.data_source("Min", "profiles.capacity.minimum"), - ], -) -vm_scale_set_info_scaling = ListDynamicLayout.set_layouts( - "Scaling", layouts=[vm_scale_set_scaling_info, vm_scale_set_scaling_rules] -) - -# TAB - Disks OS Disks and Data Disks -# Image reference, Storage Type, Size, MAX iops, max throughput, encryption, host caching -# : LUN, Storage Type, Size, MAx iops, max throughput, encryption, host caching -os_disk = ItemDynamicLayout.set_fields( - "OS Disk", - "data.virtual_machine_profile.storage_profile", - fields=[ - TextDyField.data_source("Image Reference", "image_reference_display"), - TextDyField.data_source( - "Storage Account Type", "os_disk.managed_disk.storage_account_type" - ), - SizeField.data_source( - "Size", "os_disk.disk_size_gb", options={"source_unit": "GB"} - ), - TextDyField.data_source("Host Caching", "os_disk.caching"), - ], -) -data_disks = SimpleTableDynamicLayout.set_fields( - "Data Disks", - "data.virtual_machine_profile.storage_profile.data_disks", - fields=[ - TextDyField.data_source("Name", "name"), - TextDyField.data_source("Storage Type", "managed_disk.storage_type"), - SizeField.data_source("Size", "disk_size_gb", options={"source_unit": "GB"}), - TextDyField.data_source("Max IOPS", "disk_iops_read_write"), - TextDyField.data_source("MAX Throughput(MBps)", "disk_m_bps_read_write"), - TextDyField.data_source("Encryption", "disk_encryption_set.id"), - TextDyField.data_source("Host Caching", "caching"), - TextDyField.data_source("LUN", "lun"), - ], -) -vm_scale_set_info_disk = ListDynamicLayout.set_layouts( - "Disks", layouts=[os_disk, data_disks] -) - -# TAB - Operating System -# Operating system, image reference, computer name prefix, administrator username, -# password authentication, vm agent, enable automatic OS upgrades, custom data and cloud init - -vm_scale_set_info_os_profile = ItemDynamicLayout.set_fields( - "Operating System", - fields=[ - TextDyField.data_source( - "Computer Name Prefix", - "data.virtual_machine_profile.os_profile.computer_name_prefix", - ), - TextDyField.data_source( - "Administrator Username", - "data.virtual_machine_profile.os_profile.admin_username", - ), - TextDyField.data_source( - "Operating System", - "data.virtual_machine_profile.os_profile.operating_system", - ), - TextDyField.data_source( - "VM Agent", - "data.virtual_machine_profile.os_profile.linux_configuration.provision_vm_agent", - ), - TextDyField.data_source( - "Automatic OS Upgrades", - "data.upgrade_policy.automatic_os_upgrade_policy.enable_automatic_os_upgrade", - ), - TextDyField.data_source( - "Custom Data", "data.virtual_machine_profile.os_profile.custom_data" - ), - ], -) - -vm_scale_set_meta = CloudServiceMeta.set_layouts( - [ - vm_scale_set_info_meta, - vm_scale_set_instance, - vm_scale_set_info_network, - vm_scale_set_info_scaling, - vm_scale_set_info_disk, - vm_scale_set_info_os_profile, - ] -) - - -class ComputeResource(CloudServiceResource): - cloud_service_group = StringType(default="VMScaleSets") - - -class VmScaleSetResource(ComputeResource): - cloud_service_type = StringType(default="ScaleSet") - data = ModelType(VirtualMachineScaleSet) - _metadata = ModelType( - CloudServiceMeta, default=vm_scale_set_meta, serialized_name="metadata" - ) - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - launched_at = DateTimeType(serialize_when_none=False) - - -class VmScaleSetResponse(CloudServiceResponse): - resource = PolyModelType(VmScaleSetResource) diff --git a/src/spaceone/inventory/model/vm_scale_sets/cloud_service_type.py b/src/spaceone/inventory/model/vm_scale_sets/cloud_service_type.py deleted file mode 100644 index 6fada7b2..00000000 --- a/src/spaceone/inventory/model/vm_scale_sets/cloud_service_type.py +++ /dev/null @@ -1,106 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -vm_scale_sets_count_by_region_conf = os.path.join(current_dir, 'widget/vm_scale_sets_count_by_region.yaml') -vm_scale_sets_count_by_subscription_conf = os.path.join(current_dir, 'widget/vm_scale_sets_count_by_subscription.yaml') -vm_scale_sets_total_instance_count_conf = os.path.join(current_dir, 'widget/vm_scale_sets_total_instance_count.yaml') - -cst_vm_scale_sets = CloudServiceTypeResource() -cst_vm_scale_sets.name = 'ScaleSet' -cst_vm_scale_sets.group = 'VMScaleSets' -cst_vm_scale_sets.service_code = 'Microsoft.Compute/virtualMachineScaleSets' -cst_vm_scale_sets.labels = ['Compute'] -cst_vm_scale_sets.is_major = True -cst_vm_scale_sets.is_primary = True -cst_vm_scale_sets.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-vm-scale-set.svg', -} - -cst_vm_scale_sets._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - TextDyField.data_source('Instance Count', 'data.instance_count'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Default', 'data.virtual_machine_scale_set_power_state.profiles.capacity.default'), - TextDyField.data_source('Max', 'data.virtual_machine_scale_set_power_state.profiles.capacity.maximum'), - TextDyField.data_source('Min', 'data.virtual_machine_scale_set_power_state.profiles.capacity.minimum'), - TextDyField.data_source('Azure Spot Eviction Policy', 'data.virtual_machine_profile.eviction_policy'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - - # is_optional fields - TextDyField.data_source('Subscription ID', 'account', options={ - 'is_optional': True - }), - TextDyField.data_source('Virtual network/subnet', 'data.virtual_machine_profile.network_profile.primary_vnet', options={ - 'is_optional': True - }), - TextDyField.data_source('Host group', 'data.host_group.id', options={ - 'is_optional': True - }), - TextDyField.data_source('Ephemeral OS Disk', - 'data.virtual_machine_profile.storage_profile.os_disk.diff_disk_settings.option.local', options={ - 'is_optional': True - }), - TextDyField.data_source('Azure Spot Eviction Policy', 'data.virtual_machine_profile.eviction_policy', options={ - 'is_optional': True - }), - TextDyField.data_source('Azure Spot Max Price', 'data.virtual_machine_profile.billing_profile.max_price', options={ - 'is_optional': True - }), - TextDyField.data_source('Termination Notification', - 'data.virtual_machine_profile.terminate_notification_display', options={ - 'is_optional': True - }), - TextDyField.data_source('OverProvisioning', 'data.overprovision', options={ - 'is_optional': True - }), - TextDyField.data_source('Proximity Placement Group', 'data.proximity_placement_group_display', options={ - 'is_optional': True - }), - TextDyField.data_source('Automatic Repairs', 'data.automatic_repairs_policy.enabled', options={ - 'is_optional': True - }), - TextDyField.data_source('Upgrade Policy', 'data.upgrade_policy.mode', options={ - 'is_optional': True - }), - TextDyField.data_source('Fault Domains (count)', 'data.platform_fault_domain_count', options={ - 'is_optional': True - }) - ], - search=[ - SearchField.set(name='Subscription ID', key='account'), - SearchField.set(name='Subscription Name', key='data.subscription_name'), - SearchField.set(name='Resource Group', key='data.resource_group'), - SearchField.set(name='Location', key='data.location'), - SearchField.set(name='Default', key='data.virtual_machine_scale_set_power_state.profiles.capacity.default'), - SearchField.set(name='Max', key='data.virtual_machine_scale_set_power_state.profiles.capacity.maximum'), - SearchField.set(name='Min', key='data.virtual_machine_scale_set_power_state.profiles.capacity.minimum'), - SearchField.set(name='Azure Spot Eviction Policy', key='data.virtual_machine_profile.eviction_policy'), - SearchField.set(name='Azure Spot Max Price', key='data.virtual_machine_profile.billing_profile.max_price'), - SearchField.set(name='Termination Notification', key='data.virtual_machine_profile.terminate_notification_display'), - SearchField.set(name='OverProvisioning', key='data.overprovision', data_type='boolean'), - SearchField.set(name='Proximity Placement Group', key='data.proximity_placement_group_display'), - SearchField.set(name='Automatic Repairs', key='data.automatic_repairs_policy.enabled', data_type='boolean'), - SearchField.set(name='Upgrade Policy', key='data.upgrade_policy.mode'), - SearchField.set(name='Fault Domains (count)', key='data.platform_fault_domain_count', data_type='integer'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(vm_scale_sets_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(vm_scale_sets_count_by_subscription_conf)), - CardWidget.set(**get_data_from_yaml(vm_scale_sets_total_instance_count_conf)) - ] - -) - - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_vm_scale_sets}), -] diff --git a/src/spaceone/inventory/model/vm_scale_sets/data.py b/src/spaceone/inventory/model/vm_scale_sets/data.py deleted file mode 100644 index 1b2aecff..00000000 --- a/src/spaceone/inventory/model/vm_scale_sets/data.py +++ /dev/null @@ -1,877 +0,0 @@ -from schematics import Model -from schematics.types import ( - ModelType, - ListType, - StringType, - IntType, - BooleanType, - DateTimeType, - TimedeltaType, - FloatType, -) -from spaceone.inventory.libs.schema.resource import AzureCloudService, AzureTags - - -class AdditionalCapabilities(Model): # belongs to VmScaleSet - ultra_ssd_enabled = BooleanType(serialize_when_none=False) - - -class AutomaticOSUpgradePolicy(Model): # belongs to VmScaleSet >> UpgradePolicy - disable_automatic_rollback = BooleanType(default=False, serialize_when_none=False) - enable_automatic_os_upgrade = BooleanType(default=False) - - -class AutomaticRepairsPolicy(Model): # belongs to VmScaleSet - enabled = BooleanType(default=False) - grace_period = StringType(serialize_when_none=False) - - -class EmailNotification(Model): - custom_emails = ListType(StringType, serialize_when_none=False) - send_to_subscription_administrator = BooleanType(serialize_when_none=False) - send_to_subscription_co_administrators = BooleanType(serialize_when_none=False) - - -class OperationType(Model): - scale = StringType(serialize_when_none=False) - - -class WebhookNotification(Model): - properties = StringType(serialize_when_none=False) - - -class AutoscaleNotification(Model): - email = ModelType(EmailNotification, serialize_when_none=False) - operation = ModelType(OperationType, serialize_when_none=False) - webhooks = ListType(ModelType(WebhookNotification), serialize_when_none=False) - - -class ScaleRuleMetricDimension(Model): - dimension_name = StringType(serialize_when_none=False) - operator = StringType(choices=("Equals", "NotEquals"), serialize_when_none=False) - values = ListType(StringType, serialize_when_none=False) - - -class MetricTrigger(Model): - dimensions = ListType( - ModelType(ScaleRuleMetricDimension), serialize_when_none=False - ) - metric_name = StringType(serialize_when_none=False) - metric_namespace = StringType(serialize_when_none=False) - metric_resource_uri = StringType(serialize_when_none=False) - operator = StringType( - choices=( - "Equals", - "GreaterThan", - "GreaterThanOrEqual", - "LessThan", - "LessThanOrEqual", - "NotEquals", - ), - serialize_when_none=False, - ) - statistic = StringType( - choices=("Average", "Max", "Min", "Sum"), serialize_when_none=False - ) - threshold = IntType(serialize_when_none=False) - time_aggregation = StringType( - choices=("Average", "Count", "Last", "Maximum", "Minimum", "Total"), - serialize_when_none=False, - ) - time_grain = TimedeltaType(serialize_when_none=False) - time_window = TimedeltaType(serialize_when_none=False) - - -class ScaleCapacity(Model): - default = StringType(serialize_when_none=False) - maximum = StringType(serialize_when_none=False) - minimum = StringType(serialize_when_none=False) - - -class TimeWindow(Model): - end = StringType(serialize_when_none=False) - start = StringType(serialize_when_none=False) - time_zone = StringType(serialize_when_none=False) - - -class RecurrentSchedule(Model): - days = ListType(StringType, serialize_when_none=False) - hours = ListType(IntType, serialize_when_none=False) - minutes = ListType(IntType, serialize_when_none=False) - time_zone = StringType(serialize_when_none=False) - - -class Recurrence(Model): - frequency = StringType( - choices=("Day", "Hour", "Minute", "Month", "None", "Second", "Week", "Year"), - serialize_when_none=False, - ) - schedule = ModelType(RecurrentSchedule) - - -class ScaleAction(Model): - direction = StringType( - choices=("Decrease", "Increase", "None"), serialize_when_none=False - ) - type = StringType( - choices=("ChangeCount", "ExactCount", "PercentChangeCount"), - serialize_when_none=False, - ) - value = StringType(serialize_when_none=False) - cooldown = TimedeltaType(serialize_when_none=False) - - -class ScaleRule(Model): - metric_trigger = ModelType(MetricTrigger, serialize_when_none=False) - scale_action = ModelType(ScaleAction, serialize_when_none=False) - - -class AutoscaleProfile(Model): - capacity = ModelType(ScaleCapacity, serialize_when_none=False) - fixed_date = ModelType(TimeWindow, serialize_when_none=False) - name = StringType(serialize_when_none=False) - recurrence = ModelType(Recurrence, serialize_when_none=False) - rules = ListType(ModelType(ScaleRule), serialize_when_none=False) - - -class AutoscaleSettingResource(Model): # belongs to VmScaleSet - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - enabled = BooleanType(default=True) - notifications = ListType( - ModelType(AutoscaleNotification), serialize_when_none=False - ) - profiles = ListType(ModelType(AutoscaleProfile), serialize_when_none=False) - profiles_display = ListType(StringType, serialize_when_none=False) - target_resource_uri = StringType(serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - - -class AutoscaleSettingResourceCollection(Model): - next_link = StringType(serialize_when_none=False) - value = ListType(ModelType(AutoscaleSettingResource), serialize_when_none=False) - - -class ApiEntityReference( - Model -): # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - id = StringType(serialize_when_none=False) - - -class BillingProfile(Model): # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - max_price = FloatType(serialize_when_none=False) - - -class BootDiagnostics(Model): - # belongs to the VmScaleSet >> VirtualMachineScaleSetVMProfile >> DiagnosticsProfile - enabled = BooleanType(serialize_when_none=False) - storage_uri = StringType(serialize_when_none=False) - - -class DiffDiskOptions(Model): # belongs to VmScaleSet >> DiffDiskSettings - local = StringType(serialize_when_none=False) - - -class DiffDiskSettings(Model): - option = StringType(serialize_when_none=False) - placement = StringType( - choices=("CacheDisk", "ResourceDisk"), serialize_when_none=False - ) - - -class DiagnosticsProfile( - Model -): # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - boot_diagnostics = ModelType(BootDiagnostics, serialize_when_none=False) - - -class ImageReference(Model): - exact_version = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - offer = StringType(serialize_when_none=False) - publisher = StringType(serialize_when_none=False) - sku = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - - -class SshPublicKey( - Model -): # belongs to VmScaleSet >> LinuxConfiguration >> SshConfiguration - key_data = StringType(serialize_when_none=False) - path = StringType(serialize_when_none=False) - - -class SshConfiguration(Model): # belongs to VmScaleSet >> LinuxConfiguration - public_keys = ListType(ModelType(SshPublicKey), serialize_when_none=False) - - -class LinuxConfiguration( - Model -): # belongs to VmScaleSet >> VirtualMachineScaleSetOSProfile - disable_password_authentication = BooleanType(serialize_when_none=False) - provision_vm_agent = BooleanType(serialize_when_none=False, default=True) - ssh = ModelType(SshConfiguration, serialize_when_none=False) - - -class Plan(Model): # belongs to VmScaleSet - name = StringType(serialize_when_none=False) - product = StringType(serialize_when_none=False) - promotion_code = StringType(serialize_when_none=False) - publisher = StringType(serialize_when_none=False) - - -class RollingUpgradePolicy(Model): # belongs to VmScaleSet >> UpgradePolicy - max_batch_instance_percent = IntType(default=20, serialize_when_none=False) - max_unhealthy_instance_percent = IntType(default=20, serialize_when_none=False) - max_unhealthy_upgraded_instance_percent = IntType( - default=20, serialize_when_none=False - ) - pause_time_between_batches = StringType(default="PT0S", serialize_when_none=False) - - -class ScaleInPolicy(Model): # belongs to VmScaleSet - rules = ListType(StringType, serialize_when_none=False) - - -class TerminateNotificationProfile( - Model -): # belongs to VmScaleSet >> ScheduledEventsProfile - enable = BooleanType(serialize_when_none=False) - not_before_timeout = StringType(default="PT5M", serialize_when_none=False) - - -class ScheduledEventsProfile(Model): # belongs to VmScaleSet - terminate_notification_profile = ModelType( - TerminateNotificationProfile, serialize_when_none=False - ) - - -class SecurityProfile(Model): # belongs to VmScaleSet - encryption_at_host = BooleanType(default=False, serialize_when_none=False) - - -class Settings(Model): - protocol = StringType(serialize_when_none=False) - port = IntType(serialize_when_none=False) - requestPath = StringType(serialize_when_none=False) - - -class Sku(Model): # belongs to VmScaleSet - capacity = IntType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - tier = StringType( - choices=("Standard", "Basic", "", None), - default="Standard", - serialize_when_none=False, - ) - - -class SubResource(Model): # belongs to VmScaleSet - id = StringType(serialize_when_none=False) - - -class InGuestPatchMode(Model): # belongs to VmScaleSet >> PatchSettings - in_guest_patch_mode = StringType( - choices=("AutomaticByOS", "Manual", "AutomaticByPlatform", "", None), - serialize_when_none=False, - ) - - -class PatchSettings(Model): # belongs to VmScaleSet - # patch_mode = ModelType(InGuestPatchMode, serialize_when_none=False) - patch_mode = StringType( - choices=("AutomaticByOS", "Manual", "AutomaticByPlatform"), - serialize_when_none=False, - ) - - -class AdditionalUnattendedContent(Model): # belongs to VmScaleSet - component_name = StringType( - choices=("Microsoft-Windows-Shell-Setup", ""), serialize_when_none=False - ) - content = StringType(serialize_when_none=False) - pass_name = StringType(choices=("OobeSystem", "", None), serialize_when_none=False) - setting_name = StringType( - choices=("AutoLogon", "FirstLogonCommands", "", None), serialize_when_none=False - ) - - -class WinRMListener(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> WindowsConfiguration >> WinRMConfiguration - certificate_url = StringType(serialize_when_none=False) - protocol_types = StringType(choices=("http", "https"), serialize_when_none=False) - - -class WinRMConfiguration(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> WindowsConfiguration - listeners = ListType(ModelType(WinRMListener), serialize_when_none=False) - - -class WindowsConfiguration(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - additional_unattended_content = ListType( - ModelType(AdditionalUnattendedContent), serialize_when_none=False - ) - enable_automatic_updates = BooleanType(serialize_when_none=False) - patch_settings = ModelType(PatchSettings, serialize_when_none=False) - provision_vm_agent = BooleanType(serialize_when_none=False) - time_zone = StringType(serialize_when_none=False) - win_rm = ModelType(WinRMConfiguration, serialize_when_none=False) - - -class UpgradePolicy(Model): # belongs to VmScaleSet - automatic_os_upgrade_policy = ModelType( - AutomaticOSUpgradePolicy, serialize_when_none=False - ) - mode = StringType( - choices=("Manual", "Automatic", "Rolling", None, ""), serialize_when_none=False - ) - rolling_upgrade_policy = ModelType(RollingUpgradePolicy, serialize_when_none=False) - - -class VirtualMachineScaleSetIdentity(Model): # belongs to VmScaleSet - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - type = StringType( - choices=( - "None", - "SystemAssigned", - " SystemAssigned,UserAssigned", - "UserAssigned", - "", - None, - ), - serialize_when_none=False, - ) - - -class VirtualMachineScaleSetExtension(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetExtensionProfile - id = StringType() - name = StringType() - auto_upgrade_minor_version = BooleanType(serialize_when_none=False) - enable_automatic_upgrade = BooleanType(serialize_when_none=False) - force_update_tag = StringType(serialize_when_none=False) - protected_settings = StringType(serialize_when_none=False) - provisioned_after_extensions = ListType(StringType, serialize_when_none=False) - provisioning_state = StringType(serialize_when_none=False) - publisher = StringType(serialize_when_none=False) - settings = ModelType(Settings, serialize_when_none=False) - type = StringType(serialize_when_none=False) - type_handler_version = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetExtensionProfile(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - extensions = ListType( - ModelType(VirtualMachineScaleSetExtension), serialize_when_none=False - ) - extensions_time_budget = StringType(serialize_when_none=False) # ISO 8601 format - - -class VirtualMachineScaleSetNetworkConfigurationDNSSettings(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetNetworkProfile - # >> VirtualMachineScaleSetNetworkConfiguration - dns_servers = ListType(StringType, serialize_when_none=False) - - -class VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetNetworkProfile >> - # VirtualMachineScaleSetNetworkConfiguration >> VirtualMachineScaleSetIPConfiguration >> - # VirtualMachineScaleSetPublicIPAddressConfiguration - domain_name_label = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetIpTag(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetNetworkProfile >> - # VirtualMachineScaleSetNetworkConfiguration >> VirtualMachineScaleSetIPConfiguration >> - # VirtualMachineScaleSetPublicIPAddressConfiguration - ip_tag_type = StringType(serialize_when_none=False) - tag = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetPublicIPAddressConfiguration(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - # >> VirtualMachineScaleSetNetworkProfile >> VirtualMachineScaleSetNetworkConfiguration - # >> VirtualMachineScaleSetIPConfiguration - name = StringType() - dns_settings = ModelType( - VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings, - serialize_when_none=False, - ) - idle_timeout_in_minutes = IntType(serialize_when_none=False) - ip_tags = ListType( - ModelType(VirtualMachineScaleSetIpTag), serialize_when_none=False - ) - public_ip_address_version = StringType( - choices=("IPv4", "IPv6"), default="IPv4", serialize_when_none=False - ) - public_ip_prefix = ModelType(SubResource, serialize_when_none=False) - - -class VirtualMachineScaleSetIPConfiguration(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - # >> VirtualMachineScaleSetNetworkProfile >> VirtualMachineScaleSetNetworkConfiguration - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - application_gateway_backend_address_pools = ListType( - ModelType(SubResource), serialize_when_none=False - ) - application_security_groups = ListType( - ModelType(SubResource), serialize_when_none=False - ) - load_balancer_backend_address_pools = ListType( - ModelType(SubResource), serialize_when_none=False - ) - load_balancer_inbound_nat_pools = ListType( - ModelType(SubResource), serialize_when_none=False - ) - primary = BooleanType(serialize_when_none=False) - private_ip_address_version = StringType( - choices=("IPv4", "IPv6"), default="IPv4", serialize_when_none=False - ) - public_ip_address_configuration = ModelType( - VirtualMachineScaleSetPublicIPAddressConfiguration, serialize_when_none=False - ) - subnet = ModelType(ApiEntityReference, serialize_when_none=False) - - -class VirtualMachineScaleSetNetworkConfiguration(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetNetworkProfile - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - dns_settings = ModelType( - VirtualMachineScaleSetNetworkConfigurationDNSSettings, serialize_when_none=False - ) - enable_accelerated_networking = BooleanType(serialize_when_none=False) - enable_ip_forwarding = BooleanType(serialize_when_none=False) - ip_configurations = ListType( - ModelType(VirtualMachineScaleSetIPConfiguration), serialize_when_none=False - ) - network_security_group = ModelType(SubResource, serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - - -class VaultCertificate(Model): - # belongs to VmScaleSet >> >> VirtualMachineScaleSetVMProfile >> VaultSecretGroup - certificate_store = StringType(serialize_when_none=False) - certificate_uri = StringType(serialize_when_none=False) - - -class VaultSecretGroup( - Model -): # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - source_vault = ModelType(SubResource, serialize_when_none=False) - vault_certificates = ListType( - ModelType(VaultCertificate), serialize_when_none=False - ) - - -class VirtualMachineScaleSetNetworkProfile( - Model -): # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - health_probe = ModelType(ApiEntityReference, serialize_when_none=False) - network_interface_configurations = ListType( - ModelType(VirtualMachineScaleSetNetworkConfiguration), serialize_when_none=False - ) - primary_vnet = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetOSProfile( - Model -): # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - admin_username = StringType(serialize_when_none=False) - admin_password = StringType(serialize_when_none=False) - computer_name_prefix = StringType(serialize_when_none=False) - custom_data = StringType(serialize_when_none=False, default="") - linux_configuration = ModelType(LinuxConfiguration, serialize_when_none=False) - secrets = ListType(ModelType(VaultSecretGroup), serialize_when_none=False) - windows_configuration = ModelType(WindowsConfiguration, serialize_when_none=False) - operating_system = StringType(serialize_when_none=False) - - -class DiskEncryptionSetParameters(Model): - id = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetManagedDiskParameters(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - # >> VirtualMachineScaleSetStorageProfile >> VirtualMachineScaleSetDataDisk - disk_encryption_set = ModelType( - DiskEncryptionSetParameters, serialize_when_none=False - ) - storage_account_type = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetDataDisk(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetStorageProfile - name = StringType(serialize_when_none=False) - caching = StringType( - choices=("None", "ReadOnly", "ReadWrite", "", None), serialize_when_none=False - ) - create_option = StringType( - choices=("Attach", "Empty", "FromImage", None, ""), - default="Empty", - serialize_when_none=False, - ) - disk_iops_read_write = IntType(serialize_when_none=False) - disk_m_bps_read_write = IntType(serialize_when_none=False) - disk_size_gb = IntType(serialize_when_none=False) - lun = IntType(serialize_when_none=False) - managed_disk = ModelType( - VirtualMachineScaleSetManagedDiskParameters, serialize_when_none=False - ) - write_accelerator_enabled = BooleanType(serialize_when_none=False) - - -class VirtualHardDisk(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetStorageProfile - # >> VirtualMachineScaleSetOSDisk - uri = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetOSDisk(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile >> VirtualMachineScaleSetStorageProfile - name = StringType() - caching = StringType( - choices=("None", "ReadOnly", "ReadWrite"), - default="None", - serialize_when_none=False, - ) - create_option = StringType( - choices=("Attach", "Empty", "FromImage"), - default="Empty", - serialize_when_none=False, - ) - diff_disk_settings = ModelType( - DiffDiskSettings, default=None, serialize_when_none=False - ) - disk_size_gb = IntType(serialize_when_none=False) - image = ModelType(VirtualHardDisk, serialize_when_none=False) - managed_disk = ModelType( - VirtualMachineScaleSetManagedDiskParameters, serialize_when_none=False - ) - os_type = StringType(choices=("Linux", "Windows"), serialize_when_none=False) - vhd_containers = ListType(StringType, serialize_when_none=False) - write_accelerator_enabled = BooleanType(serialize_when_none=False) - - -class VirtualMachineScaleSetStorageProfile( - Model -): # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - data_disks = ListType( - ModelType(VirtualMachineScaleSetDataDisk), serialize_when_none=False - ) - image_reference = ModelType(ImageReference, serialize_when_none=False) - os_disk = ModelType(VirtualMachineScaleSetOSDisk, serialize_when_none=False) - image_reference_display = StringType(serialize_when_none=False) - - -class VirtualMachineScaleSetVMProfile(Model): # belongs to VmScaleSet - billing_profile = ModelType(BillingProfile, serialize_when_none=False) - diagnostics_profile = ModelType(DiagnosticsProfile, serialize_when_none=False) - eviction_policy = StringType( - choices=("Deallocate", "Delete", "None"), default="None" - ) - extension_profile = ModelType( - VirtualMachineScaleSetExtensionProfile, serialize_when_none=False - ) - license_type = StringType( - choices=("Windows_Client", "Windows_Server", "RHEL_BYOS", "SLES_BYOS", None), - serialize_when_none=False, - ) - network_profile = ModelType( - VirtualMachineScaleSetNetworkProfile, serialize_when_none=False - ) - os_profile = ModelType(VirtualMachineScaleSetOSProfile, serialize_when_none=False) - priority = StringType( - choices=("Low", "Regular", "Spot", "", None), serialize_when_none=False - ) - scheduled_events_profile = ModelType( - ScheduledEventsProfile, serialize_when_none=False - ) - security_profile = ModelType(SecurityProfile, serialize_when_none=False) - storage_profile = ModelType( - VirtualMachineScaleSetStorageProfile, serialize_when_none=False - ) - terminate_notification_display = StringType(serialize_when_none=False) - - -# vm instances class -class InstanceViewStatus(Model): - code = StringType(serialize_when_none=False) - display_status = StringType(serialize_when_none=False) - level = StringType(choices=("Error", "Info", "Warning"), serialize_when_none=False) - message = StringType(serialize_when_none=False) - time = DateTimeType(serialize_when_none=False) - - -class VirtualMachineExtensionInstanceView(Model): - name = StringType(serialize_when_none=False) - statuses = ListType(ModelType(InstanceViewStatus)) - substatuses = ListType(ModelType(InstanceViewStatus)) - type = StringType(serialize_when_none=False) - type_handler_version = StringType(serialize_when_none=False) - display_status = StringType(serialize_when_none=False) - - -class VirtualMachineExtension(Model): - id = StringType(serialize_when_none=False) - location = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - auto_upgrade_minor_version = BooleanType(serialize_when_none=False) - enable_automatic_upgrade = BooleanType(serialize_when_none=False) - force_update_tag = StringType(serialize_when_none=False) - instance_view = ModelType(VirtualMachineExtensionInstanceView) - protected_settings = StringType(serialize_when_none=False) - provisioning_state = StringType(serialize_when_none=False) - publisher = StringType(serialize_when_none=False) - settings = ModelType(Settings, serialize_when_none=False) - type = StringType(serialize_when_none=False) - type_handler_version = StringType(serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - - -class KeyVaultSecretReference(Model): - secret_url = StringType(serialize_when_none=False) - source_vault = ModelType(SubResource, serialize_when_none=False) - - -class KeyVaultKeyReference(Model): - key_url = StringType(serialize_when_none=False) - source_vault = ModelType(SubResource, serialize_when_none=False) - - -class DiskEncryptionSettings(Model): - disk_encryption_key = ModelType(KeyVaultSecretReference, serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - key_encryption_key = ModelType(KeyVaultKeyReference, serialize_when_none=False) - - -class ManagedDiskParameters(Model): - # belongs to VmScaleSet >> VirtualMachineScaleSetVMProfile - # >> VirtualMachineScaleSetStorageProfile >> VirtualMachineScaleSetDataDisk - disk_encryption_set = ModelType( - DiskEncryptionSetParameters, serialize_when_none=False - ) - storage_account_type = StringType(serialize_when_none=False) - storage_type = StringType(serialize_when_none=False) - id = StringType(serialize_when_none=False) - - -class OSDisk(Model): - name = StringType(serialize_when_none=False) - caching = StringType( - choices=("None", "ReadOnly", "ReadWrite"), - default="None", - serialize_when_none=False, - ) - create_option = StringType( - choices=("Attach", "Empty", "FromImage"), - default="Empty", - serialize_when_none=False, - ) - diff_disk_settings = ModelType(DiffDiskSettings, serialize_when_none=False) - disk_size_gb = IntType(serialize_when_none=False) - encryption_settings = ModelType(DiskEncryptionSettings, serialize_when_none=False) - image = ModelType(VirtualHardDisk, serialize_when_none=False) - managed_disk = ModelType(ManagedDiskParameters, serialize_when_none=False) - os_type = StringType(choices=("Linux", "Windows"), serialize_when_none=False) - vhd = ModelType(VirtualHardDisk, serialize_when_none=False) - write_accelerator_enabled = BooleanType(serialize_when_none=False) - - -class DataDisk(Model): - caching = StringType( - choices=("None", "ReadOnly", "ReadWrite", None), serialize_when_none=False - ) - name = StringType(serialize_when_none=False) - create_option = StringType( - choices=("Attach", "Empty", "FromImage", None), - default="Empty", - serialize_when_none=False, - ) - disk_iops_read_write = IntType(serialize_when_none=False) - disk_m_bps_read_write = IntType(serialize_when_none=False) - disk_size_gb = IntType(serialize_when_none=False) - lun = IntType(serialize_when_none=False) - managed_disk = ModelType(ManagedDiskParameters, serialize_when_none=False) - write_accelerator_enabled = BooleanType(serialize_when_none=False) - image = ModelType(VirtualHardDisk, serialize_when_none=False) - to_be_detached = BooleanType(serialize_when_none=False) - vhd = ModelType(VirtualHardDisk, serialize_when_none=False) - - -class StorageProfile(Model): - data_disks = ListType(ModelType(DataDisk), serialize_when_none=False) - image_reference = ModelType(ImageReference, serialize_when_none=False) - os_disk = ModelType(OSDisk, serialize_when_none=False) - - -class VirtualMachineScaleSetVMProtectionPolicy(Model): - protect_from_scale_in = BooleanType(default=False) - protect_from_scale_set_actions = BooleanType(default=False) - - -class OSProfile(Model): # belongs to VirtualMachineScaleSetVM - admin_username = StringType(serialize_when_none=False) - admin_password = StringType(serialize_when_none=False) - allow_extension_operations = BooleanType(serialize_when_none=False) - computer_name = StringType(serialize_when_none=False) - custom_data = StringType(serialize_when_none=False) - linux_configuration = ModelType(LinuxConfiguration, serialize_when_none=False) - windows_configuration = ModelType(WindowsConfiguration, serialize_when_none=False) - require_guest_provision_signal = BooleanType(serialize_when_none=False) - secrets = ListType(ModelType(VaultSecretGroup), serialize_when_none=False) - - -class HardwareProfile(Model): # belongs to VMScaleSet >> vm instances - vm_size = StringType(serialize_when_none=False) - - -class NetworkInterfaceReference(Model): - id = StringType(serialize_when_none=False) - primary = BooleanType(serialize_when_none=False) - - -class NetworkProfile(Model): # belongs to VirtualMachineScaleSetVM - network_interfaces = ListType( - ModelType(NetworkInterfaceReference), serialize_when_none=False - ) - - -class VirtualMachineScaleSetVMNetworkProfileConfiguration(Model): - network_interface_configurations = ListType( - ModelType(VirtualMachineScaleSetNetworkConfiguration), serialize_when_none=False - ) - - -class VirtualMachineAgentInstanceView(Model): - statuses = ListType(ModelType(InstanceViewStatus), serialize_when_none=False) - vm_agent_version = StringType(serialize_when_none=False) - display_status = StringType(serialize_when_none=False) # # - - -class VirtualMachineExtensionVMInstanceView(Model): - assigned_host = StringType(serialize_when_none=False) - # boot_diagnostics = ModelType(BootDiagnosticsInstanceView, serialize_when_none=False) - extensions = ListType( - ModelType(VirtualMachineExtensionInstanceView), serialize_when_none=False - ) - placement_group_id = StringType(serialize_when_none=False) - statuses = ListType(ModelType(InstanceViewStatus), serialize_when_none=False) - display_status = StringType(serialize_when_none=False) - vm_agent = ModelType(VirtualMachineAgentInstanceView, serialize_when_none=False) - - -class VirtualMachineScaleSetVM(Model): # data model for actual instances - id = StringType() - instance_id = StringType() - location = StringType() - name = StringType() - plan = ModelType(Plan, serialize_when_none=False) - additional_capabilities = ModelType( - AdditionalCapabilities, serialize_when_none=False - ) - available_set = ModelType(SubResource, serialize_when_none=False) - diagnostics_profile = ModelType(DiagnosticsProfile, serialize_when_none=False) - hardware_profile = ModelType(HardwareProfile, serialize_when_none=False) - latest_model_applied = BooleanType(default=True, serialize_when_none=False) - licence_type = StringType(serialize_when_none=False) - model_definition_applied = StringType(serialize_when_none=False) - network_profile = ModelType(NetworkProfile, serialize_when_none=False) - network_profile_configuration = ModelType( - VirtualMachineScaleSetVMNetworkProfileConfiguration, serialize_when_none=False - ) - primary_vnet = StringType(serialize_when_none=False) - os_profile = ModelType(OSProfile, serialize_when_none=False) - protection_policy = ModelType( - VirtualMachineScaleSetVMProtectionPolicy, serialize_when_none=False - ) - provisioning_state = StringType(serialize_when_none=False) - vm_instance_status_display = StringType(serialize_when_none=False) - security_profile = ModelType(SecurityProfile, serialize_when_none=False) - storage_profile = ModelType(StorageProfile, serialize_when_none=False) - vm_id = StringType(serialize_when_none=False) - vm_instance_status_profile = ModelType( - VirtualMachineExtensionVMInstanceView, serialize_when_none=False - ) - resources = ListType(ModelType(VirtualMachineExtension), serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - - -class VirtualMachineScaleSetPowerState(Model): - # id = StringType() - # vm_instances = ListType(ModelType(VirtualMachineScaleSetVM), serialize_when_none=False) - # instance_count = IntType() - # mode = StringType(choices=('Custom', 'Manual'), serialize_when_none=False) - location = StringType() - profiles = ListType(ModelType(AutoscaleProfile), serialize_when_none=False) - enabled = BooleanType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - notifications = ListType( - ModelType(AutoscaleNotification), serialize_when_none=False - ) - target_resource_uri = StringType(serialize_when_none=False) - tags = ModelType(AzureTags, serialize_when_none=False) - - -class VirtualMachineScaleSet(AzureCloudService): - id = StringType(serialize_when_none=False) - autoscale_setting_resource_collection = ModelType( - AutoscaleSettingResourceCollection, serialize_when_none=False - ) - location = StringType(serialize_when_none=False) - identity = ModelType(VirtualMachineScaleSetIdentity, serialize_when_none=False) - instance_count = IntType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - plan = ModelType(Plan, serialize_when_none=False) - additional_capabilities = ModelType( - AdditionalCapabilities, serialize_when_none=False - ) - automatic_repairs_policy = ModelType( - AutomaticRepairsPolicy, serialize_when_none=False - ) - do_not_run_extensions_on_overprovisioned_v_ms = BooleanType( - serialize_when_none=False - ) - host_group = ModelType(SubResource, serialize_when_none=False) - overprovision = BooleanType(default=True, serialize_when_none=False) - platform_fault_domain_count = IntType(serialize_when_none=False) - provisioning_state = StringType( - choices=("Failed", "Succeeded"), serialize_when_none=False - ) - proximity_placement_group = ModelType(SubResource, serialize_when_none=False) - proximity_placement_group_display = StringType( - serialize_when_none=False, default="None" - ) - scale_in_policy = ModelType(ScaleInPolicy, serialize_when_none=False) - single_placement_group = BooleanType(serialize_when_none=False) - unique_id = StringType(serialize_when_none=False) - upgrade_policy = ModelType(UpgradePolicy, serialize_when_none=False) - virtual_machine_profile = ModelType( - VirtualMachineScaleSetVMProfile, serialize_when_none=False - ) - terminate_notification_display = StringType(serialize_when_none=False) - virtual_machine_scale_set_power_state = ListType( - ModelType(VirtualMachineScaleSetPowerState) - ) - zone_balance = BooleanType(serialize_when_none=False) - sku = ModelType(Sku, serialize_when_none=False) - type = StringType(serialize_when_none=False) - zones = ListType(StringType, serialize_when_none=False) - vm_instances = ListType( - ModelType(VirtualMachineScaleSetVM), serialize_when_none=False - ) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_region.yaml b/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_region.yaml deleted file mode 100644 index f18ea2a8..00000000 --- a/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: VMScaleSets -cloud_service_type: ScaleSet -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code diff --git a/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_subscription.yaml b/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_subscription.yaml deleted file mode 100644 index f79e4b2d..00000000 --- a/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_count_by_subscription.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -cloud_service_group: VMScaleSets -cloud_service_type: ScaleSet -name: Count by Subscription -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_total_instance_count.yaml b/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_total_instance_count.yaml deleted file mode 100644 index 4d782595..00000000 --- a/src/spaceone/inventory/model/vm_scale_sets/widget/vm_scale_sets_total_instance_count.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -cloud_service_group: VMScaleSets -cloud_service_type: ScaleSet -name: Total Instance Count -query: - aggregate: - - group: - fields: - - name: value - key: data.instance_count - operator: sum diff --git a/src/spaceone/inventory/model/web_pubsub_service/__init__.py b/src/spaceone/inventory/model/web_pubsub_service/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/spaceone/inventory/model/web_pubsub_service/cloud_service.py b/src/spaceone/inventory/model/web_pubsub_service/cloud_service.py deleted file mode 100644 index 6810fac6..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/cloud_service.py +++ /dev/null @@ -1,202 +0,0 @@ -from schematics.types import ModelType, StringType, PolyModelType, FloatType, DateTimeType -from spaceone.inventory.model.web_pubsub_service.data import WebPubSubService, WebPubSubHub -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, ListDyField -from spaceone.inventory.libs.schema.metadata.dynamic_layout import ItemDynamicLayout, TableDynamicLayout, \ - ListDynamicLayout -from spaceone.inventory.libs.schema.cloud_service import CloudServiceResource, CloudServiceResponse, CloudServiceMeta - -''' -Web PubSub Service -''' - -# TAB - Web PubSub Service -web_pubsub_svc_info_meta = ItemDynamicLayout.set_fields('Web PubSub Service', fields=[ - TextDyField.data_source('Name', 'name'), - EnumDyField.data_source('Service State', 'data.provisioning_state', default_state={ - 'safe': ['Running', 'Succeeded'], - 'warning': ['Creating', 'Updating', 'Deleting', 'Moving', 'Updating'], - 'alert': ['Failed', 'Canceled'], - 'disable': ['Unknown']}), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Region', 'data.location'), - TextDyField.data_source('Hub count', 'data.web_pubsub_hub_count_display'), - TextDyField.data_source('SKU', 'data.sku.tier'), - TextDyField.data_source('Unit', 'data.sku.capacity'), - TextDyField.data_source('Version', 'data.version'), - TextDyField.data_source('Host name', 'data.host_name'), - TextDyField.data_source('Host name prefix', 'data.host_name_prefix'), - TextDyField.data_source('Public IP', 'data.external_ip'), - TextDyField.data_source('Public access', 'data.public_network_access'), - TextDyField.data_source('Public port', 'data.public_port'), - TextDyField.data_source('Server port', 'data.server_port'), - TextDyField.data_source('Disable add auth', 'data.disable_aad_auth'), - TextDyField.data_source('Disable local auth', 'data.disable_local_auth'), - TextDyField.data_source('TLS', 'data.tls.client_cert_enabled'), -]) - -# TAB - Keys -web_pubsub_svc_keys_info = ItemDynamicLayout.set_fields('Keys', fields=[ - TextDyField.data_source('Host name', 'data.host_name'), - TextDyField.data_source('Access Key', 'data.disable_local_auth'), - TextDyField.data_source('Primary Key', 'data.web_pubsub_key.primary_key'), - TextDyField.data_source('Primary Connection string', 'data.web_pubsub_key.primary_connection_string'), - TextDyField.data_source('Secondary Key', 'data.web_pubsub_key.secondary_key'), - TextDyField.data_source('Secondary Connection string', 'data.web_pubsub_key.secondary_connection_string'), -]) - -# TAB - Hub -web_pubsub_svc_hubs_info = TableDynamicLayout.set_fields('Hubs', root_path='data.web_pubsub_hubs', fields=[ - TextDyField.data_source('Hub name', 'name'), - EnumDyField.data_source('Anonymous Connect', 'properties.anonymous_connect_policy', default_badge={ - 'indigo.500': ['allow'], 'coral.600': ['deny'] - }), - ListDyField.data_source('Event Handlers', 'properties.event_handlers.url_template', options={'delimiter': '
'}) -]) - -# TAB - Public access -web_pubsub_svc_public_access_info = ItemDynamicLayout.set_fields('Public access', fields=[ - EnumDyField.data_source('Public network access', 'data.public_network_access', default_badge={ - 'indigo.500': ['Enabled'], 'coral.600': ['Disabled'] - }) -]) - -# TAB - Private access -private_endpoint_connections_private_access = TableDynamicLayout.set_fields('Private endpoint connections', root_path='data.private_endpoint_connections', fields=[ - TextDyField.data_source('Connection name', 'name'), - EnumDyField.data_source('Connection state', 'private_link_service_connection_state.status', default_state={ - 'safe': ['Approved'], - 'warning': ['Pending'], - 'alert': ['Disconnected', 'Rejected'], - 'disable': []}), - TextDyField.data_source('Private Endpoint', 'private_endpoint.private_endpoint_name_display'), - TextDyField.data_source('Description', 'private_link_service_connection_state.status'), - ListDyField.data_source('Group ids', 'group_ids', options={'delimiter': '
'}), - TextDyField.data_source('Provisioning state', 'provisioning_state') -]) -shared_private_endpoints_private_access = TableDynamicLayout.set_fields('Shared private endpoints', root_path='data.shared_private_link_resources', fields=[ - TextDyField.data_source('Name', 'name'), - TextDyField.data_source('Private link resource ID', 'private_link_resource_id'), - TextDyField.data_source('Group ID', 'group_id'), - EnumDyField.data_source('Connection state', 'status', default_state={ - 'safe': ['Approved'], - 'warning': ['Pending'], - 'alert': ['Disconnected', 'Rejected'], - 'disable': []}), - TextDyField.data_source('Description', 'request_message'), - TextDyField.data_source('Provisioning state', 'provisioning_state') -]) - -web_pubsub_svc_private_access_info = ListDynamicLayout.set_layouts('Private access', layouts=[ - private_endpoint_connections_private_access, shared_private_endpoints_private_access]) - -# TAB - Access control rules -default_action_access_control_rules = ItemDynamicLayout.set_fields('Default action', fields=[ - EnumDyField.data_source('Default action', 'data.network_ac_ls.default_action', default_badge={ - 'indigo.500': ['Allow'], 'coral.600': ['Deny']}) -]) - -public_network_access_control_rules = ItemDynamicLayout.set_fields('Public network', fields=[ - ListDyField.data_source('Allow', 'data.network_ac_ls.public_network.allow', options={'delimiter': ','}) -]) - -private_endpoint_connections_access_control_rules = TableDynamicLayout.set_fields('Private endpoint connections', - root_path='data.network_ac_ls.private_endpoints' ,fields=[ - TextDyField.data_source('Connection name', 'name'), - ListDyField.data_source('Allow', 'allow', options={'delimiter': ', '}) - ]) - -web_pubsub_svc_access_control_rules_info = ListDynamicLayout.set_layouts(' Access control rules', layouts=[ - default_action_access_control_rules, public_network_access_control_rules, - private_endpoint_connections_access_control_rules -]) - -# TAB - System data -web_pub_sub_svc_system_data_info = ItemDynamicLayout.set_fields('System data', root_path='data.system_data', fields=[ - DateTimeDyField.data_source('Created at', 'created_at'), - TextDyField.data_source('Created by', 'created_by'), - TextDyField.data_source('Created by type', 'created_by_type'), - DateTimeDyField.data_source('Last modified at', 'last_modified_at'), - TextDyField.data_source('Last modified by', 'last_modified_by'), - TextDyField.data_source('Last modified by type', 'last_modified_by_type'), -]) - -# TAB - Custom domain is not yet supported - -web_pubsub_service_meta = CloudServiceMeta.set_layouts( - [web_pubsub_svc_info_meta, web_pubsub_svc_keys_info, web_pubsub_svc_hubs_info, web_pubsub_svc_public_access_info, - web_pubsub_svc_private_access_info, web_pubsub_svc_access_control_rules_info, web_pub_sub_svc_system_data_info]) - - -class ApplicationIntegrationResource(CloudServiceResource): - cloud_service_group = StringType(default='WebPubSubService') - - -class WebPubSubServiceResource(ApplicationIntegrationResource): - cloud_service_type = StringType(default='Service') - data = ModelType(WebPubSubService) - _metadata = ModelType(CloudServiceMeta, default=web_pubsub_service_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class WebPubSubServiceResponse(CloudServiceResponse): - resource = PolyModelType(WebPubSubServiceResource) - - -''' -Web PubSub Hub -''' - -# TAB - Web PubSub Hub -web_pubsub_hub_info_meta = ItemDynamicLayout.set_fields('Web PubSub Hub', fields=[ - TextDyField.data_source('Hub name', 'name'), - TextDyField.data_source('Resource ID', 'data.id'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Subscription', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Region', 'data.location'), - EnumDyField.data_source('Anonymous Connect', 'data.properties.anonymous_connect_policy', default_badge={ - 'indigo.500': ['allow'], 'coral.600': ['deny'] - }), - TextDyField.data_source('EventHandler count', 'data.web_pubsub_hub_evnet_handler_count_display') -]) - -# TAB - Event Handlers -web_pubsub_hub_event_handlers_info = TableDynamicLayout.set_fields('Event Handlers', root_path='data.properties.event_handlers', fields=[ - TextDyField.data_source('Url template', 'url_template'), - TextDyField.data_source('User events', 'user_event_pattern'), - ListDyField.data_source('System events', 'system_events', options={'delimiter': ', '}), - TextDyField.data_source('Authentication', 'auth.type') -]) - -# TAB - System data -web_pubsub_hub_system_data_info = ItemDynamicLayout.set_fields('System data', root_path='data.system_data', fields=[ - DateTimeDyField.data_source('Created at', 'created_at'), - TextDyField.data_source('Created by', 'created_by'), - TextDyField.data_source('Created by type', 'created_by_type'), - DateTimeDyField.data_source('Last modified at', 'last_modified_at'), - TextDyField.data_source('Last modified by', 'last_modified_by'), - TextDyField.data_source('Last modified by type', 'last_modified_by_type'), -]) - -web_pubsub_hub_meta = CloudServiceMeta.set_layouts( - [web_pubsub_hub_info_meta, web_pubsub_hub_event_handlers_info, web_pubsub_hub_system_data_info]) - - -class WebPubSubHubResource(ApplicationIntegrationResource): - cloud_service_type = StringType(default='Hub') - data = ModelType(WebPubSubHub) - _metadata = ModelType(CloudServiceMeta, default=web_pubsub_hub_meta, serialized_name='metadata') - name = StringType() - account = StringType(serialize_when_none=False) - instance_type = StringType(serialize_when_none=False) - instance_size = FloatType(serialize_when_none=False) - - -class WebPubSubHubResponse(CloudServiceResponse): - resource = PolyModelType(WebPubSubHubResource) diff --git a/src/spaceone/inventory/model/web_pubsub_service/cloud_service_type.py b/src/spaceone/inventory/model/web_pubsub_service/cloud_service_type.py deleted file mode 100644 index bd1d4502..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/cloud_service_type.py +++ /dev/null @@ -1,151 +0,0 @@ -import os -from spaceone.inventory.libs.utils import * -from spaceone.inventory.libs.schema.metadata.dynamic_widget import CardWidget, ChartWidget -from spaceone.inventory.libs.schema.metadata.dynamic_field import TextDyField, SearchField, DateTimeDyField, \ - ListDyField, \ - EnumDyField -from spaceone.inventory.libs.schema.cloud_service_type import CloudServiceTypeResource, CloudServiceTypeResponse, \ - CloudServiceTypeMeta -from spaceone.inventory.conf.cloud_service_conf import ASSET_URL - -current_dir = os.path.abspath(os.path.dirname(__file__)) - -''' -Service -''' - -web_pubsub_svc_count_by_region_conf = os.path.join(current_dir, 'widget/web_pubsub_svc_count_by_region.yaml') -web_pubsub_svc_count_by_resource_group_conf = os.path.join(current_dir, 'widget/web_pubsub_svc_count_by_resource_group.yaml') -web_pubsub_svc_count_by_account_conf = os.path.join(current_dir, 'widget/web_pubsub_svc_count_by_account.yaml') -web_pubsub_svc_total_count_conf = os.path.join(current_dir, 'widget/web_pubsub_svc_total_count.yaml') -web_pubsub_svc_total_unit_count_conf = os.path.join(current_dir, 'widget/web_pubsub_svc_total_unit_count.yaml') -web_pubsub_svc_unit_count_by_tier_conf = os.path.join(current_dir, 'widget/web_pubsub_svc_unit_count_by_tier.yaml') - -cst_web_pubsub_svc = CloudServiceTypeResource() -cst_web_pubsub_svc.name = 'Service' -cst_web_pubsub_svc.group = 'WebPubSubService' -cst_web_pubsub_svc.service_code = 'Microsoft.SignalRService/WebPubSub' -cst_web_pubsub_svc.labels = ['Application Integration'] -cst_web_pubsub_svc.is_major = True -cst_web_pubsub_svc.is_primary = True -cst_web_pubsub_svc.tags = { - 'spaceone:icon': f'{ASSET_URL}/azure-web-pubsub-service.svg', -} - -cst_web_pubsub_svc._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - EnumDyField.data_source('Service State', 'data.provisioning_state', default_state={ - 'safe': ['Running', 'Succeeded'], - 'warning': ['Creating', 'Updating', 'Deleting', 'Moving', 'Updating'], - 'alert': ['Failed', 'Canceled'], - 'disable': ['Unknown']}), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account', options={ - 'is_optional': True - }), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - TextDyField.data_source('Hub count', 'data.web_pubsub_hub_count_display'), - TextDyField.data_source('SKU', 'data.sku.tier'), - TextDyField.data_source('Unit', 'data.sku.capacity'), - TextDyField.data_source('Version', 'data.version', options={ - 'is_optional': True - }), - TextDyField.data_source('Host name', 'data.host_name'), - TextDyField.data_source('Host name prefix', 'data.host_name_prefix', options={ - 'is_optional': True - }), - TextDyField.data_source('Public IP', 'data.external_ip'), - TextDyField.data_source('Public access', 'data.public_network_access'), - TextDyField.data_source('Public port', 'data.public_port', options={ - 'is_optional': True - }), - TextDyField.data_source('Server port', 'data.server_port', options={ - 'is_optional': True - }), - TextDyField.data_source('TLS', 'data.tls.client_cert_enabled', options={ - 'is_optional': True - }), - - ], - search=[ - SearchField.set('Service State', key='data.provisioning_state'), - SearchField.set('Subscription Name', key='data.subscription_name'), - SearchField.set('Subscription ID', key='account'), - SearchField.set('Resource Group', key='data.resource_group'), - SearchField.set('Location', key='data.location'), - SearchField.set('Hub count', key='data.web_pubsub_hub_count_display', data_type='integer'), - SearchField.set('SKU', key='data.sku.tier'), - SearchField.set('Unit', key='data.sku.capacity', data_type='integer'), - SearchField.set('Version', key='data.version', data_type='float'), - SearchField.set('Host name', key='data.host_name'), - SearchField.set('Host name prefix', key='data.host_name_prefix'), - SearchField.set('Public IP', key='data.external_ip'), - SearchField.set('Public access', key='data.public_network_access'), - SearchField.set('Public port', key='data.public_port'), - SearchField.set('Server port', key='data.server_port'), - SearchField.set('TLS', key='data.tls.client_cert_enabled'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(web_pubsub_svc_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(web_pubsub_svc_count_by_resource_group_conf)), - ChartWidget.set(**get_data_from_yaml(web_pubsub_svc_count_by_region_conf)), - ChartWidget.set(**get_data_from_yaml(web_pubsub_svc_unit_count_by_tier_conf)), - CardWidget.set(**get_data_from_yaml(web_pubsub_svc_total_count_conf)), - CardWidget.set(**get_data_from_yaml(web_pubsub_svc_total_unit_count_conf)), - ] -) - -''' -Hub -''' -web_pubsub_hub_count_by_region_conf = os.path.join(current_dir, 'widget/web_pubsub_hub_count_by_region.yaml') -web_pubsub_hub_count_by_resource_group_conf = os.path.join(current_dir, 'widget/web_pubsub_hub_count_by_resource_group.yaml') -web_pubsub_hub_count_by_account_conf = os.path.join(current_dir, 'widget/web_pubsub_hub_count_by_account.yaml') -web_pubsub_hub_event_handler_total_count_conf = os.path.join(current_dir, 'widget/web_pubsub_hub_event_handler_total_count.yaml') -web_pubsub_hub_total_count_conf = os.path.join(current_dir, 'widget/web_pubsub_hub_total_count.yaml') - -cst_web_pubsub_hub = CloudServiceTypeResource() -cst_web_pubsub_hub.name = 'Hub' -cst_web_pubsub_hub.group = 'WebPubSubService' -cst_web_pubsub_hub.service_code = 'Microsoft.SignalRService/WebPubSub/hubs' -cst_web_pubsub_hub.labels = ['Application Integration'] -cst_web_pubsub_hub.is_major = False -cst_web_pubsub_hub.is_primary = False -cst_web_pubsub_hub.tags = { - 'spaceone:icon': 'https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-web-pubsub-service.svg', -} - -cst_web_pubsub_hub._metadata = CloudServiceTypeMeta.set_meta( - fields=[ - EnumDyField.data_source('Anonymous Connect', 'data.properties.anonymous_connect_policy', default_badge={ - 'indigo.500': ['allow'], 'coral.600': ['deny']}), - TextDyField.data_source('Event Handlers count', 'data.web_pubsub_hub_evnet_handler_count_display'), - TextDyField.data_source('Web SubSub Service', 'data.web_pubsub_svc_name'), - TextDyField.data_source('Subscription Name', 'data.subscription_name'), - TextDyField.data_source('Subscription ID', 'account'), - TextDyField.data_source('Resource Group', 'data.resource_group'), - TextDyField.data_source('Location', 'data.location'), - ], - search=[ - SearchField.set('Anonymous Connect', key='data.properties.anonymous_connect_policy'), - SearchField.set('Event Handlers count', key='data.web_pubsub_hub_evnet_handler_count_display', data_type='integer'), - SearchField.set('Web SubSub Service', 'data.web_pubsub_svc_name'), - SearchField.set('Subscription Name', key='data.subscription_name'), - SearchField.set('Subscription ID', key='account'), - SearchField.set('Resource Group', key='data.resource_group'), - SearchField.set('Location', key='data.location'), - ], - widget=[ - ChartWidget.set(**get_data_from_yaml(web_pubsub_hub_count_by_account_conf)), - ChartWidget.set(**get_data_from_yaml(web_pubsub_hub_count_by_resource_group_conf)), - ChartWidget.set(**get_data_from_yaml(web_pubsub_hub_count_by_region_conf)), - CardWidget.set(**get_data_from_yaml(web_pubsub_hub_total_count_conf)), - CardWidget.set(**get_data_from_yaml(web_pubsub_hub_event_handler_total_count_conf)) - ] -) - -CLOUD_SERVICE_TYPES = [ - CloudServiceTypeResponse({'resource': cst_web_pubsub_svc}), - CloudServiceTypeResponse({'resource': cst_web_pubsub_hub}), -] diff --git a/src/spaceone/inventory/model/web_pubsub_service/data.py b/src/spaceone/inventory/model/web_pubsub_service/data.py deleted file mode 100644 index 7b733298..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/data.py +++ /dev/null @@ -1,222 +0,0 @@ -from schematics import Model -from schematics.types import ModelType, ListType, StringType, IntType, BooleanType, DateTimeType -from spaceone.inventory.libs.schema.resource import AzureCloudService - - -# SkuResource -class SkuResource(Model): - name = StringType(serialize_when_none=False) - tier = StringType(serialize_when_none=False) - size = StringType(serialize_when_none=False) - family = StringType(serialize_when_none=False) - capacity = IntType(serialize_when_none=False) - - -# ManagedIdentity - -# ManagedIdentity - UserAssignedIdentityProperty -class UserAssignedIdentityProperty(Model): - principal_id = StringType(serialize_when_none=False) - client_id = StringType(serialize_when_none=False) - - -class ManagedIdentity(Model): - type = StringType(serialize_when_none=False) - user_assigned_identities = ModelType(UserAssignedIdentityProperty) - principal_id = StringType(serialize_when_none=False) - tenant_id = StringType(serialize_when_none=False) - - -# SystemData -class SystemData(Model): - created_by = StringType(serialize_when_none=False) - created_by_type = StringType(serialize_when_none=False) - created_at = DateTimeType(serialize_when_none=False) - last_modified_by = StringType(serialize_when_none=False) - last_modified_by_type = StringType(serialize_when_none=False) - last_modified_at = DateTimeType(serialize_when_none=False) - - -# PrivateEndpointConnection - -# PrivateEndpointConnection - PrivateEndpoint -class PrivateEndpoint(Model): - id = StringType(serialize_when_none=False) - private_endpoint_name_display = StringType(serialize_when_none=False) - - -# PrivateEndpointConnection - PrivateLinkServiceConnectionState -class PrivateLinkServiceConnectionState(Model): - status = StringType(choices=('Approved', 'Disconnected', 'Pending', 'Rejected')) - description = StringType(serialize_when_none=False) - actions_required = StringType(serialize_when_none=False) - - -class PrivateEndpointConnection(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - system_data = ModelType(SystemData, serialize_when_none=False) - provisioning_state = StringType(choices=('Canceled', 'Creating', 'Deleting', 'Failed', 'Moving', 'Running', - 'Succeeded', 'Unknown', 'Updating')) - private_endpoint = ModelType(PrivateEndpoint) - group_ids = ListType(StringType, serialize_when_none=False) - private_link_service_connection_state = ModelType(PrivateLinkServiceConnectionState) - - -# SharedPrivateLinkResource -class SharedPrivateLinkResource(Model): - id = StringType(serialize_when_none=False) - name = StringType(serialize_when_none=False) - type = StringType(serialize_when_none=False) - system_data = ModelType(SystemData) - group_id = StringType(serialize_when_none=False) - private_link_resource_id = StringType(serialize_when_none=False) - provisioning_state = StringType(choices=('Canceled', 'Creating', 'Deleting', 'Failed', 'Moving', 'Running', - 'Succeeded', 'Unknown', 'Updating')) - request_message = StringType(serialize_when_none=False) - status = StringType(choices=('Approved', 'Disconnected', 'Pending', 'Rejected')) - - -# WebPubSubTlsSettings -class WebPubSubTlsSettings(Model): - client_cert_enabled = BooleanType(default=True) - - -# LiveTraceConfiguration - -# LiveTraceConfiguration - LiveTraceCategory -class LiveTraceCategory(Model): - name = StringType(serialize_when_none=False) - enabled = StringType(serialize_when_none=False) - - -class LiveTraceConfiguration(Model): - enabled = StringType(serialize_when_none=False) - categories = ListType(ModelType(LiveTraceCategory), serialize_when_none=False) - - -# ResourceLogConfiguration - -# ResourceLogConfiguration - ResourceLogCategory -class ResourceLogCategory(Model): - name = StringType(serialize_when_none=False) - enabled = StringType(serialize_when_none=False) - - -class ResourceLogConfiguration(Model): - categories = ListType(ModelType(ResourceLogCategory), serialize_when_none=False) - - -# WebPubSubNetworkACLs - -# WebPubSubNetworkACLs - NetworkACL -class NetworkACL(Model): - allow = ListType(StringType, serialize_when_none=False) - deny = ListType(StringType, serialize_when_none=False) - - -# WebPubSubNetworkACLs - PrivateEndpointACL -class PrivateEndpointACL(Model): - allow = ListType(StringType, serialize_when_none=False) - deny = ListType(StringType, serialize_when_none=False) - name = StringType(serialize_when_none=False) - - -class WebPubSubNetworkACLs(Model): - default_action = StringType(serialize_when_none=False) - public_network = ModelType(NetworkACL) - private_endpoints = ListType(ModelType(PrivateEndpointACL), serialize_when_none=False) - - -# WebPubSubHub - -# WebPubSubHub- WebPubSubNetworkACLs- UpstreamAuthSettings - ManagedIdentitySettings -class ManagedIdentitySettings(Model): - resource = StringType(serialize_when_none=False) - - -# WebPubSubHub- WebPubSubNetworkACLs- UpstreamAuthSettings -class UpstreamAuthSettings(Model): - type = StringType(serialize_when_none=False) - managed_identity = ModelType(ManagedIdentitySettings) - - -# WebPubSubHub - WebPubSubHubProperties - EventHandler -class EventHandler(Model): - url_template = StringType(serialize_when_none=False) - user_event_pattern = StringType(serialize_when_none=False) - system_events = ListType(StringType, serialize_when_none=False) - auth = ModelType(UpstreamAuthSettings) - - -# WebPubSubHub - WebPubSubHubProperties -class WebPubSubHubProperties(Model): - event_handlers = ListType(ModelType(EventHandler)) - anonymous_connect_policy = StringType(default='deny', choices=('allow', 'deny')) - - -class WebPubSubHub(AzureCloudService): - id = StringType() - name = StringType() - location = StringType() - type = StringType(serialize_when_none=False) - system_data = ModelType(SystemData) - properties = ModelType(WebPubSubHubProperties) - web_pubsub_svc_name = StringType(serialize_when_none=False) - web_pubsub_hub_evnet_handler_count_display = IntType(default=0) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } - - -# CustomDomain -class CustomDomain(Model): - pass - - -# WebPubSubKeys -class WebPubSubKey(Model): - primary_key = StringType(serialize_when_none=False) - primary_connection_string = StringType(serialize_when_none=False) - secondary_key = StringType(serialize_when_none=False) - secondary_connection_string = StringType(serialize_when_none=False) - - -class WebPubSubService(AzureCloudService): # Main Class - id = StringType() - name = StringType() - location = StringType() - sku = ModelType(SkuResource, serialize_when_none=False) - identity = ModelType(ManagedIdentity, serialize_when_none=False) - system_data = ModelType(SystemData, serialize_when_none=False) - provisioning_state = StringType(choices=('Canceled', 'Creating', 'Deleting', 'Failed', 'Moving', 'Running', - 'Succeeded', 'Unknown', 'Updating')) - external_ip = StringType(serialize_when_none=False) - host_name = StringType(serialize_when_none=False) - public_port = StringType(serialize_when_none=False) - server_port = StringType(serialize_when_none=False) - version = StringType(serialize_when_none=False) - private_endpoint_connections = ListType(ModelType(PrivateEndpointConnection)) - shared_private_link_resources = ListType(ModelType(SharedPrivateLinkResource)) - tls = ModelType(WebPubSubTlsSettings) - host_name_prefix = StringType(serialize_when_none=False) - live_trace_configuration = ModelType(LiveTraceConfiguration) - resource_log_configuration = ModelType(ResourceLogConfiguration) - network_ac_ls = ModelType(WebPubSubNetworkACLs) - public_network_access = StringType(default='Enabled') - disable_local_auth = BooleanType(default=False) - disable_aad_auth = BooleanType(default=False) - web_pubsub_hubs = ListType(ModelType(WebPubSubHub)) - web_pubsub_hub_count_display = IntType(default=0) - custom_domains = ListType(ModelType(CustomDomain)) # not yet supported - web_pubsub_key = ModelType(WebPubSubKey) - - def reference(self): - return { - "resource_id": self.id, - "external_link": f"https://portal.azure.com/#@.onmicrosoft.com/resource{self.id}/overview", - } diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_account.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_account.yaml deleted file mode 100644 index 4b0f9cea..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_account.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Hub -name: Count by Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_region.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_region.yaml deleted file mode 100644 index 236115ad..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Hub -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_resource_group.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_resource_group.yaml deleted file mode 100644 index e48ae666..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_count_by_resource_group.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Hub -name: Count by Resource Group -query: - aggregate: - - group: - keys: - - name: name - key: data.resource_group - fields: - - name: value - operator: count -options: - chart_type: DONUT \ No newline at end of file diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_event_handler_total_count.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_event_handler_total_count.yaml deleted file mode 100644 index cf93d4fb..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_event_handler_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Hub -name: Total EventHandler Count -query: - aggregate: - - group: - fields: - - name: value - key: data.web_pubsub_hub_evnet_handler_count_display - operator: sum -options: - value_options: - key: value - options: - default: 0 \ No newline at end of file diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_total_count.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_total_count.yaml deleted file mode 100644 index 0ca0abc4..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_hub_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Hub -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_account.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_account.yaml deleted file mode 100644 index d63b1c64..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_account.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Service -name: Count by Account -query: - aggregate: - - group: - keys: - - name: name - key: account - fields: - - name: value - key: account - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_region.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_region.yaml deleted file mode 100644 index 13e03a59..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_region.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Service -name: Count by Region -query: - aggregate: - - group: - keys: - - name: name - key: region_code - fields: - - name: value - operator: count -options: - chart_type: COLUMN - name_options: - key: name - reference: - resource_type: inventory.Region - reference_key: region_code \ No newline at end of file diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_resource_group.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_resource_group.yaml deleted file mode 100644 index e506ff16..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_count_by_resource_group.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Service -name: Count by Resource Group -query: - aggregate: - - group: - keys: - - name: name - key: data.resource_group - fields: - - name: value - operator: count -options: - chart_type: DONUT \ No newline at end of file diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_count.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_count.yaml deleted file mode 100644 index 48223b36..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Service -name: Total Count -query: - aggregate: - - group: - fields: - - name: value - operator: count -options: - value_options: - key: value - type: text - options: - default: 0 diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_unit_count.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_unit_count.yaml deleted file mode 100644 index 955255cb..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_total_unit_count.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Service -name: Total Unit Count -query: - aggregate: - - group: - fields: - - name: value - key: data.sku.capacity - operator: sum -options: - value_options: - key: value - options: - default: 0 diff --git a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_unit_count_by_tier.yaml b/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_unit_count_by_tier.yaml deleted file mode 100644 index 1d13b078..00000000 --- a/src/spaceone/inventory/model/web_pubsub_service/widget/web_pubsub_svc_unit_count_by_tier.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -cloud_service_group: WebPubSubService -cloud_service_type: Service -name: Unit Count by Tier -query: - aggregate: - - group: - keys: - - name: name - key: data.sku.tier - fields: - - name: value - key: data.sku.tier - operator: count -options: - chart_type: DONUT diff --git a/src/spaceone/inventory/service/__init__.py b/src/spaceone/inventory/service/__init__.py deleted file mode 100644 index 5880d009..00000000 --- a/src/spaceone/inventory/service/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from spaceone.inventory.service.collector_service import CollectorService -from spaceone.inventory.service.job_service import JobService diff --git a/src/spaceone/inventory/service/collector_service.py b/src/spaceone/inventory/service/collector_service.py deleted file mode 100644 index 24bd263a..00000000 --- a/src/spaceone/inventory/service/collector_service.py +++ /dev/null @@ -1,181 +0,0 @@ -import concurrent.futures -import logging -import time -import os - -from spaceone.inventory.libs.manager import AzureManager -from spaceone.inventory.manager.subscriptions.subscription_manager import ( - SubscriptionsManager, -) -from spaceone.core import utils -from spaceone.core.service import * -from spaceone.inventory.conf.cloud_service_conf import * - -_LOGGER = logging.getLogger(__name__) - -_CURRENT_DIR = os.path.dirname(__file__) -_BEFORE_CURRENT_DIR, _ = _CURRENT_DIR.rsplit("/", 1) -_METRIC_DIR = os.path.join(_BEFORE_CURRENT_DIR, "metrics/") - - -@authentication_handler -class CollectorService(BaseService): - resource = "Collector" - - def __init__(self, metadata): - super().__init__(metadata) - - @check_required(["options"]) - def init(self, params): - """init plugin by options""" - capability = { - "filter_format": FILTER_FORMAT, - "supported_resource_type": SUPPORTED_RESOURCE_TYPE, - "supported_features": SUPPORTED_FEATURES, - "supported_schedules": SUPPORTED_SCHEDULES, - } - return {"metadata": capability} - - @transaction - @check_required(["options", "secret_data"]) - def verify(self, params): - """ - Args: - params: - - options - - secret_data - """ - options = params["options"] - secret_data = params.get("secret_data", {}) - if secret_data != {}: - azure_manager = AzureManager() - active = azure_manager.verify({}, secret_data=secret_data) - - return {} - - @transaction - @check_required(["options", "secret_data", "filter"]) - def collect(self, params: dict): - """ - Args: - params: - - options - - schema - - secret_data - - filter - - task_options - """ - - start_time = time.time() - options = params.get("options", {}) - task_options = params.get("task_options", {}) - params.update({"subscription_info": self.get_subscription_info(params)}) - - _LOGGER.debug("[ EXECUTOR START: Azure Cloud Service ]") - target_execute_managers = self._get_target_execute_manger(options, task_options) - - # Thread per cloud services - with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKER) as executor: - future_executors = [] - - for execute_manager in target_execute_managers: - _LOGGER.info(f"@@@ {execute_manager} @@@") - _manager = self.locator.get_manager(execute_manager) - future_executors.append( - executor.submit(_manager.collect_resources, params) - ) - - for future in concurrent.futures.as_completed(future_executors): - for result in future.result(): - yield result.to_primitive() - - """ - for manager in self.execute_managers: - _LOGGER.debug(f'@@@ {manager} @@@') - _manager = self.locator.get_manager(manager) - - for resource in _manager.collect_resources(params): - yield resource.to_primitive() - """ - - if cloud_service_types := params.get("options", {}).get("cloud_service_types"): - for service in cloud_service_types: - for response in self.collect_metrics(service): - yield response - else: - for service in CLOUD_SERVICE_GROUP_MAP.keys(): - for response in self.collect_metrics(service): - yield response - _LOGGER.debug(f"TOTAL TIME : {time.time() - start_time} Seconds") - - def get_subscription_info(self, params): - subscription_manager: SubscriptionsManager = self.locator.get_manager( - "SubscriptionsManager" - ) - return subscription_manager.get_subscription_info(params) - - def list_location_info(self, params): - subscription_manager: SubscriptionsManager = self.locator.get_manager( - "SubscriptionsManager" - ) - return subscription_manager.list_location_info(params) - - def _get_target_execute_manger(self, options: dict, task_options: dict) -> list: - if "cloud_service_types" in options: - execute_managers = self._match_execute_manager( - options["cloud_service_types"] - ) - elif "cloud_service_types" in task_options: - execute_managers = self._match_execute_manager( - task_options["cloud_service_types"] - ) - else: - execute_managers = list(CLOUD_SERVICE_GROUP_MAP.values()) - - return execute_managers - - @staticmethod - def _match_execute_manager(cloud_service_groups): - return [ - CLOUD_SERVICE_GROUP_MAP[_cloud_service_group] - for _cloud_service_group in cloud_service_groups - if _cloud_service_group in CLOUD_SERVICE_GROUP_MAP - ] - - def collect_metrics(self, service: str) -> list: - if not os.path.exists(os.path.join(_METRIC_DIR, service)): - os.mkdir(os.path.join(_METRIC_DIR, service)) - for dirname in os.listdir(os.path.join(_METRIC_DIR, service)): - for filename in os.listdir(os.path.join(_METRIC_DIR, service, dirname)): - if filename.endswith(".yaml"): - file_path = os.path.join(_METRIC_DIR, service, dirname, filename) - info = utils.load_yaml_from_file(file_path) - if filename == "namespace.yaml": - yield self.make_namespace_or_metric_response( - namespace=info, - resource_type="inventory.Namespace", - ) - else: - yield self.make_namespace_or_metric_response( - metric=info, - resource_type="inventory.Metric", - ) - - @staticmethod - def make_namespace_or_metric_response( - metric=None, - namespace=None, - resource_type: str = "inventory.Metric", - ) -> dict: - response = { - "state": "SUCCESS", - "resource_type": resource_type, - "match_rules": {}, - } - - if resource_type == "inventory.Metric" and metric is not None: - response["resource"] = metric - elif resource_type == "inventory.Namespace" and namespace is not None: - response["resource"] = namespace - - return response diff --git a/src/spaceone/inventory/service/job_service.py b/src/spaceone/inventory/service/job_service.py deleted file mode 100644 index f367b532..00000000 --- a/src/spaceone/inventory/service/job_service.py +++ /dev/null @@ -1,49 +0,0 @@ -import logging - -from spaceone.core.service import * -from spaceone.inventory.model.job_model import Tasks -from spaceone.inventory.conf.cloud_service_conf import * - -_LOGGER = logging.getLogger(__name__) - - -@authentication_handler -class JobService(BaseService): - resource = "Job" - - def __init__(self, metadata): - super().__init__(metadata) - - @transaction - @check_required(["options", "secret_data"]) - def get_tasks(self, params: dict): - """ - Args: - params: - - options - - schema - - secret_data - - task_filter - """ - - options = params.get("options", {}) - secret_data = params.get("secret_data", {}) - - tasks = [] - - cloud_service_types = options.get( - "cloud_service_types", CLOUD_SERVICE_GROUP_MAP.keys() - ) - - for cloud_service_type in cloud_service_types: - tasks.append( - { - "task_options": { - "cloud_service_types": [cloud_service_type], - } - } - ) - tasks = Tasks({"tasks": tasks}) - tasks.validate() - - return tasks.to_primitive() diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test/api/config.yml b/test/api/config.yml deleted file mode 100644 index 9cc5091b..00000000 --- a/test/api/config.yml +++ /dev/null @@ -1,7 +0,0 @@ -GLOBAL: - SERVICE: inventory - ENDPOINTS: - inventory: - plugin: localhost:50051 - #plugin: dev-docker.pyengine.net:50062 - diff --git a/test/api/scenario.json b/test/api/scenario.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/api/scenario.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/api/test_cloud_service_api.py b/test/api/test_cloud_service_api.py deleted file mode 100644 index e9436b9f..00000000 --- a/test/api/test_cloud_service_api.py +++ /dev/null @@ -1,73 +0,0 @@ -import os -import unittest -import json - -from spaceone.core.unittest.result import print_data -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core import utils -from spaceone.core.transaction import Transaction -from spaceone.tester import TestCase, print_json - - -class TestCollector(TestCase): - @classmethod - def setUpClass(cls): - azure_cred = os.environ.get("AZURE_CRED") - test_config = utils.load_yaml_from_file(azure_cred) - - cls.schema = "azure_client_secret" - cls.azure_credentials = test_config.get("AZURE_CREDENTIALS", {}) - super().setUpClass() - - def test_init(self): - v_info = self.inventory.Collector.init({"options": {}}) - print_json(v_info) - - def test_verify(self): - options = {} - v_info = self.inventory.Collector.verify( - {"options": options, "secret_data": self.azure_credentials} - ) - print_json(v_info) - - def test_get_tasks(self): - options = { - "cloud_service_types": ["KeyVaults"], - # 'custom_asset_url': 'https://xxxxx.cloudforet.dev.icon/azure' - } - # options = {} - v_info = self.inventory.Job.get_tasks( - { - "options": options, - "secret_data": self.azure_credentials, - } - ) - print_json(v_info) - - def test_collect(self): - options = { - # "cloud_service_types": ["KeyVaults"], - # 'custom_asset_url': 'https://xxxxx.cloudforet.dev.icon/azure' - } - - # options = {} - task_options = { - # "cloud_service_types": ["StorageAccounts"], - } - filter = {} - resource_stream = self.inventory.Collector.collect( - { - "options": options, - "secret_data": self.azure_credentials, - "task_options": task_options, - "filter": filter, - } - ) - - for res in resource_stream: - print_json(res) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) diff --git a/test/connector/__init__.py b/test/connector/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test/connector/test_disk_connector.py b/test/connector/test_disk_connector.py deleted file mode 100644 index 3d4cbd2f..00000000 --- a/test/connector/test_disk_connector.py +++ /dev/null @@ -1,47 +0,0 @@ -import unittest -import os -from datetime import datetime, timedelta -from unittest.mock import patch - -from spaceone.core.unittest.result import print_data -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core import utils -from spaceone.core.transaction import Transaction -from spaceone.inventory.connector.disk import DiskConnector - - -class TestDiskConnector(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = { - 'secret_data': test_config.get('AZURE_CREDENTIALS', {}) - } - - cls.azure_connector = DiskConnector(transaction=Transaction(), config={}, - secret_data=test_config.get('AZURE_CREDENTIALS', {})) - #cls.azure_connector = DiskConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials['secret_data']) - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_list_disks(self): - #self.azure_connector.set_connect(self.azure_credentials) - disks = self.azure_connector.list_disks() - - for disk in disks: - print('=====') - print(disk) - print('=====') - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) diff --git a/test/connector/test_load_balancer_connector.py b/test/connector/test_load_balancer_connector.py deleted file mode 100644 index 53727d12..00000000 --- a/test/connector/test_load_balancer_connector.py +++ /dev/null @@ -1,47 +0,0 @@ -import unittest -import os -from datetime import datetime, timedelta -from unittest.mock import patch - -from spaceone.core.unittest.result import print_data -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core import utils -from spaceone.core.transaction import Transaction -from spaceone.inventory.connector.loadbalncer import LoadBalancerConnector - - -class TestLoadBalancerConnector(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = { - 'secret_data': test_config.get('AZURE_CREDENTIALS', {}) - } - - cls.azure_connector = LoadBalancerConnector(transaction=Transaction(), config={}, - secret_data=test_config.get('AZURE_CREDENTIALS', {})) - #cls.azure_connector = DiskConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials['secret_data']) - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_list_load_balancers(self): - # self.azure_connector.set_connect(self.azure_credentials) - load_balancers = self.azure_connector.list_load_balancers() - - for load_balancer in load_balancers: - print('=====') - print(load_balancer) - print('=====') - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) diff --git a/test/connector/test_snapshot_connector.py b/test/connector/test_snapshot_connector.py deleted file mode 100644 index a1092439..00000000 --- a/test/connector/test_snapshot_connector.py +++ /dev/null @@ -1,47 +0,0 @@ -import unittest -import os -from datetime import datetime, timedelta -from unittest.mock import patch - -from spaceone.core.unittest.result import print_data -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core import utils -from spaceone.core.transaction import Transaction -from spaceone.inventory.connector.snapshot import SnapshotConnector - - -class TestSnapshotConnector(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = { - 'secret_data': test_config.get('AZURE_CREDENTIALS', {}) - } - - cls.azure_connector = SnapshotConnector(transaction=Transaction(), config={}, - secret_data=test_config.get('AZURE_CREDENTIALS', {})) - # cls.azure_connector = DiskConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials['secret_data']) - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_list_snapshots(self): - # self.azure_connector.set_connect(self.azure_credentials) - snapshots = self.azure_connector.list_snapshots() - - for snapshot in snapshots: - print('=====') - print(snapshot) - print('=====') - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) diff --git a/test/manager/__init__.py b/test/manager/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test/manager/test_application_gateway_manager.py b/test/manager/test_application_gateway_manager.py deleted file mode 100644 index deed7e00..00000000 --- a/test/manager/test_application_gateway_manager.py +++ /dev/null @@ -1,44 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.application_gateway import ApplicationGatewayConnector -from spaceone.inventory.manager.application_gateways.instance_manager import ApplicationGatewayManager - - -class TestApplicationGatewayManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.application_gateway_connector = ApplicationGatewayConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.application_gateway_manager = ApplicationGatewayManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - application_gateways = self.application_gateway_manager.collect_cloud_service(params) - - for applicaiton_gateway in application_gateways: - print(applicaiton_gateway.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_cosmos_db_manager.py b/test/manager/test_cosmos_db_manager.py deleted file mode 100644 index e790a0d9..00000000 --- a/test/manager/test_cosmos_db_manager.py +++ /dev/null @@ -1,49 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.cosmos_db import CosmosDBConnector -from spaceone.inventory.manager.cosmos_db.instance_manager import CosmosDBManager - - -class TestCosmosDBManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.cosmos_db_connector = CosmosDBConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.cosmos_db_manager = CosmosDBManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - subscription_info = { - 'subscription_id': '3ec64e1e-1ce8-4f2c-82a0-a7f6db0899ca', - 'subscription_name': 'Azure subscription 1', - 'tenant_id': '35f43e22-0c0b-4ff3-90aa-b2c04ef1054c' - } - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}, 'subscription_info': subscription_info} - - cosmos_dbs = self.cosmos_db_manager.collect_cloud_service(params) - - for cosmos_db in cosmos_dbs: - print(cosmos_db.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_disk_manager.py b/test/manager/test_disk_manager.py deleted file mode 100644 index 8856ecb0..00000000 --- a/test/manager/test_disk_manager.py +++ /dev/null @@ -1,45 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.disk import DiskConnector -from spaceone.inventory.manager.disks.disk_manager import DiskManager - - -class TestDiskManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.disk_connector = DiskConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - - cls.disk_manager = DiskManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - disks = self.disk_manager.collect_cloud_service(params) - - for disk in disks: - print(disk.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_key_vault_manager.py b/test/manager/test_key_vault_manager.py deleted file mode 100644 index bf3facf7..00000000 --- a/test/manager/test_key_vault_manager.py +++ /dev/null @@ -1,50 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.key_vault import KeyVaultConnector -from spaceone.inventory.manager.key_vaults.instance_manager import KeyVaultManager - - -class TestKeyVaultManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.key_vault_connector = KeyVaultConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.key_vault_manager = KeyVaultManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - subscription_info = { - 'subscription_id': '3ec64e1e-1ce8-4f2c-82a0-a7f6db0899ca', - 'subscription_name': 'Azure subscription 1', - 'tenant_id': '35f43e22-0c0b-4ff3-90aa-b2c04ef1054c' - } - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}, 'subscription_info': subscription_info} - - key_vaults = self.key_vault_manager.collect_cloud_service(params) - - for key_vault in key_vaults: - print(key_vault.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_load_balancer_manager.py b/test/manager/test_load_balancer_manager.py deleted file mode 100644 index de647c6b..00000000 --- a/test/manager/test_load_balancer_manager.py +++ /dev/null @@ -1,45 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.loadbalncer import LoadBalancerConnector -from spaceone.inventory.manager.load_balancers.instance_manager import LoadBalancerManager - - -class TestLoadBalancerManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.load_balancer_connector = LoadBalancerConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - - cls.load_balancer_manager = LoadBalancerManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - load_balancers = self.load_balancer_manager.collect_cloud_service(params) - - for load_balancer in load_balancers: - print(load_balancer.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_mysql_server_manager.py b/test/manager/test_mysql_server_manager.py deleted file mode 100644 index 6f4adecc..00000000 --- a/test/manager/test_mysql_server_manager.py +++ /dev/null @@ -1,45 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.mysql_server import MySQLServerConnector -from spaceone.inventory.manager.mysql_servers.server_manager import MySQLServerManager - - -class TestMySQLServerManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - cls.subscription_info = test_config.get('SUBSCRIPTION_INFO', {}) - - cls.mysql_servers_connector = MySQLServerConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.mysql_servers_manager = MySQLServerManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - subscription_info = self.subscription_info - params = {'options': {}, 'secret_data': secret_data, 'filter': {}, 'subscription_info': subscription_info} - - mysql_servers = self.mysql_servers_manager.collect_cloud_service(params) - - for mysql_server in mysql_servers: - print(mysql_server.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_nat_gateway_manager.py b/test/manager/test_nat_gateway_manager.py deleted file mode 100644 index af244bab..00000000 --- a/test/manager/test_nat_gateway_manager.py +++ /dev/null @@ -1,44 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.nat_gateway import NATGatewayConnector -from spaceone.inventory.manager.nat_gateways.instance_manager import NATGatewayManager - - -class TestVirtualNetworkManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.nat_gateway_connector = NATGatewayConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.nat_gateway_manager = NATGatewayManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - nat_gateways = self.nat_gateway_manager.collect_cloud_service(params) - - for nat_gateway in nat_gateways: - print(nat_gateway.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_network_security_group_manager.py b/test/manager/test_network_security_group_manager.py deleted file mode 100644 index 9a67399a..00000000 --- a/test/manager/test_network_security_group_manager.py +++ /dev/null @@ -1,44 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.network_security_group import NetworkSecurityGroupConnector -from spaceone.inventory.manager.network_security_groups.instance_manager import NetworkSecurityGroupManager - - -class TestNetworkSecurityGroupManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.network_security_group_connector = NetworkSecurityGroupConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.network_security_group_manager = NetworkSecurityGroupManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - network_security_groups = self.network_security_group_manager.collect_cloud_service(params) - - for network_security_group in network_security_groups: - print(network_security_group.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_postgresql_server_manager.py b/test/manager/test_postgresql_server_manager.py deleted file mode 100644 index 34014d17..00000000 --- a/test/manager/test_postgresql_server_manager.py +++ /dev/null @@ -1,49 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.postgresql_server import PostgreSQLServerConnector -from spaceone.inventory.manager.postgresql_servers.server_manager import PostgreSQLServerManager - - -class TestPostgreSQLServerManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.postgresql_server_connector = PostgreSQLServerConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.postgresql_server_manager = PostgreSQLServerManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - subscription_info = { - 'subscription_id': '3ec64e1e-1ce8-4f2c-82a0-a7f6db0899ca', - 'subscription_name': 'Azure subscription 1', - 'tenant_id': '35f43e22-0c0b-4ff3-90aa-b2c04ef1054c' - } - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}, 'subscription_info': subscription_info} - - postgre_sql_servers = self.postgresql_server_manager.collect_cloud_service(params) - - for postgre_sql_server in postgre_sql_servers: - print(postgre_sql_server.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_public_ip_address_manager.py b/test/manager/test_public_ip_address_manager.py deleted file mode 100644 index 31472288..00000000 --- a/test/manager/test_public_ip_address_manager.py +++ /dev/null @@ -1,44 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.public_ip_address import PublicIPAddressConnector -from spaceone.inventory.manager.public_ip_addresses.ip_address_manager import PublicIPAddressManager - - -class TestPublicIPAddressManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.public_ip_address_connector = PublicIPAddressConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.public_ip_address_manager = PublicIPAddressManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - public_ip_addresses = self.public_ip_address_manager.collect_cloud_service(params) - - for public_ip_address in public_ip_addresses: - print(public_ip_address.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_snapshot_manager.py b/test/manager/test_snapshot_manager.py deleted file mode 100644 index 45d84895..00000000 --- a/test/manager/test_snapshot_manager.py +++ /dev/null @@ -1,45 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.snapshot import SnapshotConnector -from spaceone.inventory.manager.snapshots.instance_manager import SnapshotManager - - -class TestSnapshotManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.snapshot_connector = SnapshotConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - - cls.snapshot_manager = SnapshotManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - snapshots = self.snapshot_manager.collect_cloud_service(params) - - for snapshot in snapshots: - print(snapshot.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_sql_server_manaer.py b/test/manager/test_sql_server_manaer.py deleted file mode 100644 index 6d330643..00000000 --- a/test/manager/test_sql_server_manaer.py +++ /dev/null @@ -1,45 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.sql import SqlConnector -from spaceone.inventory.manager.sql_databases.database_manager import SqlServerManager - - -class TestSqlServerManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.sql_server_connector = SqlConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - - cls.sql_server_manager = SqlServerManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - sql_servers = self.sql_server_manager.collect_cloud_service(params) - - for sql_server in sql_servers: - print(sql_server.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_storage_account_manager.py b/test/manager/test_storage_account_manager.py deleted file mode 100644 index 31b2e42c..00000000 --- a/test/manager/test_storage_account_manager.py +++ /dev/null @@ -1,48 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.storage_account import StorageAccountConnector -from spaceone.inventory.manager.storage_accounts.instance_manager import StorageAccountManager - - -class TestVirtualNetworkManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.storage_account_connector = StorageAccountConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.storage_account_manager = StorageAccountManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - subscription_info = { - 'subscription_id': '3ec64e1e-1ce8-4f2c-82a0-a7f6db0899ca', - 'subscription_name': 'Azure subscription 1', - 'tenant_id': '35f43e22-0c0b-4ff3-90aa-b2c04ef1054c' - } - params = {'options': {}, 'secret_data': secret_data, 'subscription_info': subscription_info, 'filter': {}} - - application_gateways = self.storage_account_manager.collect_cloud_service(params) - - for application_gateway in application_gateways: - print(application_gateway.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_virtualnetwork_manager.py b/test/manager/test_virtualnetwork_manager.py deleted file mode 100644 index fe003ebf..00000000 --- a/test/manager/test_virtualnetwork_manager.py +++ /dev/null @@ -1,44 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.virtual_network import VirtualNetworkConnector -from spaceone.inventory.manager.virtual_networks.instance_manager import VirtualNetworkManager - - -class TestVirtualNetworkManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.vnet_connector = VirtualNetworkConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - cls.vnet_manager = VirtualNetworkManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - virtual_networks = self.vnet_manager.collect_cloud_service(params) - - for virtual_network in virtual_networks: - print(virtual_network.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file diff --git a/test/manager/test_vmss_manager.py b/test/manager/test_vmss_manager.py deleted file mode 100644 index ec480cf5..00000000 --- a/test/manager/test_vmss_manager.py +++ /dev/null @@ -1,45 +0,0 @@ -import unittest -import os -from spaceone.core.unittest.runner import RichTestRunner -from spaceone.core import config -from spaceone.core.transaction import Transaction -from spaceone.core import utils -from spaceone.inventory.connector.vmscaleset import VmScaleSetConnector -from spaceone.inventory.manager.vm_scale_sets.scale_set_manager import VmScaleSetManager - - -class TestVMScaleSetManager(unittest.TestCase): - - @classmethod - def setUpClass(cls): - config.init_conf(package='spaceone.inventory') - - config_path = os.environ.get('TEST_CONFIG') - test_config = utils.load_yaml_from_file(config_path) - - cls.schema = 'azure_client_secret' - cls.azure_credentials = test_config.get('AZURE_CREDENTIALS', {}) - - cls.vmss_connector = VmScaleSetConnector(transaction=Transaction(), config={}, secret_data=cls.azure_credentials) - - cls.vmss_manager = VmScaleSetManager(Transaction()) - - super().setUpClass() - - @classmethod - def tearDownClass(cls) -> None: - super().tearDownClass() - - def test_collect_cloud_service(self, *args): - secret_data = self.azure_credentials - - params = {'options': {}, 'secret_data': secret_data, 'filter': {}} - - vm_scale_sets = self.vmss_manager.collect_cloud_service(params) - - for vm_scale_set in vm_scale_sets: - print(vm_scale_set.to_primitive()) - - -if __name__ == "__main__": - unittest.main(testRunner=RichTestRunner) \ No newline at end of file From 5b7f9932a99aa7112c7038abfc90b62b9bac4516 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 17 Jul 2024 17:50:26 +0900 Subject: [PATCH 02/35] feat: Completed Disks Collector migration --- .gitignore | 2 +- pkg/pip_requirements.txt | 2 +- src/plugin/conf/__init__.py | 0 src/plugin/conf/cloud_service_conf.py | 1 + src/plugin/connector/__init__.py | 0 src/plugin/connector/base.py | 33 +++ src/plugin/connector/disks/__init__.py | 0 src/plugin/connector/disks/disks_connector.py | 14 ++ .../connector/subscriptions/__init__.py | 0 .../subscriptions/subscriptions_connector.py | 18 ++ src/plugin/main.py | 199 ++++++++-------- src/plugin/manager/__init__.py | 1 + src/plugin/manager/base.py | 223 ++++++++++++++++++ src/plugin/manager/disks/__init__.py | 0 src/plugin/manager/disks/disks_manager.py | 186 +++++++++++++++ src/plugin/manager/subscriptions/__init__.py | 0 .../subscriptions/subscriptions_manager.py | 47 ++++ src/plugin/metadata/disks/disk.yaml | 155 ++++++++++++ src/plugin/metrics/Disks/Disk/disk_count.yaml | 46 ++++ src/plugin/metrics/Disks/Disk/disk_size.yaml | 52 ++++ src/plugin/metrics/Disks/Disk/namespace.yaml | 8 + .../IpAddress/ip_addresses_count.yaml | 39 +++ .../IpAddress/namespace.yaml | 8 + 23 files changed, 930 insertions(+), 104 deletions(-) create mode 100644 src/plugin/conf/__init__.py create mode 100644 src/plugin/conf/cloud_service_conf.py create mode 100644 src/plugin/connector/__init__.py create mode 100644 src/plugin/connector/base.py create mode 100644 src/plugin/connector/disks/__init__.py create mode 100644 src/plugin/connector/disks/disks_connector.py create mode 100644 src/plugin/connector/subscriptions/__init__.py create mode 100644 src/plugin/connector/subscriptions/subscriptions_connector.py create mode 100644 src/plugin/manager/__init__.py create mode 100644 src/plugin/manager/base.py create mode 100644 src/plugin/manager/disks/__init__.py create mode 100644 src/plugin/manager/disks/disks_manager.py create mode 100644 src/plugin/manager/subscriptions/__init__.py create mode 100644 src/plugin/manager/subscriptions/subscriptions_manager.py create mode 100644 src/plugin/metadata/disks/disk.yaml create mode 100644 src/plugin/metrics/Disks/Disk/disk_count.yaml create mode 100644 src/plugin/metrics/Disks/Disk/disk_size.yaml create mode 100644 src/plugin/metrics/Disks/Disk/namespace.yaml create mode 100644 src/plugin/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml create mode 100644 src/plugin/metrics/PublicIPAddresses/IpAddress/namespace.yaml diff --git a/.gitignore b/.gitignore index 52363a75..0ab95c00 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ local-conf.yml .venv/ .venv.nosync/ .DS_Store -!src/spaceone/inventory/metrics/Disks/disk \ No newline at end of file +!src/plugin/metrics/Disks/Disk \ No newline at end of file diff --git a/pkg/pip_requirements.txt b/pkg/pip_requirements.txt index 5bf4bf43..c1f89042 100644 --- a/pkg/pip_requirements.txt +++ b/pkg/pip_requirements.txt @@ -1,4 +1,4 @@ -schematics +spaceone-api azure-identity azure-mgmt-resource azure-mgmt-compute diff --git a/src/plugin/conf/__init__.py b/src/plugin/conf/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/conf/cloud_service_conf.py b/src/plugin/conf/cloud_service_conf.py new file mode 100644 index 00000000..bf51dac5 --- /dev/null +++ b/src/plugin/conf/cloud_service_conf.py @@ -0,0 +1 @@ +ICON_URL = "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure" diff --git a/src/plugin/connector/__init__.py b/src/plugin/connector/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py new file mode 100644 index 00000000..247b374b --- /dev/null +++ b/src/plugin/connector/base.py @@ -0,0 +1,33 @@ +import os +import logging + +from azure.identity import DefaultAzureCredential +from azure.mgmt.compute import ComputeManagementClient +from azure.mgmt.resource import SubscriptionClient + +from spaceone.core.connector import BaseConnector + +DEFAULT_SCHEMA = 'azure_client_secret' +_LOGGER = logging.getLogger(__name__) + + +class AzureBaseConnector(BaseConnector): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.compute_client = None + + def set_connect(self, secret_data: dict): + subscription_id = secret_data['subscription_id'] + + os.environ["AZURE_SUBSCRIPTION_ID"] = subscription_id + os.environ["AZURE_TENANT_ID"] = secret_data['tenant_id'] + os.environ["AZURE_CLIENT_ID"] = secret_data['client_id'] + os.environ["AZURE_CLIENT_SECRET"] = secret_data['client_secret'] + + credential = DefaultAzureCredential() + + self.subscription_client = SubscriptionClient(credential=credential) + self.compute_client = ComputeManagementClient(credential=credential, subscription_id=subscription_id) + + def get_connector(self, cloud_service_group: str, cloud_service_type: str): + pass diff --git a/src/plugin/connector/disks/__init__.py b/src/plugin/connector/disks/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/disks/disks_connector.py b/src/plugin/connector/disks/disks_connector.py new file mode 100644 index 00000000..34c654d8 --- /dev/null +++ b/src/plugin/connector/disks/disks_connector.py @@ -0,0 +1,14 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class DisksConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_disks(self): + return self.compute_client.disks.list() \ No newline at end of file diff --git a/src/plugin/connector/subscriptions/__init__.py b/src/plugin/connector/subscriptions/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/subscriptions/subscriptions_connector.py b/src/plugin/connector/subscriptions/subscriptions_connector.py new file mode 100644 index 00000000..3cf7c9e8 --- /dev/null +++ b/src/plugin/connector/subscriptions/subscriptions_connector.py @@ -0,0 +1,18 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class SubscriptionsConnector(AzureBaseConnector): + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def get_subscription(self, subscription_id: str): + return self.subscription_client.subscriptions.get(subscription_id) + + def list_location_info(self, subscription_id: str): + return self.subscription_client.subscriptions.list_locations(subscription_id) diff --git a/src/plugin/main.py b/src/plugin/main.py index 5c2baf11..f919f6b5 100644 --- a/src/plugin/main.py +++ b/src/plugin/main.py @@ -1,128 +1,123 @@ +import logging +import time +from typing import Generator + +from spaceone.core.error import ERROR_REQUIRED_PARAMETER from spaceone.inventory.plugin.collector.lib.server import CollectorPluginServer +from plugin.manager.base import AzureBaseManager +from plugin.manager.subscriptions.subscriptions_manager import SubscriptionsManager + app = CollectorPluginServer() +_LOGGER = logging.getLogger("spaceone") + +DEFAULT_RESOURCE_TYPES = ["inventory.CloudService", "inventory.CloudServiceType", "inventory.Metric", + "inventory.Region"] + @app.route('Collector.init') def collector_init(params: dict) -> dict: - """ init plugin by options - - Args: - params (CollectorInitRequest): { - 'options': 'dict', # Required - 'domain_id': 'str' + metadata = { + "options_schema": { + "type": "object", + "properties": { + "cloud_service_groups": { + "title": "Specific services", + "type": "string", + "items": {"type": "string"}, + "default": "All", + "enum": ["All", "Disks"], + "description": "Choose one of the service to collect data. If you choose 'All', it will collect all services." + } + } } - - Returns: - PluginResponse: { - 'metadata': 'dict' - } - """ - pass + } + return {"metadata": metadata} @app.route('Collector.verify') def collector_verify(params: dict) -> None: - """ Verifying collector plugin - - Args: - params (CollectorVerifyRequest): { - 'options': 'dict', # Required - 'secret_data': 'dict', # Required - 'schema': 'str', - 'domain_id': 'str' - } - - Returns: - None - """ pass @app.route('Collector.collect') -def collector_collect(params: dict) -> dict: - """ Collect external data - - Args: - params (CollectorCollectRequest): { - 'options': 'dict', # Required - 'secret_data': 'dict', # Required - 'schema': 'str', - 'task_options': 'dict', - 'domain_id': 'str' - } +def collector_collect(params: dict) -> Generator[dict, None, None]: + options: dict = params.get("options", {}) or {} + secret_data: dict = params["secret_data"] + schema: str = params.get("schema") + task_options: dict = params.get("task_options", {}) or {} + domain_id: str = params["domain_id"] + subscription_id = secret_data.get("subscription_id") + + _check_secret_data(secret_data) + + start_time = time.time() + _LOGGER.debug(f"[collector_collect] Start Collecting Azure Resources {subscription_id}") + + cloud_service_groups = _get_cloud_service_groups_from_options_and_task_options(options, task_options) + resource_type = task_options.get("resource_type") + + if resource_type == "inventory.Region": + subscriptions_mgr = SubscriptionsManager() + location_info = subscriptions_mgr.list_location_info(secret_data) + print("hererere") + print(location_info) + yield from AzureBaseManager().collect_region(location_info) + else: + for manager in AzureBaseManager.list_managers_by_cloud_service_groups(cloud_service_groups): + if resource_type == "inventory.CloudService": + yield from manager().collect_cloud_services(options, secret_data, schema) + elif resource_type == "inventory.CloudServiceType": + yield from manager().collect_cloud_service_type() + elif resource_type == "inventory.Metric": + yield from AzureBaseManager.collect_metrics(manager.cloud_service_group) + else: + yield from manager().collect_resources(options, secret_data, schema) + _LOGGER.debug( + f"[collector_collect] Finished Collecting Azure Resources {subscription_id} duration: {time.time() - start_time} seconds") - Returns: - Generator[ResourceResponse, None, None] - { - 'state': 'SUCCESS | FAILURE', - 'resource_type': 'inventory.CloudService | inventory.CloudServiceType | inventory.Region', - 'cloud_service_type': CloudServiceType, - 'cloud_service': CloudService, - 'region': Region, - 'match_keys': 'list', - 'error_message': 'str' - 'metadata': 'dict' - } - CloudServiceType - { - 'name': 'str', # Required - 'group': 'str', # Required - 'provider': 'str', # Required - 'is_primary': 'bool', - 'is_major': 'bool', - 'metadata': 'dict', # Required - 'service_code': 'str', - 'tags': 'dict' - 'labels': 'list' - } +@app.route('Job.get_tasks') +def job_get_tasks(params: dict) -> dict: + domain_id = params["domain_id"] + options = params.get("options", {}) + cloud_service_groups = options.get("cloud_service_groups", []) + resource_types = options.get("resource_types", DEFAULT_RESOURCE_TYPES) - CloudService - { - 'name': 'str', - 'cloud_service_type': 'str', # Required - 'cloud_service_group': 'str', # Required - 'provider': 'str', # Required - 'ip_addresses' : 'list', - 'account' : 'str', - 'instance_type': 'str', - 'instance_size': 'float', - 'region_code': 'str', - 'data': 'dict' # Required - 'metadata': 'dict' # Required - 'reference': 'dict' - 'tags' : 'dict' - } + tasks = [] - Region - { - 'name': 'str', - 'region_code': 'str', # Required - 'provider': 'str', # Required - 'tags': 'dict' - } + if not resource_types: + resource_types = DEFAULT_RESOURCE_TYPES - Only one of the cloud_service_type, cloud_service and region fields is required. - """ - pass + for manager in AzureBaseManager.list_managers_by_cloud_service_groups(cloud_service_groups): + for resource_type in resource_types: + tasks.append({ + "task_options": { + "resource_type": resource_type, + "cloud_service_groups": [manager.cloud_service_group] + } + }) + return {"tasks": tasks} -@app.route('Job.get_tasks') -def job_get_tasks(params: dict) -> dict: - """ Get job tasks - Args: - params (JobGetTaskRequest): { - 'options': 'dict', # Required - 'secret_data': 'dict', # Required - 'domain_id': 'str' - } +def _get_cloud_service_groups_from_options_and_task_options(options: dict, task_options: dict) -> list: + cloud_service_groups = options.get("cloud_service_groups", []) + if task_options: + cloud_service_groups = task_options.get("cloud_service_groups", cloud_service_groups) + return cloud_service_groups - Returns: - TasksResponse: { - 'tasks': 'list' - } - """ - pass +def _check_secret_data(secret_data: dict): + if "tenant_id" not in secret_data: + raise ERROR_REQUIRED_PARAMETER(key='secret_data.tenant_id') + + if "subscription_id" not in secret_data: + raise ERROR_REQUIRED_PARAMETER(key='secret_data.subscription_id') + + if "client_id" not in secret_data: + raise ERROR_REQUIRED_PARAMETER(key='secret_data.client_id') + + if "client_secret" not in secret_data: + raise ERROR_REQUIRED_PARAMETER(key='secret_data.client_secret') diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py new file mode 100644 index 00000000..7899c9dc --- /dev/null +++ b/src/plugin/manager/__init__.py @@ -0,0 +1 @@ +from plugin.manager.disks.disks_manager import DisksManager diff --git a/src/plugin/manager/base.py b/src/plugin/manager/base.py new file mode 100644 index 00000000..e6241280 --- /dev/null +++ b/src/plugin/manager/base.py @@ -0,0 +1,223 @@ +import os +import abc +import logging +import datetime +import time +import re +from typing import Union + +from spaceone.core.manager import BaseManager +from spaceone.core import utils +from spaceone.inventory.plugin.collector.lib import * + +_LOGGER = logging.getLogger("spaceone") +_CURRENT_DIR = os.path.dirname(__file__) +_METRIC_DIR = os.path.join(_CURRENT_DIR, "../metrics/") +_METADATA_DIR = os.path.join(_CURRENT_DIR, "../metadata/") + +__all__ = ["AzureBaseManager"] + + +class AzureBaseManager(BaseManager): + service = None + cloud_service_group = None + cloud_service_type = None + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.provider = "azure" + + @abc.abstractmethod + def create_cloud_service_type(self): + raise NotImplementedError( + "method `create_cloud_service_type` should be implemented" + ) + + @abc.abstractmethod + def create_cloud_service(self, options, secret_data, schema): + raise NotImplementedError("method `create_cloud_service` should be implemented") + + @classmethod + def list_managers_by_cloud_service_groups(cls, cloud_service_groups: list): + if cloud_service_groups in ["All"]: + yield from cls.__subclasses__() + elif cloud_service_groups: + for manager in cls.__subclasses__(): + if manager.cloud_service_group and manager.cloud_service_group in cloud_service_groups: + yield manager + else: + yield from cls.__subclasses__() + + @classmethod + def collect_metrics(cls, cloud_service_group: str): + if not os.path.exists(os.path.join(_METRIC_DIR, cloud_service_group)): + os.mkdir(os.path.join(_METRIC_DIR, cloud_service_group)) + for dirname in os.listdir(os.path.join(_METRIC_DIR, cloud_service_group)): + for filename in os.listdir(os.path.join(_METRIC_DIR, cloud_service_group, dirname)): + if filename.endswith(".yaml"): + file_path = os.path.join(_METRIC_DIR, cloud_service_group, dirname, filename) + info = utils.load_yaml_from_file(file_path) + if filename == "namespace.yaml": + yield make_response( + namespace=info, + resource_type="inventory.Namespace", + match_keys=[] + ) + else: + yield make_response( + metric=info, + resource_type="inventory.Metric", + match_keys=[] + ) + + def collect_resources(self, options: dict, secret_data: dict, schema: str): + subscription_id = secret_data.get("subscription_id") + start_time = time.time() + _LOGGER.debug( + f"[START] Collecting {self.__repr__()} (subscription_id: {subscription_id})" + ) + success_count, error_count = [0, 0] + try: + yield from self.collect_cloud_service_type() + + cloud_services, total_count = self.collect_cloud_service( + options, secret_data, schema + ) + for cloud_service in cloud_services: + yield cloud_service + success_count, error_count = total_count + + yield from self.collect_region(secret_data) + + except Exception as e: + yield make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + + _LOGGER.debug( + f"[DONE] {self.__repr__()} Collected Time: {time.time() - start_time:.2f}s, Total Count: {success_count + error_count} (Success: {success_count}, Failure: {error_count})" + ) + + def collect_cloud_service_type(self): + _LOGGER.debug(f"[START] Collecting cloud service type {self.__repr__()}") + + cloud_service_type = self.create_cloud_service_type() + yield make_response( + cloud_service_type=cloud_service_type, + match_keys=[["name", "group", "provider"]], + resource_type="inventory.CloudServiceType", + ) + + def collect_cloud_services(self, options: dict, secret_data: dict, schema: str): + subscription_id = secret_data.get("subscription_id") + start_time = time.time() + _LOGGER.debug( + f"[START] Collecting cloud services {self.__repr__()} (subscription_id: {subscription_id})" + ) + success_count, error_count = [0, 0] + try: + cloud_services, total_count = self.collect_cloud_service( + options, secret_data, schema + ) + for cloud_service in cloud_services: + yield cloud_service + success_count, error_count = total_count + + except Exception as e: + yield make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + + _LOGGER.debug( + f"[DONE] {self.__repr__()} Collected Time: {time.time() - start_time:.2f}s, Total Count: {success_count + error_count} (Success: {success_count}, Failure: {error_count})" + ) + + def collect_cloud_service(self, options: dict, secret_data: dict, schema: str): + total_resources = [] + cloud_services, error_resources = self.create_cloud_service( + options, secret_data, schema + ) + + for cloud_service in cloud_services: + total_resources.append( + make_response( + cloud_service=cloud_service, + match_keys=[ + [ + "reference.resource_id", + "provider", + "cloud_service_type", + "cloud_service_group", + "account" + ] + ], + ) + ) + total_resources.extend(error_resources) + total_count = [len(cloud_services), len(error_resources)] + return total_resources, total_count + + def collect_region(self, location_info: dict): + _LOGGER.debug(f"[START] Collecting region {self.__repr__()}") + for region_info in location_info.values(): + yield make_response( + region=region_info, + match_keys=[["region_code", "provider"]], + resource_type="inventory.Region", + ) + + def get_metadata_path(self): + _cloud_service_group = self._camel_to_snake(self.cloud_service_group) + _cloud_service_type = self._camel_to_snake(self.cloud_service_type) + return os.path.join(_METADATA_DIR, _cloud_service_group, f"{_cloud_service_type}.yaml") + + def convert_nested_dictionary(self, cloud_svc_object: object) -> Union[object, dict]: + cloud_svc_dict = {} + if hasattr( + cloud_svc_object, "__dict__" + ): # if cloud_svc_object is not a dictionary type but has dict method + cloud_svc_dict = cloud_svc_object.__dict__ + elif isinstance(cloud_svc_object, dict): + cloud_svc_dict = cloud_svc_object + elif not isinstance( + cloud_svc_object, list + ): # if cloud_svc_object is one of type like int, float, char, ... + return cloud_svc_object + + # if cloud_svc_object is dictionary type + for key, value in cloud_svc_dict.items(): + if hasattr(value, "__dict__") or isinstance(value, dict): + cloud_svc_dict[key] = self.convert_nested_dictionary(value) + if "azure" in str(type(value)): + cloud_svc_dict[key] = self.convert_nested_dictionary(value) + elif isinstance(value, list): + value_list = [] + for v in value: + value_list.append(self.convert_nested_dictionary(v)) + cloud_svc_dict[key] = value_list + elif isinstance(value, datetime.datetime): + cloud_svc_dict[key] = utils.datetime_to_iso8601(value) + + return cloud_svc_dict + + @staticmethod + def make_reference(resource_id: str, external_link_format: str = None) -> dict: + if external_link_format: + external_link = external_link_format.format(resource_id=resource_id) + else: + external_link = f"https://portal.azure.com/#@.onmicrosoft.com/resource{resource_id}/overview" + return { + "resource_id": resource_id, + "external_link": external_link + } + + @staticmethod + def _camel_to_snake(name): + name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) + return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower() diff --git a/src/plugin/manager/disks/__init__.py b/src/plugin/manager/disks/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/manager/disks/disks_manager.py b/src/plugin/manager/disks/disks_manager.py new file mode 100644 index 00000000..c35e53b0 --- /dev/null +++ b/src/plugin/manager/disks/disks_manager.py @@ -0,0 +1,186 @@ +import logging + +from spaceone.core.utils import datetime_to_iso8601 +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.disks.disks_connector import DisksConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class DisksManager(AzureBaseManager): + cloud_service_group = "Disks" + cloud_service_type = "Disk" + service_code = "/Microsoft.Compute/disks" + + def create_cloud_service(self, options: dict, secret_data: dict, schema: str): + cloud_services = [] + error_responses = [] + + disks_conn = DisksConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + disks = disks_conn.list_disks() + + for disk in disks: + disk_id = "" + + try: + disk_dict = self.convert_nested_dictionary(disk) + disk_id = disk_dict["id"] + + # Switch DiskStorageAccountType to disk_sku_name for user-friendly words. (ex.Premium SSD, Standard HDD..) + if disk_dict.get("sku") is not None: + sku_dict = disk_dict["sku"] + sku_dict.update({"name": self.get_disk_sku_name(sku_dict["name"])}) + disk_dict.update({"sku": sku_dict}) + + # update disk_data dict + disk_dict.update( + { + "resource_group": self.get_resource_group_from_id( + disk_dict["id"] + ), # parse resource_group from ID + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "size": disk_dict["disk_size_bytes"], + "tier_display": self.get_tier_display( + disk_dict["disk_iops_read_write"], + disk_dict["disk_m_bps_read_write"], + ), + "azure_monitor": {"resource_id": disk_id}, + "time_created": datetime_to_iso8601(disk_dict["time_created"]), + } + ) + + # Update Network access policy to user-friendly words + if disk_dict.get("network_access_policy") is not None: + disk_dict.update( + { + "network_access_policy_display": self.get_network_access_policy( + disk_dict["network_access_policy"] + ) + } + ) + + # get attached vm's name + if disk_dict.get("managed_by") is not None: + managed_by = disk_dict["managed_by"] + disk_dict.update( + { + "managed_by": self.get_attached_vm_name_from_managed_by( + managed_by + ) + } + ) + + max_shares = disk_dict.get("max_shares") + if max_shares is not None and max_shares > 0: + disk_dict.update({"enable_shared_disk_display": True}) + + if disk_dict.get("bursting_enabled") is None: + disk_dict["bursting_enabled"] = False + + disk_dict = self.update_tenant_id_from_secret_data( + disk_dict, secret_data + ) + + cloud_services.append( + make_cloud_service( + name=disk_dict["name"], + account=secret_data["subscription_id"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + region_code=disk_dict["location"], + data=disk_dict, + reference=self.make_reference(disk_dict["id"]) + ) + ) + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + + ) + + return cloud_services, error_responses + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Compute", "Storage"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-disk.svg" + } + ) + + @staticmethod + def get_attached_vm_name_from_managed_by(managed_by): + attached_vm_name = managed_by.split("/")[8] + return attached_vm_name + + @staticmethod + def get_disk_sku_name(sku_tier): + if sku_tier == "Premium_LRS": + sku_name = "Premium SSD" + elif sku_tier == "StandardSSD_LRS": + sku_name = "Standard SSD" + elif sku_tier == "Standard_LRS": + sku_name = "Standard HDD" + else: + sku_name = "Ultra SSD" + return sku_name + + @staticmethod + def get_network_access_policy(network_access_policy): + network_access_policy_display = "" + if network_access_policy == "AllowAll": + network_access_policy_display = "Public endpoint (all network)" + elif network_access_policy == "AllowPrivate": + network_access_policy_display = "Private endpoint (through disk access)" + elif network_access_policy == "DenyAll": + network_access_policy_display = "Deny all" + + return network_access_policy_display + + @staticmethod + def get_tier_display(disk_iops_read_write, disk_m_bps_read_write): + tier_display = ( + str(disk_iops_read_write) + + " IOPS" + + ", " + + str(disk_m_bps_read_write) + + " Mbps" + ) + return tier_display + + @staticmethod + def update_tenant_id_from_secret_data( + cloud_service_data: dict, secret_data: dict + ) -> dict: + if tenant_id := secret_data.get("tenant_id"): + cloud_service_data.update({"tenant_id": tenant_id}) + return cloud_service_data + + @staticmethod + def get_resource_group_from_id(dict_id): + resource_group = dict_id.split("/")[4] + return resource_group diff --git a/src/plugin/manager/subscriptions/__init__.py b/src/plugin/manager/subscriptions/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/manager/subscriptions/subscriptions_manager.py b/src/plugin/manager/subscriptions/subscriptions_manager.py new file mode 100644 index 00000000..49571a93 --- /dev/null +++ b/src/plugin/manager/subscriptions/subscriptions_manager.py @@ -0,0 +1,47 @@ +import logging +import re + +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class SubscriptionsManager(AzureBaseManager): + # cloud_service_group = "Subscriptions" + # cloud_service_type = "Subscription" + service_code = "/Microsoft.subscriptions" + + def create_cloud_service_type(self): + pass + + def create_cloud_service(self, options: dict, secret_data: dict, schema: str): + pass + + def list_location_info(self, secret_data: dict): + subscription_connector = SubscriptionsConnector(secret_data=secret_data) + location_infos = subscription_connector.list_location_info(secret_data['subscription_id']) + + region_info = {} + for location_info in location_infos: + _loc_info = self.convert_nested_dictionary(location_info) + _name = f'{re.sub(r"[/()]", "", _loc_info.get("regional_display_name"))} ({_loc_info.get("metadata").get("physical_location")})' + _latitude = _loc_info.get('metadata', {}).get('latitude') + _longitude = _loc_info.get('metadata', {}).get('longitude') + _continent = _loc_info.get('metadata', {}).get('geography_group') + + if _name and _latitude and _longitude and _continent: + region_info.update({ + _loc_info['name']: { + 'region_code': _loc_info['name'], + 'provider': self.provider, + 'name': _name, + 'tags': { + 'latitude': _latitude, + 'longitude': _longitude, + 'continent': _continent.replace(' ', '_').lower() + } + } + }) + + return region_info diff --git a/src/plugin/metadata/disks/disk.yaml b/src/plugin/metadata/disks/disk.yaml new file mode 100644 index 00000000..ef693adf --- /dev/null +++ b/src/plugin/metadata/disks/disk.yaml @@ -0,0 +1,155 @@ +--- +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metrics/Disks/Disk/disk_count.yaml b/src/plugin/metrics/Disks/Disk/disk_count.yaml new file mode 100644 index 00000000..4744998a --- /dev/null +++ b/src/plugin/metrics/Disks/Disk/disk_count.yaml @@ -0,0 +1,46 @@ +--- +metric_id: metric-azure-disks-disk-count +name: Disk Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.Disks.Disk +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.zones + name: Zone + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: instance_type + name: Disk Type + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.disk_state + name: Disk State + default: true + - key: data.os_type + name: OS Type + - key: data.managed_by + name: Managed By + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-disks-disk +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/Disks/Disk/disk_size.yaml b/src/plugin/metrics/Disks/Disk/disk_size.yaml new file mode 100644 index 00000000..7b949a25 --- /dev/null +++ b/src/plugin/metrics/Disks/Disk/disk_size.yaml @@ -0,0 +1,52 @@ +--- +metric_id: metric-azure-disks-disk-size +name: Disk Size +metric_type: GAUGE +resource_type: inventory.CloudService:azure.Disks.Disk +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + - key: data.zones + name: Zone + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: instance_type + name: Disk Type + - key: data.provisioning_state + name: Provisioning State + + default: true + - key: data.disk_state + name: Disk State + default: true + - key: data.os_type + name: OS Type + - key: data.managed_by + name: Managed By + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + fields: + value: + key: data.disk_size_gb + operator: sum +unit: GB +namespace_id: ns-azure-disks-disk +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/Disks/Disk/namespace.yaml b/src/plugin/metrics/Disks/Disk/namespace.yaml new file mode 100644 index 00000000..a2c4f412 --- /dev/null +++ b/src/plugin/metrics/Disks/Disk/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-disks-disk +name: Disks/Disk +resource_type: inventory.CloudService:azure.Disks.Disk +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-disk.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml b/src/plugin/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml new file mode 100644 index 00000000..9d3d3471 --- /dev/null +++ b/src/plugin/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml @@ -0,0 +1,39 @@ +--- +metric_id: metric-azure-pubipaddrs-ipaddrs-count +name: IP Address Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.PublicIPAddresses.IPAddress +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.zones + name: Zone + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + - key: data.associated_to + name: Associated To + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-pubipaddrs-ipaddrs +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/PublicIPAddresses/IpAddress/namespace.yaml b/src/plugin/metrics/PublicIPAddresses/IpAddress/namespace.yaml new file mode 100644 index 00000000..54add6ef --- /dev/null +++ b/src/plugin/metrics/PublicIPAddresses/IpAddress/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-pubipaddrs-ipaddrs +name: PublicIPAddresses/IPAddresses +resource_type: inventory.CloudService:azure.PublicIPAddresses.IPAddresses +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-public-ip-address.svg +version: '1.0' \ No newline at end of file From a2ee849dfc4ba137575eba3ccd87ebf9d91ca998 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 19 Jul 2024 17:17:04 +0900 Subject: [PATCH 03/35] refactor: disks_manager and manager/base Refactoring --- src/plugin/main.py | 2 - src/plugin/manager/__init__.py | 4 +- src/plugin/manager/base.py | 34 ++++++- src/plugin/manager/disks/__init__.py | 1 + src/plugin/manager/disks/disks_manager.py | 92 ++++++++----------- src/plugin/manager/subscriptions/__init__.py | 1 + .../subscriptions/subscriptions_manager.py | 2 +- src/plugin/metadata/disks/disk.yaml | 3 + 8 files changed, 78 insertions(+), 61 deletions(-) diff --git a/src/plugin/main.py b/src/plugin/main.py index f919f6b5..67e59f98 100644 --- a/src/plugin/main.py +++ b/src/plugin/main.py @@ -61,8 +61,6 @@ def collector_collect(params: dict) -> Generator[dict, None, None]: if resource_type == "inventory.Region": subscriptions_mgr = SubscriptionsManager() location_info = subscriptions_mgr.list_location_info(secret_data) - print("hererere") - print(location_info) yield from AzureBaseManager().collect_region(location_info) else: for manager in AzureBaseManager.list_managers_by_cloud_service_groups(cloud_service_groups): diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 7899c9dc..71b09f4a 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -1 +1,3 @@ -from plugin.manager.disks.disks_manager import DisksManager +from .disks import * +from .subscriptions import * + diff --git a/src/plugin/manager/base.py b/src/plugin/manager/base.py index e6241280..52eb496a 100644 --- a/src/plugin/manager/base.py +++ b/src/plugin/manager/base.py @@ -4,7 +4,7 @@ import datetime import time import re -from typing import Union +from typing import Union, List, Type from spaceone.core.manager import BaseManager from spaceone.core import utils @@ -48,6 +48,13 @@ def list_managers_by_cloud_service_groups(cls, cloud_service_groups: list): else: yield from cls.__subclasses__() + @classmethod + def get_managers_by_cloud_service_group(cls, cloud_service_group: str): + sub_cls = cls.__subclasses__() + for manager in sub_cls: + if manager.__name__ == cloud_service_group: + return manager + @classmethod def collect_metrics(cls, cloud_service_group: str): if not os.path.exists(os.path.join(_METRIC_DIR, cloud_service_group)): @@ -80,14 +87,17 @@ def collect_resources(self, options: dict, secret_data: dict, schema: str): try: yield from self.collect_cloud_service_type() - cloud_services, total_count = self.collect_cloud_service( - options, secret_data, schema - ) + cloud_services, total_count = self.collect_cloud_service(options, secret_data, schema + ) for cloud_service in cloud_services: yield cloud_service success_count, error_count = total_count - yield from self.collect_region(secret_data) + subscriptions_manager = AzureBaseManager.get_managers_by_cloud_service_group("SubscriptionsManager") + location_info = subscriptions_manager().list_location_info(secret_data) + + yield from self.collect_region(location_info) + # yield from self.collect_region(secret_data) except Exception as e: yield make_error_response( @@ -175,6 +185,7 @@ def collect_region(self, location_info: dict): def get_metadata_path(self): _cloud_service_group = self._camel_to_snake(self.cloud_service_group) _cloud_service_type = self._camel_to_snake(self.cloud_service_type) + return os.path.join(_METADATA_DIR, _cloud_service_group, f"{_cloud_service_type}.yaml") def convert_nested_dictionary(self, cloud_svc_object: object) -> Union[object, dict]: @@ -221,3 +232,16 @@ def make_reference(resource_id: str, external_link_format: str = None) -> dict: def _camel_to_snake(name): name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower() + + @staticmethod + def get_resource_group_from_id(dict_id): + resource_group = dict_id.split("/")[4] + return resource_group + + @staticmethod + def update_tenant_id_from_secret_data( + cloud_service_data: dict, secret_data: dict + ) -> dict: + if tenant_id := secret_data.get("tenant_id"): + cloud_service_data.update({"tenant_id": tenant_id}) + return cloud_service_data diff --git a/src/plugin/manager/disks/__init__.py b/src/plugin/manager/disks/__init__.py index e69de29b..5d8aa1d7 100644 --- a/src/plugin/manager/disks/__init__.py +++ b/src/plugin/manager/disks/__init__.py @@ -0,0 +1 @@ +from .disks_manager import DisksManager diff --git a/src/plugin/manager/disks/disks_manager.py b/src/plugin/manager/disks/disks_manager.py index c35e53b0..6313336e 100644 --- a/src/plugin/manager/disks/disks_manager.py +++ b/src/plugin/manager/disks/disks_manager.py @@ -16,7 +16,22 @@ class DisksManager(AzureBaseManager): cloud_service_type = "Disk" service_code = "/Microsoft.Compute/disks" - def create_cloud_service(self, options: dict, secret_data: dict, schema: str): + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Compute", "Storage"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-disk.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): cloud_services = [] error_responses = [] @@ -29,7 +44,6 @@ def create_cloud_service(self, options: dict, secret_data: dict, schema: str): disks = disks_conn.list_disks() for disk in disks: - disk_id = "" try: disk_dict = self.convert_nested_dictionary(disk) @@ -44,9 +58,7 @@ def create_cloud_service(self, options: dict, secret_data: dict, schema: str): # update disk_data dict disk_dict.update( { - "resource_group": self.get_resource_group_from_id( - disk_dict["id"] - ), # parse resource_group from ID + "resource_group": self.get_resource_group_from_id(disk_dict["id"]), "subscription_id": subscription_info["subscription_id"], "subscription_name": subscription_info["display_name"], "size": disk_dict["disk_size_bytes"], @@ -87,22 +99,26 @@ def create_cloud_service(self, options: dict, secret_data: dict, schema: str): if disk_dict.get("bursting_enabled") is None: disk_dict["bursting_enabled"] = False - disk_dict = self.update_tenant_id_from_secret_data( + disk_data = self.update_tenant_id_from_secret_data( disk_dict, secret_data ) cloud_services.append( make_cloud_service( - name=disk_dict["name"], - account=secret_data["subscription_id"], + name=disk_data["name"], cloud_service_type=self.cloud_service_type, cloud_service_group=self.cloud_service_group, provider=self.provider, - region_code=disk_dict["location"], - data=disk_dict, - reference=self.make_reference(disk_dict["id"]) + data=disk_data, + account=secret_data["subscription_id"], + instance_type=disk_data["sku"]["name"], + instance_size=disk_data["disk_size_bytes"], + region_code=disk_data["location"], + reference=self.make_reference(disk_data.get("id")), + data_format="dict" ) ) + except Exception as e: _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) error_responses.append( @@ -117,26 +133,6 @@ def create_cloud_service(self, options: dict, secret_data: dict, schema: str): return cloud_services, error_responses - def create_cloud_service_type(self): - return make_cloud_service_type( - name=self.cloud_service_type, - group=self.cloud_service_group, - provider=self.provider, - service_code=self.service_code, - metadata_path=self.get_metadata_path(), - is_primary=True, - is_major=True, - labels=["Compute", "Storage"], - tags={ - "spaceone:icon": f"{ICON_URL}/azure-disk.svg" - } - ) - - @staticmethod - def get_attached_vm_name_from_managed_by(managed_by): - attached_vm_name = managed_by.split("/")[8] - return attached_vm_name - @staticmethod def get_disk_sku_name(sku_tier): if sku_tier == "Premium_LRS": @@ -149,18 +145,6 @@ def get_disk_sku_name(sku_tier): sku_name = "Ultra SSD" return sku_name - @staticmethod - def get_network_access_policy(network_access_policy): - network_access_policy_display = "" - if network_access_policy == "AllowAll": - network_access_policy_display = "Public endpoint (all network)" - elif network_access_policy == "AllowPrivate": - network_access_policy_display = "Private endpoint (through disk access)" - elif network_access_policy == "DenyAll": - network_access_policy_display = "Deny all" - - return network_access_policy_display - @staticmethod def get_tier_display(disk_iops_read_write, disk_m_bps_read_write): tier_display = ( @@ -173,14 +157,18 @@ def get_tier_display(disk_iops_read_write, disk_m_bps_read_write): return tier_display @staticmethod - def update_tenant_id_from_secret_data( - cloud_service_data: dict, secret_data: dict - ) -> dict: - if tenant_id := secret_data.get("tenant_id"): - cloud_service_data.update({"tenant_id": tenant_id}) - return cloud_service_data + def get_network_access_policy(network_access_policy): + network_access_policy_display = "" + if network_access_policy == "AllowAll": + network_access_policy_display = "Public endpoint (all network)" + elif network_access_policy == "AllowPrivate": + network_access_policy_display = "Private endpoint (through disk access)" + elif network_access_policy == "DenyAll": + network_access_policy_display = "Deny all" + + return network_access_policy_display @staticmethod - def get_resource_group_from_id(dict_id): - resource_group = dict_id.split("/")[4] - return resource_group + def get_attached_vm_name_from_managed_by(managed_by): + attached_vm_name = managed_by.split("/")[8] + return attached_vm_name diff --git a/src/plugin/manager/subscriptions/__init__.py b/src/plugin/manager/subscriptions/__init__.py index e69de29b..cb525928 100644 --- a/src/plugin/manager/subscriptions/__init__.py +++ b/src/plugin/manager/subscriptions/__init__.py @@ -0,0 +1 @@ +from .subscriptions_manager import SubscriptionsManager diff --git a/src/plugin/manager/subscriptions/subscriptions_manager.py b/src/plugin/manager/subscriptions/subscriptions_manager.py index 49571a93..a0919d00 100644 --- a/src/plugin/manager/subscriptions/subscriptions_manager.py +++ b/src/plugin/manager/subscriptions/subscriptions_manager.py @@ -8,7 +8,7 @@ class SubscriptionsManager(AzureBaseManager): - # cloud_service_group = "Subscriptions" + cloud_service_group = "Subscriptions" # cloud_service_type = "Subscription" service_code = "/Microsoft.subscriptions" diff --git a/src/plugin/metadata/disks/disk.yaml b/src/plugin/metadata/disks/disk.yaml index ef693adf..852ae406 100644 --- a/src/plugin/metadata/disks/disk.yaml +++ b/src/plugin/metadata/disks/disk.yaml @@ -62,6 +62,9 @@ table: - Subscription ID: data.subscription_id is_optional: true - Zone: data.zones + type: list + options: + delimiter: ', ' is_optional: true - Encryption Type: data.encryption.type is_optional: true From b5f2956cf5a051e0ebae6ada6c70733d60fed5c2 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 19 Jul 2024 17:29:06 +0900 Subject: [PATCH 04/35] fix: Dockerfile configuration --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7398579c..1a809366 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ RUN python3 setup.py install && \ EXPOSE ${CLOUDONE_PORT} ENTRYPOINT ["spaceone"] -CMD ["run", "grpc-server", "spaceone.inventory"] +CMD ["run", "plugin-server", "plugin"] From f955046047498904e896726ed47e008119367443 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Tue, 23 Jul 2024 18:01:40 +0900 Subject: [PATCH 05/35] feat: PublicIPAddresses, SQLDatabases, SQLServers, VirtualNetworks, ApplicationGateways Collector migration --- Dockerfile | 2 +- src/VERSION | 1 + .../application_gateways/__init__.py | 0 .../application_gateways_connector.py | 18 + src/plugin/connector/base.py | 10 + src/plugin/connector/monitor/__init__.py | 0 .../connector/monitor/monitor_connector.py | 18 + .../connector/public_ip_addresses/__init__.py | 0 .../public_ip_addresses_connector.py | 14 + .../connector/sql_databases/__init__.py | 0 .../sql_databases/sql_databases_connector.py | 38 + src/plugin/connector/sql_servers/__init__.py | 0 .../sql_servers/sql_servers_connector.py | 59 ++ .../connector/virtual_networks/__init__.py | 0 .../virtual_networks_connector.py | 17 + src/plugin/main.py | 45 +- src/plugin/manager/__init__.py | 7 +- .../manager/application_gatways/__init__.py | 1 + .../application_gatways/instance_manager.py | 393 ++++++++++ src/plugin/manager/base.py | 33 +- src/plugin/manager/disks/__init__.py | 2 +- .../{disks_manager.py => disk_manager.py} | 7 +- .../manager/public_ip_addresses/__init__.py | 1 + .../public_ip_addresses/ip_address_manager.py | 101 +++ src/plugin/manager/sql_databases/__init__.py | 1 + .../manager/sql_databases/database_manager.py | 272 +++++++ src/plugin/manager/sql_servers/__init__.py | 1 + .../manager/sql_servers/server_manager.py | 669 ++++++++++++++++++ src/plugin/manager/subscriptions/__init__.py | 1 - ...ons_manager.py => subscription_manager.py} | 2 +- .../manager/virtual_networks/__init__.py | 1 + .../virtual_networks/instance_manager.py | 217 ++++++ .../application_gateways/instance.yaml | 157 ++++ src/plugin/metadata/disks/disk.yaml | 1 - .../public_ip_addresses/ip_address.yaml | 157 ++++ .../metadata/sql_databases/database.yaml | 157 ++++ src/plugin/metadata/sql_servers/server.yaml | 157 ++++ .../metadata/virtual_networks/instance.yaml | 157 ++++ .../Instance/instance_count.yaml | 32 + .../Instance/namespace.yaml | 8 + .../ip_addresses_count.yaml | 0 .../{IpAddress => IPAddress}/namespace.yaml | 0 .../SQLDatabases/Database/database_count.yaml | 42 ++ .../SQLDatabases/Database/database_size.yaml | 43 ++ .../SQLDatabases/Database/namespace.yaml | 8 + .../metrics/SQLServers/Server/namespace.yaml | 8 + .../SQLServers/Server/server_count.yaml | 36 + .../instance/instance_count.yaml | 32 + .../VirtualNetworks/instance/namespace.yaml | 8 + src/setup.py | 45 ++ 50 files changed, 2946 insertions(+), 33 deletions(-) create mode 100644 src/VERSION create mode 100644 src/plugin/connector/application_gateways/__init__.py create mode 100644 src/plugin/connector/application_gateways/application_gateways_connector.py create mode 100644 src/plugin/connector/monitor/__init__.py create mode 100644 src/plugin/connector/monitor/monitor_connector.py create mode 100644 src/plugin/connector/public_ip_addresses/__init__.py create mode 100644 src/plugin/connector/public_ip_addresses/public_ip_addresses_connector.py create mode 100644 src/plugin/connector/sql_databases/__init__.py create mode 100644 src/plugin/connector/sql_databases/sql_databases_connector.py create mode 100644 src/plugin/connector/sql_servers/__init__.py create mode 100644 src/plugin/connector/sql_servers/sql_servers_connector.py create mode 100644 src/plugin/connector/virtual_networks/__init__.py create mode 100644 src/plugin/connector/virtual_networks/virtual_networks_connector.py create mode 100644 src/plugin/manager/application_gatways/__init__.py create mode 100644 src/plugin/manager/application_gatways/instance_manager.py rename src/plugin/manager/disks/{disks_manager.py => disk_manager.py} (97%) create mode 100644 src/plugin/manager/public_ip_addresses/__init__.py create mode 100644 src/plugin/manager/public_ip_addresses/ip_address_manager.py create mode 100644 src/plugin/manager/sql_databases/__init__.py create mode 100644 src/plugin/manager/sql_databases/database_manager.py create mode 100644 src/plugin/manager/sql_servers/__init__.py create mode 100644 src/plugin/manager/sql_servers/server_manager.py rename src/plugin/manager/subscriptions/{subscriptions_manager.py => subscription_manager.py} (97%) create mode 100644 src/plugin/manager/virtual_networks/__init__.py create mode 100644 src/plugin/manager/virtual_networks/instance_manager.py create mode 100644 src/plugin/metadata/application_gateways/instance.yaml create mode 100644 src/plugin/metadata/public_ip_addresses/ip_address.yaml create mode 100644 src/plugin/metadata/sql_databases/database.yaml create mode 100644 src/plugin/metadata/sql_servers/server.yaml create mode 100644 src/plugin/metadata/virtual_networks/instance.yaml create mode 100644 src/plugin/metrics/ApplicationGateways/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/ApplicationGateways/Instance/namespace.yaml rename src/plugin/metrics/PublicIPAddresses/{IpAddress => IPAddress}/ip_addresses_count.yaml (100%) rename src/plugin/metrics/PublicIPAddresses/{IpAddress => IPAddress}/namespace.yaml (100%) create mode 100644 src/plugin/metrics/SQLDatabases/Database/database_count.yaml create mode 100644 src/plugin/metrics/SQLDatabases/Database/database_size.yaml create mode 100644 src/plugin/metrics/SQLDatabases/Database/namespace.yaml create mode 100644 src/plugin/metrics/SQLServers/Server/namespace.yaml create mode 100644 src/plugin/metrics/SQLServers/Server/server_count.yaml create mode 100644 src/plugin/metrics/VirtualNetworks/instance/instance_count.yaml create mode 100644 src/plugin/metrics/VirtualNetworks/instance/namespace.yaml create mode 100644 src/setup.py diff --git a/Dockerfile b/Dockerfile index 1a809366..d812e5b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ ENV SRC_DIR /tmp/src COPY pkg/*.txt ${PKG_DIR}/ RUN pip install --upgrade pip && \ pip install --upgrade -r ${PKG_DIR}/pip_requirements.txt && \ - pip install --upgrade spaceone-api + pip install --upgrade spaceone-api spaceone-inventory==2.0.dev212 COPY src ${SRC_DIR} diff --git a/src/VERSION b/src/VERSION new file mode 100644 index 00000000..8acdd82b --- /dev/null +++ b/src/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/src/plugin/connector/application_gateways/__init__.py b/src/plugin/connector/application_gateways/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/application_gateways/application_gateways_connector.py b/src/plugin/connector/application_gateways/application_gateways_connector.py new file mode 100644 index 00000000..2c62ee3f --- /dev/null +++ b/src/plugin/connector/application_gateways/application_gateways_connector.py @@ -0,0 +1,18 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class ApplicationGatewaysConnector(AzureBaseConnector): + + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_all_application_gateways(self): + return self.network_client.application_gateways.list_all() + + def get_public_ip_addresses(self, public_ip_address_name, resource_group_name): + return self.network_client.public_ip_addresses.get(public_ip_address_name, resource_group_name) \ No newline at end of file diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index 247b374b..dd3e71ad 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -4,6 +4,9 @@ from azure.identity import DefaultAzureCredential from azure.mgmt.compute import ComputeManagementClient from azure.mgmt.resource import SubscriptionClient +from azure.mgmt.network import NetworkManagementClient +from azure.mgmt.sql import SqlManagementClient +from azure.mgmt.monitor import MonitorManagementClient from spaceone.core.connector import BaseConnector @@ -14,7 +17,11 @@ class AzureBaseConnector(BaseConnector): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.subscription_client = None self.compute_client = None + self.network_client = None + self.sql_client = None + self.monitor_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -28,6 +35,9 @@ def set_connect(self, secret_data: dict): self.subscription_client = SubscriptionClient(credential=credential) self.compute_client = ComputeManagementClient(credential=credential, subscription_id=subscription_id) + self.network_client = NetworkManagementClient(credential=credential, subscription_id=subscription_id) + self.sql_client = SqlManagementClient(credential=credential, subscription_id=subscription_id) + self.monitor_client = MonitorManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/monitor/__init__.py b/src/plugin/connector/monitor/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/monitor/monitor_connector.py b/src/plugin/connector/monitor/monitor_connector.py new file mode 100644 index 00000000..59470a86 --- /dev/null +++ b/src/plugin/connector/monitor/monitor_connector.py @@ -0,0 +1,18 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class MonitorConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_diagnostic_settings(self, resource_uri): + return self.monitor_client.diagnostic_settings.list(resource_uri=resource_uri) + + def list_metrics(self, resource_uri, metricnames, aggregation, timespan=None, interval=None): + return self.monitor_client.metrics.list(resource_uri, metricnames=metricnames, aggregation=aggregation, + timespan=timespan, interval=interval) \ No newline at end of file diff --git a/src/plugin/connector/public_ip_addresses/__init__.py b/src/plugin/connector/public_ip_addresses/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/public_ip_addresses/public_ip_addresses_connector.py b/src/plugin/connector/public_ip_addresses/public_ip_addresses_connector.py new file mode 100644 index 00000000..6bddf41c --- /dev/null +++ b/src/plugin/connector/public_ip_addresses/public_ip_addresses_connector.py @@ -0,0 +1,14 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class PublicIPAddressesConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_all_public_ip_addresses(self): + return self.network_client.public_ip_addresses.list_all() \ No newline at end of file diff --git a/src/plugin/connector/sql_databases/__init__.py b/src/plugin/connector/sql_databases/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/sql_databases/sql_databases_connector.py b/src/plugin/connector/sql_databases/sql_databases_connector.py new file mode 100644 index 00000000..87168c00 --- /dev/null +++ b/src/plugin/connector/sql_databases/sql_databases_connector.py @@ -0,0 +1,38 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class SqlDatabasesConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_servers(self): + return self.sql_client.servers.list() + + def list_databases_in_server(self, resource_group_name, server_name): + return self.sql_client.databases.list_by_server(resource_group_name=resource_group_name, server_name=server_name) + + def list_sync_groups_by_databases(self, resource_group, server_name, database_name): + return self.sql_client.sync_groups.list_by_database(resource_group_name=resource_group, + database_name=database_name, + server_name=server_name) + + def list_sync_agents_by_server(self, resource_group, server_name): + return self.sql_client.sync_agents.list_by_server(resource_group_name=resource_group, server_name=server_name) + + def list_replication_link_by_server(self, resource_group_name, server_name): + return self.sql_client.replication_links.list_by_server(resource_group_name=resource_group_name, + server_name=server_name) + + def list_replication_link(self, resource_group_name, server_name, database_name): + return self.sql_client.replication_links.list_by_database(resource_group_name=resource_group_name, + server_name=server_name, database_name=database_name) + + def get_database_auditing_settings(self, resource_group_name, server_name, database_name): + return self.sql_client.database_blob_auditing_policies.get(resource_group_name=resource_group_name, + server_name=server_name, + database_name=database_name) \ No newline at end of file diff --git a/src/plugin/connector/sql_servers/__init__.py b/src/plugin/connector/sql_servers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/sql_servers/sql_servers_connector.py b/src/plugin/connector/sql_servers/sql_servers_connector.py new file mode 100644 index 00000000..861c9ee9 --- /dev/null +++ b/src/plugin/connector/sql_servers/sql_servers_connector.py @@ -0,0 +1,59 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class SqlServersConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_servers(self): + return self.sql_client.servers.list() + + def list_server_azure_ad_administrators(self, resource_group, server_name): + return self.sql_client.server_azure_ad_administrators.list_by_server(resource_group, server_name) + + def get_server_automatic_tuning(self, resource_group, server_name): + return self.sql_client.server_automatic_tuning.get(resource_group, server_name) + + def get_server_auditing_settings(self, resource_group, server_name): + return self.sql_client.server_blob_auditing_policies.get(resource_group, server_name) + + def list_failover_groups(self, resource_group, server_name): + return self.sql_client.failover_groups.list_by_server(resource_group, server_name) + + def list_encryption_protectors(self, resource_group, server_name): + return self.sql_client.encryption_protectors.list_by_server(resource_group_name=resource_group, server_name=server_name) + + def list_databases_by_server(self, resource_group_name, server_name): + return self.sql_client.databases.list_by_server(resource_group_name=resource_group_name, server_name=server_name) + + def list_elastic_pools_by_server(self, resource_group, server_name): + return self.sql_client.elastic_pools.list_by_server(resource_group, server_name) + + def list_databases_by_elastic_pool(self, elastic_pool_name, resource_group, server_name): + return self.sql_client.databases.list_by_elastic_pool(elastic_pool_name=elastic_pool_name, resource_group_name=resource_group, server_name=server_name) + + def list_restorable_dropped_databases_by_server(self, resource_group, server_name): + return self.sql_client.restorable_dropped_databases.list_by_server(resource_group_name=resource_group, server_name=server_name) + + def list_firewall_rules_by_server(self, resource_group, server_name): + return self.sql_client.firewall_rules.list_by_server(resource_group_name=resource_group, server_name=server_name) + + def list_virtual_network_rules_by_server(self, resource_group, server_name): + return self.sql_client.virtual_network_rules.list_by_server(resource_group_name=resource_group, server_name=server_name) + + def list_sync_groups_by_databases(self, resource_group, server_name, database_name): + return self.sql_client.sync_groups.list_by_database(resource_group_name=resource_group, database_name=database_name, server_name=server_name) + + def list_sync_agents_by_server(self, resource_group, server_name): + return self.sql_client.sync_agents.list_by_server(resource_group_name=resource_group, server_name=server_name) + + def list_data_masking_rules_by_database(self, resource_group, server_name, database_name): + return self.sql_client.data_masking_rules.list_by_database(resource_group_name=resource_group, server_name=server_name, database_name=database_name) + + def list_replication_link(self, resource_group, server_name, database_name): + return self.sql_client.replication_links.list_by_database(resource_group_name=resource_group, server_name=server_name, database_name=database_name) diff --git a/src/plugin/connector/virtual_networks/__init__.py b/src/plugin/connector/virtual_networks/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/virtual_networks/virtual_networks_connector.py b/src/plugin/connector/virtual_networks/virtual_networks_connector.py new file mode 100644 index 00000000..caf03583 --- /dev/null +++ b/src/plugin/connector/virtual_networks/virtual_networks_connector.py @@ -0,0 +1,17 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class VirtualNetworksConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_all_virtual_networks(self): + return self.network_client.virtual_networks.list_all() + + def list_all_firewalls(self, resource_group_name): + return self.network_client.azure_firewalls.list(resource_group_name) \ No newline at end of file diff --git a/src/plugin/main.py b/src/plugin/main.py index 67e59f98..b7589714 100644 --- a/src/plugin/main.py +++ b/src/plugin/main.py @@ -6,7 +6,7 @@ from spaceone.inventory.plugin.collector.lib.server import CollectorPluginServer from plugin.manager.base import AzureBaseManager -from plugin.manager.subscriptions.subscriptions_manager import SubscriptionsManager +from plugin.manager.subscriptions.subscription_manager import SubscriptionsManager app = CollectorPluginServer() @@ -18,22 +18,7 @@ @app.route('Collector.init') def collector_init(params: dict) -> dict: - metadata = { - "options_schema": { - "type": "object", - "properties": { - "cloud_service_groups": { - "title": "Specific services", - "type": "string", - "items": {"type": "string"}, - "default": "All", - "enum": ["All", "Disks"], - "description": "Choose one of the service to collect data. If you choose 'All', it will collect all services." - } - } - } - } - return {"metadata": metadata} + return _create_init_metadata() @app.route('Collector.verify') @@ -57,6 +42,7 @@ def collector_collect(params: dict) -> Generator[dict, None, None]: cloud_service_groups = _get_cloud_service_groups_from_options_and_task_options(options, task_options) resource_type = task_options.get("resource_type") + print("test", cloud_service_groups) if resource_type == "inventory.Region": subscriptions_mgr = SubscriptionsManager() @@ -100,6 +86,31 @@ def job_get_tasks(params: dict) -> dict: return {"tasks": tasks} +def _create_init_metadata() -> dict: + enum = ["All"] + for manager in AzureBaseManager.__subclasses__(): + if manager.cloud_service_group: + enum.append(manager.cloud_service_group) + + return { + "metadata": { + "options_schema": { + "type": "object", + "properties": { + "cloud_service_groups": { + "title": "Specific services", + "type": "string", + "items": {"type": "string"}, + "default": "All", + "enum": enum, + "description": "Choose one of the service to collect data. If you choose 'All', it will collect all services." + } + } + } + } + } + + def _get_cloud_service_groups_from_options_and_task_options(options: dict, task_options: dict) -> list: cloud_service_groups = options.get("cloud_service_groups", []) if task_options: diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 71b09f4a..e139cf89 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -1,3 +1,6 @@ from .disks import * -from .subscriptions import * - +from .public_ip_addresses import * +from .sql_databases import * +from .sql_servers import * +from .virtual_networks import * +from .application_gatways import * diff --git a/src/plugin/manager/application_gatways/__init__.py b/src/plugin/manager/application_gatways/__init__.py new file mode 100644 index 00000000..8ffe4b83 --- /dev/null +++ b/src/plugin/manager/application_gatways/__init__.py @@ -0,0 +1 @@ +from .instance_manager import InstanceManager diff --git a/src/plugin/manager/application_gatways/instance_manager.py b/src/plugin/manager/application_gatways/instance_manager.py new file mode 100644 index 00000000..dacfb456 --- /dev/null +++ b/src/plugin/manager/application_gatways/instance_manager.py @@ -0,0 +1,393 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.application_gateways.application_gateways_connector import ApplicationGatewaysConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class InstanceManager(AzureBaseManager): + cloud_service_group = "ApplicationGateways" + cloud_service_type = "Instance" + service_code = "/Microsoft.Network/applicationGateways" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Networking"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-application-gateways.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + application_gateways_conn = ApplicationGatewaysConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + application_gateways_list = application_gateways_conn.list_all_application_gateways() + + for application_gateway in application_gateways_list: + + try: + application_gateway_dict = self.convert_nested_dictionary(application_gateway) + application_gateway_id = application_gateway_dict["id"] + + # update application_gateway_dict + application_gateway_dict.update( + { + "resource_group": self.get_resource_group_from_id( + application_gateway_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": application_gateway_id}, + } + ) + + backend_address_pools = application_gateway_dict.get( + "backend_address_pools", [] + ) + url_path_maps = application_gateway_dict.get("url_path_maps", []) + request_routing_rules = application_gateway_dict.get( + "request_routing_rules", [] + ) + rewrite_rule_sets = application_gateway_dict.get( + "rewrite_rule_sets", [] + ) + frontend_ip_configurations = application_gateway_dict.get( + "frontend_ip_configurations", [] + ) + ip_configurations = application_gateway_dict.get( + "gateway_ip_configurations", [] + ) + + for frontend_ip_configuration_dict in frontend_ip_configurations: + if ( + frontend_ip_configuration_dict.get("private_ip_address") + is not None + ): + application_gateway_dict.update( + { + "private_ip_address": frontend_ip_configuration_dict[ + "private_ip_address" + ] + } + ) + frontend_ip_configuration_dict.update( + { + "ip_type": "Private", + "ip_address": frontend_ip_configuration_dict[ + "private_ip_address" + ], + } + ) + elif ( + frontend_ip_configuration_dict.get("public_ip_address") + is not None + ): + public_ip_address_name = frontend_ip_configuration_dict[ + "public_ip_address" + ]["id"].split("/")[8] + public_ip_address_dict = self.get_public_ip_address( + application_gateways_conn, + application_gateway_dict["resource_group"], + public_ip_address_name, + ) + application_gateway_dict.update( + {"public_ip_address": public_ip_address_dict} + ) + frontend_ip_configuration_dict.update( + { + "ip_type": "Public", + "ip_address": f'{public_ip_address_dict.get("ip_address", "-")} ({public_ip_address_dict.get("name", "")})', + "associated_listener": self.get_associated_listener( + frontend_ip_configuration_dict, + application_gateway_dict.get("http_listeners", []), + ), + } + ) + + for ip_configuration in ip_configurations: + application_gateway_dict.update( + { + "virtual_network": ip_configuration.get("subnet")[ + "id" + ].split("/")[8], + "subnet": ip_configuration.get("subnet")["id"].split("/")[ + 10 + ], + } + ) + + if ( + application_gateway_dict.get("backend_http_settings_collection") + is not None + ): + for backend_setting in application_gateway_dict[ + "backend_http_settings_collection" + ]: + if backend_setting.get("probe") is not None: + custom_probe = backend_setting["probe"]["id"].split("/")[10] + backend_setting.update({"custom_probe": custom_probe}) + + if application_gateway_dict.get("http_listeners") is not None: + custom_error_configurations_list = [] + + for http_listener in application_gateway_dict["http_listeners"]: + # Update Port information + if http_listener.get("frontend_port") is not None: + frontend_port_id = http_listener["frontend_port"]["id"] + http_listener["frontend_port"].update( + { + "port": self.get_port( + frontend_port_id, + application_gateway_dict.get( + "frontend_ports", [] + ), + ) + } + ) + http_listener.update( + { + "port": http_listener.get("frontend_port", {}).get( + "port", "" + ) + } + ) + + # Update custom error configuration + if http_listener.get("custom_error_configurations") is not None: + for custom_error_conf in http_listener[ + "custom_error_configurations" + ]: + custom_error_conf.update( + {"listener_name": http_listener["name"]} + ) + custom_error_configurations_list.append( + custom_error_conf + ) + + application_gateway_dict.update( + { + "custom_error_configurations": custom_error_configurations_list + } + ) + + for rewrite_rule in rewrite_rule_sets: + rewrite_rule_id = rewrite_rule.get("id") + rewrite_config_rule_displays = ( + self.list_rewrite_config_rule_display(rewrite_rule) + ) + rewrite_rule.update( + {"rewrite_rules_display": rewrite_config_rule_displays} + ) + + rules_applied_list = self.list_rewrite_rule_rules_applied( + rewrite_rule_id, request_routing_rules, url_path_maps + ) + rewrite_rule.update({"rules_applied": rules_applied_list}) + + # Update request routing rules + for request_routing_rule in request_routing_rules: + if request_routing_rule.get("http_listener") is not None: + request_routing_rule.update( + { + "http_listener_name": request_routing_rule[ + "http_listener" + ]["id"].split("/")[10] + } + ) + # Find http listener attached to this rule, and put rule's name to http_listeners dict + http_applied_rules_list = [] + http_listener_id = request_routing_rule["http_listener"]["id"] + + for request_routing_rule in application_gateway_dict.get( + "request_routing_rules", [] + ): + if http_listener_id in request_routing_rule.get( + "http_listener" + ).get("id", ""): + http_applied_rules_list.append( + request_routing_rule["name"] + ) + + self.update_http_listeners_list( + application_gateway_dict["http_listeners"], + http_listener_id, + http_applied_rules_list, + ) + + for backend_address_pool in backend_address_pools: + backend_address_pool_associated_rules = ( + self.get_backend_pool_associated_rules( + backend_address_pool, url_path_maps, request_routing_rules + ) + ) + backend_address_pool.update( + {"associated_rules": backend_address_pool_associated_rules} + ) + + backend_addresses = backend_address_pool.get( + "backend_addresses", [] + ) + backend_addresses_display = [ + backend_address.get("fqdn") + for backend_address in backend_addresses + ] + backend_address_pool.update( + {"backend_addresses_display": backend_addresses_display} + ) + + self.set_region_code(application_gateway_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=application_gateway_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=application_gateway_dict, + account=application_gateway_dict["subscription_id"], + instance_type=application_gateway_dict["sku"]["name"], + region_code=application_gateway_dict["location"], + reference=self.make_reference(application_gateway_dict.get("id")), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_public_ip_address( + self, application_gateway_conn, resource_group_name, pip_name + ): + public_ip_address_obj = application_gateway_conn.get_public_ip_addresses( + resource_group_name, pip_name + ) + public_ip_address_dict = self.convert_nested_dictionary(public_ip_address_obj) + + # _LOGGER.debug(f'[Public IP Address]{public_ip_address_dict}') + + return public_ip_address_dict + + @staticmethod + def get_associated_listener(frontend_ip_configuration_dict, http_listeners_list): + associated_listener = [] + for http_listener in http_listeners_list: + if http_listener.get("frontend_ip_configuration") is not None: + if frontend_ip_configuration_dict["id"] in http_listener.get( + "frontend_ip_configuration", {} + ).get("id", ""): + associated_listener.append(http_listener.get("name")) + return associated_listener + + @staticmethod + def get_port(port_id, frontend_ports_list): + port = 0 + for fe_port in frontend_ports_list: + if port_id == fe_port.get("id"): + port = fe_port.get("port") + break + return port + + @staticmethod + def get_backend_pool_associated_rules( + backend_address_pool, url_path_maps, request_routing_rules + ): + backend_address_pool_associated_rules = [] + backend_address_pool_id = backend_address_pool.get("id") + + for url_path_map in url_path_maps: + default_backend_address_pool = url_path_map.get( + "default_backend_address_pool" + ) + if ( + default_backend_address_pool is not None + and default_backend_address_pool.get("id") == backend_address_pool_id + ): + backend_address_pool_associated_rules.append(url_path_map.get("name")) + + for request_routing_rule in request_routing_rules: + request_backend_address_pool = request_routing_rule.get( + "backend_address_pool" + ) + if ( + request_backend_address_pool is not None + and request_backend_address_pool.get("id") == backend_address_pool_id + ): + backend_address_pool_associated_rules.append( + request_routing_rule.get("name") + ) + return backend_address_pool_associated_rules + + @staticmethod + def update_http_listeners_list( + http_listeners_list, http_listener_id, http_applied_rules + ): + for http_listener in http_listeners_list: + if http_listener["id"] == http_listener_id: + http_listener.update({"associated_rules": http_applied_rules}) + + @staticmethod + def list_rewrite_config_rule_display(rewrite_rule): + rewrite_config_rule_displays = [] + rewrite_rule_list = rewrite_rule.get("rewrite_rules", []) + for rule in rewrite_rule_list: + rewrite_config_rule_displays.append( + str(rule.get("name")) + ", " + str(rule.get("rule_sequence")) + ) + return rewrite_config_rule_displays + + @staticmethod + def list_rewrite_rule_rules_applied( + rewrite_rule_id, request_routing_rules, url_path_maps + ): + rules_applied_list = [] + for request_routing_rule in request_routing_rules: + if request_routing_rule.get("rewrite_rule_set") is not None: + if ( + request_routing_rule["rewrite_rule_set"].get("id") + == rewrite_rule_id + ): + rules_applied_list.append(request_routing_rule["name"]) + + for url_path_map in url_path_maps: + if url_path_map.get("default_rewrite_rule_set") is not None: + if ( + url_path_map["default_rewrite_rule_set"].get("id") + == rewrite_rule_id + ): + rules_applied_list.append(url_path_map["name"]) + + if url_path_map.get("path_rules") is not None: + for path_rule in url_path_map["path_rules"]: + if path_rule.get("rewrite_rule_set") is not None: + if path_rule["rewrite_rule_set"].get("id") == rewrite_rule_id: + rules_applied_list.append(url_path_map["name"]) + return rules_applied_list diff --git a/src/plugin/manager/base.py b/src/plugin/manager/base.py index 52eb496a..6306542a 100644 --- a/src/plugin/manager/base.py +++ b/src/plugin/manager/base.py @@ -4,7 +4,7 @@ import datetime import time import re -from typing import Union, List, Type +from typing import Union from spaceone.core.manager import BaseManager from spaceone.core import utils @@ -22,6 +22,8 @@ class AzureBaseManager(BaseManager): service = None cloud_service_group = None cloud_service_type = None + region_info = {} + collected_region_codes = [] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -39,14 +41,14 @@ def create_cloud_service(self, options, secret_data, schema): @classmethod def list_managers_by_cloud_service_groups(cls, cloud_service_groups: list): - if cloud_service_groups in ["All"]: - yield from cls.__subclasses__() + if cloud_service_groups in ["All"] or not cloud_service_groups: + for manager in cls.__subclasses__(): + if manager.cloud_service_group: + yield manager elif cloud_service_groups: for manager in cls.__subclasses__(): if manager.cloud_service_group and manager.cloud_service_group in cloud_service_groups: yield manager - else: - yield from cls.__subclasses__() @classmethod def get_managers_by_cloud_service_group(cls, cloud_service_group: str): @@ -217,6 +219,13 @@ def convert_nested_dictionary(self, cloud_svc_object: object) -> Union[object, d return cloud_svc_dict + def set_region_code(self, region): + if region not in self.region_info: + region = "global" + + if region not in self.collected_region_codes: + self.collected_region_codes.append(region) + @staticmethod def make_reference(resource_id: str, external_link_format: str = None) -> dict: if external_link_format: @@ -245,3 +254,17 @@ def update_tenant_id_from_secret_data( if tenant_id := secret_data.get("tenant_id"): cloud_service_data.update({"tenant_id": tenant_id}) return cloud_service_data + + @staticmethod + def convert_dictionary(obj): + return vars(obj) + + @staticmethod + def convert_tag_format(tags): + convert_tags = [] + + if tags: + for k, v in tags.items(): + convert_tags.append({"key": k, "value": v}) + + return convert_tags diff --git a/src/plugin/manager/disks/__init__.py b/src/plugin/manager/disks/__init__.py index 5d8aa1d7..3b627d7d 100644 --- a/src/plugin/manager/disks/__init__.py +++ b/src/plugin/manager/disks/__init__.py @@ -1 +1 @@ -from .disks_manager import DisksManager +from .disk_manager import DisksManager diff --git a/src/plugin/manager/disks/disks_manager.py b/src/plugin/manager/disks/disk_manager.py similarity index 97% rename from src/plugin/manager/disks/disks_manager.py rename to src/plugin/manager/disks/disk_manager.py index 6313336e..1ed2f620 100644 --- a/src/plugin/manager/disks/disks_manager.py +++ b/src/plugin/manager/disks/disk_manager.py @@ -1,6 +1,5 @@ import logging -from spaceone.core.utils import datetime_to_iso8601 from spaceone.inventory.plugin.collector.lib import * from plugin.conf.cloud_service_conf import ICON_URL @@ -66,8 +65,7 @@ def create_cloud_service(self, options, secret_data, schema): disk_dict["disk_iops_read_write"], disk_dict["disk_m_bps_read_write"], ), - "azure_monitor": {"resource_id": disk_id}, - "time_created": datetime_to_iso8601(disk_dict["time_created"]), + "azure_monitor": {"resource_id": disk_id} } ) @@ -103,6 +101,8 @@ def create_cloud_service(self, options, secret_data, schema): disk_dict, secret_data ) + self.set_region_code(disk_data["location"]) + cloud_services.append( make_cloud_service( name=disk_data["name"], @@ -128,7 +128,6 @@ def create_cloud_service(self, options, secret_data, schema): cloud_service_group=self.cloud_service_group, cloud_service_type=self.cloud_service_type, ) - ) return cloud_services, error_responses diff --git a/src/plugin/manager/public_ip_addresses/__init__.py b/src/plugin/manager/public_ip_addresses/__init__.py new file mode 100644 index 00000000..5da389f1 --- /dev/null +++ b/src/plugin/manager/public_ip_addresses/__init__.py @@ -0,0 +1 @@ +from .ip_address_manager import IPAddressManager diff --git a/src/plugin/manager/public_ip_addresses/ip_address_manager.py b/src/plugin/manager/public_ip_addresses/ip_address_manager.py new file mode 100644 index 00000000..889809d3 --- /dev/null +++ b/src/plugin/manager/public_ip_addresses/ip_address_manager.py @@ -0,0 +1,101 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.public_ip_addresses.public_ip_addresses_connector import PublicIPAddressesConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class IPAddressManager(AzureBaseManager): + cloud_service_group = "PublicIPAddresses" + cloud_service_type = "IPAddress" + service_code = "/Microsoft.Network/publicIPAddresses" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Networking"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-public-ip-address.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + public_ip_addresses_conn = PublicIPAddressesConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + public_ip_addresses_list = public_ip_addresses_conn.list_all_public_ip_addresses() + + for ip_address in public_ip_addresses_list: + + try: + ip_address_dict = self.convert_nested_dictionary(ip_address) + ip_address_id = ip_address_dict["id"] + + ip_address_dict.update( + { + "resource_group": self.get_resource_group_from_id( + ip_address_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": ip_address_id}, + } + ) + + if ip_address_dict.get("ip_configuration") is not None: + associated_to = ip_address_dict["ip_configuration"]["id"].split("/")[8] + + if associated_to: + ip_address_dict.update({"associated_to": associated_to}) + + ip_address_dict = self.update_tenant_id_from_secret_data( + ip_address_dict, secret_data + ) + + self.set_region_code(ip_address_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=ip_address_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=ip_address_dict, + account=secret_data["subscription_id"], + instance_type=ip_address_dict["sku"]["name"], + tags=ip_address_dict.get("tags", {}), + region_code=ip_address_dict["location"], + reference=self.make_reference(ip_address_dict.get("id")), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses diff --git a/src/plugin/manager/sql_databases/__init__.py b/src/plugin/manager/sql_databases/__init__.py new file mode 100644 index 00000000..fe06eff5 --- /dev/null +++ b/src/plugin/manager/sql_databases/__init__.py @@ -0,0 +1 @@ +from .database_manager import DatabaseManager diff --git a/src/plugin/manager/sql_databases/database_manager.py b/src/plugin/manager/sql_databases/database_manager.py new file mode 100644 index 00000000..7877aecf --- /dev/null +++ b/src/plugin/manager/sql_databases/database_manager.py @@ -0,0 +1,272 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.sql_databases.sql_databases_connector import SqlDatabasesConnector +from plugin.connector.monitor.monitor_connector import MonitorConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class DatabaseManager(AzureBaseManager): + cloud_service_group = "SQLDatabases" + cloud_service_type = "Database" + service_code = "/Microsoft.Sql/servers/databases" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Database"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-sql-databases.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + sql_databases_conn = SqlDatabasesConnector(secret_data=secret_data) + sql_monitor_conn = MonitorConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + # get resource_group_name and server_name from sql_server for sql_databases list + sql_servers = sql_databases_conn.list_servers() + for sql_server in sql_servers: + try: + sql_server_dict = self.convert_nested_dictionary(sql_server) + + server_name = sql_server_dict["name"] + resource_group_name = self.get_resource_group_from_id(sql_server_dict["id"]) + server_admin_name = sql_server_dict.get("administrator_login") + + # get list + sql_databases = sql_databases_conn.list_databases_in_server(resource_group_name, server_name) + replication_links = self.list_replication_links( + sql_databases_conn.list_replication_link_by_server(resource_group_name=resource_group_name, + server_name=server_name)) + + # database for loop + for sql_database in sql_databases: + sql_database_dict = self.convert_nested_dictionary(sql_database) + database_name = sql_database_dict["name"] + sql_database_id = sql_database_dict["id"] + current_sku_tier = sql_database_dict.get("current_sku").get("tier") + + if sql_database_dict.get('sku'): + if sql_database_dict.get('name') != 'master': # No pricing tier for system database + sql_database_dict.update({ + 'pricing_tier_display': self.get_pricing_tier_display(sql_database_dict['sku']), + 'service_tier_display': sql_database_dict['sku'].get('tier') + }) + + if db_id := sql_database_dict.get('id'): + sql_database_dict.update({ + 'server_name': db_id.split('/')[8], + 'subscription_id': db_id.split('/')[2], + 'resource_group': db_id.split('/')[4], + 'azure_monitor': {'resource_id': db_id} + }) + + if compute_tier := sql_database_dict.get('kind'): + sql_database_dict.update({ + 'compute_tier': self.get_db_compute_tier(compute_tier) + }) + + if sql_database_dict.get('max_size_bytes'): + sql_database_dict.update({ + 'max_size_gb': sql_database_dict['max_size_bytes'] / 1073741824 # 2^30 + }) + + # Get Sync Groups by databases + if current_sku_tier != 'DataWarehouse': + sql_database_sync_groups = sql_databases_conn.list_sync_groups_by_databases( + resource_group=resource_group_name, + server_name=server_name, + database_name=database_name) + + sql_database_dict.update({ + 'sync_group': self.get_sync_group_by_databases(sql_database_sync_groups) + }) + + if sql_database_dict.get('sync_group'): + sql_database_dict.update({ + 'sync_group_display': self.get_sync_group_display(sql_database_dict['sync_group']) + }) + + # Get Sync Agents by servers + sql_database_dict.update({ + 'sync_agent': self.get_sync_agent_by_servers(sql_databases_conn, resource_group_name, + server_name) + }) + + if sql_database_dict['sync_agent']: + sql_database_dict.update({ + 'sync_agent_display': self.get_sync_agent_display(sql_database_dict['sync_agent']) + }) + + # Get Diagnostic Settings + sql_database_dict.update({ + 'diagnostic_settings_resource': self.list_diagnostics_settings(sql_monitor_conn, + sql_database_dict['id']) + }) + # Get Database Replication Type + sql_database_dict.update({ + 'replication_link': self.list_replication_link_in_database(replication_links, + database_name=database_name) + }) + # Get azure_ad_admin name + if server_admin_name is not None: + sql_database_dict.update({ + 'administrator_login': server_admin_name + }) + + # Get Database Auditing settings + sql_database_dict.update({ + 'database_auditing_settings': self.get_database_auditing_settings(sql_databases_conn, + resource_group_name, + server_name, + database_name=database_name) + }) + + sql_database_dict.update({ + 'resource_group': resource_group_name, + 'subscription_id': subscription_info['subscription_id'], + 'subscription_name': subscription_info['display_name'], + 'azure_monitor': {'resource_id': sql_database_id} + }) + + self.set_region_code(sql_database_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=database_name, + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=sql_database_dict, + account=secret_data["subscription_id"], + instance_type=sql_database_dict["sku"]["tier"], + instance_size=float(sql_database_dict["max_size_gb"]), + region_code=sql_database_dict["location"], + reference=self.make_reference(sql_database_dict.get("id")), + # launched_at=datetime_to_iso8601(sql_database_dict["creation_date"]), + tags=sql_database_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def list_replication_links(self, replication_links_from_params) -> list: + replication_links = [] + for replication_link in replication_links_from_params: + replication_link_dict = self.convert_nested_dictionary(replication_link) + replication_link_dict['replica_state'] = 'Online' if replication_link_dict['role'] == 'Primary' \ + else 'Readable' + replication_links.append(replication_link_dict) + + return replication_links + + def get_sync_group_by_databases(self, replication_links_from_params: list) -> list: + sync_groups = [] + for sync_group in replication_links_from_params: + sync_group_dict = self.convert_nested_dictionary(sync_group) + sync_group_dict['automatic_sync'] = True if sync_group_dict['interval'] > 0 else True + sync_groups.append(sync_group_dict) + + return sync_groups + + def get_sync_agent_by_servers(self, sql_servers_conn, rg_name, server_name): + sync_agent_list = list() + sync_agent_obj = sql_servers_conn.list_sync_agents_by_server(rg_name, server_name) + + for sync_agent in sync_agent_obj: + sync_agent_dict = self.convert_nested_dictionary(sync_agent) + sync_agent_list.append(sync_agent_dict) + + return sync_agent_list + + def list_diagnostics_settings(self, sql_monitor_conn, resource_uri): + diagnostic_settings_list = list() + diagnostic_settings_objs = sql_monitor_conn.list_diagnostic_settings(resource_uri=resource_uri) + + for diagnostic_setting in diagnostic_settings_objs: + diagnostic_setting_dict = self.convert_nested_dictionary(diagnostic_setting) + diagnostic_settings_list.append(diagnostic_setting_dict) + + return diagnostic_settings_list + + def get_database_auditing_settings(self, sql_databases_conn, resource_group_name, server_name, database_name): + database_auditing_settings = sql_databases_conn.get_database_auditing_settings( + resource_group_name=resource_group_name, + server_name=server_name, + database_name=database_name) + return self.convert_nested_dictionary(database_auditing_settings) + + @staticmethod + def get_pricing_tier_display(sku_dict): + if sku_dict['name'] in ['Basic', 'Standard', 'Premium']: + pricing_tier = f'{sku_dict["tier"]}: {sku_dict["capacity"]} DTU' + else: + pricing_tier = f'{str(sku_dict["tier"])} : {str(sku_dict["family"])} , {str(sku_dict["capacity"])} vCores' + return pricing_tier + + @staticmethod + def get_db_compute_tier(kind): + if 'serverless' in kind: + compute_tier = 'Serverless' + else: + compute_tier = 'Provisioned' + + return compute_tier + + @staticmethod + def get_sync_group_display(sync_group_list): + sync_group_display_list = [] + for sync_group in sync_group_list: + sync_display = f"{sync_group['name']} / {sync_group['conflict_resolution_policy']} / {sync_group['sync_state']}" + sync_group_display_list.append(sync_display) + + return sync_group_display_list + + @staticmethod + def get_sync_agent_display(sync_agent_list): + sync_agent_display_list = [] + for sync_agent in sync_agent_list: + sync_display = f"{sync_agent['name']} / {sync_agent['state']}" + sync_agent_display_list.append(sync_display) + + return sync_agent_display_list + + @staticmethod + def list_replication_link_in_database(replication_links_from_params, database_name) -> list: + replication_links = [] + for replication_link in replication_links_from_params: + if replication_link['partner_database'] == database_name: + replication_links.append(replication_link) + + return replication_links diff --git a/src/plugin/manager/sql_servers/__init__.py b/src/plugin/manager/sql_servers/__init__.py new file mode 100644 index 00000000..77c0e89e --- /dev/null +++ b/src/plugin/manager/sql_servers/__init__.py @@ -0,0 +1 @@ +from .server_manager import ServerManager \ No newline at end of file diff --git a/src/plugin/manager/sql_servers/server_manager.py b/src/plugin/manager/sql_servers/server_manager.py new file mode 100644 index 00000000..d24c2db3 --- /dev/null +++ b/src/plugin/manager/sql_servers/server_manager.py @@ -0,0 +1,669 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.sql_servers.sql_servers_connector import SqlServersConnector +from plugin.connector.monitor.monitor_connector import MonitorConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class ServerManager(AzureBaseManager): + cloud_service_group = "SQLServers" + cloud_service_type = "Server" + service_code = "/Microsoft.Sql/servers" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Database"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-sql-servers.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + sql_servers_conn = SqlServersConnector(secret_data=secret_data) + monitor_conn = MonitorConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + sql_servers = sql_servers_conn.list_servers() + + for sql_server in sql_servers: + + try: + sql_server_dict = self.convert_nested_dictionary(sql_server) + sql_server_id = sql_server_dict["id"] + + # update sql_servers_data dict + sql_server_dict = self.update_tenant_id_from_secret_data( + sql_server_dict, secret_data + ) + + sql_server_dict.update( + { + "resource_group": self.get_resource_group_from_id( + sql_server_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": sql_server_id}, + } + ) + + resource_group_name = sql_server_dict["resource_group"] + name = sql_server_dict["name"] + + # Get Server Auditing Settings, Failover groups. azure ad administrators + server_auditing_settings_dict = self.get_server_auditing_settings( + sql_servers_conn, resource_group_name, name + ) + failover_group_list = self.list_failover_groups( + sql_servers_conn, resource_group_name, name + ) + transparent_data_encryption_dict = self.list_encryption_protectors( + sql_servers_conn, resource_group_name, name + ) + azure_ad_admin_list = self.list_azure_ad_administrators( + sql_servers_conn, resource_group_name, name + ) + server_automatic_tuning_dict = self.get_server_automatic_tuning( + sql_servers_conn, resource_group_name, name + ) + databases_list = self.list_databases( + sql_servers_conn=sql_servers_conn, + sql_monitor_conn=monitor_conn, + resource_group_name=resource_group_name, + server_name=name, + server_admin_name=sql_server_dict.get("administrator_login"), + ) + elastic_pools_list = self.list_elastic_pools( + sql_servers_conn, resource_group_name, name + ) + deleted_databases_list = self.list_deleted_databases( + sql_servers_conn, resource_group_name, name + ) + virtual_network_rules_list = self.list_virtual_network_rules( + sql_servers_conn, resource_group_name, name + ) + firewall_rules_list = self.list_firewall_rules( + sql_servers_conn, resource_group_name, name + ) + + sql_server_dict.update( + { + "azure_ad_administrators": azure_ad_admin_list, + "server_auditing_settings": server_auditing_settings_dict, + "failover_groups": failover_group_list, + "server_automatic_tuning": server_automatic_tuning_dict, + "databases": databases_list, + "elastic_pools": elastic_pools_list, + "deleted_databases": deleted_databases_list, + "virtual_network_rules": virtual_network_rules_list, + "firewall_rules": firewall_rules_list, + "encryption_protectors": transparent_data_encryption_dict, + } + ) + + if sql_server_dict.get("azure_ad_administrators") is not None: + sql_server_dict.update( + { + "azure_ad_admin_name": self.get_azure_ad_admin_name( + sql_server_dict["azure_ad_administrators"] + ) + } + ) + + if sql_server_dict.get("private_endpoint_connections") is not None: + sql_server_dict.update( + { + "private_endpoint_connections": self.get_private_endpoint_connections( + sql_server_dict["private_endpoint_connections"] + ) + } + ) + + self.set_region_code(sql_server_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=sql_server_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=sql_server_dict, + account=secret_data["subscription_id"], + region_code=sql_server_dict["location"], + reference=self.make_reference(sql_server_dict.get("id")), + tags=sql_server_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def list_elastic_pools(self, sql_servers_conn, rg_name, server_name): + elastic_pools_list = [] + elastic_pools = sql_servers_conn.list_elastic_pools_by_server( + resource_group=rg_name, server_name=server_name + ) + + for elastic_pool in elastic_pools: + elastic_pool_dict = self.convert_nested_dictionary(elastic_pool) + + # Get Databases list by elastic pool + elastic_pool_dict["databases"] = self.get_databases_by_elastic_pools( + sql_servers_conn, elastic_pool_dict["name"], rg_name, server_name + ) + + # Get pricing tier for display + if elastic_pool_dict.get("per_database_settings") is not None: + elastic_pool_dict.update( + { + "pricing_tier_display": self.get_pricing_tier_display( + elastic_pool_dict["sku"] + ), + "per_db_settings_display": self.get_per_db_settings( + elastic_pool_dict["per_database_settings"] + ), + "number_of_databases": len(elastic_pool_dict["databases"]), + "unit_display": elastic_pool_dict["sku"]["tier"], + "server_name_display": elastic_pool_dict["id"].split("/")[8], + "resource_group_display": elastic_pool_dict["id"].split("/")[4], + "max_size_gb": elastic_pool_dict["max_size_bytes"] / 1073741824, + } + ) + + elastic_pools_list.append(elastic_pool_dict) + + return elastic_pools_list + + def get_databases_by_elastic_pools( + self, sql_servers_conn, elastic_pool_name, rg_name, server_name + ): + databases_obj = sql_servers_conn.list_databases_by_elastic_pool( + elastic_pool_name, rg_name, server_name + ) + databases_list = [] + for database in databases_obj: + database_dict = self.convert_nested_dictionary(database) + databases_list.append(database_dict) + + return databases_list + + def list_deleted_databases(self, sql_servers_conn, rg_name, server_name): + deleted_databases_obj = ( + sql_servers_conn.list_restorable_dropped_databases_by_server( + resource_group=rg_name, server_name=server_name + ) + ) + deleted_databases_list = [] + for deleted_database in deleted_databases_obj: + deleted_database_dict = self.convert_nested_dictionary(deleted_database) + deleted_databases_list.append(deleted_database_dict) + + return deleted_databases_list + + def list_firewall_rules(self, sql_servers_conn, rg_name, server_name): + firewall_obj = sql_servers_conn.list_firewall_rules_by_server( + resource_group=rg_name, server_name=server_name + ) + firewall_list = [] + for firewall in firewall_obj: + firewall_rule_dict = self.convert_nested_dictionary(firewall) + firewall_list.append(firewall_rule_dict) + + return firewall_list + + def list_virtual_network_rules(self, sql_servers_conn, rg_name, server_name): + virtual_network_rule_obj = ( + sql_servers_conn.list_virtual_network_rules_by_server( + resource_group=rg_name, server_name=server_name + ) + ) + virtual_network_rules_list = [] + + for virtual_network_rule in virtual_network_rule_obj: + virtual_network_rule_dict = self.convert_nested_dictionary( + virtual_network_rule + ) + + if ( + virtual_network_rule_dict.get("id") is not None + ): # Get Virtual Network's name + virtual_network_rule_dict.update( + { + "virtual_network_name_display": virtual_network_rule_dict[ + "virtual_network_subnet_id" + ].split("/")[8], + "subscription_id": virtual_network_rule_dict["id"].split("/")[ + 2 + ], + "resource_group": virtual_network_rule_dict["id"].split("/")[4], + } + ) + virtual_network_rules_list.append(virtual_network_rule_dict) + + return virtual_network_rules_list + + def list_encryption_protectors(self, sql_servers_conn, rg_name, server_name): + encryption_protectors_list = [] + encryption_protectors_obj = sql_servers_conn.list_encryption_protectors( + resource_group=rg_name, server_name=server_name + ) + + for encryption_protector in encryption_protectors_obj: + encryption_protectors_dict = self.convert_nested_dictionary( + encryption_protector + ) + encryption_protectors_list.append(encryption_protectors_dict) + + return encryption_protectors_list + + def list_azure_ad_administrators(self, sql_servers_conn, rg_name, server_name): + ad_admin_list = [] # return list + ad_admin_obj = sql_servers_conn.list_server_azure_ad_administrators( + resource_group=rg_name, server_name=server_name + ) + + for ad_admin in ad_admin_obj: + ad_admin_list.append(self.convert_dictionary(ad_admin)) + + return ad_admin_list + + def get_server_automatic_tuning(self, sql_servers_conn, rg_name, server_name): + server_automatic_tuning_obj = sql_servers_conn.get_server_automatic_tuning( + rg_name, server_name + ) + server_automatic_tuning_dict = self.convert_nested_dictionary( + server_automatic_tuning_obj + ) + server_automatic_tuning_dict.update( + { + "options": self.get_server_automatic_tuning_options( + server_automatic_tuning_dict["options"] + ) + } + ) + + return server_automatic_tuning_dict + + def get_server_automatic_tuning_options(self, options_dict): + options_list = [] + created_index_dict = self.convert_nested_dictionary(options_dict["createIndex"]) + drop_index_dict = self.convert_nested_dictionary(options_dict["dropIndex"]) + force_plan_dict = self.convert_nested_dictionary( + options_dict["forceLastGoodPlan"] + ) + + created_index_dict.update({"tuning_type": "createIndex"}) + drop_index_dict.update({"tuning_type": "dropIndex"}) + force_plan_dict.update({"tuning_type": "forceLastGoodPlan"}) + + options_list.append(created_index_dict) + options_list.append(drop_index_dict) + options_list.append(force_plan_dict) + + return options_list + + def get_server_auditing_settings(self, sql_servers_conn, rg_name, server_name): + server_auditing_settings_obj = sql_servers_conn.get_server_auditing_settings( + rg_name, server_name + ) + server_auditing_settings_dict = self.convert_nested_dictionary( + server_auditing_settings_obj + ) + + return server_auditing_settings_dict + + def list_failover_groups(self, sql_servers_conn, rg_name, server_name): + failover_groups_list = [] + failover_groups_obj = sql_servers_conn.list_failover_groups( + rg_name, server_name + ) + for failover in failover_groups_obj: + failover_dict = self.convert_nested_dictionary(failover) + + if failover_dict.get("id") is not None: # Get Primary server's name + failover_dict.update( + {"primary_server": failover_dict["id"].split("/")[8]} + ) + + if ( + failover_dict.get("partner_servers") is not None + ): # Get Secondary Server's name + failover_dict.update( + { + "secondary_server": self.get_failover_secondary_server( + failover_dict["partner_servers"] + ) + } + ) + + if failover_dict.get("read_write_endpoint") is not None: + failover_dict.update( + { + "failover_policy_display": failover_dict[ + "read_write_endpoint" + ].get("failover_policy"), + "grace_period_display": failover_dict[ + "read_write_endpoint" + ].get("failover_with_data_loss_grace_period_minutes"), + } + ) + + failover_groups_list.append(failover_dict) + + return failover_groups_list + + def list_data_masking_rules( + self, sql_servers_conn, rg_name, server_name, database_name + ): + data_masking_rules_list = [] + data_masking_rule_obj = sql_servers_conn.list_data_masking_rules_by_database( + resource_group=rg_name, server_name=server_name, database_name=database_name + ) + + for data_masking_rule in data_masking_rule_obj: + data_masking_dict = self.convert_nested_dictionary(data_masking_rule) + data_masking_rules_list.append(data_masking_dict) + + return data_masking_rules_list + + def list_databases( + self, + sql_servers_conn, + sql_monitor_conn, + resource_group_name, + server_name, + server_admin_name, + ): + databases_list = [] + databases = sql_servers_conn.list_databases_by_server( + resource_group_name=resource_group_name, server_name=server_name + ) + + for database in databases: + database_dict = self.convert_nested_dictionary(database) + if database_dict.get("sku"): + if ( + database_dict.get("name") != "master" + ): # No pricing tier for system database + database_dict.update( + { + "pricing_tier_display": self.get_pricing_tier_display( + database_dict["sku"] + ), + "service_tier_display": database_dict["sku"].get("tier"), + } + ) + + if db_id := database_dict.get("id"): + database_dict.update( + { + "server_name": db_id.split("/")[8], + "subscription_id": db_id.split("/")[2], + "resource_group": db_id.split("/")[4], + "azure_monitor": {"resource_id": db_id}, + } + ) + + if compute_tier := database_dict.get("kind"): + database_dict.update( + {"compute_tier": self.get_db_compute_tier(compute_tier)} + ) + + if database_dict.get("max_size_bytes"): + database_dict.update( + { + "max_size_gb": database_dict["max_size_bytes"] + / 1073741824 # 2의 30승 + } + ) + + # Get Sync Groups by databases + if database_dict.get("service_tier_display") != "DataWarehouse": + database_dict.update( + { + "sync_group": self.get_sync_group_by_databases( + sql_servers_conn, + resource_group_name, + server_name, + database_dict["name"], + ), + } + ) + + if database_dict.get("sync_group"): + database_dict.update( + { + "sync_group_display": self.get_sync_group_display( + database_dict["sync_group"] + ) + } + ) + + # Get Sync Agents by servers + database_dict.update( + { + "sync_agent": self.get_sync_agent_by_servers( + sql_servers_conn, resource_group_name, server_name + ) + } + ) + + if database_dict.get("sync_agent"): + database_dict.update( + { + "sync_agent_display": self.get_sync_agent_display( + database_dict["sync_agent"] + ) + } + ) + """ + # Get Data masking rules + database_dict.update({ + 'data_masking_rules': self.list_data_masking_rules(self, sql_servers_conn, rg_name, server_name, database_dict['name']) + }) + """ + + # Get Diagnostic Settings + database_dict.update( + { + "diagnostic_settings_resource": self.list_diagnostics_settings( + sql_monitor_conn, database_dict["id"] + ) + } + ) + + # Get Database Replication Type + database_dict.update( + { + "replication_link": self.list_replication_link( + sql_servers_conn, + resource_group_name, + server_name, + database_dict["name"], + ) + } + ) + + # Get azure_ad_admin name + if server_admin_name is not None: + database_dict.update({"administrator_login": server_admin_name}) + + # switch tags form + tags = database_dict.get("tags", {}) + _tags = self.convert_tag_format(tags) + database_dict.update({"tags": _tags}) + + databases_list.append(database_dict) + + return databases_list + + def get_sync_agent_by_servers(self, sql_servers_conn, rg_name, server_name): + sync_agent_list = [] + sync_agent_obj = sql_servers_conn.list_sync_agents_by_server( + rg_name, server_name + ) + + for sync_agent in sync_agent_obj: + sync_agent_dict = self.convert_nested_dictionary(sync_agent) + sync_agent_list.append(sync_agent_dict) + + return sync_agent_list + + def list_diagnostics_settings(self, sql_monitor_conn, resource_uri): + diagnostic_settings_list = [] + diagnostic_settings_objs = sql_monitor_conn.list_diagnostic_settings( + resource_uri=resource_uri + ) + + for diagnostic_setting in diagnostic_settings_objs: + diagnostic_setting_dict = self.convert_nested_dictionary(diagnostic_setting) + diagnostic_settings_list.append(diagnostic_setting_dict) + + return diagnostic_settings_list + + def list_replication_link( + self, sql_servers_conn, rg_name, server_name, database_name + ): + replication_link_list = [] + replication_link_obj = sql_servers_conn.list_replication_link( + rg_name, server_name, database_name + ) + + for replication_link in replication_link_obj: + replication_link_dict = self.convert_nested_dictionary(replication_link) + replication_link_list.append(replication_link_dict) + + return replication_link_list + + def get_sync_group_by_databases( + self, sql_servers_conn, resource_group_name, server_name, database_name + ): + sync_group_obj = sql_servers_conn.list_sync_groups_by_databases( + resource_group=resource_group_name, + server_name=server_name, + database_name=database_name, + ) + sync_group_list = [] + for sync_group in sync_group_obj: + sync_group_dict = self.convert_nested_dictionary(sync_group) + sync_group_list.append(sync_group_dict) + return sync_group_list + + @staticmethod + def get_private_endpoint_connections(private_endpoint_connection_list): + for pec in private_endpoint_connection_list: + if pec.get("id") is not None: + pec.update({"connection_id": pec["id"].split("/")[10]}) + + if pec.get("properties") is not None: + pec.update( + { + "private_endpoint_name": pec["properties"] + .get("private_endpoint") + .get("id") + .split("/")[8], + "description": pec["properties"] + .get("private_link_service_connection_state") + .get("description"), + "status": pec["properties"] + .get("private_link_service_connection_state") + .get("status"), + } + ) + + return private_endpoint_connection_list + + @staticmethod + def get_per_db_settings(per_database_settings_dict): + per_db_settings = ( + f"{str(per_database_settings_dict['min_capacity'])} - " + f"{str(per_database_settings_dict['max_capacity'])} vCores" + ) + return per_db_settings + + @staticmethod + def get_failover_secondary_server(partner_servers): + secondary_server = None + + for partner_server in partner_servers: + if partner_server["replication_role"] == "Secondary": + secondary_server = partner_server["id"].split("/")[8] + + return secondary_server + + @staticmethod + def get_azure_ad_admin_name(azure_ad_administrators_list): + az_admin_name = "" + + for az_admin in azure_ad_administrators_list: + if az_admin.get("login") is not None: + az_admin_name = az_admin.get("login") + + return az_admin_name + + @staticmethod + def get_db_compute_tier(kind): + if "serverless" in kind: + compute_tier = "Serverless" + else: + compute_tier = "Provisioned" + + return compute_tier + + @staticmethod + def get_sync_agent_display(sync_agent_list): + sync_agent_display_list = [] + for sync_agent in sync_agent_list: + sync_display = f"{sync_agent['name']} / {sync_agent['state']}" + sync_agent_display_list.append(sync_display) + + return sync_agent_display_list + + @staticmethod + def get_pricing_tier_display(sku_dict): + pricing_tier = None + if sku_dict.get("capacity") is not None: + pricing_tier = f'{str(sku_dict["tier"])} : {str(sku_dict["family"])} , {str(sku_dict["capacity"])} vCores' + + return pricing_tier + + @staticmethod + def get_sync_group_display(sync_group_list): + sync_group_display_list = [] + for sync_group in sync_group_list: + sync_display = f"{sync_group['name']} / {sync_group['conflict_resolution_policy']} / {sync_group['sync_state']}" + sync_group_display_list.append(sync_display) + + return sync_group_display_list + + diff --git a/src/plugin/manager/subscriptions/__init__.py b/src/plugin/manager/subscriptions/__init__.py index cb525928..e69de29b 100644 --- a/src/plugin/manager/subscriptions/__init__.py +++ b/src/plugin/manager/subscriptions/__init__.py @@ -1 +0,0 @@ -from .subscriptions_manager import SubscriptionsManager diff --git a/src/plugin/manager/subscriptions/subscriptions_manager.py b/src/plugin/manager/subscriptions/subscription_manager.py similarity index 97% rename from src/plugin/manager/subscriptions/subscriptions_manager.py rename to src/plugin/manager/subscriptions/subscription_manager.py index a0919d00..49571a93 100644 --- a/src/plugin/manager/subscriptions/subscriptions_manager.py +++ b/src/plugin/manager/subscriptions/subscription_manager.py @@ -8,7 +8,7 @@ class SubscriptionsManager(AzureBaseManager): - cloud_service_group = "Subscriptions" + # cloud_service_group = "Subscriptions" # cloud_service_type = "Subscription" service_code = "/Microsoft.subscriptions" diff --git a/src/plugin/manager/virtual_networks/__init__.py b/src/plugin/manager/virtual_networks/__init__.py new file mode 100644 index 00000000..8ffe4b83 --- /dev/null +++ b/src/plugin/manager/virtual_networks/__init__.py @@ -0,0 +1 @@ +from .instance_manager import InstanceManager diff --git a/src/plugin/manager/virtual_networks/instance_manager.py b/src/plugin/manager/virtual_networks/instance_manager.py new file mode 100644 index 00000000..ebb3ee2e --- /dev/null +++ b/src/plugin/manager/virtual_networks/instance_manager.py @@ -0,0 +1,217 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.virtual_networks.virtual_networks_connector import VirtualNetworksConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class InstanceManager(AzureBaseManager): + cloud_service_group = "VirtualNetworks" + cloud_service_type = "Instance" + service_code = "/Microsoft.Network/virtualNetworks" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Networking"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-virtual-networks.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + virtual_networks_conn = VirtualNetworksConnector() + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + virtual_networks = virtual_networks_conn.list_all_virtual_networks() + + for virtual_network in virtual_networks: + + try: + virtual_network_dict = self.convert_nested_dictionary(virtual_network) + virtual_network_id = virtual_network_dict["id"] + + # update vnet_dict + virtual_network_dict = self.update_tenant_id_from_secret_data( + virtual_network_dict, secret_data + ) + virtual_network_dict.update( + { + "resource_group": self.get_resource_group_from_id( + virtual_network_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": virtual_network_id}, + } + ) + + if virtual_network_dict.get("subnets") is not None: + subnets = virtual_network_dict["subnets"] + resource_group = virtual_network_dict["resource_group"] + + # Change attached network interfaces objects to id + self.change_subnet_object_to_ids_list(subnets) + + virtual_network_dict.update( + { + "subnets": self.update_subnet_info(subnets), + "service_endpoints": self.get_service_endpoints(subnets), + "private_endpoints": self.get_private_endpoints(subnets), + "azure_firewall": self.get_azure_firewall( + virtual_networks_conn, subnets, resource_group + ), + "connected_devices": self.get_connected_devices(subnets), + } + ) + + # If not 'custom dns servers', add default azure dns server dict to vnet + if virtual_network_dict.get("dhcp_options") is None: + dhcp_option_dict = {"dns_servers": ["Azure provided DNS service"]} + virtual_network_dict.update({"dhcp_options": dhcp_option_dict}) + + self.set_region_code(virtual_network_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=virtual_network_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=virtual_network_dict, + account=virtual_network_dict["subscription_id"], + region_code=virtual_network_dict["location"], + reference=self.make_reference(virtual_network_dict.get("id")), + tags=virtual_network_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + return cloud_services, error_responses + + def get_azure_firewall(self, vnet_conn, subnet_list, resource_group_name): + # Get Azure firewall information + azure_firewall_list = [] + for subnet in subnet_list: + if subnet.get("connected_devices_list"): + for device in subnet["connected_devices_list"]: + if ( + device["type"] == "azureFirewalls" + ): # The subnet which has 'AzureFirewall' is typed as 'azureFirewalls' + firewall_obj = vnet_conn.list_all_firewalls( + resource_group_name + ) # List all firewalls in the resource group + for firewall in firewall_obj: + firewall_dict = self.convert_nested_dictionary(firewall) + for ip_configuration in firewall_dict["ip_configurations"]: + if ip_configuration.get("subnet") is not None: + if ( + subnet["id"] in ip_configuration["subnet"]["id"] + ): # If subnet id matches the firewall's subnet id + firewall_dict["subnet"] = subnet["id"].split( + "/" + )[10] + azure_firewall_list.append(firewall_dict) + + return azure_firewall_list + + @staticmethod + def change_subnet_object_to_ids_list(subnets_dict): + subnet_id_list = [] + for subnet in subnets_dict: + subnet_id_list.append(subnet["id"]) + if subnet.get("private_endpoints") is not None: + for private_endpoint in subnet["private_endpoints"]: + if private_endpoint.get("network_interfaces") is not None: + for ni in private_endpoint["network_interfaces"]: + if ni.get("network_security_group") is not None: + ni["network_interfaces"] = ni["id"] + ni["subnets"] = subnet_id_list + + return subnet_id_list + + @staticmethod + def update_subnet_info(subnet_list): + for subnet in subnet_list: + # Get network security group's name + if subnet.get("network_security_group") is not None: + subnet["network_security_group"]["name"] = subnet[ + "network_security_group" + ]["id"].split("/")[8] + + # Get private endpoints + if subnet.get("private_endpoints") is not None: + for private_endpoint in subnet["private_endpoints"]: + private_endpoint.update( + { + "name": private_endpoint["id"].split("/")[8], + "subnet": subnet["name"], + "resource_group": private_endpoint["id"].split("/")[4], + } + ) + + return subnet_list + + @staticmethod + def get_service_endpoints(subnet_list): + service_endpoint_list = [] + for subnet in subnet_list: + # Put subnet name to service endpoints dictionary + if subnet.get("service_endpoints") is not None: + for service_endpoint in subnet["service_endpoints"]: + service_endpoint["subnet"] = subnet["name"] + service_endpoint_list.append(service_endpoint) + + return service_endpoint_list + + @staticmethod + def get_private_endpoints(subnet_list): + private_endpoint_list = [] + for subnet in subnet_list: + if subnet.get("private_endpoints") is not None: + for private_endpoint in subnet["private_endpoints"]: + private_endpoint_list.append(private_endpoint) + + return private_endpoint_list + + @staticmethod + def get_connected_devices(subnet_list): + connected_devices_list = [] + for subnet in subnet_list: + device_dict = {} + + if subnet.get("ip_configurations") is not None: + for ip_configuration in subnet["ip_configurations"]: + device_dict["name"] = subnet["name"] + device_dict["type"] = ip_configuration["id"].split("/")[7] + device_dict["device"] = ip_configuration["id"].split("/")[8] + connected_devices_list.append(device_dict) + + return connected_devices_list diff --git a/src/plugin/metadata/application_gateways/instance.yaml b/src/plugin/metadata/application_gateways/instance.yaml new file mode 100644 index 00000000..6afcc410 --- /dev/null +++ b/src/plugin/metadata/application_gateways/instance.yaml @@ -0,0 +1,157 @@ +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + type: list + options: + delimiter: ', ' + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metadata/disks/disk.yaml b/src/plugin/metadata/disks/disk.yaml index 852ae406..6afcc410 100644 --- a/src/plugin/metadata/disks/disk.yaml +++ b/src/plugin/metadata/disks/disk.yaml @@ -1,4 +1,3 @@ ---- search: fields: - Tier: data.tier diff --git a/src/plugin/metadata/public_ip_addresses/ip_address.yaml b/src/plugin/metadata/public_ip_addresses/ip_address.yaml new file mode 100644 index 00000000..6afcc410 --- /dev/null +++ b/src/plugin/metadata/public_ip_addresses/ip_address.yaml @@ -0,0 +1,157 @@ +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + type: list + options: + delimiter: ', ' + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metadata/sql_databases/database.yaml b/src/plugin/metadata/sql_databases/database.yaml new file mode 100644 index 00000000..6afcc410 --- /dev/null +++ b/src/plugin/metadata/sql_databases/database.yaml @@ -0,0 +1,157 @@ +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + type: list + options: + delimiter: ', ' + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metadata/sql_servers/server.yaml b/src/plugin/metadata/sql_servers/server.yaml new file mode 100644 index 00000000..6afcc410 --- /dev/null +++ b/src/plugin/metadata/sql_servers/server.yaml @@ -0,0 +1,157 @@ +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + type: list + options: + delimiter: ', ' + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metadata/virtual_networks/instance.yaml b/src/plugin/metadata/virtual_networks/instance.yaml new file mode 100644 index 00000000..6afcc410 --- /dev/null +++ b/src/plugin/metadata/virtual_networks/instance.yaml @@ -0,0 +1,157 @@ +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + type: list + options: + delimiter: ', ' + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metrics/ApplicationGateways/Instance/instance_count.yaml b/src/plugin/metrics/ApplicationGateways/Instance/instance_count.yaml new file mode 100644 index 00000000..3bd083ba --- /dev/null +++ b/src/plugin/metrics/ApplicationGateways/Instance/instance_count.yaml @@ -0,0 +1,32 @@ +--- +metric_id: metric-azure-ags-instance-count +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.ApplicationGateways.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + default: true + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group.resource_group_name + name: Resource Group + - key: data.operational_state + name: Operational State + default: true + - key: data.subnet + name: Subnet + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-ags-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/ApplicationGateways/Instance/namespace.yaml b/src/plugin/metrics/ApplicationGateways/Instance/namespace.yaml new file mode 100644 index 00000000..3659a5f1 --- /dev/null +++ b/src/plugin/metrics/ApplicationGateways/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-ags-instance +name: ApplicationGateways/Instance +category: ASSET +resource_type: inventory.CloudService:azure.ApplicationGateways.Instance +group: azure +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-application-gateways.svg +version: '1.0' diff --git a/src/plugin/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml b/src/plugin/metrics/PublicIPAddresses/IPAddress/ip_addresses_count.yaml similarity index 100% rename from src/plugin/metrics/PublicIPAddresses/IpAddress/ip_addresses_count.yaml rename to src/plugin/metrics/PublicIPAddresses/IPAddress/ip_addresses_count.yaml diff --git a/src/plugin/metrics/PublicIPAddresses/IpAddress/namespace.yaml b/src/plugin/metrics/PublicIPAddresses/IPAddress/namespace.yaml similarity index 100% rename from src/plugin/metrics/PublicIPAddresses/IpAddress/namespace.yaml rename to src/plugin/metrics/PublicIPAddresses/IPAddress/namespace.yaml diff --git a/src/plugin/metrics/SQLDatabases/Database/database_count.yaml b/src/plugin/metrics/SQLDatabases/Database/database_count.yaml new file mode 100644 index 00000000..be4494d8 --- /dev/null +++ b/src/plugin/metrics/SQLDatabases/Database/database_count.yaml @@ -0,0 +1,42 @@ +--- +metric_id: metric-azure-sql-databases-database-count +name: Database Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.SQLDatabases.Database +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku Name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.status + name: Status + default: true + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.server_name + name: Server Name + - key: data.compute_tier + name: Compute Tier + - key: data.default_secondary_location + name: Default Secondary Location + - key: data.read_scale + name: Read Scale + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-sql-databases-database +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/SQLDatabases/Database/database_size.yaml b/src/plugin/metrics/SQLDatabases/Database/database_size.yaml new file mode 100644 index 00000000..7a9ef8dd --- /dev/null +++ b/src/plugin/metrics/SQLDatabases/Database/database_size.yaml @@ -0,0 +1,43 @@ +--- +metric_id: metric-azure-sql-databases-database-size +name: Database Size +metric_type: GAUGE +resource_type: inventory.CloudService:azure.SQLDatabases.Database +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku Name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.status + name: Status + default: true + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.server_name + name: Server Name + - key: data.compute_tier + name: Compute Tier + - key: data.default_secondary_location + name: Default Secondary Location + - key: data.read_scale + name: Read Scale + fields: + value: + key: data.max_size_gb + operator: sum +unit: GB +namespace_id: ns-azure-sql-databases-database +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/SQLDatabases/Database/namespace.yaml b/src/plugin/metrics/SQLDatabases/Database/namespace.yaml new file mode 100644 index 00000000..278f21e6 --- /dev/null +++ b/src/plugin/metrics/SQLDatabases/Database/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-sql-databases-database +name: SQLDatabases/Database +resource_type: inventory.CloudService:azure.SQLDatabases.Database +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-sql-databases.svg +version: '1.0' diff --git a/src/plugin/metrics/SQLServers/Server/namespace.yaml b/src/plugin/metrics/SQLServers/Server/namespace.yaml new file mode 100644 index 00000000..f19ed717 --- /dev/null +++ b/src/plugin/metrics/SQLServers/Server/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-sql-servers-server +name: SQLServers/Server +resource_type: inventory.CloudService:azure.SQLServers.Server +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-sql-servers.svg +version: '1.0' diff --git a/src/plugin/metrics/SQLServers/Server/server_count.yaml b/src/plugin/metrics/SQLServers/Server/server_count.yaml new file mode 100644 index 00000000..69a632fd --- /dev/null +++ b/src/plugin/metrics/SQLServers/Server/server_count.yaml @@ -0,0 +1,36 @@ +--- +metric_id: metric-azure-sql-servers-server-count +name: Server Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.SQLServers.Server +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.state + name: Server State + default: true + - key: data.version + name: Version + - key: data.minimal_tls_version + name: Minimal TLS Version + - key: data.administrators.principal_type + name: Administrator Principal Type + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-sql-servers-server +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/VirtualNetworks/instance/instance_count.yaml b/src/plugin/metrics/VirtualNetworks/instance/instance_count.yaml new file mode 100644 index 00000000..bcc9923e --- /dev/null +++ b/src/plugin/metrics/VirtualNetworks/instance/instance_count.yaml @@ -0,0 +1,32 @@ +--- +metric_id: metric-azure-vnets-instance-count +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.VirtualNetworks.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-vnets-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/VirtualNetworks/instance/namespace.yaml b/src/plugin/metrics/VirtualNetworks/instance/namespace.yaml new file mode 100644 index 00000000..181f1e29 --- /dev/null +++ b/src/plugin/metrics/VirtualNetworks/instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-vnets-instance +name: VirtualNetworks/Instance +resource_type: inventory.CloudService:azure.VirtualNetworks.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-virtual-networks.svg +version: '1.0' \ No newline at end of file diff --git a/src/setup.py b/src/setup.py new file mode 100644 index 00000000..a2789788 --- /dev/null +++ b/src/setup.py @@ -0,0 +1,45 @@ +# +# Copyright 2020 The SpaceONE Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from setuptools import setup, find_packages + +with open("VERSION", "r") as f: + VERSION = f.read().strip() + f.close() + +setup( + name="plugin-azure-inven-v2-collector-migration-test", + version=VERSION, + description="MS Azure cloud service inventory v2 collector", + long_description="", + url="https://cloudforet.io/", + author="Cloudforet Admin", + author_email="admin@cloudforet.io", + license="Apache License 2.0", + packages=find_packages(), + install_requires=[ + "spaceone-api", + "azure-identity", + "azure-mgmt-resource", + ], + package_data={ + "plugin": [ + "metadata/*/*.yaml", + "metrics/**/**/*.yaml", + ] + }, + zip_safe=False, +) From 4ab260e0ab8a68a6931c3abac2ebaeed48a8ddda Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 24 Jul 2024 10:43:08 +0900 Subject: [PATCH 06/35] refactor: Rename class in manager --- src/plugin/connector/nat_gateways/__init__.py | 0 src/plugin/manager/nat_gateways/__init__.py | 0 .../manager/public_ip_addresses/__init__.py | 2 +- .../public_ip_addresses/ip_address_manager.py | 2 +- src/plugin/manager/sql_databases/__init__.py | 2 +- .../manager/sql_databases/database_manager.py | 2 +- src/plugin/manager/sql_servers/__init__.py | 2 +- .../manager/sql_servers/server_manager.py | 2 +- .../manager/virtual_networks/__init__.py | 2 +- .../virtual_networks/instance_manager.py | 2 +- .../metadata/nat_gateways/instance.yaml | 157 ++++++++++++++++++ .../NATGateways/Instance/instance_count.yaml | 39 +++++ .../NATGateways/Instance/namespace.yaml | 8 + 13 files changed, 212 insertions(+), 8 deletions(-) create mode 100644 src/plugin/connector/nat_gateways/__init__.py create mode 100644 src/plugin/manager/nat_gateways/__init__.py create mode 100644 src/plugin/metadata/nat_gateways/instance.yaml create mode 100644 src/plugin/metrics/NATGateways/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/NATGateways/Instance/namespace.yaml diff --git a/src/plugin/connector/nat_gateways/__init__.py b/src/plugin/connector/nat_gateways/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/manager/nat_gateways/__init__.py b/src/plugin/manager/nat_gateways/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/manager/public_ip_addresses/__init__.py b/src/plugin/manager/public_ip_addresses/__init__.py index 5da389f1..bbe21011 100644 --- a/src/plugin/manager/public_ip_addresses/__init__.py +++ b/src/plugin/manager/public_ip_addresses/__init__.py @@ -1 +1 @@ -from .ip_address_manager import IPAddressManager +from .ip_address_manager import PublicIPAddressesManager diff --git a/src/plugin/manager/public_ip_addresses/ip_address_manager.py b/src/plugin/manager/public_ip_addresses/ip_address_manager.py index 889809d3..ac3d2659 100644 --- a/src/plugin/manager/public_ip_addresses/ip_address_manager.py +++ b/src/plugin/manager/public_ip_addresses/ip_address_manager.py @@ -10,7 +10,7 @@ _LOGGER = logging.getLogger(__name__) -class IPAddressManager(AzureBaseManager): +class PublicIPAddressesManager(AzureBaseManager): cloud_service_group = "PublicIPAddresses" cloud_service_type = "IPAddress" service_code = "/Microsoft.Network/publicIPAddresses" diff --git a/src/plugin/manager/sql_databases/__init__.py b/src/plugin/manager/sql_databases/__init__.py index fe06eff5..f16b5621 100644 --- a/src/plugin/manager/sql_databases/__init__.py +++ b/src/plugin/manager/sql_databases/__init__.py @@ -1 +1 @@ -from .database_manager import DatabaseManager +from .database_manager import SQLDatabasesManager diff --git a/src/plugin/manager/sql_databases/database_manager.py b/src/plugin/manager/sql_databases/database_manager.py index 7877aecf..19a6fd91 100644 --- a/src/plugin/manager/sql_databases/database_manager.py +++ b/src/plugin/manager/sql_databases/database_manager.py @@ -11,7 +11,7 @@ _LOGGER = logging.getLogger(__name__) -class DatabaseManager(AzureBaseManager): +class SQLDatabasesManager(AzureBaseManager): cloud_service_group = "SQLDatabases" cloud_service_type = "Database" service_code = "/Microsoft.Sql/servers/databases" diff --git a/src/plugin/manager/sql_servers/__init__.py b/src/plugin/manager/sql_servers/__init__.py index 77c0e89e..19ba993c 100644 --- a/src/plugin/manager/sql_servers/__init__.py +++ b/src/plugin/manager/sql_servers/__init__.py @@ -1 +1 @@ -from .server_manager import ServerManager \ No newline at end of file +from .server_manager import SQLServersManager diff --git a/src/plugin/manager/sql_servers/server_manager.py b/src/plugin/manager/sql_servers/server_manager.py index d24c2db3..b6bc8127 100644 --- a/src/plugin/manager/sql_servers/server_manager.py +++ b/src/plugin/manager/sql_servers/server_manager.py @@ -11,7 +11,7 @@ _LOGGER = logging.getLogger(__name__) -class ServerManager(AzureBaseManager): +class SQLServersManager(AzureBaseManager): cloud_service_group = "SQLServers" cloud_service_type = "Server" service_code = "/Microsoft.Sql/servers" diff --git a/src/plugin/manager/virtual_networks/__init__.py b/src/plugin/manager/virtual_networks/__init__.py index 8ffe4b83..ec0863d8 100644 --- a/src/plugin/manager/virtual_networks/__init__.py +++ b/src/plugin/manager/virtual_networks/__init__.py @@ -1 +1 @@ -from .instance_manager import InstanceManager +from .instance_manager import VirtualNetworksManager diff --git a/src/plugin/manager/virtual_networks/instance_manager.py b/src/plugin/manager/virtual_networks/instance_manager.py index ebb3ee2e..c8ef27ac 100644 --- a/src/plugin/manager/virtual_networks/instance_manager.py +++ b/src/plugin/manager/virtual_networks/instance_manager.py @@ -10,7 +10,7 @@ _LOGGER = logging.getLogger(__name__) -class InstanceManager(AzureBaseManager): +class VirtualNetworksManager(AzureBaseManager): cloud_service_group = "VirtualNetworks" cloud_service_type = "Instance" service_code = "/Microsoft.Network/virtualNetworks" diff --git a/src/plugin/metadata/nat_gateways/instance.yaml b/src/plugin/metadata/nat_gateways/instance.yaml new file mode 100644 index 00000000..6afcc410 --- /dev/null +++ b/src/plugin/metadata/nat_gateways/instance.yaml @@ -0,0 +1,157 @@ +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + type: list + options: + delimiter: ', ' + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metrics/NATGateways/Instance/instance_count.yaml b/src/plugin/metrics/NATGateways/Instance/instance_count.yaml new file mode 100644 index 00000000..5f3d533a --- /dev/null +++ b/src/plugin/metrics/NATGateways/Instance/instance_count.yaml @@ -0,0 +1,39 @@ +--- +metric_id: metric-azure-nat-gateways-instance +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.NATGateways.Instance +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.zones + name: Zone + - key: data.sku.name + name: SKU Name + - key: data.sku.tier + name: SKU Tier + - key: data.tenant_id + name: Tenant ID + default: true + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-nat-gateways-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/NATGateways/Instance/namespace.yaml b/src/plugin/metrics/NATGateways/Instance/namespace.yaml new file mode 100644 index 00000000..dc841110 --- /dev/null +++ b/src/plugin/metrics/NATGateways/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-nat-gateways-instance +name: NATGateways/Instance +resource_type: inventory.CloudService:azure.NATGateways.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-nat.svg +version: '1.0' From 93e879bbdf568cc2f81f632053dc1dd68d23c4b9 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 24 Jul 2024 11:35:19 +0900 Subject: [PATCH 07/35] feat: NatGateways Collector migration --- .../nat_gateways/nat_gateways_connector.py | 23 +++ src/plugin/manager/__init__.py | 1 + src/plugin/manager/nat_gateways/__init__.py | 1 + .../manager/nat_gateways/instance_manager.py | 176 ++++++++++++++++++ .../virtual_networks/instance_manager.py | 2 +- 5 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 src/plugin/connector/nat_gateways/nat_gateways_connector.py create mode 100644 src/plugin/manager/nat_gateways/instance_manager.py diff --git a/src/plugin/connector/nat_gateways/nat_gateways_connector.py b/src/plugin/connector/nat_gateways/nat_gateways_connector.py new file mode 100644 index 00000000..9f303c14 --- /dev/null +++ b/src/plugin/connector/nat_gateways/nat_gateways_connector.py @@ -0,0 +1,23 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class NATGatewaysConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_all_nat_gateways(self): + return self.network_client.nat_gateways.list_all() + + def get_public_ip_addresses(self, resource_group_name, public_ip_address_name): + return self.network_client.public_ip_addresses.get(resource_group_name, public_ip_address_name) + + def get_public_ip_prefixes(self, resource_group_name, public_ip_prefixes_name): + return self.network_client.public_ip_prefixes.get(resource_group_name, public_ip_prefixes_name) + + def get_subnet(self, resource_group_name, subnet_name, vnet_name): + return self.network_client.subnets.get(resource_group_name=resource_group_name, virtual_network_name=vnet_name, subnet_name=subnet_name) \ No newline at end of file diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index e139cf89..d9cc54aa 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -4,3 +4,4 @@ from .sql_servers import * from .virtual_networks import * from .application_gatways import * +from .nat_gateways import * diff --git a/src/plugin/manager/nat_gateways/__init__.py b/src/plugin/manager/nat_gateways/__init__.py index e69de29b..6af62b84 100644 --- a/src/plugin/manager/nat_gateways/__init__.py +++ b/src/plugin/manager/nat_gateways/__init__.py @@ -0,0 +1 @@ +from .instance_manager import NATGatewaysManager diff --git a/src/plugin/manager/nat_gateways/instance_manager.py b/src/plugin/manager/nat_gateways/instance_manager.py new file mode 100644 index 00000000..93c2f013 --- /dev/null +++ b/src/plugin/manager/nat_gateways/instance_manager.py @@ -0,0 +1,176 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.nat_gateways.nat_gateways_connector import NATGatewaysConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class NATGatewaysManager(AzureBaseManager): + cloud_service_group = "NATGateways" + cloud_service_type = "Instance" + service_code = "/Microsoft.Network/natGateways" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Networking"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-nat.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + nat_gateways_conn = NATGatewaysConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + nat_gateways = nat_gateways_conn.list_all_nat_gateways() + + for nat_gateway in nat_gateways: + try: + nat_gateway_dict = self.convert_nested_dictionary(nat_gateway) + nat_gateway_id = nat_gateway_dict["id"] + + if ( + sku_tier := nat_gateway_dict["sku"] + .get("additional_properties") + .get("tier") + ): + nat_gateway_dict["sku"]["tier"] = sku_tier + + nat_gateway_dict = self.update_tenant_id_from_secret_data( + nat_gateway_dict, secret_data + ) + + # update application_gateway_dict + nat_gateway_dict.update( + { + "resource_group": self.get_resource_group_from_id( + nat_gateway_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": nat_gateway_id}, + } + ) + + if nat_gateway_dict.get("public_ip_addresses") is not None: + # Get Count of Public IP Address + nat_gateway_dict.update( + { + "public_ip_addresses_count": len( + nat_gateway_dict["public_ip_addresses"] + ) + } + ) + + # Get Public IP Address Dictionary + if not nat_gateway_dict["public_ip_addresses"]: + break + + pip_list = [] + + for pip in nat_gateway_dict["public_ip_addresses"]: + public_ip_prefixes_id = pip["id"] + pip_dict = self.get_public_ip_address_dict( + nat_gateways_conn, public_ip_prefixes_id + ) + pip_list.append(pip_dict) + + nat_gateway_dict["public_ip_addresses"] = pip_list + + if nat_gateway_dict.get("subnets") is not None: + nat_gateway_dict.update( + { + "subnets": self.get_subnets( + nat_gateways_conn, nat_gateway_dict["subnets"] + ), + "subnets_count": len(nat_gateway_dict["subnets"]), + } + ) + + self.set_region_code(nat_gateway_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=nat_gateway_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=nat_gateway_dict, + account=nat_gateway_dict["subscription_id"], + instance_type=nat_gateway_dict["sku"]["name"], + region_code=nat_gateway_dict["location"], + reference=self.make_reference(nat_gateway_dict.get("id")), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_public_ip_address_dict(self, nat_gateway_conn, pip_id): + pip_name = pip_id.split("/")[8] + resource_group_name = pip_id.split("/")[4] + pip_obj = nat_gateway_conn.get_public_ip_addresses( + resource_group_name=resource_group_name, public_ip_address_name=pip_name + ) + pip_dict = self.convert_nested_dictionary(pip_obj) + return pip_dict + + def get_public_ip_prefixes_dict(self, nat_gateway_conn, pip_id): + pip_name = pip_id.split("/")[8] + resource_group_name = pip_id.split("/")[4] + pip_obj = nat_gateway_conn.get_public_ip_prefixes( + resource_group_name=resource_group_name, public_ip_prefixes_name=pip_name + ) + + pip_dict = self.convert_nested_dictionary(pip_obj) + return pip_dict + + def get_subnets(self, nat_gateway_conn, subnets): + subnet_list = [] + + for subnet in subnets: + resource_group_name = subnet["id"].split("/")[4] + subnet_name = subnet["id"].split("/")[10] + vnet_name = subnet["id"].split("/")[8] + + subnet_obj = nat_gateway_conn.get_subnet( + resource_group_name=resource_group_name, + subnet_name=subnet_name, + vnet_name=vnet_name, + ) + subnet_dict = self.convert_nested_dictionary(subnet_obj) + subnet_dict.update({"virtual_network": vnet_name}) + + subnet_list.append(subnet_dict) + + return subnet_list + diff --git a/src/plugin/manager/virtual_networks/instance_manager.py b/src/plugin/manager/virtual_networks/instance_manager.py index c8ef27ac..c1529b38 100644 --- a/src/plugin/manager/virtual_networks/instance_manager.py +++ b/src/plugin/manager/virtual_networks/instance_manager.py @@ -34,7 +34,7 @@ def create_cloud_service(self, options, secret_data, schema): cloud_services = [] error_responses = [] - virtual_networks_conn = VirtualNetworksConnector() + virtual_networks_conn = VirtualNetworksConnector(secret_data=secret_data) subscription_conn = SubscriptionsConnector(secret_data=secret_data) subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) From ef426f60a0325413f942f4a5dbf63ec8af23b127 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 24 Jul 2024 15:42:39 +0900 Subject: [PATCH 08/35] feat: ContainerInstance Collector migration --- src/plugin/connector/base.py | 3 + .../connector/container_instances/__init__.py | 0 .../container_instances_connector.py | 18 ++ src/plugin/manager/__init__.py | 1 + .../manager/container_instances/__init__.py | 1 + .../container_instances/container_manager.py | 172 ++++++++++++++++++ .../container_instances/container.yaml | 157 ++++++++++++++++ .../Container/container_count.yaml | 39 ++++ .../Container/gpu_size.yaml | 38 ++++ .../Container/memory_size.yaml | 38 ++++ .../Container/namespace.yaml | 8 + .../Container/vcpu_count.yaml | 38 ++++ 12 files changed, 513 insertions(+) create mode 100644 src/plugin/connector/container_instances/__init__.py create mode 100644 src/plugin/connector/container_instances/container_instances_connector.py create mode 100644 src/plugin/manager/container_instances/__init__.py create mode 100644 src/plugin/manager/container_instances/container_manager.py create mode 100644 src/plugin/metadata/container_instances/container.yaml create mode 100644 src/plugin/metrics/ContainerInstances/Container/container_count.yaml create mode 100644 src/plugin/metrics/ContainerInstances/Container/gpu_size.yaml create mode 100644 src/plugin/metrics/ContainerInstances/Container/memory_size.yaml create mode 100644 src/plugin/metrics/ContainerInstances/Container/namespace.yaml create mode 100644 src/plugin/metrics/ContainerInstances/Container/vcpu_count.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index dd3e71ad..88a6608a 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -7,6 +7,7 @@ from azure.mgmt.network import NetworkManagementClient from azure.mgmt.sql import SqlManagementClient from azure.mgmt.monitor import MonitorManagementClient +from azure.mgmt.containerinstance import ContainerInstanceManagementClient from spaceone.core.connector import BaseConnector @@ -22,6 +23,7 @@ def __init__(self, *args, **kwargs): self.network_client = None self.sql_client = None self.monitor_client = None + self.container_instance_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -38,6 +40,7 @@ def set_connect(self, secret_data: dict): self.network_client = NetworkManagementClient(credential=credential, subscription_id=subscription_id) self.sql_client = SqlManagementClient(credential=credential, subscription_id=subscription_id) self.monitor_client = MonitorManagementClient(credential=credential, subscription_id=subscription_id) + self.container_instance_client = ContainerInstanceManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/container_instances/__init__.py b/src/plugin/connector/container_instances/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/container_instances/container_instances_connector.py b/src/plugin/connector/container_instances/container_instances_connector.py new file mode 100644 index 00000000..301ee294 --- /dev/null +++ b/src/plugin/connector/container_instances/container_instances_connector.py @@ -0,0 +1,18 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class ContainerInstancesConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_container_groups(self): + return self.container_instance_client.container_groups.list() + + def get_container_groups(self, resource_group_name, container_group_name): + return self.container_instance_client.container_groups.get(resource_group_name=resource_group_name, + container_group_name=container_group_name) \ No newline at end of file diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index d9cc54aa..86d45c99 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -5,3 +5,4 @@ from .virtual_networks import * from .application_gatways import * from .nat_gateways import * +from .container_instances import * diff --git a/src/plugin/manager/container_instances/__init__.py b/src/plugin/manager/container_instances/__init__.py new file mode 100644 index 00000000..f47d688a --- /dev/null +++ b/src/plugin/manager/container_instances/__init__.py @@ -0,0 +1 @@ +from .container_manager import ContainerInstancesManage diff --git a/src/plugin/manager/container_instances/container_manager.py b/src/plugin/manager/container_instances/container_manager.py new file mode 100644 index 00000000..edd4c607 --- /dev/null +++ b/src/plugin/manager/container_instances/container_manager.py @@ -0,0 +1,172 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.container_instances.container_instances_connector import ContainerInstancesConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class ContainerInstancesManage(AzureBaseManager): + cloud_service_group = "ContainerInstances" + cloud_service_type = "Container" + service_code = "/Microsoft.Compute/disks" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Container"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-container-instances.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + container_instances_conn = ContainerInstancesConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + container_instances = container_instances_conn.list_container_groups() + for container_instance in container_instances: + + try: + container_instance_dict = self.convert_nested_dictionary(container_instance) + container_instance_id = container_instance_dict["id"] + + resource_group_name = self.get_resource_group_from_id(container_instance_id) + container_group_name = container_instance_dict["name"] + + container_instance = container_instances_conn.get_container_groups( + resource_group_name=resource_group_name, + container_group_name=container_group_name, + ) + container_instance_dict = self.convert_nested_dictionary(container_instance) + + # Update data info in Container Instance's Raw Data + _cpu_count_display = 0 + _gpu_count_display = 0 + _memory_size_display = 0.0 + + for container in container_instance_dict["containers"]: + _cpu_count_display += int(container["resources"]["requests"]["cpu"]) + _memory_size_display += float( + container["resources"]["requests"]["memory_in_gb"] + ) + _gpu_count_display += int(self._get_gpu_count_display(container)) + + # Set detail volume info for container + if container_instance_dict["volumes"] is not None: + for volume in container_instance_dict["volumes"]: + self._set_volumes_detail_info( + volume, container_instance_dict["containers"] + ) + + # Set Container Instance volume type and volume count + self._set_container_instance_volume_type( + container_instance_dict["volumes"] + ) + container_instance_dict["volume_count_display"] = len( + container_instance_dict["volumes"] + ) + + container_instance_dict = self.update_tenant_id_from_secret_data( + container_instance_dict, secret_data + ) + + container_instance_dict.update( + { + "resource_group": self.get_resource_group_from_id( + container_instance_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": container_instance_id}, + "container_count_display": len( + container_instance_dict["containers"] + ), + "cpu_count_display": _cpu_count_display, + "memory_size_display": _memory_size_display, + "gpu_count_display": _gpu_count_display, + } + ) + + self.set_region_code(container_instance_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=container_instance_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=container_instance_dict, + account=container_instance_dict["subscription_id"], + region_code=container_instance_dict["location"], + reference=self.make_reference(container_instance_dict.get("id")), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + @staticmethod + def _set_container_instance_volume_type(volumes): + for volume in volumes: + if volume.get("git_repo") is not None: + volume["volume_type"] = "Git repo" + elif volume.get("azure_file") is not None: + volume["volume_type"] = "Azure file" + elif volume.get("empty_dir") is not None: + volume["volume_type"] = "Empty directory" + elif volume.get("secret") is not None: + volume["volume_type"] = "Secret" + + @staticmethod + def _set_volumes_detail_info(volume, containers): + for container in containers: + if volume_mounts := container["volume_mounts"]: + container["volume_mount_count_display"] = len(volume_mounts) + for volume_mount in volume_mounts: + if volume_mount["name"] == volume["name"]: + volume.update( + { + "mount_path": volume_mount["mount_path"], + "container_name": container["name"], + } + ) + return + + @staticmethod + def _get_gpu_count_display(container): + _gpu_count = 0 + if ( + _gpu_info := container.get("resources", {}) + .get("requests", {}) + .get("gpu", {}) + ): + _gpu_count = _gpu_info.get("count", 0) + return _gpu_count diff --git a/src/plugin/metadata/container_instances/container.yaml b/src/plugin/metadata/container_instances/container.yaml new file mode 100644 index 00000000..6afcc410 --- /dev/null +++ b/src/plugin/metadata/container_instances/container.yaml @@ -0,0 +1,157 @@ +search: + fields: + - Tier: data.tier + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + - Resource Group: data.resource_group + - Location: data.location + - Zone: data.zones + - Last updated at: data.last_updated + - Storage Account Type: data.sku.name + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): data.disk_size_gb + - Disk IOPS: data.disk_iops_read_write + - OS Type: data.os_type + - Provisioning State: data.provisioning_state + - Time Created: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Storage Account Type: data.sku.name + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Owner: data.managed_by + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - Zone: data.zones + type: list + options: + delimiter: ', ' + is_optional: true + - Encryption Type: data.encryption.type + is_optional: true + - Networking: data.network_access_policy_display + is_optional: true + - Max Shares: data.max_shares + is_optional: true + - Time Created: data.time_created + is_optional: true + + + +tabs.0: + name: Disks + type: item + fields: + - Name: name + - Storage Account Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Disk State: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.500 + type: state + - Attached VM: data.managed_by + - Location: data.location + - Resource Group: data.resource_group + - Resource ID: data.id + - Zones: data.zones + - Subscription ID: data.subscription_id + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type + - Networking: data.network_access_policy_display + - Os Type: data.os_type + - Max Shares: data.max_shares + - VM Generation: data.hyper_v_generation + - VM architecture: data.supported_capabilities.architecture + - DateTimeDyField.data_sourceTime Created: data.time_created + source_type: iso8601 + type: datetime + + + +tabs.1: + name: Configuration + items: + - name: Shared Disk + type: item + fields: + - Enable shared disk: data.enable_shared_disk_display + - Max shares: data.max_shares + - name: On-demand bursting + type: item + fields: + - Enable bursting: data.bursting_enabled + - Enable bursting time: data.bursting_enabled_time + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Networking + type: item + fields: + - Network access: data.network_access_policy_display \ No newline at end of file diff --git a/src/plugin/metrics/ContainerInstances/Container/container_count.yaml b/src/plugin/metrics/ContainerInstances/Container/container_count.yaml new file mode 100644 index 00000000..58dcc669 --- /dev/null +++ b/src/plugin/metrics/ContainerInstances/Container/container_count.yaml @@ -0,0 +1,39 @@ +--- +metric_id: metric-azure-cis-container-count +name: Container Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.ContainerInstances.Container +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.zones + name: Zone + - key: data.sku + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.os_type + name: OS Type + fields: + value: + key: data.container_count_display + operator: count +unit: Count +namespace_id: ns-azure-cis-container +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/ContainerInstances/Container/gpu_size.yaml b/src/plugin/metrics/ContainerInstances/Container/gpu_size.yaml new file mode 100644 index 00000000..572a4b8d --- /dev/null +++ b/src/plugin/metrics/ContainerInstances/Container/gpu_size.yaml @@ -0,0 +1,38 @@ +--- +metric_id: metric-azure-cis-container-gpu-size +name: GPU Size +metric_type: GAUGE +resource_type: inventory.CloudService:azure.ContainerInstances.Container +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.zones + name: Zone + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku + name: Sku Tier + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.os_type + name: OS Type + fields: + value: + key: data.gpu_count_display + operator: sum +unit: GB +namespace_id: ns-azure-cis-container +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/ContainerInstances/Container/memory_size.yaml b/src/plugin/metrics/ContainerInstances/Container/memory_size.yaml new file mode 100644 index 00000000..7a7cbe74 --- /dev/null +++ b/src/plugin/metrics/ContainerInstances/Container/memory_size.yaml @@ -0,0 +1,38 @@ +--- +metric_id: metric-azure-cis-container-memory-size +name: Memory Size +metric_type: GAUGE +resource_type: inventory.CloudService:azure.ContainerInstances.Container +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.zones + name: Zone + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku + name: Sku Tier + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.os_type + name: OS Type + fields: + value: + key: data.memory_size_display + operator: sum +unit: GB +namespace_id: ns-azure-cis-container +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/ContainerInstances/Container/namespace.yaml b/src/plugin/metrics/ContainerInstances/Container/namespace.yaml new file mode 100644 index 00000000..1f40fbe2 --- /dev/null +++ b/src/plugin/metrics/ContainerInstances/Container/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-cis-container +name: ContainerInstances/Container +resource_type: inventory.CloudService:azure.ContainerInstances.Container +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-container-instances.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/ContainerInstances/Container/vcpu_count.yaml b/src/plugin/metrics/ContainerInstances/Container/vcpu_count.yaml new file mode 100644 index 00000000..e1481fc9 --- /dev/null +++ b/src/plugin/metrics/ContainerInstances/Container/vcpu_count.yaml @@ -0,0 +1,38 @@ +--- +metric_id: metric-azure-cis-container-vcpu-count +name: vCPU Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.ContainerInstances.Container +query_options: + unwind: + path: data.zones + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.zones + name: Zone + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku + name: Sku Tier + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.os_type + name: OS Type + fields: + value: + key: data.cpu_count_display + operator: sum +unit: Core +namespace_id: ns-azure-cis-container +version: '1.0' \ No newline at end of file From ab101fd67d8031531f3d72d8efc26910c474d12c Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 25 Jul 2024 14:27:04 +0900 Subject: [PATCH 09/35] feat: Add Disks, Application Gateways, Container Instances Metadata --- .../application_gateways/instance.yaml | 408 +++++++++++++----- .../container_instances/container.yaml | 216 ++++++---- src/plugin/metadata/disks/disk.yaml | 4 +- 3 files changed, 429 insertions(+), 199 deletions(-) diff --git a/src/plugin/metadata/application_gateways/instance.yaml b/src/plugin/metadata/application_gateways/instance.yaml index 6afcc410..8cb297c2 100644 --- a/src/plugin/metadata/application_gateways/instance.yaml +++ b/src/plugin/metadata/application_gateways/instance.yaml @@ -1,19 +1,47 @@ search: fields: - - Tier: data.tier - - Subscription Name: data.subscription_name - Subscription ID: data.subscription_id + - Subscription Name: data.display_name - Resource Group: data.resource_group - Location: data.location - - Zone: data.zones - - Last updated at: data.last_updated - - Storage Account Type: data.sku.name - - Disk Size (Bytes): data.disk_size_bytes - - Disk Size (GB): data.disk_size_gb - - Disk IOPS: data.disk_iops_read_write - - OS Type: data.os_type - - Provisioning State: data.provisioning_state - - Time Created: data.time_created + - Public IP Address: data.public_ip_address.ip_address + - Private IP Address: data.private_ip_address + - Capacity: data.sku.tier + - Minimum Instance Count: data.autoscale_configuration.min_capacity + data_type: integer + - Maximum Instance Count: data.autoscale_configuration.max_capacity + data_type: integer + - Enable HTTP2: data.enable_http2 + data_type: integer + - Firewall Mode: data.web_application_firewall_configuration.firewall_mode + - Firewall Rule Set Type: data.web_application_firewall_configuration.rule_set_type + - Firewall Rule Set Version: data.web_application_firewall_configuration.rule_set_version + - Backend Address Pool Name: data.backend_address_pools.name + - Backend Address Rule Associated: data.backend_address_pools.associated_rules + - HTTP Backend Name: data.backend_http_settings_collection.name + - HTTP Backend Port: data.backend_http_settings_collection.port + - HTTP Backend Protocol: data.backend_http_settings_collection.protocol + - SSL Profile Name: data.ssl_profiles.name + - SSL Client Certificates: data.ssl_profiles.trusted_client_certificates.id + - SSL Policy Type: data.ssl_profiles.ssl_policy.policy_type + - Frontend IP Type: data.frontend_ip_configurations.ip_type + - Frontend IP Configuration Name: data.frontend_ip_configurations.name + - Frontend IP Address: data.frontend_ip_configurations.ip_address + - Frontend Associated Listeners: data.frontend_ip_configurations.associated_listeners + - HTTP Listener Name: data.http_listeners.name + - HTTP Listener Protocol: data.http_listeners.protocol + - HTTP Listener Port: data.http_listeners.port + - HTTP Listener Associated Rule: data.http_listeners.associated_rules + - HTTP Listener Host name: data.http_listeners.host_name + - Request Routing Rule Name: data.request_routing_rules.name + - Request Routing Rule Type: data.request_routing_rules.rule_type + - Request Routing Rule Listener: data.request_routing_rules.http_listener_name + - Health Probes Name: data.probes.name + - Health Probes Protocol: data.probes.protocol + - Health Probes Host: data.probes.host + - Health Probes Path: data.probes.path + - Health Probes Timeout(Seconds): data.probes.timeout + data_type: integer @@ -22,136 +50,304 @@ table: key: data.id desc: false fields: - - Storage Account Type: data.sku.name - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state - type: enum - enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Owner: data.managed_by + - Public IP Address: data.public_ip_address.ip_address + - Private IP Address: data.private_ip_address - Resource Group: data.resource_group - Location: data.location - - Subscription Name: data.subscription_name + - Subscription: data.display_name - Subscription ID: data.subscription_id is_optional: true - - Zone: data.zones + - Capacity: data.sku.tier + is_optional: true + - Minimum Instance Count: data.autoscale_configuration.min_capacity + is_optional: true + - Maximum Instance Count: data.autoscale_configuration.max_capacity + is_optional: true + - Enable HTTP2: data.enable_http2 + is_optional: true + - Firewall Mode: data.web_application_firewall_configuration.firewall_mode + is_optional: true + - Firewall Max Request Body Size(KB): data.web_application_firewall_configuration.max_request_body_size_in_kb + is_optional: true + - Firewall File Upload Limit(MB): data.web_application_firewall_configuration.file_upload_limit_in_mb + is_optional: true + - Firewall Rule Set Type: data.web_application_firewall_configuration.rule_set_type + is_optional: true + - Firewall Rule Set Version: data.web_application_firewall_configuration.rule_set_version + is_optional: true + - Backend Address Pool Name: data.backend_address_pools.name + is_optional: true + - Backend Address Rule Associated: data.backend_address_pools.associated_rules type: list options: delimiter: ', ' is_optional: true - - Encryption Type: data.encryption.type + - HTTP Backend Name: data.backend_http_settings_collection.name + is_optional: true + - HTTP Backend Port: data.backend_http_settings_collection.port + is_optional: true + - HTTP Backend Protocol: data.backend_http_settings_collection.protocol is_optional: true - - Networking: data.network_access_policy_display + - SSL Profile Name: data.ssl_profiles.name + is_optional: true + - SSL Client Certificates: data.ssl_profiles.trusted_client_certificates.id + type: list + options: + delimiter: ', ' is_optional: true - - Max Shares: data.max_shares + - SSL Policy Type: data.ssl_profiles.ssl_policy.policy_type is_optional: true - - Time Created: data.time_created + - Frontend IP Type: data.frontend_ip_configurations.ip_type + is_optional: true + - Frontend IP Configuration Name: data.frontend_ip_configurations.name + is_optional: true + - Frontend IP Address: data.frontend_ip_configurations.ip_address + is_optional: true + - Frontend Associated Listeners: data.frontend_ip_configurations.associated_listeners + is_optional: true + - HTTP Listener Name: data.http_listeners.name + is_optional: true + - HTTP Listener Protocol: data.http_listeners.protocol + is_optional: true + - HTTP Listener Port: data.http_listeners.port + is_optional: true + - HTTP Listener Associated Rule: data.http_listeners.associated_rules + is_optional: true + - HTTP Listener Host name: data.http_listeners.host_name + is_optional: true + - Request Routing Rule Name: data.request_routing_rules.name + is_optional: true + - Request Routing Rule Type: data.request_routing_rules.rule_type + is_optional: true + - Request Routing Rule Listener: data.request_routing_rules.http_listener_name + is_optional: true + - Health Probes Name: data.probes.name + is_optional: true + - Health Probes Protocol: data.probes.protocol + is_optional: true + - Health Probes Host: data.probes.host + is_optional: true + - Health Probes Path: data.probes.path + is_optional: true + - Health Probes Timeout(Seconds): data.probes.timeout is_optional: true tabs.0: - name: Disks + name: Application Gateway type: item fields: - Name: name - - Storage Account Type: instance_type - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - Resource ID: data.id + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.display_name + - Subscription ID: data.subscription_id + - Virtual Network: data.virtual_network + - Subnet: data.subnet + - Frontend public IP Address: data.public_ip_address.ip_address + - Frontend private IP Address: data.private_ip_address + - Tier: data.sku.tier + + + +tabs.1: + name: Configuration + type: item + fields: + - Capacity: data.sku.tier + - Minimum Instance Count: data.autoscale_configuration.min_capacity + - Maximum Instance Count: data.autoscale_configuration.max_capacity + - Enable HTTP2: data.enable_http2 + + + +tabs.2: + name: Subnets + items: + - name: Web Application Firewall + type: item + fields: + - Firewall Status Enabled: data.web_application_firewall_configuration.enabled + type: enum + enums: + - True: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - False: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Firewall Mode: data.web_application_firewall_configuration.firewall_mode + - Inspect Request Body: data.web_application_firewall_configuration.request_body_check + type: enum + enums: + - True: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - False: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Max Request Body Size(KB): data.web_application_firewall_configuration.max_request_body_size_in_kb + - File Upload Limit(MB): data.web_application_firewall_configuration.file_upload_limit_in_mb + - Rule Set Type: data.web_application_firewall_configuration.rule_set_type + - Rule Set Version: data.web_application_firewall_configuration.rule_set_version + - name: Exclusions + type: simple-table + root_path: data.web_application_firewall_configuration.exclusions + fields: + - Field: match_variable + - Operator: selector_match_operator + - Selector: selector + + + +tabs.3: + name: Backend Pools + type: simple-table + root_path: data.backend_address_pools + fields: + - Name: name + - Rule Associated: associated_rules + type: list + options: + delimiter: ', ' + - Targets: backend_addresses_display + type: list + options: + delimiter: ', ' + +tabs.4: + name: Backend HTTP Settings + type : simple-table + root_path: data.backend_http_settings_collection + fields: + - Name: name + - Port: port + - Protocol: protocol + - Cookie Based Affinity: cookie_based_affinity type: enum enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: + - Enabled: icon_image: ic_circle-filled icon_color: green.500 type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: + - Disabled: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Attached VM: data.managed_by - - Location: data.location - - Resource Group: data.resource_group - - Resource ID: data.id - - Zones: data.zones - - Subscription ID: data.subscription_id - - Subscription Name: data.subscription_name - - Encryption Type: data.encryption.type - - Networking: data.network_access_policy_display - - Os Type: data.os_type - - Max Shares: data.max_shares - - VM Generation: data.hyper_v_generation - - VM architecture: data.supported_capabilities.architecture - - DateTimeDyField.data_sourceTime Created: data.time_created - source_type: iso8601 - type: datetime + - Custom Probe: custom_probe + - Connection draining: connection_draining.enabled + - Request time-out: request_timeout + - Override backend path: path + - Override with new host name: pick_host_name_from_backend_address + - Host name: host_name -tabs.1: - name: Configuration +tabs.5: + name: SSL Settings + type: simple-table + root_path: data.ssl_profiles + fields: + - Name: name + - Client Certificates: trusted_client_certificates.id + - SSL Policy Type: ssl_policy.policy_type + is_optional: true + + + +tabs.6: + name: Frontend IP Configurations + type: simple-table + root_path: data.frontend_ip_configurations + fields: + - Type: ip_type + - Name: name + - IP Address: ip_address + - Associated Listeners: associated_listener + type: list + options: + delimiter: ', ' + + + +tabs.7: + name: Listeners items: - - name: Shared Disk - type: item + - name: Listeners + type: simple-table + root_path: data.http_listeners fields: - - Enable shared disk: data.enable_shared_disk_display - - Max shares: data.max_shares - - name: On-demand bursting - type: item + - Name: name + - Protocol: protocol + - Port: port + - Associated Rule: associated_rules + - Host name: host_name + - name: Custom Error Configurations + type: simple-table + root_path: data.custom_error_configurations fields: - - Enable bursting: data.bursting_enabled - - Enable bursting time: data.bursting_enabled_time - source_type: iso8601 - type: datetime + - Listener Name: listener_name + - Status Code: status_code + - Custom Error Page URL: custom_error_page_url -tabs.2: - name: Networking +tabs.8: + name: Rules + type: simple-table + root_path: data.request_routing_rules + fields: + - Name: name + - Type: rule_type + - Listener: http_listener_name + - Priority: priority + + + +tabs.9: + name: Rewrites + type: simple-table + root_path: data.rewrite_rule_sets + fields: + - Rewrite Sets: name + - Rules Applied: rules_applied + - Rewrite Rule Configuration: rewrite_rules_display + type: list + options: + delimiter: ', ' + + + +tabs.10: + name: Health Probes + type: simple-table + root_path: data.probes + fields: + - Name: name + - Protocol: protocol + - Host: host + - Path: path + - Timeout(Seconds): timeout + + + +tabs.11: + name: Managed Identity type: item fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - Type: data.identity.type + - Principal ID: data.identity.principal_id + - Tenant ID: data.identity.tenant_id + - User Assigned Identities: data.identity.output_display + popup_key: data.identity.user_assigned_identities + popup_name: User Assigned Identities + popup_type: raw + type: more + + diff --git a/src/plugin/metadata/container_instances/container.yaml b/src/plugin/metadata/container_instances/container.yaml index 6afcc410..a602d983 100644 --- a/src/plugin/metadata/container_instances/container.yaml +++ b/src/plugin/metadata/container_instances/container.yaml @@ -1,19 +1,23 @@ search: fields: - - Tier: data.tier - - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - Status: data.instance_view.state - Resource Group: data.resource_group - - Location: data.location - - Zone: data.zones - - Last updated at: data.last_updated - - Storage Account Type: data.sku.name - - Disk Size (Bytes): data.disk_size_bytes - - Disk Size (GB): data.disk_size_gb - - Disk IOPS: data.disk_iops_read_write - - OS Type: data.os_type + - OS type: data.os_type + - Subscription ID: account + - Subscription Name: data.subscription_name - Provisioning State: data.provisioning_state - - Time Created: data.time_created + - Restart Policy: data.restart_policy + - IP Address: data.ip_address.ip + - FQDN: data.ip_address.fqdn + - Location: data.location + - SKU: data.sku + - Container count: data.container_count_display + - vCPU: data.cpu_count_display + - Memory size(GB): data.memory_size_display + - GPU count: data.gpu_count_display + - Volume count: data.volume_count_display + - DNS name label: data.ip_address.dns_name_label + - DNS name label scope reuse: data.ip_address.auto_generated_domain_name_label_scope @@ -22,136 +26,166 @@ table: key: data.id desc: false fields: - - Storage Account Type: data.sku.name - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - State: data.instance_view.state type: enum enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: + - Running: icon_image: ic_circle-filled icon_color: green.500 type: state - - Attached: + - Succeeded: icon_image: ic_circle-filled icon_color: green.500 type: state - - Reserved: + - Pending: icon_image: ic_circle-filled - icon_color: green.500 + icon_color: yellow.500 type: state - - ReadyToUpload: + - Stopped: red.500 icon_image: ic_circle-filled - icon_color: yellow.500 + icon_color: red.500 type: state - - Unattached: + - Failed: red.500 icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: red.500 type: state - - Owner: data.managed_by + - Subscription Name: data.display_name + - Subscription ID: account + is_optional: true - Resource Group: data.resource_group - Location: data.location - - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - OS type: data.os_type + - Container count: data.container_count_display + - vCPU count: data.container_count_display + - Memory size(GB): data.memory_size_display + - Volume count: data.volume_count_display + - GPU count: data.gpu_count_display + - Provisioning State: data.provisioning_state is_optional: true - - Zone: data.zones - type: list - options: - delimiter: ', ' + - Restart Policy: data.restart_policy + is_optional: true + - IP Address: data.ip_address.ip is_optional: true - - Encryption Type: data.encryption.type + - IP Address Type: data.ip_address.type is_optional: true - - Networking: data.network_access_policy_display + - FQDN: data.ip_address.fqdn is_optional: true - - Max Shares: data.max_shares + - DNS name label: data.ip_address.dns_name_label is_optional: true - - Time Created: data.time_created + - DNS name label scope reuse: data.ip_address.auto_generated_domain_name_label_scope is_optional: true + + tabs.0: - name: Disks + name: Container Instances type: item fields: - Name: name - - Storage Account Type: instance_type - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - State: data.instance_view.state type: enum enums: - - ActiveSAS: + - Running: icon_image: ic_circle-filled icon_color: green.500 type: state - - ActiveUpload: + - Succeeded: icon_image: ic_circle-filled icon_color: green.500 type: state - - Attached: + - Pending: icon_image: ic_circle-filled - icon_color: green.500 + icon_color: yellow.500 type: state - - Reserved: + - Stopped: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Failed: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Resource ID: data.id + - Resource Group: data.resource_group + - Subscription: data.subscription_name + - Subscription ID: account + - Region: region_code + - SKU: data.sku + - OS type: data.os_type + - Container count: data.container_count_display + - vCPU count: data.container_count_display + - Memory size(GB): data.memory_size_display + - GPU count: data.gpu_count_display + - Volume count: data.volume_count_display + - IP Address: data.ip_address.ip + - IP Address Type: data.ip_address.type + - FQDN: data.ip_address.fqdn + - DNS name label: data.ip_address.dns_name_label + - DNS name label scope reuse: data.ip_address.auto_generated_domain_name_label_scope + - Ports: data.ip_address.ports.port + type: list + options: + delimiter: '
' + + + + +tabs.1: + name: Container + type: table + root_path: data.containers + fields: + - Name: name + - State: instance_view.current_state.state + type: enum + enums: + - Running: icon_image: ic_circle-filled icon_color: green.500 type: state - - ReadyToUpload: + - Waiting: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unattached: + - Terminated: red.500 icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: red.500 type: state - - Attached VM: data.managed_by - - Location: data.location - - Resource Group: data.resource_group - - Resource ID: data.id - - Zones: data.zones - - Subscription ID: data.subscription_id - - Subscription Name: data.subscription_name - - Encryption Type: data.encryption.type - - Networking: data.network_access_policy_display - - Os Type: data.os_type - - Max Shares: data.max_shares - - VM Generation: data.hyper_v_generation - - VM architecture: data.supported_capabilities.architecture - - DateTimeDyField.data_sourceTime Created: data.time_created + - Previous state: instance_view.previous_state.state + - Restart count: instance_view.restart_count + - Volume count: volume_mount_count_display + - CPU cores: resources.requests.cpu + - Memory(GB): resources.requests.memory_in_gb + - Image: image + - Start time: instance_view.current_state.start_time source_type: iso8601 type: datetime - - - -tabs.1: - name: Configuration - items: - - name: Shared Disk - type: item - fields: - - Enable shared disk: data.enable_shared_disk_display - - Max shares: data.max_shares - - name: On-demand bursting - type: item - fields: - - Enable bursting: data.bursting_enabled - - Enable bursting time: data.bursting_enabled_time - source_type: iso8601 - type: datetime + - Finish time: instance_view.current_state.finish + source_type: iso8601 + type: datetime + - GPU SKU: resources.requests.gpu.sku + - GPU count: resources.requests.gpu.count + - Ports: ports.port + type: list + options: + delimiter: '
' + - Commands: command + type: list + options: + delimiter: '
' tabs.2: - name: Networking - type: item + name: Volume + type: table + root_path: data.volumes fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - Name: name + - Volume type: volume_type + - Mount path: mount_path + - Git repository: git_repo.repository + - Container name: container_name + diff --git a/src/plugin/metadata/disks/disk.yaml b/src/plugin/metadata/disks/disk.yaml index 6afcc410..bd70c7b0 100644 --- a/src/plugin/metadata/disks/disk.yaml +++ b/src/plugin/metadata/disks/disk.yaml @@ -52,7 +52,7 @@ table: type: state - Unattached: icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: blue.400 type: state - Owner: data.managed_by - Resource Group: data.resource_group @@ -111,7 +111,7 @@ tabs.0: type: state - Unattached: icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: blue.400 type: state - Attached VM: data.managed_by - Location: data.location From fafc711e953fa2b1f633728f11b907fcc9df27bc Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 26 Jul 2024 15:37:43 +0900 Subject: [PATCH 10/35] feat: Add SQL Databases, SQL Servers, Public IP Addresses Metadata --- src/plugin/main.py | 16 +- .../application_gateways/instance.yaml | 22 +- .../container_instances/container.yaml | 20 +- src/plugin/metadata/disks/disk.yaml | 12 +- .../public_ip_addresses/ip_address.yaml | 154 ++--- .../metadata/sql_databases/database.yaml | 392 ++++++++++--- src/plugin/metadata/sql_servers/server.yaml | 545 +++++++++++++++--- 7 files changed, 838 insertions(+), 323 deletions(-) diff --git a/src/plugin/main.py b/src/plugin/main.py index b7589714..97025969 100644 --- a/src/plugin/main.py +++ b/src/plugin/main.py @@ -87,11 +87,6 @@ def job_get_tasks(params: dict) -> dict: def _create_init_metadata() -> dict: - enum = ["All"] - for manager in AzureBaseManager.__subclasses__(): - if manager.cloud_service_group: - enum.append(manager.cloud_service_group) - return { "metadata": { "options_schema": { @@ -102,7 +97,7 @@ def _create_init_metadata() -> dict: "type": "string", "items": {"type": "string"}, "default": "All", - "enum": enum, + "enum": _get_cloud_service_group_enum(), "description": "Choose one of the service to collect data. If you choose 'All', it will collect all services." } } @@ -111,6 +106,15 @@ def _create_init_metadata() -> dict: } +def _get_cloud_service_group_enum() -> list: + enum = ["All"] + for manager in AzureBaseManager.__subclasses__(): + if manager.cloud_service_group: + enum.append(manager.cloud_service_group) + + return enum + + def _get_cloud_service_groups_from_options_and_task_options(options: dict, task_options: dict) -> list: cloud_service_groups = options.get("cloud_service_groups", []) if task_options: diff --git a/src/plugin/metadata/application_gateways/instance.yaml b/src/plugin/metadata/application_gateways/instance.yaml index 8cb297c2..41d29159 100644 --- a/src/plugin/metadata/application_gateways/instance.yaml +++ b/src/plugin/metadata/application_gateways/instance.yaml @@ -1,7 +1,7 @@ search: fields: - Subscription ID: data.subscription_id - - Subscription Name: data.display_name + - Subscription Name: data.subscription_name - Resource Group: data.resource_group - Location: data.location - Public IP Address: data.public_ip_address.ip_address @@ -54,7 +54,7 @@ table: - Private IP Address: data.private_ip_address - Resource Group: data.resource_group - Location: data.location - - Subscription: data.display_name + - Subscription: data.subscription_name - Subscription ID: data.subscription_id is_optional: true - Capacity: data.sku.tier @@ -142,7 +142,7 @@ tabs.0: - Resource ID: data.id - Resource Group: data.resource_group - Location: data.location - - Subscription: data.display_name + - Subscription: data.subscription_name - Subscription ID: data.subscription_id - Virtual Network: data.virtual_network - Subnet: data.subnet @@ -240,12 +240,12 @@ tabs.4: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Custom Probe: custom_probe - - Connection draining: connection_draining.enabled - - Request time-out: request_timeout - - Override backend path: path - - Override with new host name: pick_host_name_from_backend_address - - Host name: host_name + - Custom Probe: custom_probe + - Connection draining: connection_draining.enabled + - Request time-out: request_timeout + - Override backend path: path + - Override with new host name: pick_host_name_from_backend_address + - Host name: host_name @@ -348,6 +348,4 @@ tabs.11: popup_key: data.identity.user_assigned_identities popup_name: User Assigned Identities popup_type: raw - type: more - - + type: more \ No newline at end of file diff --git a/src/plugin/metadata/container_instances/container.yaml b/src/plugin/metadata/container_instances/container.yaml index a602d983..49670243 100644 --- a/src/plugin/metadata/container_instances/container.yaml +++ b/src/plugin/metadata/container_instances/container.yaml @@ -41,15 +41,17 @@ table: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Stopped: red.500 + - Stopped: + text_color: red.500 icon_image: ic_circle-filled icon_color: red.500 type: state - - Failed: red.500 + - Failed: + text_color: red.500 icon_image: ic_circle-filled icon_color: red.500 type: state - - Subscription Name: data.display_name + - Subscription Name: data.subscription_name - Subscription ID: account is_optional: true - Resource Group: data.resource_group @@ -77,8 +79,6 @@ table: - - tabs.0: name: Container Instances type: item @@ -99,11 +99,13 @@ tabs.0: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Stopped: red.500 + - Stopped: + text_color: red.500 icon_image: ic_circle-filled icon_color: red.500 type: state - - Failed: red.500 + - Failed: + text_color: red.500 icon_image: ic_circle-filled icon_color: red.500 type: state @@ -131,7 +133,6 @@ tabs.0: - tabs.1: name: Container type: table @@ -149,7 +150,8 @@ tabs.1: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Terminated: red.500 + - Terminated: + text_color: red.500 icon_image: ic_circle-filled icon_color: red.500 type: state diff --git a/src/plugin/metadata/disks/disk.yaml b/src/plugin/metadata/disks/disk.yaml index bd70c7b0..bdbba9e5 100644 --- a/src/plugin/metadata/disks/disk.yaml +++ b/src/plugin/metadata/disks/disk.yaml @@ -15,8 +15,6 @@ search: - Provisioning State: data.provisioning_state - Time Created: data.time_created - - table: sort: key: data.id @@ -63,7 +61,7 @@ table: - Zone: data.zones type: list options: - delimiter: ', ' + delimiter: ", " is_optional: true - Encryption Type: data.encryption.type is_optional: true @@ -74,8 +72,6 @@ table: - Time Created: data.time_created is_optional: true - - tabs.0: name: Disks type: item @@ -130,8 +126,6 @@ tabs.0: source_type: iso8601 type: datetime - - tabs.1: name: Configuration items: @@ -148,10 +142,8 @@ tabs.1: source_type: iso8601 type: datetime - - tabs.2: name: Networking type: item fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - Network access: data.network_access_policy_display diff --git a/src/plugin/metadata/public_ip_addresses/ip_address.yaml b/src/plugin/metadata/public_ip_addresses/ip_address.yaml index 6afcc410..1ca1f263 100644 --- a/src/plugin/metadata/public_ip_addresses/ip_address.yaml +++ b/src/plugin/metadata/public_ip_addresses/ip_address.yaml @@ -1,19 +1,17 @@ search: fields: - - Tier: data.tier + - Subscription ID: account - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id - Resource Group: data.resource_group - Location: data.location - - Zone: data.zones - - Last updated at: data.last_updated - - Storage Account Type: data.sku.name - - Disk Size (Bytes): data.disk_size_bytes - - Disk Size (GB): data.disk_size_gb - - Disk IOPS: data.disk_iops_read_write - - OS Type: data.os_type - - Provisioning State: data.provisioning_state - - Time Created: data.time_created + - SKU: instance_type + - Tier: data.sku.tier + - IP Address: data.ip_address + - DNS Name: data.dns_settings.fqdn + - IP Address Assignment: data.public_ip_allocation_method + - Idle Timeout(Minutes): data.idle_timeout_in_minutes + - DNS Name Label(Optional): data.dns_settings.domain_name_label + - Associated To: data.associated_to @@ -22,136 +20,52 @@ table: key: data.id desc: false fields: - - Storage Account Type: data.sku.name - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state - type: enum - enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Owner: data.managed_by - Resource Group: data.resource_group - Location: data.location - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - Associated To: data.associated_to + - Subscription ID: account is_optional: true - - Zone: data.zones - type: list - options: - delimiter: ', ' + - SKU: instance_type is_optional: true - - Encryption Type: data.encryption.type + - Tier: data.sku.tier is_optional: true - - Networking: data.network_access_policy_display + - IP Address: data.ip_address is_optional: true - - Max Shares: data.max_shares + - DNS Name: data.dns_settings.fqdn is_optional: true - - Time Created: data.time_created + - IP Address Assignment: data.public_ip_allocation_method + is_optional: true + - Idle Timeout(Minutes): data.idle_timeout_in_minutes + is_optional: true + - DNS Name Label(Optional): data.dns_settings.domain_name_label is_optional: true tabs.0: - name: Disks + name: Public IP Address type: item fields: - Name: name - - Storage Account Type: instance_type - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state - type: enum - enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Attached VM: data.managed_by - - Location: data.location - - Resource Group: data.resource_group - Resource ID: data.id - - Zones: data.zones - - Subscription ID: data.subscription_id - - Subscription Name: data.subscription_name - - Encryption Type: data.encryption.type - - Networking: data.network_access_policy_display - - Os Type: data.os_type - - Max Shares: data.max_shares - - VM Generation: data.hyper_v_generation - - VM architecture: data.supported_capabilities.architecture - - DateTimeDyField.data_sourceTime Created: data.time_created - source_type: iso8601 - type: datetime + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - SKU: instance_type + - Tier: data.sku.tier + - IP Address: data.ip_address + - DNS Name: data.dns_settings.fqdn + - Associated To: data.associated_to tabs.1: name: Configuration - items: - - name: Shared Disk - type: item - fields: - - Enable shared disk: data.enable_shared_disk_display - - Max shares: data.max_shares - - name: On-demand bursting - type: item - fields: - - Enable bursting: data.bursting_enabled - - Enable bursting time: data.bursting_enabled_time - source_type: iso8601 - type: datetime - - - -tabs.2: - name: Networking type: item fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - IP Address Assignment: data.public_ip_allocation_method + - Idle Timeout(Minutes): data.idle_timeout_in_minutes + - DNS Name Label(Optional): data.dns_settings.domain_name_label + diff --git a/src/plugin/metadata/sql_databases/database.yaml b/src/plugin/metadata/sql_databases/database.yaml index 6afcc410..250c0cb9 100644 --- a/src/plugin/metadata/sql_databases/database.yaml +++ b/src/plugin/metadata/sql_databases/database.yaml @@ -1,19 +1,36 @@ search: fields: - - Tier: data.tier - - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - Database ID: data.database_id + - Subscription ID: account - Resource Group: data.resource_group - Location: data.location - - Zone: data.zones - - Last updated at: data.last_updated - - Storage Account Type: data.sku.name - - Disk Size (Bytes): data.disk_size_bytes - - Disk Size (GB): data.disk_size_gb - - Disk IOPS: data.disk_iops_read_write - - OS Type: data.os_type - - Provisioning State: data.provisioning_state - - Time Created: data.time_created + - Tier: instance_type + - Server Name: data.managed_by + - Status: data.status + - Replication Partner Server: data.replication_link.partner_server + - Pricing Tier: data.pricing_tier_display + - Elastic Pool: data.elastic_pool_id + - Earliest Restore Point: data.earliest_restore_date + - Collation: data.collation + - Server Admin Login: data.administrator_login + - Service Tier: data.service_tier_display + - Compute Tier: data.compute_tier + - Compute Hardware: data.sku.family + - Licence Type: data.license_type + - vCores: data.current_sku.capacity + data_type: integer + - Data max size: instance_size + data_type: integer + - Zone Redundant: data.zone_redundant + - Sync Groups: data.sync_group_display + - Sync Agents: data.sync_agent_display + - Diagnostic Setting Name: data.diagnostic_settings_resource.name + - Diagnostic Setting Storage Account: data.diagnostic_settings_resource.storage_account_id + - Event Hub: data.diagnostic_settings_resource.event_hub_name + - Log Analytics Workspace: data.diagnostic_settings_resource.workspace_id + - Creation Date: data.creation_date + source_type: iso8601 + type: datetime @@ -22,136 +39,361 @@ table: key: data.id desc: false fields: - - Storage Account Type: data.sku.name - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - Status: data.status type: enum enums: - - ActiveSAS: + - Online: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Creating: icon_image: ic_circle-filled icon_color: green.500 type: state - - ActiveUpload: + - Copying: icon_image: ic_circle-filled icon_color: green.500 type: state - - Attached: + - OnlineChangingDwPerformanceTiers: icon_image: ic_circle-filled icon_color: green.500 type: state - - Reserved: + - Restoring: icon_image: ic_circle-filled icon_color: green.500 type: state - - ReadyToUpload: + - Resuming: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Scaling: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Standby: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - AutoClosed: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unattached: + - Inaccessible: icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: yellow.500 type: state - - Owner: data.managed_by - - Resource Group: data.resource_group + - Offline: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - OfflineChangingDwPerformanceTiers: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - OfflineSecondary: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Pausing: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Recovering: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - RecoveryPending: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Suspect: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - Paused: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - Shutdown: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - EmergencyMode: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Replication Partner Server: data.replication_link.partner_server + - Server: data.server_name + - Pricing Tier: data.pricing_tier_display - Location: data.location - - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - Subscription ID: account + - Resource Group: data.resource_group + - Elastic Pool: data.elastic_pool_id + is_optional: true + - Earliest Restore Point: data.earliest_restore_date + source_type: iso8601 + type: datetime + is_optional: true + - Collation: data.collation + is_optional: true + - Creation Date: data.creation_date + source_type: iso8601 + type: datetime + is_optional: true + - Server Admin Login: data.administrator_login + is_optional: true + - Service Tier: data.service_tier_display + is_optional: true + - Compute Tier: data.compute_tier + is_optional: true + - Compute Hardware: data.sku.family is_optional: true - - Zone: data.zones + - Licence Type: data.license_type + is_optional: true + - vCores: data.current_sku.capacity + is_optional: true + - Data max size: instance_size + is_optional: true + - Zone Redundant: data.zone_redundant + is_optional: true + - Sync Groups: data.sync_group_display type: list options: delimiter: ', ' is_optional: true - - Encryption Type: data.encryption.type + - Sync Agents: data.sync_agent_display + type: list + options: + delimiter: ', ' is_optional: true - - Networking: data.network_access_policy_display + - Diagnostic Setting Name: data.diagnostic_settings_resource.name is_optional: true - - Max Shares: data.max_shares + - Diagnostic Setting Storage Account: data.diagnostic_settings_resource.storage_account_id is_optional: true - - Time Created: data.time_created + - Event Hub: data.diagnostic_settings_resource.event_hub_name + is_optional: true + - Log Analytics Workspace: data.diagnostic_settings_resource.workspace_id is_optional: true tabs.0: - name: Disks + name: SQL Databases type: item fields: - Name: name - - Storage Account Type: instance_type - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - Status: data.status type: enum enums: - - ActiveSAS: + - Online: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Creating: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Copying: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - OnlineChangingDwPerformanceTiers: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Restoring: icon_image: ic_circle-filled icon_color: green.500 type: state - - ActiveUpload: + - Resuming: icon_image: ic_circle-filled icon_color: green.500 type: state - - Attached: + - Scaling: icon_image: ic_circle-filled icon_color: green.500 type: state - - Reserved: + - Standby: icon_image: ic_circle-filled icon_color: green.500 type: state - - ReadyToUpload: + - AutoClosed: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unattached: + - Inaccessible: icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: yellow.500 + type: state + - Offline: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - OfflineChangingDwPerformanceTiers: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - OfflineSecondary: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Pausing: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Recovering: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - RecoveryPending: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Suspect: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - Paused: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - Shutdown: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - EmergencyMode: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 type: state - - Attached VM: data.managed_by - - Location: data.location - - Resource Group: data.resource_group - Resource ID: data.id - - Zones: data.zones - - Subscription ID: data.subscription_id - - Subscription Name: data.subscription_name - - Encryption Type: data.encryption.type - - Networking: data.network_access_policy_display - - Os Type: data.os_type - - Max Shares: data.max_shares - - VM Generation: data.hyper_v_generation - - VM architecture: data.supported_capabilities.architecture - - DateTimeDyField.data_sourceTime Created: data.time_created + - Resource Group: data.resource_group + - Location: data.location + - Subscription ID: account + - Server Name: data.server_name + - Elastic Pool: data.elastic_pool_id + - Pricing Tier: data.pricing_tier_display + - Earliest Restore Point: data.earliest_restore_date + source_type: iso8601 + type: datetime + - Collation: data.collation + - Creation Date: data.creation_date source_type: iso8601 type: datetime + - Server Admin Login: data.administrator_login tabs.1: - name: Configuration + name: Configure + type: item + fields: + - Service Tier: data.service_tier_display + - Compute Tier: data.compute_tier + - Compute Hardware: data.sku.family + - Licence Type: data.license_type + - vCores: data.current_sku.capacity + - Data max size: instance_size + - Zone Redundant: data.zone_redundant + - Sync Groups: data.sync_group_display + type: list + options: + delimiter: ', ' + - Sync Agents: data.sync_agent_display + type: list + options: + delimiter: ', ' + - Collation: data.collation + - Creation Date: data.creation_date + source_type: iso8601 + type: datetime + + + +tabs.2: + name: Backups + type: table + root_path: data + fields: + - Database: name + - Earliest PITR Restore Point (UTC): earliest_restore_date + - Available LTR backups: long_term_retention_backup_resource_id + + + +tabs.3: + name: Replication + type: table + root_path: data.replication_link + fields: + - Name: name + - linkType: link_type + - Region: partner_location + - Replica state: replica_state + + + +tabs.4: + name: Sync to other databases items: - - name: Shared Disk - type: item + - name: Sync Group + type: table + root_path: data.sync_group fields: - - Enable shared disk: data.enable_shared_disk_display - - Max shares: data.max_shares - - name: On-demand bursting - type: item + - Name: name + - Status: sync_state + - Use private link: use_private_link_connection + - Automatic Sync: automatic_sync + - Conflict Resolution: conflict_resolution_policy + - Interval: interval + - name: Sync Agent + type: table + root_path: data.sync_agent fields: - - Enable bursting: data.bursting_enabled - - Enable bursting time: data.bursting_enabled_time - source_type: iso8601 - type: datetime + - Name: name + - Status: state + - version: version -tabs.2: - name: Networking +tabs.5: + name: Auditing type: item fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - Enable SQL Auditing: data.database_auditing_settings.state + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Audit Log Destination: data.database_auditing_settings.storage_endpoint + - Storage Account ID: data.database_auditing_settings.storage_account_subscription_id + - Retention days: data.database_auditing_settings.retention_days + - Secondary Storage access key used: data.database_auditing_settings.is_storage_secondary_key_in_use + - Storage Authentication Type: data.database_auditing_settings.storage_account_access_key + + + +tabs.6: + name: Diagnostic Settings + type: simple-table + root_path: data.diagnostic_settings_resource + fields: + - Name: name + - Storage Account: storage_account_id + - Event Hub: event_hub_name + - Log Analytics Workspace: workspace_id \ No newline at end of file diff --git a/src/plugin/metadata/sql_servers/server.yaml b/src/plugin/metadata/sql_servers/server.yaml index 6afcc410..5b325b23 100644 --- a/src/plugin/metadata/sql_servers/server.yaml +++ b/src/plugin/metadata/sql_servers/server.yaml @@ -1,19 +1,63 @@ search: fields: - - Tier: data.tier + - Subscription ID: account - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id - Resource Group: data.resource_group - Location: data.location - - Zone: data.zones - - Last updated at: data.last_updated - - Storage Account Type: data.sku.name - - Disk Size (Bytes): data.disk_size_bytes - - Disk Size (GB): data.disk_size_gb - - Disk IOPS: data.disk_iops_read_write - - OS Type: data.os_type - - Provisioning State: data.provisioning_state - - Time Created: data.time_created + - Server Admin: data.administrator_login + - Active Directory Admin: data.azure_ad_admin_name + - Server Name: data.fully_qualified_domain_name + - Failover Group ID: data.failover_groups.id + - Failover Group Name: data.failover_groups.name + - Failover Groups Primary Server: data.failover_groups.primary_server + - Failover Groups Secondary Server: data.failover_groups.secondary_server + - Read/Write Failover Policy: data.failover_groups.failover_policy_display + - Grace Period (minutes): data.failover_groups.grace_period_display + data_type: integer + - Backup Database: data.databases.name + - Backup Earliest PITR Restore Point (UTC): data.databases.earliest_restore_date + source_type: iso8601 + type: datetime + - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id + - Elastic Pool Name: data.elastic_pools.name + - Elastic Pool Resource Group: data.elastic_pools.resource_group_display + - Per DB Settings: data.elastic_pools.per_db_settings_display + - Pricing Tier: data.elastic_pools.pricing_tier_display + - Number of DBs: data.elastic_pools.number_of_databases + data_type: integer + - Elastic Pool Unit: data.elastic_pools.unit_display + - Elastic Pool Server Name: data.elastic_pools.server_name_display + - Elastic Pool Resource Configuration: data.elastic_pools.pricing_tier_display + - Elastic Pool Maximum Storage Size: data.elastic_pools.max_size_gb + - Deleted Database: data.deleted_databases.database_name + - Deletion Time (UTC): data.deleted_databases.deletion_date + source_type: iso8601 + type: datetime + - Deleted Databases Creation Time (UTC): data.deleted_databases.creation_date + source_type: iso8601 + type: datetime + - Deleted Databases Edition Time (UTC): data.deleted_databases.edition + source_type: iso8601 + type: datetimecv + - Audit Log Destination: data.server_auditing_settings.storage_endpoint + - Audit Storage Account ID: data.server_auditing_settings.storage_account_subscription_id + - Minimum TLS Version: data.minimal_tls_version + - Connection Policy: data.server_auditing_settings.name + - Allow Azure Services and Resources to Access this server: data.server_auditing_settings.is_azure_monitor_target_enabled + - Firewall Rule Name: data.firewall_rules.name + - Firewall Start IP: data.firewall_rules.start_ip_address + - Firewall End IP: data.firewall_rules.end_ip_address + - Private Endpoint Connection ID: data.private_endpoint_connections.connection_id + - Private Endpoint State: data.private_endpoint_connections.status + - Private Endpoint Name: data.private_endpoint_connections.private_endpoint_name + - Request / Response Message: data.private_endpoint_connections.description + - Transparent Data Encryption: data.encryption_protectors.kind + - Encryption Key: data.encryption_protectors.server_key_name + - Encryption Key Type: data.encryption_protectors.server_key_type + - Encryption URI: data.encryption_protectors.uri + - Tuning Type: data.server_automatic_tuning.options.tuning_type + - Tuning Desired State: data.server_automatic_tuning.options.desired_state + - Tuning Current State: data.server_automatic_tuning.options.actual_state @@ -22,136 +66,455 @@ table: key: data.id desc: false fields: - - Storage Account Type: data.sku.name - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - Status: data.state type: enum enums: - - ActiveSAS: + - Ready: icon_image: ic_circle-filled icon_color: green.500 type: state - - ActiveUpload: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: + - Disabled: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Owner: data.managed_by - Resource Group: data.resource_group - Location: data.location - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - Subscription ID: account is_optional: true - - Zone: data.zones - type: list - options: - delimiter: ', ' + - Server Admin: data.administrator_login + is_optional: true + - Active Directory Admin: data.azure_ad_admin_name + is_optional: true + - Server Name: data.fully_qualified_domain_name + is_optional: true + - Failover Group ID: data.failover_groups.id + is_optional: true + - Failover Group Name: data.failover_groups.name + is_optional: true + - Failover Groups Primary Server: data.failover_groups.primary_server + is_optional: true + - Failover Groups Secondary Server: data.failover_groups.secondary_server + is_optional: true + - Read/Write Failover Policy: data.failover_groups.failover_policy_display + is_optional: true + - Grace Period (minutes): data.failover_groups.grace_period_display + is_optional: true + - Backup Database: data.databases.name + is_optional: true + - Backup Earliest PITR Restore Point (UTC): data.databases.earliest_restore_date + is_optional: true + - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id + is_optional: true + - Elastic Pool Name: data.elastic_pools.name is_optional: true - - Encryption Type: data.encryption.type + - Elastic Pool Resource Group: data.elastic_pools.resource_group_display is_optional: true - - Networking: data.network_access_policy_display + - Per DB Settings: data.elastic_pools.per_db_settings_display is_optional: true - - Max Shares: data.max_shares + - Pricing Tier: data.elastic_pools.pricing_tier_display is_optional: true - - Time Created: data.time_created + - # of DBs: data.elastic_pools.number_of_databases + - is_optional: true + - Elastic Pool Unit: data.elastic_pools.unit_display + is_optional: true + - Elastic Pool Server Name: data.elastic_pools.server_name_display + is_optional: true + - Elastic Pool Resource Configuration: data.elastic_pools.pricing_tier_display + is_optional: true + - Elastic Pool Maximum Storage Size: data.elastic_pools.max_size_gb + is_optional: true + - Deleted Database: data.deleted_databases.database_name + is_optional: true + - Deletion Time (UTC): data.deleted_databases.deletion_date + is_optional: true + - Deleted Databases Creation Time (UTC): data.deleted_databases.creation_date + is_optional: true + - Deleted Databases Edition Time (UTC): data.deleted_databases.edition + is_optional: true + - Audit Log Destination: data.server_auditing_settings.storage_endpoint + is_optional: true + - Audit Storage Account ID: data.server_auditing_settings.storage_account_subscription_id + is_optional: true + - Minimum TLS Version: data.minimal_tls_version + is_optional: true + - Connection Policy: data.server_auditing_settings.name + is_optional: true + - Allow Azure Services and Resources to Access this server: data.server_auditing_settings.is_azure_monitor_target_enabled + is_optional: true + - Firewall Rule Name: data.firewall_rules.name + is_optional: true + - Firewall Start IP: data.firewall_rules.start_ip_address + is_optional: true + - Firewall End IP: data.firewall_rules.end_ip_address + is_optional: true + - Private Endpoint Connection ID: data.private_endpoint_connections.connection_id + is_optional: true + - Private Endpoint State: data.private_endpoint_connections.status + is_optional: true + - Private Endpoint Name: data.private_endpoint_connections.private_endpoint_name + is_optional: true + - Request / Response Message: data.private_endpoint_connections.description + is_optional: true + - Transparent Data Encryption: data.encryption_protectors.kind + is_optional: true + - Encryption Key: data.encryption_protectors.server_key_name + is_optional: true + - Encryption Key Type: data.encryption_protectors.server_key_type + is_optional: true + - Encryption URI: data.encryption_protectors.uri + is_optional: true + - Tuning Type: data.server_automatic_tuning.options.tuning_type + is_optional: true + - Tuning Desired State: data.server_automatic_tuning.options.desired_state + is_optional: true + - Tuning Current State: data.server_automatic_tuning.options.actual_state is_optional: true tabs.0: - name: Disks + name: SQL Servers type: item fields: - Name: name - - Storage Account Type: instance_type - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - Resource Group: data.resource_group + - Resource ID: data.id + - Status: data.state type: enum enums: - - ActiveSAS: + - Ready: icon_image: ic_circle-filled icon_color: green.500 type: state - - ActiveUpload: + - Disabled: icon_image: ic_circle-filled - icon_color: green.500 + icon_color: yellow.500 type: state - - Attached: + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - Server Admin: data.administrator_login + - Active Directory Admin: data.azure_ad_admin_name + - Server Name: data.fully_qualified_domain_name + + + +tabs.1: + name: Failover Groups + type: table + root_path: data.failover_groups + fields: + - ID: id + - Name: name + - Primary Server: primary_server + - Secondary Server: secondary_server + - Read/Write Failover Policy: failover_policy_display + - Grace Period (minutes): grace_period_display + + + +tabs.2: + name: Backups + type: table + root_path: data.databases + fields: + - Database: name + - Earliest PITR Restore Point (UTC): earliest_restore_date + - Available LTR backups: long_term_retention_backup_resource_id + + + +tabs.3: + name: Active Directory Admin + type: item + fields: + - Active Directory Admin: data.azure_ad_admin_name + + + +tabs.4: + name: SQL Databases + items: + - name: Databases + type: table + root_path: data.databases + fields: + - Database: name + - Resource ID: id + - Status: status + type: enum + enums: + - Online: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Creating: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Copying: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - OnlineChangingDwPerformanceTiers: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Restoring: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Resuming: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Scaling: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Standby: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - AutoClosed: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Inaccessible: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Offline: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - OfflineChangingDwPerformanceTiers: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - OfflineSecondary: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Pausing: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Recovering: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - RecoveryPending: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Suspect: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - Paused: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - Shutdown: + icon_image: ic_circle-filled + icon_color: gray.400 + type: state + - EmergencyMode: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Resource Group: resource_group + - Subscription ID: subscription_id + - Location: location + - Server Name: server_name + - Elastic Pool: + - Pricing Tier: pricing_tier_display + - Earliest Restore Point: earliest_restore_date + - name: Databases Configure + type: table + root_path: data.databases + fields: + - Service Tier: service_tier_display + - Compute Tier: compute_tier + - Compute Hardware: sku.family + - License Type: license_type + - vCores: sku.capacity + - Data Max Size: max_size_gb + - Zone Redundant: zone_redundant + - Sync Groups: sync_group_display + type: list + options: + delimiter: ', ' + - Sync Agents: sync_agent_display + type: list + options: + delimiter: ', ' + - Collation: collation + - Creation Date: creation_date + source_type: iso8601 + type: datetime + - name: Tags + type: table + root_path: data.tags + fields: + - Key: key + - Value: value + + + +tabs.5: + name: Elastic Pools + type: table + root_path: data.elastic_pools + fields: + - Name: name + - Resource Group: resource_group_display + - Per DB Settings: per_db_settings_display + - Pricing Tier: pricing_tier_display + - # of DBs: number_of_databases + - Unit: unit_display + - Status: state + type: enum + enums: + - Ready: icon_image: ic_circle-filled icon_color: green.500 type: state - - Reserved: + - Creating: icon_image: ic_circle-filled icon_color: green.500 type: state - - ReadyToUpload: + - Disabled: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unattached: + - Server Name: server_name_display + - Resource Configuration: pricing_tier_display + - Maximum Storage Size: max_size_gb + - Tags: tags + type: list + options: + delimiter: ', ' + + +tabs.6: + name: Auditing + type: item + fields: + - Enable SQL Auditing: data.server_auditing_settings.state + type: enum + enums: + - Enabled: icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: green.500 type: state - - Attached VM: data.managed_by - - Location: data.location - - Resource Group: data.resource_group - - Resource ID: data.id - - Zones: data.zones - - Subscription ID: data.subscription_id - - Subscription Name: data.subscription_name - - Encryption Type: data.encryption.type - - Networking: data.network_access_policy_display - - Os Type: data.os_type - - Max Shares: data.max_shares - - VM Generation: data.hyper_v_generation - - VM architecture: data.supported_capabilities.architecture - - DateTimeDyField.data_sourceTime Created: data.time_created - source_type: iso8601 - type: datetime + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Audit Log Destination: data.server_auditing_settings.storage_endpoint + - Storage Account ID: data.server_auditing_settings.storage_account_subscription_id -tabs.1: - name: Configuration +tabs.7: + name: Firewalls and Network items: - - name: Shared Disk + - name: Network type: item fields: - - Enable shared disk: data.enable_shared_disk_display - - Max shares: data.max_shares - - name: On-demand bursting - type: item + - Public Network Access: data.public_network_access + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Minimum TLS Version: data.minimal_tls_version + - Connection Policy: data.server_auditing_settings.name + - Allow Azure Services and Resources to Access this server: data.server_auditing_settings.is_azure_monitor_target_enabled + - name: Firewall Rules + type: table + root_path: data.firewall_rules fields: - - Enable bursting: data.bursting_enabled - - Enable bursting time: data.bursting_enabled_time - source_type: iso8601 - type: datetime + - Rule Name: name + - Start IP: start_ip_address + - End IP: end_ip_address + - name: Virtual Network Rules + type: table + root_path: data.virtual_network_rules + fields: + - Rule Name: name + - Virtual Network: virtual_network_name_display + - Subnet ID: virtual_network_subnet_id + - Resource Group: resource_group + - Subscription: subscription_id + - State: state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - InProgress: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Initializing: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Deleting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unknown: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state -tabs.2: - name: Networking - type: item +tabs.8: + name: Private Endpoint Connections + type: table + root_path: data.private_endpoint_connections + fields: + - Connection ID: connection_id + - State: status + - Private Endpoint Name: private_endpoint_name + - Request / Response Message: description + + + +tabs.9: + name: Transparent Data Encryption + type: table + root_path: data.encryption_protectors + fields: + - Transparent Data Encryption: kind + - Key: server_key_name + - Key Type: server_key_type + - Uri: uri + + + +tabs.10: + name: Tuning Options + type: table + root_path: data.server_automatic_tuning.options fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - Tuning Type: tuning_type + - Desired State: desired_state + - Current State: actual_state \ No newline at end of file From 305366bedf8be417528964e4be4f38294002b450 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Tue, 30 Jul 2024 17:52:47 +0900 Subject: [PATCH 11/35] fix: Fix Application Gateway, SQL Servers metadata --- .../network_security_groups/__init__.py | 0 .../connector/virtual_machines/__init__.py | 0 src/plugin/manager/__init__.py | 1 + .../network_security_groups/__init__.py | 1 + .../manager/virtual_machines/__init__.py | 0 .../application_gateways/instance.yaml | 8 ++--- src/plugin/metadata/sql_servers/server.yaml | 9 +++-- .../NATGateways/Instance/namespace.yaml | 2 +- .../Instance/instance_count.yaml | 30 ++++++++++++++++ .../Instance/namespace.yaml | 8 +++++ .../Instance/instance_count.yaml | 34 ++++++++++++++++++ .../VirtualMachines/Instance/memory_size.yaml | 35 +++++++++++++++++++ .../VirtualMachines/Instance/namespace.yaml | 8 +++++ .../VirtualMachines/Instance/vcpu_count.yaml | 30 ++++++++++++++++ .../instance_count.yaml | 0 .../{instance => Instance}/namespace.yaml | 0 16 files changed, 156 insertions(+), 10 deletions(-) create mode 100644 src/plugin/connector/network_security_groups/__init__.py create mode 100644 src/plugin/connector/virtual_machines/__init__.py create mode 100644 src/plugin/manager/network_security_groups/__init__.py create mode 100644 src/plugin/manager/virtual_machines/__init__.py create mode 100644 src/plugin/metrics/NetworkSecurityGroups/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/NetworkSecurityGroups/Instance/namespace.yaml create mode 100644 src/plugin/metrics/VirtualMachines/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/VirtualMachines/Instance/memory_size.yaml create mode 100644 src/plugin/metrics/VirtualMachines/Instance/namespace.yaml create mode 100644 src/plugin/metrics/VirtualMachines/Instance/vcpu_count.yaml rename src/plugin/metrics/VirtualNetworks/{instance => Instance}/instance_count.yaml (100%) rename src/plugin/metrics/VirtualNetworks/{instance => Instance}/namespace.yaml (100%) diff --git a/src/plugin/connector/network_security_groups/__init__.py b/src/plugin/connector/network_security_groups/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/virtual_machines/__init__.py b/src/plugin/connector/virtual_machines/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 86d45c99..84b7d5b0 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -6,3 +6,4 @@ from .application_gatways import * from .nat_gateways import * from .container_instances import * +from .network_security_groups import * diff --git a/src/plugin/manager/network_security_groups/__init__.py b/src/plugin/manager/network_security_groups/__init__.py new file mode 100644 index 00000000..a700acfd --- /dev/null +++ b/src/plugin/manager/network_security_groups/__init__.py @@ -0,0 +1 @@ +from .instance_manager import NetworkSecurityGroupsManager \ No newline at end of file diff --git a/src/plugin/manager/virtual_machines/__init__.py b/src/plugin/manager/virtual_machines/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/metadata/application_gateways/instance.yaml b/src/plugin/metadata/application_gateways/instance.yaml index 41d29159..38a4f281 100644 --- a/src/plugin/metadata/application_gateways/instance.yaml +++ b/src/plugin/metadata/application_gateways/instance.yaml @@ -172,11 +172,11 @@ tabs.2: - Firewall Status Enabled: data.web_application_firewall_configuration.enabled type: enum enums: - - True: + - 'True': icon_image: ic_circle-filled icon_color: green.500 type: state - - False: + - 'False': icon_image: ic_circle-filled icon_color: yellow.500 type: state @@ -184,11 +184,11 @@ tabs.2: - Inspect Request Body: data.web_application_firewall_configuration.request_body_check type: enum enums: - - True: + - 'True': icon_image: ic_circle-filled icon_color: green.500 type: state - - False: + - 'False': icon_image: ic_circle-filled icon_color: yellow.500 type: state diff --git a/src/plugin/metadata/sql_servers/server.yaml b/src/plugin/metadata/sql_servers/server.yaml index 5b325b23..18620372 100644 --- a/src/plugin/metadata/sql_servers/server.yaml +++ b/src/plugin/metadata/sql_servers/server.yaml @@ -23,7 +23,7 @@ search: - Elastic Pool Resource Group: data.elastic_pools.resource_group_display - Per DB Settings: data.elastic_pools.per_db_settings_display - Pricing Tier: data.elastic_pools.pricing_tier_display - - Number of DBs: data.elastic_pools.number_of_databases + - '# of DBs': data.elastic_pools.number_of_databases data_type: integer - Elastic Pool Unit: data.elastic_pools.unit_display - Elastic Pool Server Name: data.elastic_pools.server_name_display @@ -114,8 +114,8 @@ table: is_optional: true - Pricing Tier: data.elastic_pools.pricing_tier_display is_optional: true - - # of DBs: data.elastic_pools.number_of_databases - - is_optional: true + - '# of DBs': data.elastic_pools.number_of_databases + is_optional: true - Elastic Pool Unit: data.elastic_pools.unit_display is_optional: true - Elastic Pool Server Name: data.elastic_pools.server_name_display @@ -334,7 +334,6 @@ tabs.4: - Subscription ID: subscription_id - Location: location - Server Name: server_name - - Elastic Pool: - Pricing Tier: pricing_tier_display - Earliest Restore Point: earliest_restore_date - name: Databases Configure @@ -378,7 +377,7 @@ tabs.5: - Resource Group: resource_group_display - Per DB Settings: per_db_settings_display - Pricing Tier: pricing_tier_display - - # of DBs: number_of_databases + - '# of DBs': number_of_databases - Unit: unit_display - Status: state type: enum diff --git a/src/plugin/metrics/NATGateways/Instance/namespace.yaml b/src/plugin/metrics/NATGateways/Instance/namespace.yaml index dc841110..65ddbf55 100644 --- a/src/plugin/metrics/NATGateways/Instance/namespace.yaml +++ b/src/plugin/metrics/NATGateways/Instance/namespace.yaml @@ -1,5 +1,5 @@ --- -namespace_id: ns-azure-nat-gateways-instance +namespace_id: ns-azure-nat-gateways-Instance name: NATGateways/Instance resource_type: inventory.CloudService:azure.NATGateways.Instance group: azure diff --git a/src/plugin/metrics/NetworkSecurityGroups/Instance/instance_count.yaml b/src/plugin/metrics/NetworkSecurityGroups/Instance/instance_count.yaml new file mode 100644 index 00000000..bcf19aeb --- /dev/null +++ b/src/plugin/metrics/NetworkSecurityGroups/Instance/instance_count.yaml @@ -0,0 +1,30 @@ +--- +metric_id: metric-azure-network-sgs-instance +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.NetworkSecurityGroups.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + default: true + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-network-sgs-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/NetworkSecurityGroups/Instance/namespace.yaml b/src/plugin/metrics/NetworkSecurityGroups/Instance/namespace.yaml new file mode 100644 index 00000000..81a69da7 --- /dev/null +++ b/src/plugin/metrics/NetworkSecurityGroups/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-network-sgs-instance +name: NetworkSecurityGroups/Instance +resource_type: inventory.CloudService:azure.NetworkSecurityGroups.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-network-security-groups.svg +version: '1.0' diff --git a/src/plugin/metrics/VirtualMachines/Instance/instance_count.yaml b/src/plugin/metrics/VirtualMachines/Instance/instance_count.yaml new file mode 100644 index 00000000..5b0a284b --- /dev/null +++ b/src/plugin/metrics/VirtualMachines/Instance/instance_count.yaml @@ -0,0 +1,34 @@ +--- +metric_id: metric-azure-vms-instance-count +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.VirtualMachines.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.subscription.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group.resource_group_name + name: Resource Group + - key: instance_type + name: Instance Type + default: true + - key: data.compute.instance_state + name: Instance State + default: true + - key: data.os.os_type + name: OS Type + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-vms-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/VirtualMachines/Instance/memory_size.yaml b/src/plugin/metrics/VirtualMachines/Instance/memory_size.yaml new file mode 100644 index 00000000..76c3ee9c --- /dev/null +++ b/src/plugin/metrics/VirtualMachines/Instance/memory_size.yaml @@ -0,0 +1,35 @@ +--- +metric_id: metric-azure-vms-Instance-memory-size +name: Memory Size +metric_type: GAUGE +resource_type: inventory.CloudService:azure.VirtualMachines.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.subscription.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group.resource_group_name + name: Resource Group + - key: instance_type + name: Instance Type + default: true + - key: data.compute.instance_state + name: Instance State + default: true + - key: data.os.os_type + name: OS Type + fields: + value: + key: data.hardware.memory + operator: sum +unit: GB +namespace_id: ns-azure-vms-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/VirtualMachines/Instance/namespace.yaml b/src/plugin/metrics/VirtualMachines/Instance/namespace.yaml new file mode 100644 index 00000000..ffe23faa --- /dev/null +++ b/src/plugin/metrics/VirtualMachines/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-vms-instance +name: VirtualMachines/Instance +resource_type: inventory.CloudService:azure.VirtualMachines.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-vm.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/VirtualMachines/Instance/vcpu_count.yaml b/src/plugin/metrics/VirtualMachines/Instance/vcpu_count.yaml new file mode 100644 index 00000000..e16207f1 --- /dev/null +++ b/src/plugin/metrics/VirtualMachines/Instance/vcpu_count.yaml @@ -0,0 +1,30 @@ +--- +metric_id: metric-azure-vms-instance-vcpu-count +name: vCPU Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.VirtualMachines.Instance +query_options: + group_by: + - key: data.subscription.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group.resource_group_name + name: Resource Group + - key: instance_type + name: Instance Type + default: true + - key: data.compute.instance_state + name: Instance State + default: true + - key: data.os.os_type + name: OS Type + fields: + value: + key: data.hardware.core + operator: sum +unit: Core +namespace_id: ns-azure-vms-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/VirtualNetworks/instance/instance_count.yaml b/src/plugin/metrics/VirtualNetworks/Instance/instance_count.yaml similarity index 100% rename from src/plugin/metrics/VirtualNetworks/instance/instance_count.yaml rename to src/plugin/metrics/VirtualNetworks/Instance/instance_count.yaml diff --git a/src/plugin/metrics/VirtualNetworks/instance/namespace.yaml b/src/plugin/metrics/VirtualNetworks/Instance/namespace.yaml similarity index 100% rename from src/plugin/metrics/VirtualNetworks/instance/namespace.yaml rename to src/plugin/metrics/VirtualNetworks/Instance/namespace.yaml From ed72b3ce7f07c1c0505753cd6195e3c68fd399e2 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Tue, 30 Jul 2024 17:54:29 +0900 Subject: [PATCH 12/35] feat: Implement Network Security Groups Collector --- Dockerfile | 2 +- src/plugin/connector/base.py | 3 + .../network_security_groups_connector.py | 25 ++ .../virtual_machines_connector.py | 81 +++++ .../instance_manager.py | 297 ++++++++++++++++++ .../metadata/nat_gateways/instance.yaml | 226 +++++++------ .../network_security_groups/instance.yaml | 146 +++++++++ 7 files changed, 659 insertions(+), 121 deletions(-) create mode 100644 src/plugin/connector/network_security_groups/network_security_groups_connector.py create mode 100644 src/plugin/connector/virtual_machines/virtual_machines_connector.py create mode 100644 src/plugin/manager/network_security_groups/instance_manager.py create mode 100644 src/plugin/metadata/network_security_groups/instance.yaml diff --git a/Dockerfile b/Dockerfile index d812e5b0..85bb345c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ ENV SRC_DIR /tmp/src COPY pkg/*.txt ${PKG_DIR}/ RUN pip install --upgrade pip && \ pip install --upgrade -r ${PKG_DIR}/pip_requirements.txt && \ - pip install --upgrade spaceone-api spaceone-inventory==2.0.dev212 + pip install --upgrade spaceone-api spaceone-inventory==2.0.dev216 COPY src ${SRC_DIR} diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index 88a6608a..05ab9670 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -8,6 +8,7 @@ from azure.mgmt.sql import SqlManagementClient from azure.mgmt.monitor import MonitorManagementClient from azure.mgmt.containerinstance import ContainerInstanceManagementClient +from azure.mgmt.resource import ResourceManagementClient from spaceone.core.connector import BaseConnector @@ -24,6 +25,7 @@ def __init__(self, *args, **kwargs): self.sql_client = None self.monitor_client = None self.container_instance_client = None + self.resource_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -41,6 +43,7 @@ def set_connect(self, secret_data: dict): self.sql_client = SqlManagementClient(credential=credential, subscription_id=subscription_id) self.monitor_client = MonitorManagementClient(credential=credential, subscription_id=subscription_id) self.container_instance_client = ContainerInstanceManagementClient(credential=credential, subscription_id=subscription_id) + self.resource_client = ResourceManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/network_security_groups/network_security_groups_connector.py b/src/plugin/connector/network_security_groups/network_security_groups_connector.py new file mode 100644 index 00000000..d4ecac9d --- /dev/null +++ b/src/plugin/connector/network_security_groups/network_security_groups_connector.py @@ -0,0 +1,25 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class NetworkSecurityGroupsConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_all_network_security_groups(self): + return self.network_client.network_security_groups.list_all() + + def list_all_network_interfaces(self): + return self.network_client.network_interfaces.list_all() + + def get_network_interfaces(self, network_interface_name, resource_group): + return self.network_client.network_interfaces.get(network_interface_name=network_interface_name, + resource_group_name=resource_group) + + def get_subnet(self, resource_group_name, subnet_name, virtual_network_name): + return self.network_client.subnets.get(resource_group_name=resource_group_name, subnet_name=subnet_name, + virtual_network_name=virtual_network_name) diff --git a/src/plugin/connector/virtual_machines/virtual_machines_connector.py b/src/plugin/connector/virtual_machines/virtual_machines_connector.py new file mode 100644 index 00000000..01857625 --- /dev/null +++ b/src/plugin/connector/virtual_machines/virtual_machines_connector.py @@ -0,0 +1,81 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class VirtualMachinesConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_resource_groups(self): + return self.resource_client.resource_groups.list() + + def list_tenants(self): + return self.subscription_client.tenants.list() + + def list_vms_in_rg(self, resource_group_name, **query): + return list(self.compute_client.virtual_machines.list(resource_group_name=resource_group_name, **query)) + + def list_all_vms(self, **query): + return list(self.compute_client.virtual_machines.list_all(**query)) + + def get_vm(self, resource_group_name, vm_name): + return self.compute_client.virtual_machines.get(resource_group_name, vm_name, expand='instanceView') + + # todo : deprecated + def list_virtual_machine_sizes(self, location): + return self.compute_client.virtual_machine_sizes.list(location=location) + + def list_resources_in_rg(self, resource_group_name): + return self.resource_client.resources.list_by_resource_group(resource_group_name=resource_group_name) + + def list_network_interfaces(self): + return self.network_client.network_interfaces.list_all() + + def list_network_interfaces_in_rg(self, resource_group_name): + return self.network_client.network_interfaces.list(resource_group_name) + + def list_disks(self): + return self.compute_client.disks.list() + + def list_virtual_networks(self): + return self.network_client.virtual_networks.list_all() + + def list_virtual_networks_in_rg(self, resource_group_name): + return self.network_client.virtual_networks.list(resource_group_name) + + def list_public_ip_addresses(self): + return self.network_client.public_ip_addresses.list_all() + + def list_public_ip_addresses_in_rg(self, resource_group_name): + return self.network_client.public_ip_addresses.list(resource_group_name) + + def list_load_balancers(self): + return self.network_client.load_balancers.list_all() + + def list_load_balancers_in_rg(self, resource_group_name): + return self.network_client.load_balancers.list(resource_group_name) + + def list_load_balancer_network_interfaces_in_rg(self, resource_group_name, lb_name): + return self.network_client.load_balancer_network_interfaces.list(resource_group_name, lb_name) + + def list_network_security_groups(self): + return self.network_client.network_security_groups.list_all() + + def list_network_security_groups_in_rg(self, resource_group_name): + return self.network_client.network_security_groups.list(resource_group_name) + + def get_subscription_info(self, subscription_id): + return self.subscription_client.subscriptions.get(subscription_id) + + def list_scale_set_vms(self, resource_group_name, scale_set_name): + return self.compute_client.virtual_machine_scale_set_vms.list(resource_group_name, scale_set_name) + + def list_virtual_machine_scale_sets_in_rg(self, resource_group_name): + return self.compute_client.virtual_machine_scale_sets.list(resource_group_name) + + def list_skus(self): + return self.compute_client.resource_skus.list() \ No newline at end of file diff --git a/src/plugin/manager/network_security_groups/instance_manager.py b/src/plugin/manager/network_security_groups/instance_manager.py new file mode 100644 index 00000000..133bffd9 --- /dev/null +++ b/src/plugin/manager/network_security_groups/instance_manager.py @@ -0,0 +1,297 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.sql_databases.sql_databases_connector import SqlDatabasesConnector +from plugin.connector.network_security_groups.network_security_groups_connector import NetworkSecurityGroupsConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class NetworkSecurityGroupsManager(AzureBaseManager): + cloud_service_group = "NetworkSecurityGroups" + cloud_service_type = "Instance" + service_code = "/Microsoft.Network/networkSecurityGroups" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Networking"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-network-security-groups.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + network_security_groups_conn = NetworkSecurityGroupsConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + network_security_groups = network_security_groups_conn.list_all_network_security_groups() + network_interfaces = [ + self.convert_nested_dictionary(ni) + for ni in network_security_groups_conn.list_all_network_interfaces() + ] + + for network_security_group in network_security_groups: + try: + network_security_group_dict = self.convert_nested_dictionary(network_security_group) + network_security_group_id = network_security_group_dict["id"] + inbound_rules = [] + outbound_rules = [] + + if network_security_group_dict.get("security_rules") is not None: + # update custom security rules + inbound, outbound = self.split_security_rules( + network_security_group_dict, "security_rules" + ) + for ib in inbound: + inbound_rules.append(ib) + for ob in outbound: + outbound_rules.append(ob) + + # update default security rules + if ( + network_security_group_dict.get("default_security_rules") + is not None + ): + inbound, outbound = self.split_security_rules( + network_security_group_dict, "default_security_rules" + ) + for ib in inbound: + inbound_rules.append(ib) + for ob in outbound: + outbound_rules.append(ob) + + network_security_group_dict.update( + { + "inbound_security_rules": inbound_rules, + "outbound_security_rules": outbound_rules, + } + ) + + # TODO : update network interface name + """ + # get network interfaces + if network_security_group_dict.get('network_interfaces') is not None: + new_network_interfaces_list, virtual_machines_display_str = self.get_network_interfaces(self, network_security_group_conn, network_security_group_dict['network_interfaces']) + network_security_group_dict['network_interfaces'] = new_network_interfaces_list # Remove existing list, append new list + network_security_group_dict.update({ + 'virtual_machines_display': virtual_machines_display_str + }) + """ + + virtual_machines_display_str = self.get_virtual_machine_name( + network_interfaces, network_security_group_id + ) + if virtual_machines_display_str is not None: + network_security_group_dict.update( + {"virtual_machines_display": virtual_machines_display_str} + ) + + # Change Subnet models to ID + if network_security_group_dict.get("network_interfaces") is not None: + self.replace_subnet_model_to_id( + network_security_group_dict["network_interfaces"] + ) + + # Get private ip address and public ip address + if network_security_group_dict.get("network_interfaces") is not None: + self.get_ip_addresses( + network_security_group_dict["network_interfaces"] + ) + + # Get Subnet information + if network_security_group_dict.get("subnets") is not None: + network_security_group_dict["subnets"] = self.get_subnet( + network_security_groups_conn, + network_security_group_dict["subnets"], + ) + if network_security_group_dict.get("subnets"): + for subnet in network_security_group_dict["subnets"]: + subnet.update( + { + "virtual_network": self.get_virtual_network( + subnet["id"] + ) + } + ) + + # update application_gateway_dict + network_security_group_dict = self.update_tenant_id_from_secret_data( + network_security_group_dict, secret_data + ) + network_security_group_dict.update( + { + "resource_group": self.get_resource_group_from_id( + network_security_group_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": network_security_group_id}, + } + ) + + self.set_region_code(network_security_group_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=network_security_group_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=network_security_group_dict, + account=secret_data["subscription_id"], + region_code=network_security_group_dict["location"], + reference=self.make_reference(network_security_group_dict.get("id")), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_network_interfaces( + self, network_security_group_conn, network_interfaces_list + ): + network_interfaces_new_list = [] + virtual_machines_display_list = [] + virtual_machines_str = "" + + for network_interface in network_interfaces_list: + resource_group = network_interface["id"].split("/")[4] + network_interface_name = network_interface["id"].split("/")[ + 8 + ] # TODO : network interface name diverse + network_interface_obj = network_security_group_conn.get_network_interfaces( + network_interface_name, resource_group + ) + network_interface_dict = self.convert_nested_dictionary( + network_interface_obj + ) + + if network_interface_dict["id"] == network_interface["id"]: + # Get virtual machine display + if network_interface_dict.get("virtual_machine") is not None: + virtual_machine_display = network_interface_dict["virtual_machine"][ + "id" + ].split("/")[8] + virtual_machines_display_list.append(virtual_machine_display) + network_interface_dict.update( + {"virtual_machine_display": virtual_machine_display} + ) + network_interfaces_new_list.append(network_interface_dict) + virtual_machines_str = ", ".join(virtual_machines_display_list) + + return network_interfaces_new_list, virtual_machines_str + + def get_subnet(self, network_security_group_conn, subnets_list): + subnets_full_list = [] + if subnets_list: + for subnet in subnets_list: + resource_group_name = subnet["id"].split("/")[4] + subnet_name = subnet["id"].split("/")[10] + virtual_network_name = subnet["id"].split("/")[8] + + subnet_obj = network_security_group_conn.get_subnet( + resource_group_name, subnet_name, virtual_network_name + ) + subnet_dict = self.convert_nested_dictionary(subnet_obj) + subnets_full_list.append(subnet_dict) + + return subnets_full_list + return + + @staticmethod + def split_security_rules(network_security_group_dict, mode): + inbound_security_rules = [] + outbound_security_rules = [] + rule_list = [] + + if mode == "security_rules": + rule_list = network_security_group_dict["security_rules"] + elif mode == "default_security_rules": + rule_list = network_security_group_dict["default_security_rules"] + + for security_rule in rule_list: + if security_rule.get("direction", "") == "Inbound": + inbound_security_rules.append(security_rule) + elif security_rule.get("direction", "") == "Outbound": + outbound_security_rules.append(security_rule) + + return inbound_security_rules, outbound_security_rules + + @staticmethod + def replace_subnet_model_to_id(network_interfaces_list): + for network_interface in network_interfaces_list: + if network_interface.get("ip_configurations") is not None: + for ip_configuration in network_interface["ip_configurations"]: + ip_configuration["subnet"] = ip_configuration.get("subnet", {}).get( + "id", "" + ) + return + + @staticmethod + def get_ip_addresses(network_interfaces_list): + if network_interfaces_list: + for network_interface in network_interfaces_list: + if network_interface.get("ip_configurations") is not None: + for ip_configuration in network_interface["ip_configurations"]: + private_ip_address = ip_configuration["private_ip_address"] + network_interface.update( + {"private_ip_address": private_ip_address} + ) + + if ip_configuration.get("public_ip_address") is not None: + public_ip_address = ip_configuration["public_ip_address"][ + "id" + ].split("/")[8] + network_interface.update( + { + "public_ip_address": public_ip_address, + } + ) + return + + @staticmethod + def get_virtual_network(subnet_id): + virtual_network = subnet_id.split("/")[8] + return virtual_network + + @staticmethod + def get_virtual_machine_name(network_interfaces:list, network_security_group_id:str): + virtual_machine_name = None + for network_interface_info in network_interfaces: + if _network_security_group := network_interface_info.get("network_security_group"): + if ( + _network_security_group["id"].split("/")[-1] + == network_security_group_id.split("/")[-1] + ): + virtual_machine_name = network_interface_info["virtual_machine"]["id"].split("/")[-1] + return virtual_machine_name + return virtual_machine_name + diff --git a/src/plugin/metadata/nat_gateways/instance.yaml b/src/plugin/metadata/nat_gateways/instance.yaml index 6afcc410..7b8f49d3 100644 --- a/src/plugin/metadata/nat_gateways/instance.yaml +++ b/src/plugin/metadata/nat_gateways/instance.yaml @@ -1,157 +1,143 @@ search: fields: - - Tier: data.tier + - Subscription ID: account - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id - Resource Group: data.resource_group - Location: data.location - - Zone: data.zones - - Last updated at: data.last_updated - - Storage Account Type: data.sku.name - - Disk Size (Bytes): data.disk_size_bytes - - Disk Size (GB): data.disk_size_gb - - Disk IOPS: data.disk_iops_read_write - - OS Type: data.os_type - - Provisioning State: data.provisioning_state - - Time Created: data.time_created - - + - Virtual Machines: data.virtual_machines_display + - Inbound Rule Priority: data.inbound_security_rules.priority + - Inbound Rule Name: data.inbound_security_rules.name + - Inbound Rule Port: data.inbound_security_rules.destination_port_range + - Inbound Rule Protocol: data.inbound_security_rules.protocol + - Inbound Rule Source: data.inbound_security_rules.source_address_prefix + - Inbound Rule Destination: data.inbound_security_rules.destination_address_prefix + - Inbound Rule Action: data.inbound_security_rules.access + - Outbound Rule Priority: data.outbound_security_rules.priority + - Outbound Rule Name: data.outbound_security_rules.name + - Outbound Rule Port: data.outbound_security_rules.destination_port_range + - Outbound Rule Protocol: data.outbound_security_rules.protocol + - Outbound Rule Source: data.outbound_security_rules.source_address_prefix + - Outbound Rule Destination: data.outbound_security_rules.destination_address_prefix + - Outbound Rule Action: data.outbound_security_rules.access + - Network Interface Name: data.network_interfaces.name + - Network Interface Public IP Address: data.network_interfaces.public_ip_address + - Network Interface Private IP Address: data.network_interfaces.private_ip_address + - Subnet Name: data.subnets.name + - Subnet Address Range: data.subnets.address_prefix + - Virtual Network: data.subnets.virtual_network table: sort: key: data.id desc: false fields: - - Storage Account Type: data.sku.name - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state - type: enum - enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Owner: data.managed_by - Resource Group: data.resource_group - Location: data.location + - Subscription ID: account - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - Virtual Machines: data.virtual_machines_display + - Inbound Rule Priority: data.inbound_security_rules.priority + is_optional: true + - Inbound Rule Name: data.inbound_security_rules.name + is_optional: true + - Inbound Rule Port: data.inbound_security_rules.destination_port_range + is_optional: true + - Inbound Rule Protocol: data.inbound_security_rules.protocol + is_optional: true + - Inbound Rule Source: data.inbound_security_rules.source_address_prefix + is_optional: true + - Inbound Rule Destination: data.inbound_security_rules.destination_address_prefix + is_optional: true + - Inbound Rule Action: data.inbound_security_rules.access + is_optional: true + - Outbound Rule Priority: data.outbound_security_rules.priority is_optional: true - - Zone: data.zones - type: list - options: - delimiter: ', ' + - Outbound Rule Name: data.outbound_security_rules.name is_optional: true - - Encryption Type: data.encryption.type + - Outbound Rule Port: data.outbound_security_rules.destination_port_range is_optional: true - - Networking: data.network_access_policy_display + - Outbound Rule Protocol: data.outbound_security_rules.protocol is_optional: true - - Max Shares: data.max_shares + - Outbound Rule Source: data.outbound_security_rules.source_address_prefix is_optional: true - - Time Created: data.time_created + - Outbound Rule Destination: data.outbound_security_rules.destination_address_prefix + is_optional: true + - Outbound Rule Action: data.outbound_security_rules.access + is_optional: true + - Network Interface Name: data.network_interfaces.name + is_optional: true + - Network Interface Public IP Address: data.network_interfaces.public_ip_address + is_optional: true + - Network Interface Private IP Address: data.network_interfaces.private_ip_address + is_optional: true + - Subnet Name: data.subnets.name + is_optional: true + - Subnet Address Range: data.subnets.address_prefix + is_optional: true + - Virtual Network: data.subnets.virtual_network is_optional: true tabs.0: - name: Disks + name: Network Security Group type: item fields: - Name: name - - Storage Account Type: instance_type - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state - type: enum - enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Attached VM: data.managed_by - - Location: data.location - - Resource Group: data.resource_group - Resource ID: data.id - - Zones: data.zones - - Subscription ID: data.subscription_id - - Subscription Name: data.subscription_name - - Encryption Type: data.encryption.type - - Networking: data.network_access_policy_display - - Os Type: data.os_type - - Max Shares: data.max_shares - - VM Generation: data.hyper_v_generation - - VM architecture: data.supported_capabilities.architecture - - DateTimeDyField.data_sourceTime Created: data.time_created - source_type: iso8601 - type: datetime + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account tabs.1: - name: Configuration - items: - - name: Shared Disk - type: item - fields: - - Enable shared disk: data.enable_shared_disk_display - - Max shares: data.max_shares - - name: On-demand bursting - type: item - fields: - - Enable bursting: data.bursting_enabled - - Enable bursting time: data.bursting_enabled_time - source_type: iso8601 - type: datetime + name: Inbound Security Rules + type: table + root_path: data.inbound_security_rules + fields: + - Priority: priority + - Name: name + - Port: destination_port_range + - Protocol: protocol + - Source: source_address_prefix + - Destination: destination_address_prefix + - Action: access tabs.2: - name: Networking - type: item + name: Outbound Security Rules + type: table + root_path: data.outbound_security_rules fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - Priority: priority + - Name: name + - Port: destination_port_range + - Protocol: protocol + - Source: source_address_prefix + - Destination: destination_address_prefix + - Action: access + + +tabs.3: + name: Network Interfaces + type: table + root_path: data.network_interfaces + fields: + - Name: name + - Public IP Address: public_ip_address + - Private IP Address: private_ip_address + - Virtual Machine: virtual_machine_display + + + +tabs.4: + name: Subnets + type: table + root_path: data.subnets + fields: + - Name: name + - Address Range: address_prefix + - Virtual Network: virtual_network diff --git a/src/plugin/metadata/network_security_groups/instance.yaml b/src/plugin/metadata/network_security_groups/instance.yaml new file mode 100644 index 00000000..1a28ac7d --- /dev/null +++ b/src/plugin/metadata/network_security_groups/instance.yaml @@ -0,0 +1,146 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Virtual Machines: data.virtual_machines_display + - Inbound Rule Priority: data.inbound_security_rules.priority + - Inbound Rule Name: data.inbound_security_rules.name + - Inbound Rule Port: data.inbound_security_rules.destination_port_range + - Inbound Rule Protocol: data.inbound_security_rules.protocol + - Inbound Rule Source: data.inbound_security_rules.source_address_prefix + - Inbound Rule Destination: data.inbound_security_rules.destination_address_prefix + - Inbound Rule Action: data.inbound_security_rules.access + - Outbound Rule Priority: data.outbound_security_rules.priority + - Outbound Rule Name: data.outbound_security_rules.name + - Outbound Rule Port: data.outbound_security_rules.destination_port_range + - Outbound Rule Protocol: data.outbound_security_rules.protocol + - Outbound Rule Source: data.outbound_security_rules.source_address_prefix + - Outbound Rule Destination: data.outbound_security_rules.destination_address_prefix + - Outbound Rule Action: data.outbound_security_rules.access + - Network Interface Name: data.network_interfaces.name + - Network Interface Public IP Address: data.network_interfaces.public_ip_address + - Network Interface Private IP Address: data.network_interfaces.private_ip_address + - Subnet Name: data.subnets.name + - Subnet Address Range: data.subnets.address_prefix + - Virtual Network: data.subnets.virtual_network + + + +table: + sort: + key: data.id + desc: false + fields: + - Resource Group: data.resource_group + - Location: data.location + - Subscription ID: account + - Subscription Name: data.subscription_name + - Virtual Machines: data.virtual_machines_display + - Inbound Rule Priority: data.inbound_security_rules.priority + is_optional: true + - Inbound Rule Name: data.inbound_security_rules.name + is_optional: true + - Inbound Rule Port: data.inbound_security_rules.destination_port_range + is_optional: true + - Inbound Rule Protocol: data.inbound_security_rules.protocol + is_optional: true + - Inbound Rule Source: data.inbound_security_rules.source_address_prefix + is_optional: true + - Inbound Rule Destination: data.inbound_security_rules.destination_address_prefix + is_optional: true + - Inbound Rule Action: data.inbound_security_rules.access + is_optional: true + - Outbound Rule Priority: data.outbound_security_rules.priority + is_optional: true + - Outbound Rule Name: data.outbound_security_rules.name + is_optional: true + - Outbound Rule Port: data.outbound_security_rules.destination_port_range + is_optional: true + - Outbound Rule Protocol: data.outbound_security_rules.protocol + is_optional: true + - Outbound Rule Source: data.outbound_security_rules.source_address_prefix + is_optional: true + - Outbound Rule Destination: data.outbound_security_rules.destination_address_prefix + is_optional: true + - Outbound Rule Action: data.outbound_security_rules.access + is_optional: true + - Network Interface Name: data.network_interfaces.name + is_optional: true + - Network Interface Public IP Address: data.network_interfaces.public_ip_address + is_optional: true + - Network Interface Private IP Address: data.network_interfaces.private_ip_address + is_optional: true + - Subnet Name: data.subnets.name + is_optional: true + - Subnet Address Range: data.subnets.address_prefix + is_optional: true + - Virtual Network: data.subnets.virtual_network + is_optional: true + + + +tabs.0: + name: Network Security Group + type: item + fields: + - Name: name + - Resource ID: data.id + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + + + +tabs.1: + name: Inbound Security Rules + type: table + root_path: data.inbound_security_rules + fields: + - Priority: priority + - Name: name + - Port: destination_port_range + - Protocol: protocol + - Source: source_address_prefix + - Destination: destination_address_prefix + - Action: access + + + +tabs.2: + name: Outbound Security Rules + type: table + root_path: data.outbound_security_rules + fields: + - Priority: priority + - Name: name + - Port: destination_port_range + - Protocol: protocol + - Source: source_address_prefix + - Destination: destination_address_prefix + - Action: access + + + +tabs.3: + name: Network Interfaces + type: table + root_path: data.network_interfaces + fields: + - Name: name + - Public IP Address: public_ip_address + - Private IP Address: private_ip_address + - Virtual Machine: virtual_machine_display + + + +tabs.4: + name: Subnets + type: table + root_path: data.subnets + fields: + - Name: name + - Address Range: address_prefix + - Virtual Network: virtual_network \ No newline at end of file From 9e93ed71955c6c75471c18e4a2ea06d0d56a440f Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 31 Jul 2024 16:47:16 +0900 Subject: [PATCH 13/35] feat: Add number_of_databases to SQL Servers metadata --- src/plugin/manager/sql_servers/server_manager.py | 4 ++++ src/plugin/metadata/sql_servers/server.yaml | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugin/manager/sql_servers/server_manager.py b/src/plugin/manager/sql_servers/server_manager.py index b6bc8127..241c8388 100644 --- a/src/plugin/manager/sql_servers/server_manager.py +++ b/src/plugin/manager/sql_servers/server_manager.py @@ -92,6 +92,9 @@ def create_cloud_service(self, options, secret_data, schema): server_name=name, server_admin_name=sql_server_dict.get("administrator_login"), ) + + number_of_databases = len(databases_list) + elastic_pools_list = self.list_elastic_pools( sql_servers_conn, resource_group_name, name ) @@ -111,6 +114,7 @@ def create_cloud_service(self, options, secret_data, schema): "server_auditing_settings": server_auditing_settings_dict, "failover_groups": failover_group_list, "server_automatic_tuning": server_automatic_tuning_dict, + "number_of_databases": number_of_databases, "databases": databases_list, "elastic_pools": elastic_pools_list, "deleted_databases": deleted_databases_list, diff --git a/src/plugin/metadata/sql_servers/server.yaml b/src/plugin/metadata/sql_servers/server.yaml index 18620372..847d8de1 100644 --- a/src/plugin/metadata/sql_servers/server.yaml +++ b/src/plugin/metadata/sql_servers/server.yaml @@ -19,11 +19,13 @@ search: source_type: iso8601 type: datetime - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id + - '# of DBs': data.number_of_databases + data_type: integer - Elastic Pool Name: data.elastic_pools.name - Elastic Pool Resource Group: data.elastic_pools.resource_group_display - Per DB Settings: data.elastic_pools.per_db_settings_display - Pricing Tier: data.elastic_pools.pricing_tier_display - - '# of DBs': data.elastic_pools.number_of_databases + - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases data_type: integer - Elastic Pool Unit: data.elastic_pools.unit_display - Elastic Pool Server Name: data.elastic_pools.server_name_display @@ -106,6 +108,8 @@ table: is_optional: true - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id is_optional: true + - '# of DBs': data.number_of_databases + is_optional: true - Elastic Pool Name: data.elastic_pools.name is_optional: true - Elastic Pool Resource Group: data.elastic_pools.resource_group_display @@ -114,7 +118,7 @@ table: is_optional: true - Pricing Tier: data.elastic_pools.pricing_tier_display is_optional: true - - '# of DBs': data.elastic_pools.number_of_databases + - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases is_optional: true - Elastic Pool Unit: data.elastic_pools.unit_display is_optional: true From 10fe166804d849f2ddb2900149869ebb0193e307 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 31 Jul 2024 16:52:54 +0900 Subject: [PATCH 14/35] feat: Implement Storage Accounts, Snapshots Collector --- src/plugin/connector/base.py | 3 + src/plugin/connector/snapshots/__init__.py | 0 .../snapshots/snapshots_connector.py | 14 + .../connector/storage_accounts/__init__.py | 0 .../storage_accounts_connector.py | 19 + src/plugin/main.py | 1 - src/plugin/manager/__init__.py | 2 + .../network_security_groups/__init__.py | 2 +- src/plugin/manager/snapshots/__init__.py | 1 + .../manager/snapshots/instance_manager.py | 205 +++++++++++ .../manager/storage_accounts/__init__.py | 1 + .../storage_accounts/instance_manager.py | 328 ++++++++++++++++++ src/plugin/metadata/snapshots/instance.yaml | 89 +++++ .../metadata/storage_accounts/instance.yaml | 219 ++++++++++++ .../metadata/virtual_networks/instance.yaml | 264 ++++++++------ .../Snapshots/Instance/instance_count.yaml | 47 +++ .../Snapshots/Instance/instance_size.yaml | 48 +++ .../metrics/Snapshots/Instance/namespace.yaml | 8 + .../StorageAccounts/Instance/blob_count.yaml | 35 ++ .../StorageAccounts/Instance/blob_size.yaml | 36 ++ .../Instance/container_count.yaml | 36 ++ .../Instance/instance_count.yaml | 35 ++ .../StorageAccounts/Instance/namespace.yaml | 8 + 23 files changed, 1296 insertions(+), 105 deletions(-) create mode 100644 src/plugin/connector/snapshots/__init__.py create mode 100644 src/plugin/connector/snapshots/snapshots_connector.py create mode 100644 src/plugin/connector/storage_accounts/__init__.py create mode 100644 src/plugin/connector/storage_accounts/storage_accounts_connector.py create mode 100644 src/plugin/manager/snapshots/__init__.py create mode 100644 src/plugin/manager/snapshots/instance_manager.py create mode 100644 src/plugin/manager/storage_accounts/__init__.py create mode 100644 src/plugin/manager/storage_accounts/instance_manager.py create mode 100644 src/plugin/metadata/snapshots/instance.yaml create mode 100644 src/plugin/metadata/storage_accounts/instance.yaml create mode 100644 src/plugin/metrics/Snapshots/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/Snapshots/Instance/instance_size.yaml create mode 100644 src/plugin/metrics/Snapshots/Instance/namespace.yaml create mode 100644 src/plugin/metrics/StorageAccounts/Instance/blob_count.yaml create mode 100644 src/plugin/metrics/StorageAccounts/Instance/blob_size.yaml create mode 100644 src/plugin/metrics/StorageAccounts/Instance/container_count.yaml create mode 100644 src/plugin/metrics/StorageAccounts/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/StorageAccounts/Instance/namespace.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index 05ab9670..6856497e 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -9,6 +9,7 @@ from azure.mgmt.monitor import MonitorManagementClient from azure.mgmt.containerinstance import ContainerInstanceManagementClient from azure.mgmt.resource import ResourceManagementClient +from azure.mgmt.storage import StorageManagementClient from spaceone.core.connector import BaseConnector @@ -26,6 +27,7 @@ def __init__(self, *args, **kwargs): self.monitor_client = None self.container_instance_client = None self.resource_client = None + self.storage_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -44,6 +46,7 @@ def set_connect(self, secret_data: dict): self.monitor_client = MonitorManagementClient(credential=credential, subscription_id=subscription_id) self.container_instance_client = ContainerInstanceManagementClient(credential=credential, subscription_id=subscription_id) self.resource_client = ResourceManagementClient(credential=credential, subscription_id=subscription_id) + self.storage_client = StorageManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/snapshots/__init__.py b/src/plugin/connector/snapshots/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/snapshots/snapshots_connector.py b/src/plugin/connector/snapshots/snapshots_connector.py new file mode 100644 index 00000000..744f7982 --- /dev/null +++ b/src/plugin/connector/snapshots/snapshots_connector.py @@ -0,0 +1,14 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class SnapshotsConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_snapshots(self): + return self.compute_client.snapshots.list() \ No newline at end of file diff --git a/src/plugin/connector/storage_accounts/__init__.py b/src/plugin/connector/storage_accounts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/storage_accounts/storage_accounts_connector.py b/src/plugin/connector/storage_accounts/storage_accounts_connector.py new file mode 100644 index 00000000..161bd025 --- /dev/null +++ b/src/plugin/connector/storage_accounts/storage_accounts_connector.py @@ -0,0 +1,19 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class StorageAccountsConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get("secret_data")) + + def list_storage_accounts(self): + return self.storage_client.storage_accounts.list() + + def list_blob_containers(self, rg_name, account_name): + return self.storage_client.blob_containers.list( + resource_group_name=rg_name, account_name=account_name + ) \ No newline at end of file diff --git a/src/plugin/main.py b/src/plugin/main.py index 97025969..ff2e8d12 100644 --- a/src/plugin/main.py +++ b/src/plugin/main.py @@ -42,7 +42,6 @@ def collector_collect(params: dict) -> Generator[dict, None, None]: cloud_service_groups = _get_cloud_service_groups_from_options_and_task_options(options, task_options) resource_type = task_options.get("resource_type") - print("test", cloud_service_groups) if resource_type == "inventory.Region": subscriptions_mgr = SubscriptionsManager() diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 84b7d5b0..4d4a59c6 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -7,3 +7,5 @@ from .nat_gateways import * from .container_instances import * from .network_security_groups import * +from .storage_accounts import * +from .snapshots import * diff --git a/src/plugin/manager/network_security_groups/__init__.py b/src/plugin/manager/network_security_groups/__init__.py index a700acfd..94a669e9 100644 --- a/src/plugin/manager/network_security_groups/__init__.py +++ b/src/plugin/manager/network_security_groups/__init__.py @@ -1 +1 @@ -from .instance_manager import NetworkSecurityGroupsManager \ No newline at end of file +from .instance_manager import NetworkSecurityGroupsManager diff --git a/src/plugin/manager/snapshots/__init__.py b/src/plugin/manager/snapshots/__init__.py new file mode 100644 index 00000000..b0e0b0de --- /dev/null +++ b/src/plugin/manager/snapshots/__init__.py @@ -0,0 +1 @@ +from .instance_manager import SnapshotsManager diff --git a/src/plugin/manager/snapshots/instance_manager.py b/src/plugin/manager/snapshots/instance_manager.py new file mode 100644 index 00000000..b084c56f --- /dev/null +++ b/src/plugin/manager/snapshots/instance_manager.py @@ -0,0 +1,205 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.snapshots.snapshots_connector import SnapshotsConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class SnapshotsManager(AzureBaseManager): + cloud_service_group = "Snapshots" + cloud_service_type = "Instance" + service_code = "/Microsoft.Compute/snapshots" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Compute", "Storage"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-disk-snapshot.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + snapshots_conn = SnapshotsConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + snapshots = snapshots_conn.list_snapshots() + for snapshot in snapshots: + try: + snapshot_dict = self.convert_nested_dictionary(snapshot) + snapshot_id = snapshot_dict["id"] + + # update sku_dict + # switch SnapshotStorageAccountType to snapshot_sku_name for user-friendly words. + # (ex.Premium_LRS -> Premium SSD, Standard HDD..) + sku_dict = snapshot_dict.get("sku", {}) + sku_dict.update( + {"name": self.get_disk_sku_name(sku_dict.get("name", ""))} + ) + + # update encryption_dict type to user-friendly words + # (ex.EncryptionAtRestWithPlatformKey -> Platform-managed key...) + if snapshot_dict.get("encryption", {}).get("type") is not None: + type = snapshot_dict["encryption"]["type"] + encryption_type = "" + if type == "EncryptionAtRestWithPlatformKey": + encryption_type = "Platform-managed key" + elif type == "EncryptionAtRestWithPlatformAndCustomerKeys": + encryption_type = "Platform and customer managed key" + elif type == "EncryptionAtRestWithCustomerKey": + encryption_type = "Customer-managed key" + + snapshot_dict["encryption"].update( + {"type_display": encryption_type} + ) + + # update snapshot_dict + snapshot_dict = self.update_tenant_id_from_secret_data( + snapshot_dict, secret_data + ) + snapshot_dict.update( + { + "resource_group": self.get_resource_group_from_id( + snapshot_id + ), # parse resource_group from ID + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "size": snapshot_dict["disk_size_bytes"], + "sku": sku_dict, + "incremental_display": self.get_incremental_display( + snapshot_dict["incremental"] + ), + "azure_monitor": {"resource_id": snapshot_id}, + "time_created": snapshot_dict["time_created"], + } + ) + + if snapshot_dict.get("network_access_policy") is not None: + snapshot_dict.update( + { + "network_access_policy_display": self.get_network_access_policy( + snapshot_dict["network_access_policy"] + ) + } + ) + + # get source_disk_name from source_resource_id + if snapshot_dict.get("creation_data") is not None: + source_resource_id = snapshot_dict["creation_data"].get( + "source_resource_id", "" + ) + snapshot_dict.update( + { + "source_disk_name": self.get_source_disk_name( + source_resource_id + ) + } + ) + + # get attached vm's name + if snapshot_dict.get("managed_by") is not None: + snapshot_dict.update( + { + "managed_by": self.get_attached_vm_name_from_managed_by( + snapshot_dict["managed_by"] + ) + } + ) + + self.set_region_code(snapshot_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=snapshot_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=snapshot_dict, + account=snapshot_dict["subscription_id"], + instance_type=snapshot_dict["sku"]["name"], + instance_size=float(snapshot_dict["disk_size_bytes"]), + region_code=snapshot_dict["location"], + reference=self.make_reference(snapshot_dict.get("id")), + tags=snapshot_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + @staticmethod + def get_attached_vm_name_from_managed_by(managed_by): + attached_vm_name = "" + if managed_by: + attached_vm_name = managed_by.split("/")[8] # parse attached_ from ID + return attached_vm_name + + @staticmethod + def get_disk_sku_name(sku_tier): + sku_name = "" + if sku_tier == "Premium_LRS": + sku_name = "Premium SSD" + elif sku_tier == "Standard_ZRS": + sku_name = "Standard zone" + elif sku_tier == "Standard_LRS": + sku_name = "Standard HDD" + + return sku_name + + @staticmethod + def get_network_access_policy(network_access_policy): + network_access_policy_display = "" + if network_access_policy == "AllowAll": + network_access_policy_display = "Public endpoint (all network)" + elif network_access_policy == "AllowPrivate": + network_access_policy_display = "Private endpoint (through disk access)" + elif network_access_policy == "DenyAll": + network_access_policy_display = "Deny all" + + return network_access_policy_display + + @staticmethod + def get_incremental_display(incremental): + if incremental is False: + incremental_display = "Full" + else: + incremental_display = "Incremental" + + return incremental_display + + @staticmethod + def get_source_disk_name(source_resource_id): + source_disk_name = "" + if source_resource_id: + source_disk_name = source_resource_id.split("/")[ + 8 + ] # parse source_disk_name from source_resource_id + return source_disk_name diff --git a/src/plugin/manager/storage_accounts/__init__.py b/src/plugin/manager/storage_accounts/__init__.py new file mode 100644 index 00000000..cda4782f --- /dev/null +++ b/src/plugin/manager/storage_accounts/__init__.py @@ -0,0 +1 @@ +from .instance_manager import StorageAccountsManager diff --git a/src/plugin/manager/storage_accounts/instance_manager.py b/src/plugin/manager/storage_accounts/instance_manager.py new file mode 100644 index 00000000..eec0162f --- /dev/null +++ b/src/plugin/manager/storage_accounts/instance_manager.py @@ -0,0 +1,328 @@ +import datetime +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.storage_accounts.storage_accounts_connector import StorageAccountsConnector +from plugin.connector.monitor.monitor_connector import MonitorConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class StorageAccountsManager(AzureBaseManager): + cloud_service_group = "StorageAccounts" + cloud_service_type = "Instance" + service_code = "/Microsoft.Storage/storageAccounts" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Storage"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-service-accounts.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + storage_accounts_conn = StorageAccountsConnector(secret_data=secret_data) + monitor_conn = MonitorConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + storage_accounts = storage_accounts_conn.list_storage_accounts() + for storage_account in storage_accounts: + try: + storage_account_dict = self.convert_nested_dictionary(storage_account) + kind = storage_account_dict.get("kind") + storage_account_id = storage_account_dict["id"] + resource_group = self.get_resource_group_from_id(storage_account_id) + + if storage_account_dict.get("network_rule_set") is not None: + storage_account_dict.update( + { + "network_rule_set": self.get_network_rule_set( + storage_account_dict["network_rule_set"] + ) + } + ) + + # https://learn.microsoft.com/en-us/rest/api/storagerp/storage-accounts/list?view=rest-storagerp-2023-01-01&tabs=HTTP#kind + if storage_account_dict.get("name") is not None and kind not in [ + "FileStorage" + ]: + container_count = self.get_blob_containers_count( + storage_accounts_conn, + resource_group, + storage_account_dict["name"], + ) + storage_account_dict.update( + {"container_count_display": container_count} + ) + if storage_account_dict.get("routing_preference") is not None: + storage_account_dict.update( + {"routing_preference_display": "Internet routing"} + ) + else: + storage_account_dict.update( + {"routing_preference_display": "Microsoft network routing"} + ) + storage_account_dict = self.update_tenant_id_from_secret_data( + storage_account_dict, secret_data + ) + storage_account_dict.update( + { + "resource_group": resource_group, + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": storage_account_id}, + "blob_count_display": self._get_blob_count_from_monitoring( + monitor_conn, storage_account_id + ), + "blob_size_display": self._get_blob_size_from_monitoring( + monitor_conn, storage_account_id + ), + } + ) + + self.set_region_code(storage_account_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=storage_account_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=storage_account_dict, + account=storage_account_dict["subscription_id"], + instance_type=storage_account_dict["sku"]["tier"], + region_code=storage_account_dict["location"], + reference=self.make_reference(storage_account_dict.get("id")), + tags=storage_account_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_public_ip_address( + self, application_gateway_conn, resource_group_name, pip_name + ): + public_ip_address_obj = application_gateway_conn.get_public_ip_addresses( + resource_group_name, pip_name + ) + public_ip_address_dict = self.convert_nested_dictionary(public_ip_address_obj) + + return public_ip_address_dict + + def get_network_rule_set(self, network_rule_dict): + if network_rule_dict.get("virtual_network_rules") is not None: + network_rule_dict.update( + { + "virtual_networks": self.get_virtual_network_names( + network_rule_dict["virtual_network_rules"] + ), + "is_public_access_allowed": False, + } + ) + if not network_rule_dict.get( + "virtual_network_rules" + ): # if virtual_network_rules are empty, this SA is public allowable + network_rule_dict.update({"is_public_access_allowed": True}) + + if network_rule_dict.get("ip_rules") is not None: + firewall_address_list = [] + for rule in network_rule_dict["ip_rules"]: + firewall_address_list.append(rule["ip_address_or_range"]) + + network_rule_dict.update({"firewall_address_range": firewall_address_list}) + + if network_rule_dict.get("resource_access_rules") is not None: + resource_access_rules_list = [] + for rule in network_rule_dict["resource_access_rules"]: + try: + resource_type = rule.get("resource_id").split("/")[6] + resource_access_rules_list.append(resource_type) + + except Exception as e: + _LOGGER.error(f"[ERROR: Azure Storage Account Network Rules]: {e}") + + network_rule_dict.update( + {"resource_access_rules_display": resource_access_rules_list} + ) + + return network_rule_dict + + def list_blob_containers(self, storage_conn, rg_name, account_name): + blob_containers_list = [] + blob_containers_obj = storage_conn.list_blob_containers( + rg_name=rg_name, account_name=account_name + ) + for blob_container in blob_containers_obj: + blob_dict = self.convert_nested_dictionary(blob_container) + blob_containers_list.append(blob_dict) + + return blob_containers_list + + def _get_blob_count_from_monitoring(self, monitor_conn, storage_account_id): + timespan = self._get_timespan_from_now(1) + aggregation = "total" + interval = "PT1H" + container_blob_count_metric = self._get_metric_data( + monitor_conn, + f"{storage_account_id}/blobServices/default", + metricnames="BlobCount", + aggregation=aggregation, + timespan=timespan, + interval=interval, + ) + + container_blob_count_metric_dict = self.convert_nested_dictionary( + container_blob_count_metric + ) + return self._get_timeseries_data_from_metric( + container_blob_count_metric_dict, aggregation + ) + + def _get_blob_size_from_monitoring(self, monitor_conn, storage_account_id): + timespan = self._get_timespan_from_now(1) + aggregation = "total" + interval = "PT1H" + container_blob_capacity_metric = self._get_metric_data( + monitor_conn, + f"{storage_account_id}/blobServices/default", + metricnames="BlobCapacity", + aggregation=aggregation, + timespan=timespan, + interval=interval, + ) + container_blob_capacity_metric_dict = self.convert_nested_dictionary( + container_blob_capacity_metric + ) + return self._get_timeseries_data_from_metric( + container_blob_capacity_metric_dict, aggregation + ) + + @staticmethod + def _get_timeseries_data_from_metric(metric_dict, aggregation): + try: + timeseries_data = metric_dict["value"][0]["timeseries"][0]["data"][0].get( + aggregation + ) + return timeseries_data if timeseries_data is not None else 0 + except Exception as e: + _LOGGER.warning(f"[_get_timeseries_data_from_metric]: {e}") + return 0 + + @staticmethod + def get_associated_listener(frontend_ip_configuration_dict, http_listeners_list): + associated_listener = "" + for http_listener in http_listeners_list: + if http_listener.get("frontend_ip_configuration") is not None: + if frontend_ip_configuration_dict["id"] in http_listener.get( + "frontend_ip_configuration", {} + ).get("id", ""): + associated_listener = http_listener.get("name", "-") + else: + associated_listener = "-" + + return associated_listener + + @staticmethod + def get_port(port_id, frontend_ports_list): + port = 0 + for fe_port in frontend_ports_list: + if port_id in fe_port["id"]: + port = fe_port.get("port", 0) + return port + else: + return port + + @staticmethod + def update_backend_pool_dict(backend_pool_list, backend_pool_id, request_rules): + for backend_pool in backend_pool_list: + if backend_pool["id"] == backend_pool_id: + backend_pool.update({"associated_rules": request_rules}) + + @staticmethod + def update_rewrite_ruleset_dict( + rewrite_rule_sets_list, rewrite_rule_id, applied_rules_list + ): + for rewrite_rule in rewrite_rule_sets_list: + if rewrite_rule["id"] == rewrite_rule_id: + rewrite_rule.update({"rules_applied": applied_rules_list}) + + @staticmethod + def update_http_listeners_list( + http_listeners_list, http_listener_id, http_applied_rules + ): + for http_listener in http_listeners_list: + if http_listener["id"] == http_listener_id: + http_listener.update({"associated_rules": http_applied_rules}) + + @staticmethod + def get_virtual_network_names(virtual_network_rules): + names = [] + try: + for virtual_network_rule in virtual_network_rules: + name = virtual_network_rule["virtual_network_resource_id"].split("/")[8] + names.append(name) + + except Exception as e: + _LOGGER.error(f"[ERROR: Azure Storage Account Network Rule Get Name]: {e}") + + return names + + @staticmethod + def _get_metric_data( + monitor_conn, + resource_uri, + metricnames, + aggregation=None, + timespan=None, + interval=None, + ): + return monitor_conn.list_metrics( + resource_uri, + metricnames=metricnames, + aggregation=aggregation, + timespan=timespan, + interval=interval, + ) + + @staticmethod + def _get_timespan_from_now(hours): + time_now = datetime.datetime.utcnow() - datetime.timedelta(hours=1) + time_now_hours_ago = time_now - datetime.timedelta(hours=hours) + return "{}/{}".format(time_now_hours_ago, time_now) + + @staticmethod + def get_blob_containers_count(storage_conn, rg_name, account_name): + blob_containers_obj = storage_conn.list_blob_containers( + rg_name=rg_name, account_name=account_name + ) + return len(list(blob_containers_obj)) diff --git a/src/plugin/metadata/snapshots/instance.yaml b/src/plugin/metadata/snapshots/instance.yaml new file mode 100644 index 00000000..4b5b9560 --- /dev/null +++ b/src/plugin/metadata/snapshots/instance.yaml @@ -0,0 +1,89 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Storage Account Type: instance_type + - Snapshot Type: data.incremental_display + - Disk Size (Bytes): data.disk_size_bytes + - Disk Size (GB): instance_size + - Encryption: data.encryption.type_display + - Network Access Policy: data.network_access_policy + - Provisioning State: data.provisioning_state + - Launched: data.time_created + + + +table: + sort: + key: data.id + desc: false + fields: + - Source disk: data.source_disk_name + - Snapshot type: data.incremental_display + - Source disk size: data.disk_size_bytes + display_unit: GB + source_unit: BYTES + type: size + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Launched: data.time_created + source_type: iso8601 + type: datetime + - Subscription ID: account + - Encryption Type: data.encryption.type_display + - Network Access Policy: data.network_access_policy_display + + + +tabs.0: + name: Snapshots + type: item + fields: + - Name: name + - Storage Type: instance_type + - Size: data.size + display_unit: GB + source_unit: BYTES + type: size + - Source Disk: data.source_disk_name + - Location: data.location + - Resource ID: data.id + - Resource Group: data.resource_group + - Snapshot state: data.disk_state + type: enum + enums: + - ActiveSAS: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ActiveUpload: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Attached: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Reserved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - ReadyToUpload: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unattached: + icon_image: ic_circle-filled + icon_color: blue.400 + type: state + - Snapshot Type: data.incremental_display + - Subscription ID: account + - Subscription Name: data.subscription_name + - Encryption Type: data.encryption.type_display + - Network Access Policy: data.network_access_policy_display + - Created Time: launched_at + source_type: iso8601 + type: datetime \ No newline at end of file diff --git a/src/plugin/metadata/storage_accounts/instance.yaml b/src/plugin/metadata/storage_accounts/instance.yaml new file mode 100644 index 00000000..4b2c6a90 --- /dev/null +++ b/src/plugin/metadata/storage_accounts/instance.yaml @@ -0,0 +1,219 @@ +search: + fields: + - Container count: data.container_count_display + - Blob count: data.blob_count_display + - Blob total size(Bytes): data.blob_size_display + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - SKU: data.sku.name + - Type: data.type + - State of Primary: data.status_of_primary + - Performance Tier: instance_type + - Access Tier: data.access_tier + - Replication: data.sku.name + - Kind of Account: data.kind + - Provisioning State: data.provisioning_state + - Is Public: data.allow_blob_public_access + - Virtual Network: data.network_acls.virtual_networks + - Firewall Address Range: data.network_acls.firewall_address_range + - Resource Instances: data.network_acls.resource_access_rules_display + - Exceptions: data.network_acls.bypass + - Routing Preference: data.routing_preference_display + - Publish Microsoft Endpoints: data.routing_preference.publish_microsoft_endpoints + - Publish Internet Endpoints: data.routing_preference.publish_internet_endpoints + - Blob: data.primary_endpoints.blob + - Queue: data.primary_endpoints.queue + - Table: data.primary_endpoints.table + - File: data.primary_endpoints.file + - Web: data.primary_endpoints.web + - DFS: data.primary_endpoints.dfs + - Microsoft Endpoints: data.routing_preference.publish_microsoft_endpoints + - Internet Endpoints: data.routing_preference.publish_internet_endpoints + - Container Name: data.container_item.name + - Container Last Modified: data.container_item.last_modified_time + - Container Public Access Level: data.container_item.public_access + - Container Lease State: data.container_item.lease_state + - Primary Location: data.primary_location + - Secondary Location: data.secondary_location + + + +table: + sort: + key: data.id + desc: false + fields: + - Container count: data.container_count_display + - Blob count: data.blob_count_display + - Blob total size: data.blob_size_display + display_unit: GB + source_unit: BYTES + type: size + - Resource Group: data.resource_group + - Location: data.location + - Subscription ID: account + - Subscription Name: data.subscription_name + - SKU: data.sku.name + - Type: data.type + - State of Primary: data.status_of_primary + is_optional: true + - Performance Tier: instance_type + is_optional: true + - Access Tier: data.access_tier + is_optional: true + - Replication: data.sku.name + is_optional: true + - Kind of Account: data.kind + is_optional: true + - Provisioning State: data.provisioning_state + is_optional: true + - Is Public: data.allow_blob_public_access + is_optional: true + - Virtual Network: data.network_acls.virtual_networks + is_optional: true + - Firewall Address Range: data.network_acls.firewall_address_range + is_optional: true + - Resource Instances: data.network_acls.resource_access_rules_display + is_optional: true + - Exceptions: data.network_acls.bypass + is_optional: true + - Routing Preference: data.routing_preference_display + is_optional: true + - Publish Microsoft Endpoints: data.routing_preference.publish_microsoft_endpoints + is_optional: true + - Publish Internet Endpoints: data.routing_preference.publish_internet_endpoints + is_optional: true + - Blob: data.primary_endpoints.blob + is_optional: true + - Queue: data.primary_endpoints.queue + is_optional: true + - Table: data.primary_endpoints.table + is_optional: true + - File: data.primary_endpoints.file + is_optional: true + - Web: data.primary_endpoints.web + is_optional: true + - DFS: data.primary_endpoints.dfs + is_optional: true + - Microsoft Endpoints: data.routing_preference.publish_microsoft_endpoints + is_optional: true + - Internet Endpoints: data.routing_preference.publish_internet_endpoints + is_optional: true + - Container Name: data.container_item.name + is_optional: true + - Container Last Modified: data.container_item.last_modified_time + is_optional: true + - Container Public Access Level: data.container_item.public_access + is_optional: true + - Container Lease State: data.container_item.lease_state + is_optional: true + - Primary Location: data.primary_location + is_optional: true + - Secondary Location: data.secondary_location + is_optional: true + + + +tabs.0: + name: Storage Account + type: item + fields: + - Name: name + - Resource ID: data.id + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - State of Primary: data.status_of_primary + - Performance Tier: instance_type + - Access Tier: data.access_tier + - Replication: data.sku.name + - Account Kind: data.kind + - Provisioning State: data.provisioning_state + - Creation Time: data.creation_time + source_type: iso8601 + type: datetime + - Container count: data.container_count_display + - Blob count: data.blob_count_display + - Blob total size: data.blob_size_display + display_unit: GB + source_unit: BYTES + type: size + + + +tabs.1: + name: Networking + type: item + fields: + - Is Public: data.network_rule_set.is_public_access_allowed + - Virtual Network: data.network_rule_set.virtual_networks + - Firewall Address Range: data.network_rule_set.firewall_address_range + type: list + options: + delimiter: ', ' + - Resource Instances: data.network_rule_set.resource_access_rules_display + type: list + options: + delimiter: ', ' + - Exceptions: data.network_rule_set.bypass + - Routing Preference: data.routing_preference_display + - Publish Microsoft Endpoints: data.routing_preference.publish_microsoft_endpoints + - Publish Internet Endpoints: data.routing_preference.publish_internet_endpoints + + + +tabs.2: + name: Primary Endpoints + type: item + fields: + - Blob: data.primary_endpoints.blob + - Queue: data.primary_endpoints.queue + - Table: data.primary_endpoints.table + - File: data.primary_endpoints.file + - Web: data.primary_endpoints.web + - DFS: data.primary_endpoints.dfs + - Microsoft Endpoints: data.routing_preference.publish_microsoft_endpoints + - Internet Endpoints: data.routing_preference.publish_internet_endpoints + + + +tabs.3: + name: Encryption + type: item + fields: + - Key Source: data.encryption.key_source + - Key Vault URI: data.encryption.key_vault_properties.key_vault_uri + + + +tabs.4: + name: Geo-Replication + type: table + fields: + - Primary Location: 'data.primary_location' + - Status of Primary: data.status_of_primary + type: enum + enums: + - available: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - unavailable: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Secondary Location: data.secondary_location + - Status of Secondary: data.status_of_secondary + type: enum + enums: + - available: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - unavailable: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state \ No newline at end of file diff --git a/src/plugin/metadata/virtual_networks/instance.yaml b/src/plugin/metadata/virtual_networks/instance.yaml index 6afcc410..5d509757 100644 --- a/src/plugin/metadata/virtual_networks/instance.yaml +++ b/src/plugin/metadata/virtual_networks/instance.yaml @@ -1,19 +1,19 @@ search: fields: - - Tier: data.tier + - Subscription ID: account - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id - Resource Group: data.resource_group - Location: data.location - - Zone: data.zones - - Last updated at: data.last_updated - - Storage Account Type: data.sku.name - - Disk Size (Bytes): data.disk_size_bytes - - Disk Size (GB): data.disk_size_gb - - Disk IOPS: data.disk_iops_read_write - - OS Type: data.os_type - - Provisioning State: data.provisioning_state - - Time Created: data.time_created + - DNS servers: data.dhcp_options.dns_servers + - Resource GUID: data.resource_guid + - Address Space: data.address_space.address_prefixes + - Connected Device: data.connected_devices.device + - Connected Device Type: data.connected_devices.type + - Connected Subnet: data.connected_devices.name + - Subnet Name: data.subnets.name + - Subnet IP Prefixes: data.subnets.address_prefixes + - Subnet Delegated To: data.subnets.delegations.name + - Subnet Network Security Group: data.subnets.network_security_group.name @@ -22,136 +22,194 @@ table: key: data.id desc: false fields: - - Storage Account Type: data.sku.name - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state - type: enum - enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Attached: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - Reserved: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ReadyToUpload: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state - - Unattached: - icon_image: ic_circle-filled - icon_color: blue.500 - type: state - - Owner: data.managed_by - Resource Group: data.resource_group - Location: data.location - Subscription Name: data.subscription_name - - Subscription ID: data.subscription_id + - Subscription ID: account is_optional: true - - Zone: data.zones + - DNS servers: data.dhcp_options.dns_servers type: list options: delimiter: ', ' is_optional: true - - Encryption Type: data.encryption.type + - Resource GUID: data.resource_guid is_optional: true - - Networking: data.network_access_policy_display + - Address Space: data.address_space.address_prefixes + type: list + options: + delimiter: ', ' + is_optional: true + - Connected Device: data.connected_devices.device is_optional: true - - Max Shares: data.max_shares + - Connected Device Type: data.connected_devices.type is_optional: true - - Time Created: data.time_created + - Connected Subnet: data.connected_devices.name + is_optional: true + - Subnet Name: data.subnets.name + is_optional: true + - Subnet IP Prefixes: data.subnets.address_prefixes + type: list + options: + delimiter: ', ' + is_optional: true + - Subnet Delegated To: data.subnets.delegations.name + is_optional: true + - Subnet Network Security Group: data.subnets.network_security_group.name + is_optional: true + - Firewall Name: data.azure_firewall.name + is_optional: true + - Firewall IP Address: data.azure_firewall.ip_configurations.private_ip_address + is_optional: true + - Firewall Subnet: data.azure_firewall.subnet + is_optional: true + - Peering Name: data.virtual_network_peerings.name + is_optional: true + - Peer: data.virtual_network_peerings.remote_virtual_network.id + is_optional: true + - Peer Gateway Transit: data.virtual_network_peerings.allow_gateway_transit + is_optional: true + - Service Endpoint: data.service_endpoints.service + is_optional: true + - Service Endpoint Subnet: data.service_endpoints.subnet + is_optional: true + - Service Endpoint Locations: data.service_endpoints.locations + is_optional: true + - Private Endpoint: data.private_endpoints.name + is_optional: true + - Private Endpoint Subnet: data.private_endpoints.subnet is_optional: true tabs.0: - name: Disks + name: Virtual Network type: item fields: - Name: name - - Storage Account Type: instance_type - - Size: data.size - display_unit: GB - source_unit: BYTES - type: size - - Disk State: data.disk_state + - Resource ID: data.id + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - DNS Servers: data.dhcp_options.dns_servers + type: list + options: + delimiter: ', ' + - DDoS Protection Standard: data.enable_ddos_protection type: enum enums: - - ActiveSAS: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - ActiveUpload: + - 'True': icon_image: ic_circle-filled icon_color: green.500 type: state - - Attached: + - 'False': icon_image: ic_circle-filled - icon_color: green.500 + icon_color: yellow.500 type: state - - Reserved: + - Resource GUID: data.resource_guid + - Address Space: data.address_space.address_prefixes + + + +tabs.1: + name: Connected Devices + type: simple-table + root_path: data.connected_devices + fields: + - Device: device + - Type: type + - Subnet: name + + + +tabs.2: + name: Subnets + type: simple-table + root_path: data.subnets + fields: + - Name: name + - IP Address Prefix: address_prefix + - IP Address Prefixes: address_prefixes + type: list + options: + delimiter: ', ' + - Delegated To: delegations.name + - Security Group: network_security_group.name + + + +tabs.3: + name: Firewall + type: simple-table + root_path: data.azure_firewall + fields: + - Name: name + - IP Address: ip_configurations.private_ip_address + - Subnet: subnet + + + +tabs.4: + name: Peerings + type: simple-table + root_path: data.virtual_network_peerings + fields: + - Name: name + - Peering Status: peering_state + type: enum + enums: + - Connected: icon_image: ic_circle-filled icon_color: green.500 type: state - - ReadyToUpload: + - Disconnected: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unattached: + - Initiated: icon_image: ic_circle-filled - icon_color: blue.500 + icon_color: yellow.500 type: state - - Attached VM: data.managed_by - - Location: data.location - - Resource Group: data.resource_group - - Resource ID: data.id - - Zones: data.zones - - Subscription ID: data.subscription_id - - Subscription Name: data.subscription_name - - Encryption Type: data.encryption.type - - Networking: data.network_access_policy_display - - Os Type: data.os_type - - Max Shares: data.max_shares - - VM Generation: data.hyper_v_generation - - VM architecture: data.supported_capabilities.architecture - - DateTimeDyField.data_sourceTime Created: data.time_created - source_type: iso8601 - type: datetime + - Peer: remote_virtual_network.id + - Gateway Transit: allow_gateway_transit -tabs.1: - name: Configuration - items: - - name: Shared Disk - type: item - fields: - - Enable shared disk: data.enable_shared_disk_display - - Max shares: data.max_shares - - name: On-demand bursting - type: item - fields: - - Enable bursting: data.bursting_enabled - - Enable bursting time: data.bursting_enabled_time - source_type: iso8601 - type: datetime +tabs.5: + name: Service Endpoints + type: simple-table + root_path: data.service_endpoints + fields: + - Service: service + - Subnet: subnet + - Status: provisioning_state + type: enum + enums: + - Succeeded: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Failed: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Deleting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Locations: locations -tabs.2: - name: Networking - type: item +tabs.6: + name: Private Endpoints + type: simple-table + root_path: data.private_endpoints fields: - - Network access: data.network_access_policy_display \ No newline at end of file + - Name: name + - Subnet: subnet + - Resource Group: resource_group diff --git a/src/plugin/metrics/Snapshots/Instance/instance_count.yaml b/src/plugin/metrics/Snapshots/Instance/instance_count.yaml new file mode 100644 index 00000000..d774af4c --- /dev/null +++ b/src/plugin/metrics/Snapshots/Instance/instance_count.yaml @@ -0,0 +1,47 @@ +--- +metric_id: metric-azure-snapshots-instance-count +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.Snapshots.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: instance_type + name: Disk Type + - key: data.provisioning_state + name: Provisioning State + - key: data.os_type + name: OS Type + - key: data.disk_state + name: Disk State + - key: data.source_disk_name + name: Source Disk Name + - key: data.supports_hibernation + name: Supports Hibernation + - key: data.supported_capabilities.architecture + name: Architecture + - key: data.hyper_v_generation + name: Hyper-V Generation + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-snapshots-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/Snapshots/Instance/instance_size.yaml b/src/plugin/metrics/Snapshots/Instance/instance_size.yaml new file mode 100644 index 00000000..a9011873 --- /dev/null +++ b/src/plugin/metrics/Snapshots/Instance/instance_size.yaml @@ -0,0 +1,48 @@ +--- +metric_id: metric-azure-snapshots-instance-size +name: Instance Size +metric_type: GAUGE +resource_type: inventory.CloudService:azure.Snapshots.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: instance_type + name: Disk Type + - key: data.provisioning_state + name: Provisioning State + - key: data.os_type + name: OS Type + - key: data.disk_state + name: Disk State + - key: data.source_disk_name + name: Source Disk Name + - key: data.supports_hibernation + name: Supports Hibernation + - key: data.supported_capabilities.architecture + name: Architecture + - key: data.hyper_v_generation + name: Hyper-V Generation + fields: + value: + key: data.disk_size_gb + operator: sum +unit: GB +namespace_id: ns-azure-snapshots-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/Snapshots/Instance/namespace.yaml b/src/plugin/metrics/Snapshots/Instance/namespace.yaml new file mode 100644 index 00000000..0ad0482b --- /dev/null +++ b/src/plugin/metrics/Snapshots/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-snapshots-instance +name: Snapshots/Instance +resource_type: inventory.CloudService:azure.Snapshots.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-disk-snapshot.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/StorageAccounts/Instance/blob_count.yaml b/src/plugin/metrics/StorageAccounts/Instance/blob_count.yaml new file mode 100644 index 00000000..bc579c81 --- /dev/null +++ b/src/plugin/metrics/StorageAccounts/Instance/blob_count.yaml @@ -0,0 +1,35 @@ +--- +metric_id: metric-azure-stg-accounts-instance-blob-count +name: Blob Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.StorageAccounts.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.kind + name: Account Kind + - key: data.access_tier + name: Access Tier + fields: + value: + key: data.blob_count_display + operator: sum +unit: Count +namespace_id: ns-azure-stg-accounts-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/StorageAccounts/Instance/blob_size.yaml b/src/plugin/metrics/StorageAccounts/Instance/blob_size.yaml new file mode 100644 index 00000000..ca447be7 --- /dev/null +++ b/src/plugin/metrics/StorageAccounts/Instance/blob_size.yaml @@ -0,0 +1,36 @@ +--- +metric_id: metric-azure-stg-accounts-instance-blob-size +name: Blob Size +metric_type: GAUGE +resource_type: inventory.CloudService:azure.StorageAccounts.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.kind + name: Account Kind + - key: data.access_tier + name: Access Tier + + fields: + value: + key: data.blob_size_display + operator: sum +unit: Bytes +namespace_id: ns-azure-stg-accounts-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/StorageAccounts/Instance/container_count.yaml b/src/plugin/metrics/StorageAccounts/Instance/container_count.yaml new file mode 100644 index 00000000..bea57a8f --- /dev/null +++ b/src/plugin/metrics/StorageAccounts/Instance/container_count.yaml @@ -0,0 +1,36 @@ +--- +metric_id: metric-azure-stg-accounts-instance-container-count +name: Container Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.StorageAccounts.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.kind + name: Account Kind + - key: data.access_tier + name: Access Tier + + fields: + value: + key: data.container_count_display + operator: sum +unit: Count +namespace_id: ns-azure-stg-accounts-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/StorageAccounts/Instance/instance_count.yaml b/src/plugin/metrics/StorageAccounts/Instance/instance_count.yaml new file mode 100644 index 00000000..cbcef9d6 --- /dev/null +++ b/src/plugin/metrics/StorageAccounts/Instance/instance_count.yaml @@ -0,0 +1,35 @@ +--- +metric_id: metric-azure-stg-accounts-instance +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.StorageAccounts.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.kind + name: Account Kind + - key: data.access_tier + name: Access Tier + + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-stg-accounts-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/StorageAccounts/Instance/namespace.yaml b/src/plugin/metrics/StorageAccounts/Instance/namespace.yaml new file mode 100644 index 00000000..bc3fccc7 --- /dev/null +++ b/src/plugin/metrics/StorageAccounts/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-stg-accounts-instance +name: StorageAccounts/Instance +resource_type: inventory.CloudService:azure.StorageAccounts.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-service-accounts.svg +version: '1.0' From 04808116cb8af8163a8ab45f12991f3443d6b8d3 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 1 Aug 2024 10:23:01 +0900 Subject: [PATCH 15/35] feat: Implement VM ScaleSets Collector --- .../connector/vm_scale_sets/__init__.py | 0 .../vm_scale_sets/vm_scale_sets_connector.py | 42 ++ src/plugin/manager/__init__.py | 1 + .../instance_manager.py | 3 +- src/plugin/manager/vm_scale_sets/__init__.py | 1 + .../vm_scale_sets/scale_set_manager.py | 478 ++++++++++++++++++ .../metadata/vm_scale_sets/scale_set.yaml | 225 +++++++++ .../VMScaleSets/ScaleSet/namespace.yaml | 8 + .../VMScaleSets/ScaleSet/sacle_set_count.yaml | 36 ++ 9 files changed, 792 insertions(+), 2 deletions(-) create mode 100644 src/plugin/connector/vm_scale_sets/__init__.py create mode 100644 src/plugin/connector/vm_scale_sets/vm_scale_sets_connector.py create mode 100644 src/plugin/manager/vm_scale_sets/__init__.py create mode 100644 src/plugin/manager/vm_scale_sets/scale_set_manager.py create mode 100644 src/plugin/metadata/vm_scale_sets/scale_set.yaml create mode 100644 src/plugin/metrics/VMScaleSets/ScaleSet/namespace.yaml create mode 100644 src/plugin/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml diff --git a/src/plugin/connector/vm_scale_sets/__init__.py b/src/plugin/connector/vm_scale_sets/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/vm_scale_sets/vm_scale_sets_connector.py b/src/plugin/connector/vm_scale_sets/vm_scale_sets_connector.py new file mode 100644 index 00000000..86e745fb --- /dev/null +++ b/src/plugin/connector/vm_scale_sets/vm_scale_sets_connector.py @@ -0,0 +1,42 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class VMScaleSetsConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get("secret_data")) + + def list_vm_scale_sets(self): + return self.compute_client.virtual_machine_scale_sets.list_all() + + def list_vm_scale_set_vms(self, resource_group, vm_scale_set_name): + return self.compute_client.virtual_machine_scale_set_vms.list( + resource_group, vm_scale_set_name + ) + + def get_vm_scale_set_instance_view( + self, resource_group, vm_scale_set_name, instance_id + ): + return self.compute_client.virtual_machine_scale_set_vms.get_instance_view( + resource_group_name=resource_group, + vm_scale_set_name=vm_scale_set_name, + instance_id="0", + ) + + def list_vm_scale_set_instance_view( + self, resource_group, vm_scale_set_name, instance_id + ): + return self.compute_client.virtual_machine_scale_set_vms.list( + resource_group_name=resource_group, + vm_scale_set_name=vm_scale_set_name, + instance_id=instance_id, + ) + + def list_auto_scale_settings(self, resource_group): + return self.monitor_client.autoscale_settings.list_by_resource_group( + resource_group_name=resource_group + ) diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 4d4a59c6..dead730c 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -9,3 +9,4 @@ from .network_security_groups import * from .storage_accounts import * from .snapshots import * +from .vm_scale_sets import * diff --git a/src/plugin/manager/network_security_groups/instance_manager.py b/src/plugin/manager/network_security_groups/instance_manager.py index 133bffd9..944919a9 100644 --- a/src/plugin/manager/network_security_groups/instance_manager.py +++ b/src/plugin/manager/network_security_groups/instance_manager.py @@ -283,7 +283,7 @@ def get_virtual_network(subnet_id): return virtual_network @staticmethod - def get_virtual_machine_name(network_interfaces:list, network_security_group_id:str): + def get_virtual_machine_name(network_interfaces: list, network_security_group_id: str): virtual_machine_name = None for network_interface_info in network_interfaces: if _network_security_group := network_interface_info.get("network_security_group"): @@ -294,4 +294,3 @@ def get_virtual_machine_name(network_interfaces:list, network_security_group_id: virtual_machine_name = network_interface_info["virtual_machine"]["id"].split("/")[-1] return virtual_machine_name return virtual_machine_name - diff --git a/src/plugin/manager/vm_scale_sets/__init__.py b/src/plugin/manager/vm_scale_sets/__init__.py new file mode 100644 index 00000000..e91926b2 --- /dev/null +++ b/src/plugin/manager/vm_scale_sets/__init__.py @@ -0,0 +1 @@ +from .scale_set_manager import VMScaleSetsManager diff --git a/src/plugin/manager/vm_scale_sets/scale_set_manager.py b/src/plugin/manager/vm_scale_sets/scale_set_manager.py new file mode 100644 index 00000000..9531a8f0 --- /dev/null +++ b/src/plugin/manager/vm_scale_sets/scale_set_manager.py @@ -0,0 +1,478 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.vm_scale_sets.vm_scale_sets_connector import VMScaleSetsConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class VMScaleSetsManager(AzureBaseManager): + cloud_service_group = "VMScaleSets" + cloud_service_type = "ScaleSet" + service_code = "/Microsoft.Compute/virtualMachineScaleSets" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Compute"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-vm-scale-set.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + vm_scale_sets_conn = VMScaleSetsConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + vm_scale_sets = vm_scale_sets_conn.list_vm_scale_sets() + for vm_scale_set in vm_scale_sets: + try: + vm_scale_set_dict = self.convert_nested_dictionary(vm_scale_set) + vm_scale_set_id = vm_scale_set_dict["id"] + + # update vm_scale_set_dict + vm_scale_set_dict.update( + { + "resource_group": self.get_resource_group_from_id( + vm_scale_set_id + ), # parse resource_group from ID + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": vm_scale_set_id}, + } + ) + + if vm_scale_set_dict.get( + "proximity_placement_group" + ): # if it has a key -> get value -> check if it isn't None / if no 'Key' -> return None + vm_scale_set_dict.update( + { + "proximity_placement_group_display": self.get_proximity_placement_group_name( + vm_scale_set_dict["proximity_placement_group"]["id"] + ) + } + ) + + # Get Instance termination notification display + if vm_scale_set_dict.get("virtual_machine_profile") is not None: + if ( + vm_scale_set_dict["virtual_machine_profile"].get( + "scheduled_events_profile" + ) + is not None + ): + if vm_scale_set.virtual_machine_profile[ + "scheduled_events_profile" + ]["terminate_notification_profile"]["enable"]: + terminate_notification_display = "On" + else: + terminate_notification_display = "Off" + vm_scale_set_dict.update( + { + "terminate_notification_display": terminate_notification_display + } + ) + # Convert disks' sku-dict to string display + if ( + vm_scale_set_dict["virtual_machine_profile"].get( + "storage_profile" + ) + is not None + ): + if vm_scale_set_dict["virtual_machine_profile"][ + "storage_profile" + ].get("image_reference"): + image_reference_dict = vm_scale_set_dict[ + "virtual_machine_profile" + ]["storage_profile"]["image_reference"] + image_reference_str = ( + str(image_reference_dict["publisher"]) + + " / " + + str(image_reference_dict["offer"]) + + " / " + + str(image_reference_dict["sku"]) + + " / " + + str(image_reference_dict["version"]) + ) + vm_scale_set_dict["virtual_machine_profile"][ + "storage_profile" + ].update({"image_reference_display": image_reference_str}) + # switch storage_account_type to storage_account_type for user-friendly words. + # (ex.Premium LRS -> Premium SSD, Standard HDD..) + if vm_scale_set_dict["virtual_machine_profile"][ + "storage_profile" + ].get("data_disks"): + for data_disk in vm_scale_set_dict[ + "virtual_machine_profile" + ]["storage_profile"]["data_disks"]: + data_disk["managed_disk"].update( + { + "storage_type": self.get_disk_storage_type( + data_disk["managed_disk"][ + "storage_account_type" + ] + ) + } + ) + # Get VM Profile's operating_system type (Linux or Windows) + if ( + vm_scale_set_dict["virtual_machine_profile"].get("os_profile") + is not None + ): + vm_scale_set_dict["virtual_machine_profile"][ + "os_profile" + ].update( + { + "operating_system": self.get_operating_system( + vm_scale_set_dict["virtual_machine_profile"][ + "os_profile" + ] + ) + } + ) + # Get VM Profile's primary Vnet\ + if ( + vm_scale_set_dict["virtual_machine_profile"].get( + "network_profile" + ) + is not None + ): + vmss_vm_network_profile_dict = vm_scale_set_dict[ + "virtual_machine_profile" + ]["network_profile"] + if primary_vnet := self.get_primary_vnet( + vmss_vm_network_profile_dict[ + "network_interface_configurations" + ] + ): + vmss_vm_network_profile_dict.update( + {"primary_vnet": primary_vnet} + ) + + # Add vm instances list attached to VMSS + vm_instances_list = list() + instance_count = 0 + resource_group = vm_scale_set_dict["resource_group"] + name = vm_scale_set_dict["name"] + + for vm_instance in vm_scale_sets_conn.list_vm_scale_set_vms( + resource_group, name + ): + instance_count += 1 + vm_scale_set_dict.update({"instance_count": instance_count}) + + vm_instance_dict = self.get_vm_instance_dict( + vm_instance, vm_scale_sets_conn, resource_group, name + ) + vm_instances_list.append(vm_instance_dict) + + vm_scale_set_dict["vm_instances"] = vm_instances_list + + # Get auto scale settings by resource group and vm id + vm_scale_set_dict.update( + { + "autoscale_settings": self.list_auto_scale_settings_obj( + vm_scale_sets_conn, resource_group, vm_scale_set_id + ) + } + ) + + # Set virtual_machine_scale_set_power_state information + if vm_scale_set_dict.get("autoscale_settings") is not None: + vm_scale_set_dict.update( + { + "virtual_machine_scale_set_power_state": self.list_virtual_machine_scale_set_power_state( + vm_scale_set_dict["autoscale_settings"] + ), + } + ) + + # update auto_scale_settings to autoscale_setting_resource_collection + auto_scale_setting_resource_col_dict = dict() + auto_scale_setting_resource_col_dict.update( + { + "value": self.list_auto_scale_settings( + vm_scale_sets_conn, resource_group, vm_scale_set_id + ) + } + ) + + vm_scale_set_dict.update( + { + "autoscale_setting_resource_collection": auto_scale_setting_resource_col_dict + } + ) + + self.set_region_code(vm_scale_set_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=vm_scale_set_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=vm_scale_set_dict, + account=vm_scale_set_dict["subscription_id"], + instance_type=vm_scale_set_dict["sku"]["name"], + region_code=vm_scale_set_dict["location"], + reference=self.make_reference(vm_scale_set_dict.get("id")), + tags=vm_scale_set_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_autoscale_rules(self, rules_dict): + rule_list = list() + for rule in rules_dict: + rule_dict = self.convert_nested_dictionary(rule) + rule_list.append(rule_dict) + return rule_list + + # Get instances of a virtual machine from a VM scale set + def get_vm_instance_dict( + self, vm_instance, vm_instance_conn, resource_group, vm_scale_set_name + ): + vm_instance_dict = self.convert_nested_dictionary(vm_instance) + + # Get Instance view of a virtual machine from a VM scale set Instance + # todo : remove + # issue ticket : https://github.com/Azure/azure-sdk-for-python/issues/35789 + # if vm_instance_dict.get("instance_id") is not None: + # vm_instance_dict.update( + # { + # "vm_instance_status_profile": self.get_vm_instance_view_dict( + # vm_instance_conn, + # resource_group, + # vm_scale_set_name, + # "0:", + # ) + # } + # ) + if vm_instance_dict.get("vm_instance_status_profile") is not None: + if ( + vm_instance_dict["vm_instance_status_profile"].get("vm_agent") + is not None + ): + vm_instance_dict.update( + { + "vm_instance_status_display": vm_instance_dict[ + "vm_instance_status_profile" + ]["vm_agent"]["display_status"] + } + ) + + # Get Primary Vnet display + if getattr(vm_instance, "network_profile_configuration") is not None: + if primary_vnet := self.get_primary_vnet( + vm_instance_dict["network_profile_configuration"][ + "network_interface_configurations" + ] + ): + vm_instance_dict.update({"primary_vnet": primary_vnet}) + + return vm_instance_dict + + # Get Instance view of a virtual machine from a VM scale set Instance + def get_vm_instance_view_dict( + self, vm_instance_conn, resource_group, vm_scale_set_name, instance_id + ): + vm_instance_status_profile = vm_instance_conn.get_vm_scale_set_instance_view( + resource_group, vm_scale_set_name, instance_id + ) + vm_instance_status_profile_dict = self.convert_nested_dictionary( + vm_instance_status_profile + ) + + if vm_instance_status_profile.vm_agent is not None: + status_str = None + + for status in vm_instance_status_profile_dict.get("vm_agent").get( + "statuses" + ): + status_str = status["display_status"] + + if status_str: + vm_instance_status_profile_dict["vm_agent"].update( + {"display_status": status_str} + ) + + return vm_instance_status_profile_dict + + def list_auto_scale_settings( + self, vm_scale_sets_conn, resource_group_name, vm_scale_set_id + ): + auto_scale_settings_list = list() + auto_scale_settings_obj = vm_scale_sets_conn.list_auto_scale_settings( + resource_group=resource_group_name + ) # List all of the Auto scaling Rules in this resource group + + """""" + for auto_scale_setting in auto_scale_settings_obj: + auto_scale_setting_dict = self.convert_nested_dictionary(auto_scale_setting) + auto_scale_setting_dict.update( + { + "profiles_display": self.get_autoscale_profiles_display( + auto_scale_setting_dict["profiles"] + ) + } + ) + if ( + auto_scale_setting_dict["target_resource_uri"].lower() + == vm_scale_set_id.lower() + ): # Compare resources' id + auto_scale_settings_list.append(auto_scale_setting_dict) + + return auto_scale_settings_list + + def get_autoscale_profiles_list(self, autoscale_setting): + profiles_list = list() + for profile in autoscale_setting.profiles: + profile_dict = self.convert_nested_dictionary(profile) + profiles_list.append(profile_dict) + + return profiles_list + + def list_virtual_machine_scale_set_power_state(self, autoscale_obj_list): + power_state_dict = dict() + power_state_list = list() + + for autoscale_setting in autoscale_obj_list: + power_state_dict.update( + { + "location": autoscale_setting.location, + "profiles": self.get_autoscale_profiles_list( + autoscale_setting + ), # profiles_list + "enabled": autoscale_setting.enabled, + "name": autoscale_setting.name, + "notifications": autoscale_setting.notifications, + "target_resource_uri": autoscale_setting.target_resource_uri, + "tags": autoscale_setting.tags, + } + ) + + if power_state_dict.get("profiles") is not None: + power_state_dict.update( + { + "profiles_display": self.get_autoscale_profiles_display( + power_state_dict["profiles"] + ) + } + ) + power_state_list.append(power_state_dict) + return power_state_list + + @staticmethod + def get_proximity_placement_group_name(placement_group_id): + placement_group_name = placement_group_id.split("/")[ + 8 + ] # parse placement_group_name from placement_group_id + return placement_group_name + + @staticmethod + def get_source_disk_name(source_resource_id): + source_disk_name = source_resource_id.split("/")[ + 8 + ] # parse source_disk_name from source_resource_id + return source_disk_name + + @staticmethod + def get_disk_storage_type(sku_tier): + if sku_tier == "Premium_LRS": + sku_name = "Premium SSD" + elif sku_tier == "StandardSSD_LRS": + sku_name = "Standard SSD" + elif sku_tier == "Standard_LRS": + sku_name = "Standard HDD" + else: + sku_name = "Ultra SSD" + return sku_name + + @staticmethod + def get_operating_system(os_profile_dictionary): + if os_profile_dictionary["linux_configuration"] is None: + operating_system = "Windows" + else: + operating_system = "Linux" + return operating_system + + @staticmethod + def get_primary_vnet(network_interface_configurations): + vnet_id = None + + # 1) Find Primary NIC + for nic in network_interface_configurations: + if nic["primary"] is True: + # 2) Find primary ip configurations + for ip_configuration in nic["ip_configurations"]: + if ip_configuration["primary"] is True: + vnet_id = ip_configuration["subnet"]["id"].split("/")[8] + + return vnet_id + + @staticmethod + def list_auto_scale_settings_obj( + vm_scale_sets_conn, resource_group_name, vm_scale_set_id + ): + auto_scale_settings_obj_list = list() + # all List of the Auto scaling Rules in this resource group + auto_scale_settings_obj = vm_scale_sets_conn.list_auto_scale_settings( + resource_group=resource_group_name + ) + + for auto_scale_setting in auto_scale_settings_obj: + if ( + auto_scale_setting.target_resource_uri.lower() + == vm_scale_set_id.lower() + ): + auto_scale_settings_obj_list.append(auto_scale_setting) + + return auto_scale_settings_obj_list + + @staticmethod + def get_autoscale_profiles_display(power_state_profiles): + profiles_list = list() + for profile in power_state_profiles: + profiles_list.append( + "minimum : " + + str(profile["capacity"]["minimum"]) + + " / " + + "maximum : " + + str( + profile["capacity"]["maximum"] + + " / " + + "default : " + + profile["capacity"]["default"] + ) + ) + + return profiles_list diff --git a/src/plugin/metadata/vm_scale_sets/scale_set.yaml b/src/plugin/metadata/vm_scale_sets/scale_set.yaml new file mode 100644 index 00000000..fae121c2 --- /dev/null +++ b/src/plugin/metadata/vm_scale_sets/scale_set.yaml @@ -0,0 +1,225 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Default: data.virtual_machine_scale_set_power_state.profiles.capacity.default + - Max: data.virtual_machine_scale_set_power_state.profiles.capacity.maximum + - Min: data.virtual_machine_scale_set_power_state.profiles.capacity.minimum + - Azure Spot Eviction Policy: data.virtual_machine_profile.eviction_policy + - Azure Spot Max Price: data.virtual_machine_profile.billing_profile.max_price + - Termination Notification: data.virtual_machine_profile.terminate_notification_display + - OverProvisioning: data.overprovision + - Proximity Placement Group: data.proximity_placement_group_display + - Automatic Repairs: data.automatic_repairs_policy.enabled + - Upgrade Policy: data.upgrade_policy.mode + - Fault Domains (count): data.platform_fault_domain_count + + + +table: + sort: + key: data.id + desc: false + fields: + - Instance Count: data.instance_count + - Resource Group: data.resource_group + - Location: data.location + - Default: data.virtual_machine_scale_set_power_state.profiles.capacity.default + - Max: data.virtual_machine_scale_set_power_state.profiles.capacity.maximum + - Min: data.virtual_machine_scale_set_power_state.profiles.capacity.minimum + - Azure Spot Eviction Policy: data.virtual_machine_profile.eviction_policy + - Subscription Name: data.subscription_name + - Subscription ID: account + is_optional: true + - Virtual network/subnet: data.virtual_machine_profile.network_profile.primary_vnet + is_optional: true + - Host group: data.host_group.id + is_optional: true + - Ephemeral OS Disk: data.virtual_machine_profile.storage_profile.os_disk.diff_disk_settings.option.local + is_optional: true + - Azure Spot Eviction Policy: data.virtual_machine_profile.eviction_policy + is_optional: true + - Azure Spot Max Price: data.virtual_machine_profile.billing_profile.max_price + is_optional: true + - Termination Notification: data.virtual_machine_profile.terminate_notification_display + is_optional: true + - OverProvisioning: data.overprovision + is_optional: true + - Proximity Placement Group: data.proximity_placement_group_display + is_optional: true + - Automatic Repairs: data.automatic_repairs_policy.enabled + is_optional: true + - Upgrade Policy: data.upgrade_policy.mode + is_optional: true + - Fault Domains (count): data.platform_fault_domain_count + is_optional: true + + + +tabs.0: + name: VmScaleSets + type: item + fields: + - Name: name + - Resource ID: data.id + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - Instances: data.instance_count + - Operating System: data.virtual_machine_profile.os_profile.operating_system + - Size: instance_type + - Virtual network/subnet: data.virtual_machine_profile.network_profile.primary_vnet + - Host group: data.host_group.id + - Ephemeral OS Disk: data.virtual_machine_profile.storage_profile.os_disk.diff_disk_settings.option.local + - Azure Spot Eviction Policy: data.virtual_machine_profile.eviction_policy + - Azure Spot Max Price: data.virtual_machine_profile.billing_profile.max_price + - Termination Notification: data.terminate_notification_display + - OverProvisioning: data.overprovision + - Proximity Placement Group: data.proximity_placement_group_display + - Automatic Repairs: data.automatic_repairs_policy.enabled + - Upgrade Policy: data.upgrade_policy.mode + - Fault Domains: data.platform_fault_domain_count + + + +tabs.1: + name: Instances + type: table + root_path: data.vm_instances + fields: + - Name: name + - Computer Name: os_profile.computer_name + - Location: location + - Status: vm_instance_status_profile.statuses.code + type: enum + enums: + - PowerState/running: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - PowerState/starting: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - PowerState/deallocated: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - PowerState/deallocating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - PowerState/stopped: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - PowerState/stopping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - PowerState/unknown: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Provisioning State: provisioning_state + - Protection From Scale-in: protection_policy.protect_from_scale_in + - Protection From Scale-set Actions: protection_policy.protect_from_scale_set_actions + - Latest Model: latest_model_applied + - Virtual Network: primary_vnet + + + +tabs.2: + name: Networking + items: + - name: Networking + type: item + fields: + - Virtual Networks: data.virtual_machine_profile.network_profile.primary_vnet + - name: Network Configuration + type: simple-table + root_path: data.virtual_machine_profile.network_profile.network_interface_configurations + fields: + - Name: name + - Network interface: enable_accelerated_networking_display + - Accelerated Networking: enable_accelerated_networking_display + - Primary: primary + - name: IP Configurations + type: simple-table + root_path: data.virtual_machine_profile.network_profile.network_interface_configurations.ip_configurations + fields: + - Public Ip Address Configuration: public_ip_address_configuration + - Private IP Address Version: private_ip_address_version + + + +tabs.3: + name: Scaling + items: + - name: Scaling + type: item + fields: + - Instance Count: data.instance_count + - Scale-in Policy: data.scale_in_policy.rules + type: list + options: + delimiter: "
" + - name: Autoscale Settings + type: simple-table + root_path: data.virtual_machine_scale_set_power_state + fields: + - Name: name + - Profiles: profiles_display + type: list + options: + delimiter: "
" + - Default: profiles.capacity.default + - Max: profiles.capacity.maximum + - Min: profiles.capacity.minimum + + + +tabs.4: + name: Disks + items: + - name: OS Disk + type: item + fields: + - Image Reference: data.virtual_machine_profile.storage_profile.image_reference_display + - Storage Account Type: data.virtual_machine_profile.storage_profile.os_disk.managed_disk.storage_account_type + - Size: data.virtual_machine_profile.storage_profile.os_disk.disk_size_gb + display_unit: GB + source_unit: BYTES + type: size + - Host Caching: data.virtual_machine_profile.storage_profile.os_disk.caching + - name: Data Disks + type: simple-table + root_path: data.virtual_machine_profile.storage_profile.data_disks + fields: + - Name: name + - Storage Type: managed_disk.storage_type + - Size: disk_size_gb + display_unit: GB + source_unit: BYTES + type: size + - Max IOPS: disk_iops_read_write + - MAX Throughput(MBps): disk_m_bps_read_write + - Encryption: disk_encryption_set.id + - Host Caching: caching + - LUN: lun + + + +tabs.5: + name: Operating System + type: item + fields: + - Computer Name Prefix: data.virtual_machine_profile.os_profile.computer_name_prefix + - Administrator Username: data.virtual_machine_profile.os_profile.admin_username + - Operating System: data.virtual_machine_profile.os_profile.operating_system + - VM Agent: data.virtual_machine_profile.os_profile.linux_configuration.provision_vm_agent + - Automatic OS Upgrades: data.upgrade_policy.automatic_os_upgrade_policy.enable_automatic_os_upgrade + - Custom Data: data.virtual_machine_profile.os_profile.custom_data diff --git a/src/plugin/metrics/VMScaleSets/ScaleSet/namespace.yaml b/src/plugin/metrics/VMScaleSets/ScaleSet/namespace.yaml new file mode 100644 index 00000000..b3c6c85e --- /dev/null +++ b/src/plugin/metrics/VMScaleSets/ScaleSet/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-vm-scale-sets-scale-set +name: VMScaleSets/ScaleSet +resource_type: inventory.CloudService:azure.VMScaleSets.ScaleSet +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-vm-scale-set.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml b/src/plugin/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml new file mode 100644 index 00000000..d607b249 --- /dev/null +++ b/src/plugin/metrics/VMScaleSets/ScaleSet/sacle_set_count.yaml @@ -0,0 +1,36 @@ +--- +metric_id: metric-azure-vm-scale-sets-scale-set-count +name: Scale Set Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.VMScaleSets.ScaleSet +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku Name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku + name: Sku Tier + - key: data.provisioning_state + name: Provisioning State + - key: instance_type + name: Instance Type + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-vm-scale-sets-scale-set +version: '1.0' \ No newline at end of file From 0dbf9f78ae64e78b695153cf69695a5eb1c7662c Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 1 Aug 2024 17:29:19 +0900 Subject: [PATCH 16/35] feat: Implement Load Balancers, CosmosDB Collector --- src/plugin/connector/base.py | 3 + src/plugin/connector/cosmos_db/__init__.py | 0 .../cosmos_db/cosmos_db_connector.py | 20 + .../connector/load_balancers/__init__.py | 0 .../load_balancers_connector.py | 26 + src/plugin/manager/__init__.py | 2 + .../container_instances/container_manager.py | 1 + src/plugin/manager/cosmos_db/__init__.py | 1 + .../manager/cosmos_db/instance_manager.py | 223 +++++++++ src/plugin/manager/load_balancers/__init__.py | 1 + .../load_balancers/instance_manager.py | 454 ++++++++++++++++++ .../manager/nat_gateways/instance_manager.py | 1 + .../instance_manager.py | 1 + .../manager/snapshots/instance_manager.py | 2 + .../manager/sql_databases/database_manager.py | 4 +- .../manager/sql_servers/server_manager.py | 6 +- .../storage_accounts/instance_manager.py | 2 + .../vm_scale_sets/scale_set_manager.py | 2 + .../container_instances/container.yaml | 5 + src/plugin/metadata/cosmos_db/instance.yaml | 254 ++++++++++ src/plugin/metadata/disks/disk.yaml | 4 + .../metadata/load_balancers/instance.yaml | 282 +++++++++++ .../metadata/nat_gateways/instance.yaml | 160 +++--- .../network_security_groups/instance.yaml | 2 + .../public_ip_addresses/ip_address.yaml | 1 + src/plugin/metadata/snapshots/instance.yaml | 2 + .../metadata/sql_databases/database.yaml | 1 - src/plugin/metadata/sql_servers/server.yaml | 16 +- .../metadata/storage_accounts/instance.yaml | 4 + .../metadata/vm_scale_sets/scale_set.yaml | 1 + .../metadata/web_pubsub_service/servuce.yaml | 183 +++++++ .../CosmosDB/Instance/instance_count.yaml | 31 ++ .../metrics/CosmosDB/Instance/namespace.yaml | 8 + .../CosmosDB/Instance/sql_database_count.yaml | 34 ++ .../Instance/instance_count.yaml | 29 ++ .../LoadBalancers/Instance/namespace.yaml | 8 + 36 files changed, 1665 insertions(+), 109 deletions(-) create mode 100644 src/plugin/connector/cosmos_db/__init__.py create mode 100644 src/plugin/connector/cosmos_db/cosmos_db_connector.py create mode 100644 src/plugin/connector/load_balancers/__init__.py create mode 100644 src/plugin/connector/load_balancers/load_balancers_connector.py create mode 100644 src/plugin/manager/cosmos_db/__init__.py create mode 100644 src/plugin/manager/cosmos_db/instance_manager.py create mode 100644 src/plugin/manager/load_balancers/__init__.py create mode 100644 src/plugin/manager/load_balancers/instance_manager.py create mode 100644 src/plugin/metadata/cosmos_db/instance.yaml create mode 100644 src/plugin/metadata/load_balancers/instance.yaml create mode 100644 src/plugin/metadata/web_pubsub_service/servuce.yaml create mode 100644 src/plugin/metrics/CosmosDB/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/CosmosDB/Instance/namespace.yaml create mode 100644 src/plugin/metrics/CosmosDB/Instance/sql_database_count.yaml create mode 100644 src/plugin/metrics/LoadBalancers/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/LoadBalancers/Instance/namespace.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index 6856497e..7eae84a1 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -10,6 +10,7 @@ from azure.mgmt.containerinstance import ContainerInstanceManagementClient from azure.mgmt.resource import ResourceManagementClient from azure.mgmt.storage import StorageManagementClient +from azure.mgmt.cosmosdb import CosmosDBManagementClient from spaceone.core.connector import BaseConnector @@ -28,6 +29,7 @@ def __init__(self, *args, **kwargs): self.container_instance_client = None self.resource_client = None self.storage_client = None + self.cosmosdb_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -47,6 +49,7 @@ def set_connect(self, secret_data: dict): self.container_instance_client = ContainerInstanceManagementClient(credential=credential, subscription_id=subscription_id) self.resource_client = ResourceManagementClient(credential=credential, subscription_id=subscription_id) self.storage_client = StorageManagementClient(credential=credential, subscription_id=subscription_id) + self.cosmosdb_client = CosmosDBManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/cosmos_db/__init__.py b/src/plugin/connector/cosmos_db/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/cosmos_db/cosmos_db_connector.py b/src/plugin/connector/cosmos_db/cosmos_db_connector.py new file mode 100644 index 00000000..911fa5ca --- /dev/null +++ b/src/plugin/connector/cosmos_db/cosmos_db_connector.py @@ -0,0 +1,20 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class CosmosDBConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_all_cosmos_db_accounts(self): + return self.cosmosdb_client.database_accounts.list() + + def list_keys(self, account_name, resource_group_name): + return self.cosmosdb_client.database_accounts.list_keys(account_name=account_name, resource_group_name=resource_group_name) + + def list_sql_resources(self, account_name, resource_group_name): + return self.cosmosdb_client.sql_resources.list_sql_databases(account_name=account_name, resource_group_name=resource_group_name) diff --git a/src/plugin/connector/load_balancers/__init__.py b/src/plugin/connector/load_balancers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/load_balancers/load_balancers_connector.py b/src/plugin/connector/load_balancers/load_balancers_connector.py new file mode 100644 index 00000000..cbde27c6 --- /dev/null +++ b/src/plugin/connector/load_balancers/load_balancers_connector.py @@ -0,0 +1,26 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class LoadBalancersConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_load_balancers(self): + return self.network_client.load_balancers.list_all() + + def get_subnets(self, resource_group_name, vnet_name, subnet_name): + return self.network_client.subnets.get(resource_group_name, vnet_name, subnet_name) + + def list_load_balancer_backend_address_pools(self, resource_group_name, lb_name): + return self.network_client.load_balancer_backend_address_pools.list(resource_group_name, lb_name) + + def list_load_balancer_network_interfaces(self, resource_group_name, lb_name): + return self.network_client.load_balancer_network_interfaces.list(resource_group_name, lb_name) + + def list_network_interface_ip_configurations(self, resource_group_name, network_interface_name): + return self.network_client.network_interface_ip_configurations.list(resource_group_name, network_interface_name) diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index dead730c..880c6718 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -10,3 +10,5 @@ from .storage_accounts import * from .snapshots import * from .vm_scale_sets import * +from .load_balancers import * +from .cosmos_db import * diff --git a/src/plugin/manager/container_instances/container_manager.py b/src/plugin/manager/container_instances/container_manager.py index edd4c607..4ae51b4c 100644 --- a/src/plugin/manager/container_instances/container_manager.py +++ b/src/plugin/manager/container_instances/container_manager.py @@ -41,6 +41,7 @@ def create_cloud_service(self, options, secret_data, schema): subscription_info = self.convert_nested_dictionary(subscription_obj) container_instances = container_instances_conn.list_container_groups() + for container_instance in container_instances: try: diff --git a/src/plugin/manager/cosmos_db/__init__.py b/src/plugin/manager/cosmos_db/__init__.py new file mode 100644 index 00000000..fad53c07 --- /dev/null +++ b/src/plugin/manager/cosmos_db/__init__.py @@ -0,0 +1 @@ +from .instance_manager import CosmosDBManager diff --git a/src/plugin/manager/cosmos_db/instance_manager.py b/src/plugin/manager/cosmos_db/instance_manager.py new file mode 100644 index 00000000..d27b87d7 --- /dev/null +++ b/src/plugin/manager/cosmos_db/instance_manager.py @@ -0,0 +1,223 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.cosmos_db.cosmos_db_connector import CosmosDBConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class CosmosDBManager(AzureBaseManager): + cloud_service_group = "CosmosDB" + cloud_service_type = "Instance" + service_code = "/Microsoft.DocumentDB/databaseAccounts" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Database"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-cosmos-db.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + cosmos_db_conn = CosmosDBConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + cosmos_db_accounts_list = cosmos_db_conn.list_all_cosmos_db_accounts() + + for cosmos_db_account in cosmos_db_accounts_list: + + try: + cosmos_db_account_dict = self.convert_nested_dictionary( + cosmos_db_account + ) + cosmos_db_account_id = cosmos_db_account_dict.get("id") + cosmos_db_account_dict["location"] = ( + cosmos_db_account_dict["location"].replace(" ", "").lower() + ) + + # update cosmosdb_dict + cosmos_db_account_dict = self.update_tenant_id_from_secret_data( + cosmos_db_account_dict, secret_data + ) + cosmos_db_account_dict.update( + { + "resource_group": self.get_resource_group_from_id( + cosmos_db_account_dict["id"] + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["subscription_name"], + "azure_monitor": {"resource_id": cosmos_db_account_id}, + } + ) + + if cosmos_db_account_dict.get("capabilities") is not None: + cosmos_db_account_dict.update( + { + "capability_display": self.get_capability_type( + cosmos_db_account_dict["capabilities"] + ) + } + ) + + if cosmos_db_account_dict.get("virtual_network_rules") is not None: + cosmos_db_account_dict.update( + { + "virtual_network_display": self.get_virtual_networks( + cosmos_db_account_dict["virtual_network_rules"] + ) + } + ) + + if ( + cosmos_db_account_dict.get("private_endpoint_connections") + is not None + ): + for private_connection in cosmos_db_account_dict[ + "private_endpoint_connections" + ]: + private_connection.update( + { + "private_endpoint": self.get_private_endpoint_name( + private_connection["private_endpoint"] + ), + "name": self.get_private_connection_name( + private_connection["id"] + ), + } + ) + + if cosmos_db_account_dict.get("cors") is not None: + cosmos_db_account_dict.update( + { + "cors_display": self.get_cors_display( + cosmos_db_account_dict["cors"] + ) + } + ) + + if cosmos_db_account_dict.get("name") is not None: + sql_databases = self.get_sql_resources( + cosmos_db_conn, + cosmos_db_account_dict["name"], + cosmos_db_account_dict["resource_group"], + ) + + cosmos_db_account_dict.update( + { + # "keys": self.get_keys( + # cosmos_db_conn, + # cosmos_db_account_dict["name"], + # cosmos_db_account_dict["resource_group"], + # ), + "sql_databases": sql_databases, + "sql_databases_count_display": len(sql_databases), + } + ) + + self.set_region_code(cosmos_db_account_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=cosmos_db_account_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=cosmos_db_account_dict, + account=secret_data["subscription_id"], + region_code=cosmos_db_account_dict["location"], + reference=self.make_reference(cosmos_db_account_dict.get("id")), + # launched_at=cosmos_db_account_dict.system_data.created_at, + tags=cosmos_db_account_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_keys(self, cosmos_db_conn, account_name, resource_group): + keys_obj = cosmos_db_conn.list_keys( + account_name=account_name, resource_group_name=resource_group + ) + key_dict = self.convert_nested_dictionary(keys_obj) + return key_dict + + def get_sql_resources(self, cosmos_db_conn, account_name, resource_group): + sql_resources = [] + sql_resources_obj = cosmos_db_conn.list_sql_resources( + account_name=account_name, resource_group_name=resource_group + ) + + for sql in sql_resources_obj: + sql_dict = self.convert_nested_dictionary(sql) + sql_resources.append(sql_dict) + return sql_resources + + @staticmethod + def get_capability_type(capabilities): + if capabilities: + capability_str_list = [] + for capability in capabilities: + capability_str_list.append(capability.get("name")) + + if "EnableServerless" in capability_str_list: + return "Serverless" + else: + return "Provisioned Throughput" + + @staticmethod + def get_virtual_networks(virtual_network_rules): + virtual_network_rules_display = [] + + for virtual_network in virtual_network_rules: + virtual_network_name = virtual_network["id"].split("/")[8] + virtual_network_rules_display.append(virtual_network_name) + + return virtual_network_rules_display + + @staticmethod + def get_private_endpoint_name(private_endpoint): + if private_endpoint.get("id") is not None: + private_endpoint.update({"name": private_endpoint["id"].split("/")[8]}) + return private_endpoint + + @staticmethod + def get_private_connection_name(private_connection_id): + private_connection_name = private_connection_id.split("/")[10] + return private_connection_name + + @staticmethod + def get_cors_display(cors_list): + cors_display = [] + + for cors in cors_list: + cors_display.append(cors.get("allowed_origins", "")) + return cors_display diff --git a/src/plugin/manager/load_balancers/__init__.py b/src/plugin/manager/load_balancers/__init__.py new file mode 100644 index 00000000..8957ae28 --- /dev/null +++ b/src/plugin/manager/load_balancers/__init__.py @@ -0,0 +1 @@ +from .instance_manager import LoadBalancersManager diff --git a/src/plugin/manager/load_balancers/instance_manager.py b/src/plugin/manager/load_balancers/instance_manager.py new file mode 100644 index 00000000..3671573a --- /dev/null +++ b/src/plugin/manager/load_balancers/instance_manager.py @@ -0,0 +1,454 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.load_balancers.load_balancers_connector import LoadBalancersConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class LoadBalancersManager(AzureBaseManager): + cloud_service_group = "LoadBalancers" + cloud_service_type = "Instance" + service_code = "/Microsoft.Network/loadBalancers" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Networking"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-loadbalancers.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + load_balancers_conn = LoadBalancersConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + load_balancers = load_balancers_conn.list_load_balancers() + + for load_balancer in load_balancers: + + try: + load_balancer_dict = self.convert_nested_dictionary(load_balancer) + load_balancer_dict = self.update_tenant_id_from_secret_data( + load_balancer_dict, secret_data + ) + + load_balancer_id = load_balancer_dict["id"] + + load_balancer_dict.update( + { + "resource_group": self.get_resource_group_from_id( + load_balancer_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": load_balancer_id}, + } + ) + + # Get Network Interfaces attached in this load balancer + load_balancer_dict.update( + { + "network_interfaces": self.get_network_interfaces( + load_balancers_conn, + load_balancer_dict["resource_group"], + load_balancer_dict["name"], + ) + } + ) + + # Get Frontend IP Configurations information + if load_balancer_dict.get("frontend_ip_configurations") is not None: + private_ip_address_list = list() + used_by_list = list() + + for fic in load_balancer_dict["frontend_ip_configurations"]: + if fic.get( + "subnet" + ): # If the 'public' type, Skip this part because there isn't subnet information for them. + fic["subnet"][ + "address_prefix" + ] = self.get_frontend_address_prefix( + load_balancers_conn, fic["subnet"] + ) + fic["subnet"]["name"] = self.get_frontend_ip_subnet_name( + fic["subnet"]["id"] + ) + + # Get used inbound NAT rules + if fic.get("inbound_nat_rules") is not None: + load_balancer_dict.update( + { + "frontend_ip_configurations_used_by_display": self.get_frontend_ip_configurations_used_by_display( + used_by_list, fic["inbound_nat_rules"] + ) + } + ) + + # Get used load balancing NAT rules + if fic.get("load_balancing_rules") is not None: + load_balancer_dict.update( + { + "frontend_ip_configurations_used_by_display": self.get_frontend_ip_configurations_used_by_display( + used_by_list, fic["load_balancing_rules"] + ), + } + ) + + # Get all of private ip addresses + private_ip_address_list.append(fic["private_ip_address"]) + + load_balancer_dict.update( + {"private_ip_address_display": private_ip_address_list} + ) + + # Since Azure python sdk returns only one backend pool, delete the backend pool list first, and then use the new API connection + if load_balancer_dict.get("backend_address_pools") is not None: + load_balancer_dict["backend_address_pools"].clear() + load_balancer_dict.update( + { + "backend_address_pools": self.list_load_balancer_backend_address_pools( + load_balancers_conn, + load_balancer_dict["resource_group"], + load_balancer_dict["name"], + ) + } + ) + + # get backend address pool's count + load_balancer_dict.update( + { + "backend_address_pools_count_display": self.get_backend_address_pools_count( + load_balancer_dict["backend_address_pools"] + ) + } + ) + + # Get load balancing Rules for display + if load_balancer_dict.get("load_balancing_rules") is not None: + load_balancer_dict.update( + { + "load_balancing_rules_display": self.get_load_balancing_rules_display( + load_balancer_dict["load_balancing_rules"] + ), + } + ) + + for lbr in load_balancer_dict["load_balancing_rules"]: + if lbr.get("backend_address_pool") is not None: + lbr.update( + { + "backend_address_pool_display": self.get_backend_address_pool_name( + lbr["backend_address_pool"] + ), + } + ) + + if lbr.get("load_distribution") is not None: + lbr.update( + { + "load_distribution_display": self.get_load_distribution_display( + lbr["load_distribution"] + ) + } + ) + + if lbr.get("frontend_ip_configuration") is not None: + lbr.update( + { + "frontend_ip_configuration_display": self.get_frontend_ip_configuration_display( + lbr["frontend_ip_configuration"] + ) + } + ) + + # Get Inbound NAT Rules for display + if load_balancer_dict.get("inbound_nat_rules") is not None: + load_balancer_dict.update( + { + "inbound_nat_rules_display": self.get_nat_rules_display( + load_balancer_dict["inbound_nat_rules"] + ) + } + ) + + for inr in load_balancer_dict["inbound_nat_rules"]: + inr.update( + { + "frontend_ip_configuration_display": self.get_frontend_ip_configuration_display( + inr["frontend_ip_configuration"] + ), + "port_mapping_display": self.get_port_mapping_display( + inr["frontend_port"], inr["backend_port"] + ), + "target_virtual_machine": self.get_matched_vm_info( + inr["backend_ip_configuration"]["id"], + load_balancer_dict["network_interfaces"], + ), + } + ) + + # Get Health Probes for display + if load_balancer_dict.get("probes") is not None: + load_balancer_dict.update( + { + "probes_display": self.get_probe_display_list( + load_balancer_dict["probes"] + ) + } + ) + + self.set_region_code(load_balancer_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=load_balancer_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=load_balancer_dict, + account=load_balancer_dict["subscription_id"], + instance_type=load_balancer_dict["sku"]["tier"], + region_code=load_balancer_dict["location"], + reference=self.make_reference(load_balancer_dict.get("id")), + tags=load_balancer_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_network_interfaces(self, load_balancer_conn, rg_name, lb_name): + network_interface_object_list = list( + load_balancer_conn.list_load_balancer_network_interfaces(rg_name, lb_name) + ) + network_interface_list = [] + + # network_interfaces >> network_interfaces >> ip_configurations + for nil in network_interface_object_list: + network_interface_dict = self.convert_nested_dictionary(nil) + nic_rg_name = network_interface_dict.get("id", "").split("/")[4] + + if network_interface_dict.get("ip_configurations") is not None: + # Get LB's name, VMs name attached to Backend Pool + for ip_configuration in network_interface_dict["ip_configurations"]: + if ( + ip_configuration.get("load_balancer_backend_address_pools") + is not None + ): + for ic in ip_configuration[ + "load_balancer_backend_address_pools" + ]: + # Get backend address vm name + backend_pool_vm_name = ic["id"].split("/")[10] + + network_interface_dict.update( + { + "load_balancer_backend_address_pools_name_display": backend_pool_vm_name, + } + ) + + # Get the primary ip configuration from a network interface card + network_interface_dict.update( + { + "private_ip_display": self.get_ip_configuration_display( + network_interface_dict["ip_configurations"] + ) + } + ) + + # 2) Get VM's name which is attached to this network interface card + if network_interface_dict.get("virtual_machine") is not None: + network_interface_dict.update( + { + "virtual_machine_name_display": network_interface_dict[ + "virtual_machine" + ]["id"].split("/")[8] + } + ) + + network_interface_list.append(network_interface_dict) + + return network_interface_list + + def get_ip_configurations_list( + self, load_balancer_conn, rg_name, network_interface_name + ): + ip_configuration_list = [] + if network_interface_name: + ip_configurations_object = ( + load_balancer_conn.list_network_interface_ip_configurations( + rg_name, network_interface_name + ) + ) + ip_configurations_object_list = list(ip_configurations_object) + + if ip_configurations_object_list: + for ip_configuration_object in ip_configurations_object_list: + ip_object_dict = self.convert_nested_dictionary( + ip_configuration_object + ) + ip_configuration_list.append(ip_object_dict) + + return ip_configuration_list + + def list_load_balancer_backend_address_pools(self, conn, rg_name, lb_name): + backend_pools_list = list() # return result list + + backend_pools_object = conn.list_load_balancer_backend_address_pools( + rg_name, lb_name + ) + backend_pools_object_list = list( + backend_pools_object + ) # Since return type is ItemPagedClass, change to the list before convert dictionary + + # Loop for converting backend pools objects to dictionary + for bp in backend_pools_object_list: + backend_pool_dict = self.convert_nested_dictionary(bp) + backend_pools_list.append(backend_pool_dict) + + return backend_pools_list + + @staticmethod + def get_ip_configuration_display(ip_configurations_list): + ic_list = list() + for ic in ip_configurations_list: + ic_list.append(ic["private_ip_address"]) + return ic_list + + @staticmethod + def get_frontend_address_prefix(conn, subnet): + # Parse Vnet, LB name from subnet id + subnet_id = subnet["id"] + resource_group_name = subnet_id.split("/")[4] + vnet_name = subnet_id.split("/")[8] + subnet_name = subnet_id.split("/")[10] + + # API request for subnet dictionary + subnet = conn.get_subnets(resource_group_name, vnet_name, subnet_name) + + return subnet.address_prefix + + @staticmethod + def get_frontend_ip_subnet_name(subnet_id): + subnet_name = subnet_id.split("/")[10] + return subnet_name + + @staticmethod + def get_frontend_ip_configurations_used_by_display(used_by_list, used_object_list): + for used_object in used_object_list: + used_by_list.append(used_object["id"].split("/")[10]) + + return used_by_list + + @staticmethod + def get_backend_address_pools_count(backend_address_dict): + backend_address_pools_count = len(backend_address_dict) + + if backend_address_pools_count == 1: + backend_address_pools_count_display = ( + str(backend_address_pools_count) + " backend pool" + ) + else: + backend_address_pools_count_display = ( + str(backend_address_pools_count) + " backend pools" + ) + + return backend_address_pools_count_display + + @staticmethod + def get_matched_vm_info(find_key, find_list_pool): + matched_vm_list = list() + for find_object in find_list_pool: + if ( + find_object["id"] in find_key + ): # if network interface card's id matches to the backend configuration's id + if find_object.get("virtual_machine") is not None: + matched_vm_list.append( + (find_object["virtual_machine"]["id"]).split("/")[8] + ) + return matched_vm_list + + @staticmethod + def get_probe_display_list(probes_list): + probe_display_list = list() + for probe in probes_list: + probe_display_list.append(probe["name"]) + return probe_display_list + + @staticmethod + def get_load_balancing_rules_display(load_balancing_rules_list): + lbr_name_list = list() + for lbr in load_balancing_rules_list: + lbr_name_list.append( + lbr["name"] + ) # 'name' key always exists if there are load balancing rules. + + return lbr_name_list + + @staticmethod + def get_nat_rules_display(inbound_nat_rules_list): + nat_rules_list = list() + for inr in inbound_nat_rules_list: + nat_rules_list.append( + inr["name"] + ) # 'name' key always exists if there are inbound NAT rules. + + return nat_rules_list + + @staticmethod + def get_backend_address_pool_name( + lbr_backend_address_pool, + ): # id must exist if there is a backend address pool object + return lbr_backend_address_pool["id"].split("/")[10] + + @staticmethod + def get_load_distribution_display(lbr_load_distribution): + if lbr_load_distribution == "Default": + lbr_load_distribution_display = "None" + elif lbr_load_distribution == "SourceIPProtocol": + lbr_load_distribution_display = "Client IP and Protocol" + elif lbr_load_distribution == "SourceIP": + lbr_load_distribution_display = "Client IP" + + return lbr_load_distribution_display + + @staticmethod + def get_frontend_ip_configuration_display(lbr_frontend_ip_configuration_dict): + return lbr_frontend_ip_configuration_dict["id"].split("/")[10] + + @staticmethod + def get_port_mapping_display(frontend_port, backend_port): + if frontend_port == backend_port: + port_mapping_display = "Default" + else: + port_mapping_display = "Custom" + return port_mapping_display diff --git a/src/plugin/manager/nat_gateways/instance_manager.py b/src/plugin/manager/nat_gateways/instance_manager.py index 93c2f013..5a6f49c0 100644 --- a/src/plugin/manager/nat_gateways/instance_manager.py +++ b/src/plugin/manager/nat_gateways/instance_manager.py @@ -43,6 +43,7 @@ def create_cloud_service(self, options, secret_data, schema): nat_gateways = nat_gateways_conn.list_all_nat_gateways() for nat_gateway in nat_gateways: + try: nat_gateway_dict = self.convert_nested_dictionary(nat_gateway) nat_gateway_id = nat_gateway_dict["id"] diff --git a/src/plugin/manager/network_security_groups/instance_manager.py b/src/plugin/manager/network_security_groups/instance_manager.py index 944919a9..59774781 100644 --- a/src/plugin/manager/network_security_groups/instance_manager.py +++ b/src/plugin/manager/network_security_groups/instance_manager.py @@ -48,6 +48,7 @@ def create_cloud_service(self, options, secret_data, schema): ] for network_security_group in network_security_groups: + try: network_security_group_dict = self.convert_nested_dictionary(network_security_group) network_security_group_id = network_security_group_dict["id"] diff --git a/src/plugin/manager/snapshots/instance_manager.py b/src/plugin/manager/snapshots/instance_manager.py index b084c56f..fc2d43f2 100644 --- a/src/plugin/manager/snapshots/instance_manager.py +++ b/src/plugin/manager/snapshots/instance_manager.py @@ -41,7 +41,9 @@ def create_cloud_service(self, options, secret_data, schema): subscription_info = self.convert_nested_dictionary(subscription_obj) snapshots = snapshots_conn.list_snapshots() + for snapshot in snapshots: + try: snapshot_dict = self.convert_nested_dictionary(snapshot) snapshot_id = snapshot_dict["id"] diff --git a/src/plugin/manager/sql_databases/database_manager.py b/src/plugin/manager/sql_databases/database_manager.py index 19a6fd91..cf15e691 100644 --- a/src/plugin/manager/sql_databases/database_manager.py +++ b/src/plugin/manager/sql_databases/database_manager.py @@ -44,7 +44,9 @@ def create_cloud_service(self, options, secret_data, schema): # get resource_group_name and server_name from sql_server for sql_databases list sql_servers = sql_databases_conn.list_servers() + for sql_server in sql_servers: + try: sql_server_dict = self.convert_nested_dictionary(sql_server) @@ -162,7 +164,7 @@ def create_cloud_service(self, options, secret_data, schema): instance_size=float(sql_database_dict["max_size_gb"]), region_code=sql_database_dict["location"], reference=self.make_reference(sql_database_dict.get("id")), - # launched_at=datetime_to_iso8601(sql_database_dict["creation_date"]), + # launched_at=sql_database_dict["creation_date"], tags=sql_database_dict.get("tags", {}), data_format="dict" ) diff --git a/src/plugin/manager/sql_servers/server_manager.py b/src/plugin/manager/sql_servers/server_manager.py index 241c8388..ca32ed32 100644 --- a/src/plugin/manager/sql_servers/server_manager.py +++ b/src/plugin/manager/sql_servers/server_manager.py @@ -93,7 +93,7 @@ def create_cloud_service(self, options, secret_data, schema): server_admin_name=sql_server_dict.get("administrator_login"), ) - number_of_databases = len(databases_list) + number_of_databases_display = len(databases_list) elastic_pools_list = self.list_elastic_pools( sql_servers_conn, resource_group_name, name @@ -114,7 +114,7 @@ def create_cloud_service(self, options, secret_data, schema): "server_auditing_settings": server_auditing_settings_dict, "failover_groups": failover_group_list, "server_automatic_tuning": server_automatic_tuning_dict, - "number_of_databases": number_of_databases, + "number_of_databases": number_of_databases_display, "databases": databases_list, "elastic_pools": elastic_pools_list, "deleted_databases": deleted_databases_list, @@ -196,7 +196,7 @@ def list_elastic_pools(self, sql_servers_conn, rg_name, server_name): "per_db_settings_display": self.get_per_db_settings( elastic_pool_dict["per_database_settings"] ), - "number_of_databases": len(elastic_pool_dict["databases"]), + "number_of_databases_display": len(elastic_pool_dict["databases"]), "unit_display": elastic_pool_dict["sku"]["tier"], "server_name_display": elastic_pool_dict["id"].split("/")[8], "resource_group_display": elastic_pool_dict["id"].split("/")[4], diff --git a/src/plugin/manager/storage_accounts/instance_manager.py b/src/plugin/manager/storage_accounts/instance_manager.py index eec0162f..23dcfaa2 100644 --- a/src/plugin/manager/storage_accounts/instance_manager.py +++ b/src/plugin/manager/storage_accounts/instance_manager.py @@ -44,7 +44,9 @@ def create_cloud_service(self, options, secret_data, schema): subscription_info = self.convert_nested_dictionary(subscription_obj) storage_accounts = storage_accounts_conn.list_storage_accounts() + for storage_account in storage_accounts: + try: storage_account_dict = self.convert_nested_dictionary(storage_account) kind = storage_account_dict.get("kind") diff --git a/src/plugin/manager/vm_scale_sets/scale_set_manager.py b/src/plugin/manager/vm_scale_sets/scale_set_manager.py index 9531a8f0..93857e8f 100644 --- a/src/plugin/manager/vm_scale_sets/scale_set_manager.py +++ b/src/plugin/manager/vm_scale_sets/scale_set_manager.py @@ -41,7 +41,9 @@ def create_cloud_service(self, options, secret_data, schema): subscription_info = self.convert_nested_dictionary(subscription_obj) vm_scale_sets = vm_scale_sets_conn.list_vm_scale_sets() + for vm_scale_set in vm_scale_sets: + try: vm_scale_set_dict = self.convert_nested_dictionary(vm_scale_set) vm_scale_set_id = vm_scale_set_dict["id"] diff --git a/src/plugin/metadata/container_instances/container.yaml b/src/plugin/metadata/container_instances/container.yaml index 49670243..7ab1840e 100644 --- a/src/plugin/metadata/container_instances/container.yaml +++ b/src/plugin/metadata/container_instances/container.yaml @@ -12,10 +12,15 @@ search: - Location: data.location - SKU: data.sku - Container count: data.container_count_display + data_type: integer - vCPU: data.cpu_count_display + data_type: integer - Memory size(GB): data.memory_size_display + data_type: float - GPU count: data.gpu_count_display + data_type: integer - Volume count: data.volume_count_display + data_type: integer - DNS name label: data.ip_address.dns_name_label - DNS name label scope reuse: data.ip_address.auto_generated_domain_name_label_scope diff --git a/src/plugin/metadata/cosmos_db/instance.yaml b/src/plugin/metadata/cosmos_db/instance.yaml new file mode 100644 index 00000000..12195a8d --- /dev/null +++ b/src/plugin/metadata/cosmos_db/instance.yaml @@ -0,0 +1,254 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Backup Policy: data.backup_policy.type + - Read Locations: data.read_locations.location_name + - Write Locations: data.write_locations.location_name + - Document Endpoint: data.document_endpoint + - Capacity Mode: data.capability_display + - Enable Automatic Failover: data.enable_automatic_failover + - Enable Free Tier: data.enable_free_tier + - Enable Analytical Storage: data.enable_analytical_storage + - CORS: data.cors_display + - Default Consistency: data.consistency_policy.default_consistency_level + - Backup Interval (Minutes): data.backup_policy.periodic_mode_properties.backup_interval_in_minutes + data_type: integer + - Backup Retention (Hours): data.backup_policy.periodic_mode_properties.backup_retention_interval_in_hours + - Backup storage redundancy: data.backup_policy.periodic_mode_properties.additional_properties.backupStorageRedundancy + - Enable Public Network Access: data.public_network_access + - Virtual Networks: data.virtual_network_display + - Private Endpoint Connection Name: data.private_endpoint_connections.name + - Private Endpoint State: data.private_endpoint_connections.private_link_service_connection_state.status + - Private Endpoint Name: data.private_endpoint_connections.name + - Private Endpoint: data.private_endpoint_connections.name + + + +table: + sort: + key: data.id + desc: false + fields: + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Resource ID: data.id + - Subscription ID: data.subscription_id + - Backup Policy: data.backup_policy.type + is_optional: true + - Read Locations: data.read_locations.location_name + type: list + options: + delimiter: ', ' + is_optional: true + - Write Locations: data.write_locations.location_name + type: list + options: + delimiter: ', ' + is_optional: true + - Document Endpoint: data.document_endpoint + is_optional: true + - Capacity Mode: data.capability_display + is_optional: true + - Enable Automatic Failover: data.enable_automatic_failover + is_optional: true + - Enable Free Tier: data.enable_free_tier + is_optional: true + - Enable Analytical Storage: data.enable_analytical_storage + is_optional: true + - Backup Policy: data.backup_policy.type + is_optional: true + - CORS: data.cors_display + type: list + options: + delimiter: ', ' + is_optional: true + - Default Consistency: data.consistency_policy.default_consistency_level + is_optional: true + - Backup Interval (Minutes): data.backup_policy.periodic_mode_properties.backup_interval_in_minutes + is_optional: true + - Backup Retention (Hours): data.backup_policy.periodic_mode_properties.backup_retention_interval_in_hours + is_optional: true + - Backup storage redundancy: data.backup_policy.periodic_mode_properties.additional_properties.backupStorageRedundancy + is_optional: true + - Enable Public Network Access: data.public_network_access + is_optional: true + - Virtual Networks: data.virtual_network_display + type: list + options: + delimiter: ', ' + is_optional: true + - Connection Name: data.private_endpoint_connections.name + is_optional: true + - Connection State: data.private_endpoint_connections.private_link_service_connection_state.status + is_optional: true + - Private Endpoint: data.private_endpoint_connections.private_endpoint.name + is_optional: true + - Description: data.private_endpoint_connections.private_link_service_connection_state.description + is_optional: true + - Private Endpoint Connection Name: data.cors.name + is_optional: true + - Private Endpoint State: data.cors.private_link_service_connection_state.status + is_optional: true + - Private Endpoint: data.cors.private_endpoint.name + is_optional: true + - COR Private Link Description: data.cors.private_link_service_connection_state.description + is_optional: true + + + +tabs.0: + name: Cosmos DB + type: item + fields: + - Name: data.name + - Resource ID: data.id + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: data.subscription_id + - Backup Policy: data.backup_policy.type + - Read Locations: data.read_locations.location_name + type: list + options: + delimiter: ', ' + - Write Locations: data.write_locations.location_name + type: list + options: + delimiter: ', ' + - URI: data.document_endpoint + - Public Network Access: data.public_network_access + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Capacity Mode: data.capability_display + + + +tabs.1: + name: Features + type: item + fields: + - Enable Automatic Failover: data.enable_automatic_failover + type: enum + enums: + - 'True': + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - 'False': + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Enable Free Tier: data.enable_free_tier + type: enum + enums: + - 'True': + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - 'False': + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Enable Analytical Storage: data.enable_analytical_storage + type: enum + enums: + - 'True': + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - 'False': + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Backup Policy: data.backup_policy.type + - CORS: data.cors_display + type: list + options: + delimiter: ', ' + + + +tabs.2: + name: Default Consistency + type: item + fields: + - Default Consistency: data.consistency_policy.default_consistency_level + + + +tabs.3: + name: Backup & Restore + type: item + fields: + - Backup Interval (Minutes): data.backup_policy.periodic_mode_properties.backup_interval_in_minutes + - Backup Retention (Hours): data.backup_policy.periodic_mode_properties.backup_retention_interval_in_hours + - Backup storage redundancy: data.backup_policy.periodic_mode_properties.additional_properties.backupStorageRedundancy + + + +tabs.4: + name: Firewall and Virtual Networks + type: item + fields: + - Enable Public Network Access: data.public_network_access + - Virtual Networks: data.virtual_network_display + type: list + options: + delimiter: ', ' + + + +tabs.5: + name: Private Endpoint Connections + type: table + root_path: data.private_endpoint_connections + fields: + - Connection Name: name + - Connection State: private_link_service_connection_state.status + - Private Endpoint: private_endpoint.name + - Description: private_link_service_connection_state.description + + + +tabs.6: + name: Cors + type: table + root_path: data.cors + fields: + - Connection Name: private_endpoint_connections.name + - Connection State: private_endpoint_connections.private_link_service_connection_state.status + - Private Endpoint: private_endpoint_connections.private_endpoint.name + - Description: private_endpoint_connections.private_link_service_connection_state.description + + + +tabs.7: + name: Keys + type: item + fields: + - Primary Readonly Master Key: data.keys.primary_readonly_master_key + - Secondary Readonly Master Key: data.keys.secondary_readonly_master_key + - Primary Master Key: data.keys.primary_master_key + - Primary Master Key: data.keys.secondary_master_key + + + +tabs.8: + name: Database + type: simple-table + root_path: data.sql_databases + fields: + - Database: name + - ID: id \ No newline at end of file diff --git a/src/plugin/metadata/disks/disk.yaml b/src/plugin/metadata/disks/disk.yaml index bdbba9e5..d681ba88 100644 --- a/src/plugin/metadata/disks/disk.yaml +++ b/src/plugin/metadata/disks/disk.yaml @@ -9,11 +9,15 @@ search: - Last updated at: data.last_updated - Storage Account Type: data.sku.name - Disk Size (Bytes): data.disk_size_bytes + data_type: integer - Disk Size (GB): data.disk_size_gb + data_type: integer - Disk IOPS: data.disk_iops_read_write + data_type: integer - OS Type: data.os_type - Provisioning State: data.provisioning_state - Time Created: data.time_created + data_type: datetime table: sort: diff --git a/src/plugin/metadata/load_balancers/instance.yaml b/src/plugin/metadata/load_balancers/instance.yaml new file mode 100644 index 00000000..177be907 --- /dev/null +++ b/src/plugin/metadata/load_balancers/instance.yaml @@ -0,0 +1,282 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Load Balancer Type: instance_type + - SKU: instance_type + - Health Probe: data.probes_display + - Load Balancing Rule: data.load_balancing_rules_display + - NAT Rules: data.inbound_nat_rules_display + - Private IP Address: data.private_ip_address_display + - Frontend Name: data.frontend_ip_configurations.name + - Frontend IP Address: data.frontend_ip_configurations.private_ip_address + - Frontend IP Version: data.frontend_ip_configurations.private_ip_address_version + - Frontend IP Used By: data.frontend_ip_configurations_used_by_display + - Backend Pool Name: data.backend_address_pools.name + - Backend Pool ID: data.backend_address_pools.id + - Health Probe Name: data.probes.name + - Health Probes Protocol: data.probes.protocol + - Health Probes Port: data.probes.port + data_type: integer + - Health Probes Interval: data.probes.interval_in_seconds + data_type: integer + - Health Probes Unhealthy Threshold: data.probes.number_of_probes + - LB Rule Name: data.load_balancing_rules.name + - LB Rule Frontend IP Address: data.load_balancing_rules.frontend_ip_configuration_display + - LB Rule Protocol: data.load_balancing_rules.protocol + - LB Rule Frontend Port: data.load_balancing_rules.frontend_port + data_type: integer + - LB Rule Backend Port: data.load_balancing_rules.backend_port + data_type: integer + - LB Rule Backend Pool: data.load_balancing_rules.backend_address_pool_display + - LB Rule Session Persistence: data.load_balancing_rules.load_distribution_display + - LB Rule Idle Timeout (minutes): data.load_balancing_rules.idle_timeout_in_minutes + data_type: integer + - LB Rule Floating IP: data.load_balancing_rules.enable_floating_ip + - LB Rule TCP Reset: data.load_balancing_rules.enable_tcp_reset + - Inbound NAT Rules Name: data.inbound_nat_rules.name + - Inbound NAT Rule Protocol: data.inbound_nat_rules.protocol + - Inbound NAT Rule Idle timeout (minutes): data.inbound_nat_rules.idle_timeout_in_minutes + data_type: integer + - Inbound NAT Rule TCP Reset: data.load_balancing_rules.enable_tcp_reset + - Inbound NAT Rule Port: data.inbound_nat_rules.frontend_port + data_type: integer + - Inbound NAT Rule Target Virtual Machine: data.inbound_nat_rules.target_virtual_machine + - Inbound NAT Rule Network IP Configuration: data.inbound_nat_rules.frontend_ip_configuration_display + - Inbound NAT Rule Port mapping: data.inbound_nat_rules.port_mapping_display + - Inbound NAT Rule Floating IP: data.inbound_nat_rules.enable_floating_ip + - Inbound NAT Rule Target Port: data.inbound_nat_rules.backend_port + data_type: integer + + + +table: + sort: + key: data.id + desc: false + fields: + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: data.subscription_id + is_optional: true + - SKU: instance_type + is_optional: true + - Health Probe: data.probes_display + type: list + options: + delimiter: '
' + is_optional: true + - Load Balancing Rule: data.load_balancing_rules_display + type: list + options: + delimiter: '
' + is_optional: true + - NAT Rules: data.inbound_nat_rules_display + type: list + options: + delimiter: '
' + is_optional: true + - Private IP Address: data.private_ip_address_display + type: list + options: + delimiter: '
' + is_optional: true + - Frontend Name: data.frontend_ip_configurations.name + is_optional: true + - Frontend IP Address: data.frontend_ip_configurations.private_ip_address + is_optional: true + - Frontend IP Version: data.frontend_ip_configurations.private_ip_address_version + is_optional: true + - Frontend IP Used By: data.frontend_ip_configurations_used_by_display + type: list + options: + delimiter: '
' + is_optional: true + - Backend Pool Name: data.backend_address_pools.name + is_optional: true + - Backend Pool ID: data.backend_address_pools.id + is_optional: true + - Health Probe Name: data.probes.name + is_optional: true + - Health Probes Protocol: data.probes.protocol + is_optional: true + - Health Probes Port: data.probes.port + is_optional: true + - Health Probes Interval: data.probes.interval_in_seconds + is_optional: true + - Health Probes Unhealthy Threshold: data.probes.number_of_probes + is_optional: true + - LB Rule Name: data.load_balancing_rules.name + is_optional: true + - LB Rule Frontend IP Address: data.load_balancing_rules.frontend_ip_configuration_display + is_optional: true + - LB Rule Protocol: data.load_balancing_rules.protocol + is_optional: true + - LB Rule Frontend Port: data.load_balancing_rules.frontend_port + is_optional: true + - LB Rule Backend Port: data.load_balancing_rules.backend_port + is_optional: true + - LB Rule Backend Pool: data.load_balancing_rules.backend_address_pool_display + type: list + options: + delimiter: ', ' + is_optional: true + - LB Rule Session Persistence: data.load_balancing_rules.load_distribution_display + is_optional: true + - LB Rule Idle Timeout (minutes): data.load_balancing_rules.idle_timeout_in_minutes + is_optional: true + - LB Rule Floating IP: data.load_balancing_rules.enable_floating_ip + is_optional: true + - LB Rule TCP Reset: data.load_balancing_rules.enable_tcp_reset + is_optional: true + - Inbound NAT Rules Name: data.inbound_nat_rules.name + is_optional: true + - Inbound NAT Rule Protocol: data.inbound_nat_rules.protocol + is_optional: true + - Inbound NAT Rule Idle timeout (minutes): data.inbound_nat_rules.idle_timeout_in_minutes + is_optional: true + - Inbound NAT Rule TCP Reset: data.inbound_nat_rules.enable_tcp_reset + is_optional: true + - Inbound NAT Rule Port: data.inbound_nat_rules.frontend_port + is_optional: true + - Inbound NAT Rule Target Virtual Machine: data.inbound_nat_rules.target_virtual_machine + type: list + options: + delimiter: ', ' + is_optional: true + - Inbound NAT Rule Network IP Configuration: data.inbound_nat_rules.frontend_ip_configuration_display + is_optional: true + - Inbound NAT Rule Port mapping: data.inbound_nat_rules.port_mapping_display + is_optional: true + - Inbound NAT Rule Floating IP: data.inbound_nat_rules.enable_floating_ip + is_optional: true + - Inbound NAT Rule Target Port: data.inbound_nat_rules.backend_port + is_optional: true + + + +tabs.0: + name: LoadBalancers + type: item + fields: + - Name: name + - Resource Group: data.resource_group + - Resource ID: data.id + - Location: data.location + - Subscription: account + - SKU: type + - Backend pools: data.backend_address_pools_count_display + - Health Probe: data.probes_display + type: list + options: + delimiter: '
' + - Load Balancing Rule: data.load_balancing_rules_display + type: list + options: + delimiter: '
' + - NAT Rules: data.inbound_nat_rules_display + type: list + options: + delimiter: '
' + - Private IP Address: data.private_ip_address_display + type: list + options: + delimiter: '
' + + + +tabs.1: + name: Frontend IP Configurations + items: + - name: Frontend IP Configurations + type: simple-table + root_path: data.frontend_ip_configurations + fields: + - Name: name + - IP Address: private_ip_address + - IP Version: private_ip_address_version + - name: Used By + type: item + fields: + - Used By: data.frontend_ip_configurations_used_by_display + type: list + options: + delimiter: '
' + + + +tabs.2: + name: Backend Pools + items: + - name: Backend Pools + type: simple-table + root_path: data.backend_address_pools + fields: + - Name: name + - ID: id + - name: Backend Pools VM information + type: simple-table + root_path: data.network_interfaces + fields: + - Backend Pool: load_balancer_backend_address_pools_name_display + - VM Name: virtual_machine_name_display + - Network Interface: name + - Private IP Address: private_ip_display + type: list + options: + delimiter: '
' + + + +tabs.3: + name: Health Probes + type: table + root_path: data.probes + fields: + - Name: name + - Protocol: protocol + - Port: port + - Interval: interval_in_seconds + - Unhealthy Threshold: number_of_probes + + + +tabs.4: + name: Load Balancing Rules + type: table + root_path: data.load_balancing_rules + fields: + - Name: name + - Frontend IP Address: frontend_ip_configuration_display + - Protocol: protocol + - Frontend Port: frontend_port + - Backend Port: backend_port + - Backend Pool: backend_address_pool_display + - Session Persistence: load_distribution_display + - Idle Timeout (minutes): idle_timeout_in_minutes + - Floating IP: enable_floating_ip + - TCP Reset: enable_tcp_reset + + + +tabs.5: + name: Inbound NAT Rules + type: table + root_path: data.inbound_nat_rules + fields: + - Name: name + - Protocol: protocol + - Idle timeout (minutes): idle_timeout_in_minutes + - TCP Reset: enable_tcp_reset + - Port: frontend_port + - Target Virtual Machine: target_virtual_machine + type: list + options: + delimiter: ', ' + - Network IP Configuration: frontend_ip_configuration_display + - Port mapping: port_mapping_display + - Floating IP: enable_floating_ip + - Target Port: backend_port \ No newline at end of file diff --git a/src/plugin/metadata/nat_gateways/instance.yaml b/src/plugin/metadata/nat_gateways/instance.yaml index 7b8f49d3..582e8be3 100644 --- a/src/plugin/metadata/nat_gateways/instance.yaml +++ b/src/plugin/metadata/nat_gateways/instance.yaml @@ -4,28 +4,17 @@ search: - Subscription Name: data.subscription_name - Resource Group: data.resource_group - Location: data.location - - Virtual Machines: data.virtual_machines_display - - Inbound Rule Priority: data.inbound_security_rules.priority - - Inbound Rule Name: data.inbound_security_rules.name - - Inbound Rule Port: data.inbound_security_rules.destination_port_range - - Inbound Rule Protocol: data.inbound_security_rules.protocol - - Inbound Rule Source: data.inbound_security_rules.source_address_prefix - - Inbound Rule Destination: data.inbound_security_rules.destination_address_prefix - - Inbound Rule Action: data.inbound_security_rules.access - - Outbound Rule Priority: data.outbound_security_rules.priority - - Outbound Rule Name: data.outbound_security_rules.name - - Outbound Rule Port: data.outbound_security_rules.destination_port_range - - Outbound Rule Protocol: data.outbound_security_rules.protocol - - Outbound Rule Source: data.outbound_security_rules.source_address_prefix - - Outbound Rule Destination: data.outbound_security_rules.destination_address_prefix - - Outbound Rule Action: data.outbound_security_rules.access - - Network Interface Name: data.network_interfaces.name - - Network Interface Public IP Address: data.network_interfaces.public_ip_address - - Network Interface Private IP Address: data.network_interfaces.private_ip_address + - Public IP Name: data.public_ip_addresses.name + - Public IP Address: data.public_ip_addresses.ip_address + - Public DNS Name: data.public_ip_addresses.dns_settings.domain_name_label + - Public IP Prefix Name: data.public_ip_prefixes.name + - Public IP Prefix: data.public_ip_prefixes.ip_prefix - Subnet Name: data.subnets.name - - Subnet Address Range: data.subnets.address_prefix + - Subnet Addresses: data.subnets.address_prefixes - Virtual Network: data.subnets.virtual_network + + table: sort: key: data.id @@ -33,54 +22,32 @@ table: fields: - Resource Group: data.resource_group - Location: data.location - - Subscription ID: account - Subscription Name: data.subscription_name - - Virtual Machines: data.virtual_machines_display - - Inbound Rule Priority: data.inbound_security_rules.priority - is_optional: true - - Inbound Rule Name: data.inbound_security_rules.name - is_optional: true - - Inbound Rule Port: data.inbound_security_rules.destination_port_range - is_optional: true - - Inbound Rule Protocol: data.inbound_security_rules.protocol - is_optional: true - - Inbound Rule Source: data.inbound_security_rules.source_address_prefix - is_optional: true - - Inbound Rule Destination: data.inbound_security_rules.destination_address_prefix - is_optional: true - - Inbound Rule Action: data.inbound_security_rules.access - is_optional: true - - Outbound Rule Priority: data.outbound_security_rules.priority - is_optional: true - - Outbound Rule Name: data.outbound_security_rules.name - is_optional: true - - Outbound Rule Port: data.outbound_security_rules.destination_port_range - is_optional: true - - Outbound Rule Protocol: data.outbound_security_rules.protocol - is_optional: true - - Outbound Rule Source: data.outbound_security_rules.source_address_prefix - is_optional: true - - Outbound Rule Destination: data.outbound_security_rules.destination_address_prefix + - Subscription ID: account + - Subnets (count): data.subnets_count + - Public IP Addresses (count): data.public_ip_prefixes_count + - Public IP Prefixes (count): data.public_ip_prefixes_count + - Public IP Name (optional): data.public_ip_addresses.name is_optional: true - - Outbound Rule Action: data.outbound_security_rules.access + - Public IP Address (optional): data.public_ip_addresses.ip_address is_optional: true - - Network Interface Name: data.network_interfaces.name + - Public DNS Name (optional): data.public_ip_addresses.dns_settings.domain_name_label is_optional: true - - Network Interface Public IP Address: data.network_interfaces.public_ip_address + - Public IP Prefix Name (optional): data.public_ip_prefixes.name is_optional: true - - Network Interface Private IP Address: data.network_interfaces.private_ip_address + - Public IP Prefix (optional): data.public_ip_prefixes.ip_prefix is_optional: true - - Subnet Name: data.subnets.name + - Subnet Name (optional): data.subnets.name is_optional: true - - Subnet Address Range: data.subnets.address_prefix + - Subnet Addresses (optional): data.subnets.address_prefixes is_optional: true - - Virtual Network: data.subnets.virtual_network + - Virtual Network (optional): data.subnets.virtual_network is_optional: true tabs.0: - name: Network Security Group + name: NAT Gateway type: item fields: - Name: name @@ -89,55 +56,60 @@ tabs.0: - Location: data.location - Subscription: data.subscription_name - Subscription ID: account + - Subnets: data.subnets_count + - Public IP Addresses: data.public_ip_addresses_count + - Public IP Prefixes: data.public_ip_prefixes_count + - Idle Timeout (minutes): data.idle_timeout_in_minutes tabs.1: - name: Inbound Security Rules - type: table - root_path: data.inbound_security_rules - fields: - - Priority: priority - - Name: name - - Port: destination_port_range - - Protocol: protocol - - Source: source_address_prefix - - Destination: destination_address_prefix - - Action: access + name: Outbound IP + items: + - name: Public IP Addresses + type: simple-table + root_path: data.public_ip_addresses + fields: + - Name: name + - IP Address: ip_address + - DNS Name: dns_settings.domain_name_label + - name: Public IP Prefixes + type: simple-table + root_path: data.public_ip_prefixes + fields: + - Name: name + - IP Prefix: ip_prefix tabs.2: - name: Outbound Security Rules - type: table - root_path: data.outbound_security_rules - fields: - - Priority: priority - - Name: name - - Port: destination_port_range - - Protocol: protocol - - Source: source_address_prefix - - Destination: destination_address_prefix - - Action: access - - -tabs.3: - name: Network Interfaces - type: table - root_path: data.network_interfaces - fields: - - Name: name - - Public IP Address: public_ip_address - - Private IP Address: private_ip_address - - Virtual Machine: virtual_machine_display - - - -tabs.4: name: Subnets - type: table + type: simple-table root_path: data.subnets fields: - - Name: name - - Address Range: address_prefix + - Subnet Name: name + - Subnet Address: address_prefix + - Subnet Addresses: address_prefixes - Virtual Network: virtual_network + - Private Endpoint Network Policies: private_endpoint_network_policies + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Private Link Service Network Policies: private_link_service_network_policies + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state \ No newline at end of file diff --git a/src/plugin/metadata/network_security_groups/instance.yaml b/src/plugin/metadata/network_security_groups/instance.yaml index 1a28ac7d..6f37aab4 100644 --- a/src/plugin/metadata/network_security_groups/instance.yaml +++ b/src/plugin/metadata/network_security_groups/instance.yaml @@ -6,6 +6,7 @@ search: - Location: data.location - Virtual Machines: data.virtual_machines_display - Inbound Rule Priority: data.inbound_security_rules.priority + data_type: integer - Inbound Rule Name: data.inbound_security_rules.name - Inbound Rule Port: data.inbound_security_rules.destination_port_range - Inbound Rule Protocol: data.inbound_security_rules.protocol @@ -13,6 +14,7 @@ search: - Inbound Rule Destination: data.inbound_security_rules.destination_address_prefix - Inbound Rule Action: data.inbound_security_rules.access - Outbound Rule Priority: data.outbound_security_rules.priority + data_type: integer - Outbound Rule Name: data.outbound_security_rules.name - Outbound Rule Port: data.outbound_security_rules.destination_port_range - Outbound Rule Protocol: data.outbound_security_rules.protocol diff --git a/src/plugin/metadata/public_ip_addresses/ip_address.yaml b/src/plugin/metadata/public_ip_addresses/ip_address.yaml index 1ca1f263..ee2ae845 100644 --- a/src/plugin/metadata/public_ip_addresses/ip_address.yaml +++ b/src/plugin/metadata/public_ip_addresses/ip_address.yaml @@ -11,6 +11,7 @@ search: - IP Address Assignment: data.public_ip_allocation_method - Idle Timeout(Minutes): data.idle_timeout_in_minutes - DNS Name Label(Optional): data.dns_settings.domain_name_label + data_type: integer - Associated To: data.associated_to diff --git a/src/plugin/metadata/snapshots/instance.yaml b/src/plugin/metadata/snapshots/instance.yaml index 4b5b9560..4cc7f0e3 100644 --- a/src/plugin/metadata/snapshots/instance.yaml +++ b/src/plugin/metadata/snapshots/instance.yaml @@ -8,10 +8,12 @@ search: - Snapshot Type: data.incremental_display - Disk Size (Bytes): data.disk_size_bytes - Disk Size (GB): instance_size + data_type: float - Encryption: data.encryption.type_display - Network Access Policy: data.network_access_policy - Provisioning State: data.provisioning_state - Launched: data.time_created + data_type: datetime diff --git a/src/plugin/metadata/sql_databases/database.yaml b/src/plugin/metadata/sql_databases/database.yaml index 250c0cb9..0d881bcf 100644 --- a/src/plugin/metadata/sql_databases/database.yaml +++ b/src/plugin/metadata/sql_databases/database.yaml @@ -29,7 +29,6 @@ search: - Event Hub: data.diagnostic_settings_resource.event_hub_name - Log Analytics Workspace: data.diagnostic_settings_resource.workspace_id - Creation Date: data.creation_date - source_type: iso8601 type: datetime diff --git a/src/plugin/metadata/sql_servers/server.yaml b/src/plugin/metadata/sql_servers/server.yaml index 847d8de1..8d0dda9c 100644 --- a/src/plugin/metadata/sql_servers/server.yaml +++ b/src/plugin/metadata/sql_servers/server.yaml @@ -16,16 +16,15 @@ search: data_type: integer - Backup Database: data.databases.name - Backup Earliest PITR Restore Point (UTC): data.databases.earliest_restore_date - source_type: iso8601 type: datetime - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id - - '# of DBs': data.number_of_databases + - '# of SQL DBs': number_of_databases_display data_type: integer - Elastic Pool Name: data.elastic_pools.name - Elastic Pool Resource Group: data.elastic_pools.resource_group_display - Per DB Settings: data.elastic_pools.per_db_settings_display - Pricing Tier: data.elastic_pools.pricing_tier_display - - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases + - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases_display data_type: integer - Elastic Pool Unit: data.elastic_pools.unit_display - Elastic Pool Server Name: data.elastic_pools.server_name_display @@ -33,14 +32,11 @@ search: - Elastic Pool Maximum Storage Size: data.elastic_pools.max_size_gb - Deleted Database: data.deleted_databases.database_name - Deletion Time (UTC): data.deleted_databases.deletion_date - source_type: iso8601 type: datetime - Deleted Databases Creation Time (UTC): data.deleted_databases.creation_date - source_type: iso8601 type: datetime - Deleted Databases Edition Time (UTC): data.deleted_databases.edition - source_type: iso8601 - type: datetimecv + type: datetime - Audit Log Destination: data.server_auditing_settings.storage_endpoint - Audit Storage Account ID: data.server_auditing_settings.storage_account_subscription_id - Minimum TLS Version: data.minimal_tls_version @@ -108,7 +104,7 @@ table: is_optional: true - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id is_optional: true - - '# of DBs': data.number_of_databases + - '# of SQL DBs': data.number_of_databases_display is_optional: true - Elastic Pool Name: data.elastic_pools.name is_optional: true @@ -118,7 +114,7 @@ table: is_optional: true - Pricing Tier: data.elastic_pools.pricing_tier_display is_optional: true - - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases + - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases_display is_optional: true - Elastic Pool Unit: data.elastic_pools.unit_display is_optional: true @@ -381,7 +377,7 @@ tabs.5: - Resource Group: resource_group_display - Per DB Settings: per_db_settings_display - Pricing Tier: pricing_tier_display - - '# of DBs': number_of_databases + - '# of SQL DBs': number_of_databases_display - Unit: unit_display - Status: state type: enum diff --git a/src/plugin/metadata/storage_accounts/instance.yaml b/src/plugin/metadata/storage_accounts/instance.yaml index 4b2c6a90..0a8939cf 100644 --- a/src/plugin/metadata/storage_accounts/instance.yaml +++ b/src/plugin/metadata/storage_accounts/instance.yaml @@ -1,8 +1,11 @@ search: fields: - Container count: data.container_count_display + data_type: integer - Blob count: data.blob_count_display + data_type: integer - Blob total size(Bytes): data.blob_size_display + data_type: integer - Subscription ID: account - Subscription Name: data.subscription_name - Resource Group: data.resource_group @@ -33,6 +36,7 @@ search: - Internet Endpoints: data.routing_preference.publish_internet_endpoints - Container Name: data.container_item.name - Container Last Modified: data.container_item.last_modified_time + data_type: datetime - Container Public Access Level: data.container_item.public_access - Container Lease State: data.container_item.lease_state - Primary Location: data.primary_location diff --git a/src/plugin/metadata/vm_scale_sets/scale_set.yaml b/src/plugin/metadata/vm_scale_sets/scale_set.yaml index fae121c2..b7f87e7b 100644 --- a/src/plugin/metadata/vm_scale_sets/scale_set.yaml +++ b/src/plugin/metadata/vm_scale_sets/scale_set.yaml @@ -15,6 +15,7 @@ search: - Automatic Repairs: data.automatic_repairs_policy.enabled - Upgrade Policy: data.upgrade_policy.mode - Fault Domains (count): data.platform_fault_domain_count + data_type: integer diff --git a/src/plugin/metadata/web_pubsub_service/servuce.yaml b/src/plugin/metadata/web_pubsub_service/servuce.yaml new file mode 100644 index 00000000..74eec186 --- /dev/null +++ b/src/plugin/metadata/web_pubsub_service/servuce.yaml @@ -0,0 +1,183 @@ +search: + fields: + - Service State: data.provisioning_state + - Subscription Name: data.subscription_name + - Subscription ID: account + - Resource Group: data.resource_group + - Location: data.location + - Hub count: data.web_pubsub_hub_count_display + - SKU: data.sku.tier + - Unit: data.sku.capacity + - Version: data.version + - Host name: data.host_name + - Host name prefix: data.host_name_prefix + - Public IP: data.external_ip + - Public access: data.public_network_access + - Public port: data.public_port + - Server port: data.server_port + - TLS: data.tls.client_cert_enabled + + + +table: + sort: + key: data.id + desc: false + fields: + - Service State: data.provisioning_state + type: enum + enums: + - Running: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Succeeded: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Creating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Deleting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Moving: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Failed: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Canceled: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Unknown: + text_color: gray.400 + type: state + - Subscription Name: data.subscription_name + - Subscription ID: account + - Resource Group: data.resource_group + - Location: data.location + - Hub count: data.web_pubsub_hub_count_display + - SKU: data.sku.tier + - Unit: data.sku.capacity + - Version: data.version + - Host name: data.host_name + - Host name prefix: data.host_name_prefix + - Public IP: data.external_ip + - Public access: data.public_network_access + - Public port: data.public_port + - Server port: data.server_port + - TLS: data.tls.client_cert_enabled + + + +tabs.0: + name: Web PubSub Service + type: item + fields: + - Name: name + - Service State: data.provisioning_state + type: enum + enums: + - Running: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Succeeded: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Creating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Deleting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Moving: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Failed: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Canceled: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Unknown: + text_color: gray.400 + type: state + - Resource ID: data.id + - Resource Group: data.resource_group + - Subscription: data.subscription_name + - Subscription ID: account + - Region: data.location + - Hub count: data.web_pubsub_hub_count_display + - SKU: data.sku.tier + - Unit: data.sku.capacity + - Version: data.version + - Host name: data.host_name + - Host name prefix: data.host_name_prefix + - Public IP: data.external_ip + - Public access: data.public_network_access + - Public port: data.public_port + - Server port: data.server_port + - Disable add auth: data.disable_aad_auth + - Disable local auth: data.disable_local_auth + - TLS: data.tls.client_cert_enabled + + + +tabs.1: + name: Keys + type: item + fields: + - Host name: data.host_name + - Access Key: data.disable_local_auth + - Primary Key: data.web_pubsub_key.primary_key + - Primary Connection string: data.web_pubsub_key.primary_connection_string + - Secondary Key: data.web_pubsub_key.secondary_key + - Secondary Connection string: data.web_pubsub_key.secondary_connection_string + + + +tabs.2: + name: Hubs + type: table + root_path: data.web_pubsub_hubs + fields: + - Hub name: name + - Anonymous Connect: properties.anonymous_connect_policy + type: enum + enums: + + + diff --git a/src/plugin/metrics/CosmosDB/Instance/instance_count.yaml b/src/plugin/metrics/CosmosDB/Instance/instance_count.yaml new file mode 100644 index 00000000..abf0ea46 --- /dev/null +++ b/src/plugin/metrics/CosmosDB/Instance/instance_count.yaml @@ -0,0 +1,31 @@ +--- +metric_id: metric-azure-cosmos-db-instance-count +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.CosmosDB.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.kind + name: Kind + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-cosmos-db-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/CosmosDB/Instance/namespace.yaml b/src/plugin/metrics/CosmosDB/Instance/namespace.yaml new file mode 100644 index 00000000..3aa32269 --- /dev/null +++ b/src/plugin/metrics/CosmosDB/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-cosmos-db-instance +name: CosmosDB/Instance +resource_type: inventory.CloudService:azure.CosmosDB.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-cosmos-db.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/CosmosDB/Instance/sql_database_count.yaml b/src/plugin/metrics/CosmosDB/Instance/sql_database_count.yaml new file mode 100644 index 00000000..fa2967bb --- /dev/null +++ b/src/plugin/metrics/CosmosDB/Instance/sql_database_count.yaml @@ -0,0 +1,34 @@ +--- +metric_id: metric-azure-cosmos-db-instance-sql-db-count +name: SQL Database Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.CosmosDB.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.instance_type + name: Instance Type + - key: data.provisioning_state + name: Provisioning State + default: true + - key: data.kind + name: Kind + fields: + value: + key: data.sql_databases_count_display + operator: sum +unit: Count +namespace_id: ns-azure-cosmos-db-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/LoadBalancers/Instance/instance_count.yaml b/src/plugin/metrics/LoadBalancers/Instance/instance_count.yaml new file mode 100644 index 00000000..61392477 --- /dev/null +++ b/src/plugin/metrics/LoadBalancers/Instance/instance_count.yaml @@ -0,0 +1,29 @@ +--- +metric_id: metric-azure-lbs-instance-count +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.LoadBalancers.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-lbs-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/LoadBalancers/Instance/namespace.yaml b/src/plugin/metrics/LoadBalancers/Instance/namespace.yaml new file mode 100644 index 00000000..66e413dd --- /dev/null +++ b/src/plugin/metrics/LoadBalancers/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-lbs-instance +name: LoadBalancers/Instance +resource_type: inventory.CloudService:azure.LoadBalancers.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-loadbalancers.svg +version: '1.0' From 054943c9a01f3c54ea6842c1052ad37756b4b94f Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 2 Aug 2024 14:15:24 +0900 Subject: [PATCH 17/35] feat: Implement Postgre SQL Servers --- src/plugin/connector/base.py | 3 + .../connector/monitor/monitor_connector.py | 2 +- .../connector/postgre_sql_servers/__init__.py | 0 .../postgresql_servers_connector.py | 34 +++ src/plugin/manager/__init__.py | 1 + .../manager/postgre_sql_servers/__init__.py | 1 + .../postgre_sql_servers/server_manager.py | 219 ++++++++++++++++ .../metadata/postgre_sql_servers/server.yaml | 234 ++++++++++++++++++ .../PostgreSQLServers/Server/namespace.yaml | 8 + .../Server/server_count.yaml | 29 +++ 10 files changed, 530 insertions(+), 1 deletion(-) create mode 100644 src/plugin/connector/postgre_sql_servers/__init__.py create mode 100644 src/plugin/connector/postgre_sql_servers/postgresql_servers_connector.py create mode 100644 src/plugin/manager/postgre_sql_servers/__init__.py create mode 100644 src/plugin/manager/postgre_sql_servers/server_manager.py create mode 100644 src/plugin/metadata/postgre_sql_servers/server.yaml create mode 100644 src/plugin/metrics/PostgreSQLServers/Server/namespace.yaml create mode 100644 src/plugin/metrics/PostgreSQLServers/Server/server_count.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index 7eae84a1..e20ab678 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -11,6 +11,7 @@ from azure.mgmt.resource import ResourceManagementClient from azure.mgmt.storage import StorageManagementClient from azure.mgmt.cosmosdb import CosmosDBManagementClient +from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient from spaceone.core.connector import BaseConnector @@ -30,6 +31,7 @@ def __init__(self, *args, **kwargs): self.resource_client = None self.storage_client = None self.cosmosdb_client = None + self.postgre_sql_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -50,6 +52,7 @@ def set_connect(self, secret_data: dict): self.resource_client = ResourceManagementClient(credential=credential, subscription_id=subscription_id) self.storage_client = StorageManagementClient(credential=credential, subscription_id=subscription_id) self.cosmosdb_client = CosmosDBManagementClient(credential=credential, subscription_id=subscription_id) + self.postgre_sql_client = PostgreSQLManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/monitor/monitor_connector.py b/src/plugin/connector/monitor/monitor_connector.py index 59470a86..fe1c8cc5 100644 --- a/src/plugin/connector/monitor/monitor_connector.py +++ b/src/plugin/connector/monitor/monitor_connector.py @@ -15,4 +15,4 @@ def list_diagnostic_settings(self, resource_uri): def list_metrics(self, resource_uri, metricnames, aggregation, timespan=None, interval=None): return self.monitor_client.metrics.list(resource_uri, metricnames=metricnames, aggregation=aggregation, - timespan=timespan, interval=interval) \ No newline at end of file + timespan=timespan, interval=interval) diff --git a/src/plugin/connector/postgre_sql_servers/__init__.py b/src/plugin/connector/postgre_sql_servers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/postgre_sql_servers/postgresql_servers_connector.py b/src/plugin/connector/postgre_sql_servers/postgresql_servers_connector.py new file mode 100644 index 00000000..964e2875 --- /dev/null +++ b/src/plugin/connector/postgre_sql_servers/postgresql_servers_connector.py @@ -0,0 +1,34 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class PostgreSQLServersConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get("secret_data")) + + def list_servers(self): + return self.postgre_sql_client.servers.list() + + def list_firewall_rules_by_server(self, resource_group_name, server_name): + return self.postgre_sql_client.firewall_rules.list_by_server( + resource_group_name=resource_group_name, server_name=server_name + ) + + def list_virtual_network_rules_by_server(self, resource_group_name, server_name): + return self.postgre_sql_client.virtual_network_rules.list_by_server( + resource_group_name=resource_group_name, server_name=server_name + ) + + def list_replicas_by_server(self, resource_group_name, server_name): + return self.postgre_sql_client.replicas.list_by_server( + resource_group_name=resource_group_name, server_name=server_name + ) + + def list_server_administrators(self, resource_group_name, server_name): + return self.postgre_sql_client.server_administrators.list( + resource_group_name=resource_group_name, server_name=server_name + ) diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 880c6718..f4a42f41 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -12,3 +12,4 @@ from .vm_scale_sets import * from .load_balancers import * from .cosmos_db import * +from .postgre_sql_servers import * diff --git a/src/plugin/manager/postgre_sql_servers/__init__.py b/src/plugin/manager/postgre_sql_servers/__init__.py new file mode 100644 index 00000000..19ed5a5d --- /dev/null +++ b/src/plugin/manager/postgre_sql_servers/__init__.py @@ -0,0 +1 @@ +from .server_manager import PostgreSQLServersManager diff --git a/src/plugin/manager/postgre_sql_servers/server_manager.py b/src/plugin/manager/postgre_sql_servers/server_manager.py new file mode 100644 index 00000000..8e887474 --- /dev/null +++ b/src/plugin/manager/postgre_sql_servers/server_manager.py @@ -0,0 +1,219 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.postgre_sql_servers.postgresql_servers_connector import PostgreSQLServersConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class PostgreSQLServersManager(AzureBaseManager): + cloud_service_group = "PostgreSQLServers" + cloud_service_type = "Server" + service_code = "/Microsoft.DBforPostgreSQL/servers" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Database"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-sql-postgresql-server.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + postgre_sql_servers_conn = PostgreSQLServersConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + postgre_sql_servers = postgre_sql_servers_conn.list_servers() + + for postgre_sql_server in postgre_sql_servers: + + try: + postgre_sql_server_dict = self.convert_nested_dictionary( + postgre_sql_server + ) + postgre_sql_server_id = postgre_sql_server_dict["id"] + + # update application_gateway_dict + postgre_sql_server_dict = self.update_tenant_id_from_secret_data( + postgre_sql_server_dict, secret_data + ) + + postgre_sql_server_dict.update( + { + "resource_group": self.get_resource_group_from_id( + postgre_sql_server_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": postgre_sql_server_id}, + } + ) + + if postgre_sql_server_dict.get("name") is not None: + resource_group = postgre_sql_server_dict["resource_group"] + server_name = postgre_sql_server_dict["name"] + postgre_sql_server_dict.update( + { + "firewall_rules": self.list_firewall_rules_by_server( + postgre_sql_servers_conn, resource_group, server_name + ), + "virtual_network_rules": self.list_virtual_network_rules_by_server( + postgre_sql_servers_conn, resource_group, server_name + ), + "replicas": self.list_replicas_by_server( + postgre_sql_servers_conn, resource_group, server_name + ), + "server_administrators": self.list_server_administrators( + postgre_sql_servers_conn, resource_group, server_name + ), + } + ) + + self.set_region_code(postgre_sql_server_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=postgre_sql_server_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=postgre_sql_server_dict, + account=secret_data["subscription_id"], + instance_type=postgre_sql_server_dict["sku"]["tier"], + instance_size=float(postgre_sql_server_dict["max_size_gb"]), + region_code=postgre_sql_server_dict["location"], + reference=self.make_reference(postgre_sql_server_dict.get("id")), + tags=postgre_sql_server_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_sql_resources(self, cosmos_db_conn, account_name, resource_group): + sql_resources = [] + sql_resources_obj = cosmos_db_conn.list_sql_resources( + account_name=account_name, resource_group_name=resource_group + ) + + for sql in sql_resources_obj: + sql_dict = self.convert_nested_dictionary(sql) + sql_resources.append(sql_dict) + return sql_resources + + def list_firewall_rules_by_server(self, postgresql_conn, resource_group, name): + firewall_rules = [] + firewall_rules_obj = postgresql_conn.list_firewall_rules_by_server( + resource_group_name=resource_group, server_name=name + ) + + for firewall_rule in firewall_rules_obj: + firewall_rule_dict = self.convert_nested_dictionary(firewall_rule) + firewall_rules.append(firewall_rule_dict) + + return firewall_rules + + def list_virtual_network_rules_by_server( + self, postgresql_conn, resource_group, name + ): + virtual_network_rules = [] + virtual_network_rules_obj = ( + postgresql_conn.list_virtual_network_rules_by_server( + resource_group_name=resource_group, server_name=name + ) + ) + + for virtual_network in virtual_network_rules_obj: + virtual_network_dict = self.convert_nested_dictionary(virtual_network) + if virtual_network_dict.get("virtual_network_subnet_id") is not None: + virtual_network_dict.update( + { + "subnet_name": self.get_subnet_name( + virtual_network_dict["virtual_network_subnet_id"] + ), + "virtual_network_name_display": self.get_virtual_network_name( + virtual_network_dict["virtual_network_subnet_id"] + ), + } + ) + virtual_network_rules.append(virtual_network_dict) + + return virtual_network_rules + + def list_replicas_by_server(self, postgresql_conn, resource_group, name): + replicas_list = [] + replicas_obj = postgresql_conn.list_replicas_by_server( + resource_group_name=resource_group, server_name=name + ) + for replica in replicas_obj: + replica_dict = self.convert_nested_dictionary(replica) + if replica_dict.get("master_server_id") is not None: + replica_dict.update( + { + "master_server_name": self.get_replica_master_server_name( + replica_dict["master_server_id"] + ) + } + ) + + replicas_list.append(replica_dict) + return replicas_list + + def list_server_administrators(self, postgresql_conn, resource_group, name): + server_administrators = [] + server_admin_obj = postgresql_conn.list_server_administrators( + resource_group_name=resource_group, server_name=name + ) + for server_admin in server_admin_obj: + server_admin_dict = self.convert_nested_dictionary(server_admin) + server_administrators.append(server_admin_dict) + + return server_administrators + + @staticmethod + def get_subnet_name(subnet_id): + subnet_name = "" + if subnet_id: + subnet_name = subnet_id.split("/")[10] + return subnet_name + + @staticmethod + def get_virtual_network_name(subnet_id): + virtual_network_name = "" + if subnet_id: + virtual_network_name = subnet_id.split("/")[8] + return virtual_network_name + + @staticmethod + def get_replica_master_server_name(master_server_id): + master_server_name = master_server_id.split("/")[8] + return master_server_name + diff --git a/src/plugin/metadata/postgre_sql_servers/server.yaml b/src/plugin/metadata/postgre_sql_servers/server.yaml new file mode 100644 index 00000000..3b8e7176 --- /dev/null +++ b/src/plugin/metadata/postgre_sql_servers/server.yaml @@ -0,0 +1,234 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Server Name: data.fully_qualified_domain_name + - Admin Username: data.administrator_login + - PostgreSQL Version: data.version + - Performance Configuration Tier: instance_type + - Performance Configuration Name: data.sku.name + - Performance Configuration Capacity: data.sku.capacity + data_type: integer + - SSL Enforce Status: data.ssl_enforcement + - SSL Enforcement: data.ssl_enforcement + - Public Network Access: data.public_network_access + - TLS Setting: data.minimal_tls_version + - Firewall Rule Name: data.firewall_rules.name + - Firewall Rule Start IP: data.firewall_rules.start_ip_address + - Firewall Rule End IP: data.firewall_rules.end_ip_address + + + +table: + sort: + key: data.id + desc: false + fields: + - Type: instance_type + - Status: data.user_visible_state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Inaccessible: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Resource Group: data.resource_group + is_optional: true + - Location: data.location + is_optional: true + - Subscription Name: data.subscription_name + is_optional: true + - Subscription ID: account + is_optional: true + - Server Name: data.fully_qualified_domain_name + is_optional: true + - Admin Username: data.administrator_login + is_optional: true + - PostgreSQL Version: data.version + is_optional: true + - Performance Configuration Tier: instance_type + is_optional: true + - Performance Configuration Name: data.sku.name + is_optional: true + - Performance Configuration Capacity: data.sku.capacity + is_optional: true + - SSL Enforce Status: data.ssl_enforcement + is_optional: true + - Public Network Access: data.public_network_access + is_optional: true + - SSL Enforcement: data.ssl_enforcement + is_optional: true + - TLS Setting: data.minimal_tls_version + is_optional: true + - Firewall Rule Name: data.firewall_rules.name + is_optional: true + - Start IP: data.firewall_rules.start_ip_address + is_optional: true + - End IP: data.firewall_rules.end_ip_address + is_optional: true + - Virtual Network Rule Name: data.virtual_network_rules.name + is_optional: true + - Virtual Network: data.virtual_network_rules.virtual_network_name_display + is_optional: true + - Subnet: data.virtual_network_rules.subnet_name + is_optional: true + - Replicas Name: data.replicas.name + is_optional: true + - Replicas Location: data.replicas.location + is_optional: true + - Replicas Master Server Name: data.replicas.master_server_name + is_optional: true + - Active Directory Name: data.server_administrators.name + is_optional: true + - Login: data.server_administrators.login + is_optional: true + - SID: data.server_administrators.sid + is_optional: true + - Tenant ID: data.server_administrators.tenant_id + is_optional: true + - Compute Generation: data.sku.name + is_optional: true + - Compute Tier: instance_type + is_optional: true + - vCore: data.sku.capacity + is_optional: true + - Backup Retention Period (Days): data.storage_profile.backup_retention_days + is_optional: true + + + +tabs.0: + name: PostgreSQL Servers + type: item + fields: + - Name: name + - Resource Group: data.resource_group + - Resource ID: data.id + - Status: data.user_visible_state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Inaccessible: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - Server Name: data.fully_qualified_domain_name + - Admin Username: data.administrator_login + - PostgreSQL Version: data.version + - Performance Configuration Tier: data.sku.tier + - Performance Configuration Name: data.sku.name + - Performance Configuration Capacity: data.sku.capacity + - SSL Enforce Status: data.ssl_enforcement + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + + + +tabs.1: + name: Connection Security + type: item + fields: + - Public Network Access: data.public_network_access + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - SSL Enforcement: data.ssl_enforcement + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - TLS Setting: data.minimal_tls_version + + + +tabs.2: + name: Firewall Rules + type: simple-table + root_path: data.firewall_rules + fields: + - Firewall Rule Name: name + - Start IP: start_ip_address + - End IP: end_ip_address + + + +tabs.3: + name: VNET Rules + type: simple-table + root_path: data.virtual_network_rules + fields: + - Rule Name: name + - Virtual Network: virtual_network_name_display + - Subnet: subnet_name + - Endpoint Status: state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - InProgress: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Deleting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Initializing: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unknown: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state \ No newline at end of file diff --git a/src/plugin/metrics/PostgreSQLServers/Server/namespace.yaml b/src/plugin/metrics/PostgreSQLServers/Server/namespace.yaml new file mode 100644 index 00000000..cd6ff421 --- /dev/null +++ b/src/plugin/metrics/PostgreSQLServers/Server/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-postgresql-servers-server +name: PostgreSQL/Server +resource_type: inventory.CloudService:azure.PostgreSQLServers.Server +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-sql-postgresql-server.svg +version: '1.0' diff --git a/src/plugin/metrics/PostgreSQLServers/Server/server_count.yaml b/src/plugin/metrics/PostgreSQLServers/Server/server_count.yaml new file mode 100644 index 00000000..2b3cee47 --- /dev/null +++ b/src/plugin/metrics/PostgreSQLServers/Server/server_count.yaml @@ -0,0 +1,29 @@ +--- +metric_id: metric-azure-postgersql-servers-server-count +name: Server Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.PostgreSQLServers.Server +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-postgresql-servers-server +version: '1.0' \ No newline at end of file From 9308138ded21990b87176fe4e73cbecd38aa2fed Mon Sep 17 00:00:00 2001 From: lhhyung Date: Mon, 5 Aug 2024 13:13:24 +0900 Subject: [PATCH 18/35] feat: Implement Web PubSub Service Collector --- src/plugin/connector/base.py | 3 + .../connector/web_pub_sub_service/__init__.py | 0 .../web_pubsub_service_connector.py | 22 ++ src/plugin/manager/__init__.py | 1 + .../manager/web_pub_sub_service/__init__.py | 2 + .../web_pub_sub_service/hub_manager.py | 125 +++++++++++ .../web_pub_sub_service/service_manager.py | 207 ++++++++++++++++++ .../metadata/web_pub_sub_service/hub.yaml | 84 +++++++ .../service.yaml} | 140 ++++++++++++ .../WebPubSubService/Hub/hub_count.yaml | 31 +++ .../WebPubSubService/Hub/namespace.yaml | 8 + .../WebPubSubService/Service/namespace.yaml | 8 + .../Service/service_count.yaml | 34 +++ 13 files changed, 665 insertions(+) create mode 100644 src/plugin/connector/web_pub_sub_service/__init__.py create mode 100644 src/plugin/connector/web_pub_sub_service/web_pubsub_service_connector.py create mode 100644 src/plugin/manager/web_pub_sub_service/__init__.py create mode 100644 src/plugin/manager/web_pub_sub_service/hub_manager.py create mode 100644 src/plugin/manager/web_pub_sub_service/service_manager.py create mode 100644 src/plugin/metadata/web_pub_sub_service/hub.yaml rename src/plugin/metadata/{web_pubsub_service/servuce.yaml => web_pub_sub_service/service.yaml} (56%) create mode 100644 src/plugin/metrics/WebPubSubService/Hub/hub_count.yaml create mode 100644 src/plugin/metrics/WebPubSubService/Hub/namespace.yaml create mode 100644 src/plugin/metrics/WebPubSubService/Service/namespace.yaml create mode 100644 src/plugin/metrics/WebPubSubService/Service/service_count.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index e20ab678..63639892 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -12,6 +12,7 @@ from azure.mgmt.storage import StorageManagementClient from azure.mgmt.cosmosdb import CosmosDBManagementClient from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient +from azure.mgmt.webpubsub import WebPubSubManagementClient from spaceone.core.connector import BaseConnector @@ -32,6 +33,7 @@ def __init__(self, *args, **kwargs): self.storage_client = None self.cosmosdb_client = None self.postgre_sql_client = None + self.web_pubsub_service_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -53,6 +55,7 @@ def set_connect(self, secret_data: dict): self.storage_client = StorageManagementClient(credential=credential, subscription_id=subscription_id) self.cosmosdb_client = CosmosDBManagementClient(credential=credential, subscription_id=subscription_id) self.postgre_sql_client = PostgreSQLManagementClient(credential=credential, subscription_id=subscription_id) + self.web_pubsub_service_client = WebPubSubManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/web_pub_sub_service/__init__.py b/src/plugin/connector/web_pub_sub_service/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/web_pub_sub_service/web_pubsub_service_connector.py b/src/plugin/connector/web_pub_sub_service/web_pubsub_service_connector.py new file mode 100644 index 00000000..c91b13c1 --- /dev/null +++ b/src/plugin/connector/web_pub_sub_service/web_pubsub_service_connector.py @@ -0,0 +1,22 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class WebPubSubServiceConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get('secret_data')) + + def list_by_subscription(self): + return self.web_pubsub_service_client.web_pub_sub.list_by_subscription() + + def list_hubs(self, resource_group_name, resource_name): + return self.web_pubsub_service_client.web_pub_sub_hubs.list(resource_group_name=resource_group_name, + resource_name=resource_name) + + def list_keys(self, resource_group_name, resource_name): + return self.web_pubsub_service_client.web_pub_sub.list_keys(resource_group_name=resource_group_name, + resource_name=resource_name) \ No newline at end of file diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index f4a42f41..6fbee67c 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -13,3 +13,4 @@ from .load_balancers import * from .cosmos_db import * from .postgre_sql_servers import * +from .web_pub_sub_service import * diff --git a/src/plugin/manager/web_pub_sub_service/__init__.py b/src/plugin/manager/web_pub_sub_service/__init__.py new file mode 100644 index 00000000..f852770b --- /dev/null +++ b/src/plugin/manager/web_pub_sub_service/__init__.py @@ -0,0 +1,2 @@ +from .service_manager import WebPubSubServiceManager +from .hub_manager import WebPubSubHubManager diff --git a/src/plugin/manager/web_pub_sub_service/hub_manager.py b/src/plugin/manager/web_pub_sub_service/hub_manager.py new file mode 100644 index 00000000..486e73b2 --- /dev/null +++ b/src/plugin/manager/web_pub_sub_service/hub_manager.py @@ -0,0 +1,125 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.web_pub_sub_service.web_pubsub_service_connector import WebPubSubServiceConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class WebPubSubHubManager(AzureBaseManager): + cloud_service_group = "WebPubSubService" + cloud_service_type = "Hub" + service_code = "/Microsoft.SignalRService/WebPubSub/hubs" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Application Integration"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-web-pubsub-service.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + return cloud_services, error_responses + + # def create_cloud_service(self, options, secret_data, schema): + # cloud_services = [] + # error_responses = [] + # + # web_pubsub_service_conn = WebPubSubServiceConnector(secret_data=secret_data) + # subscription_conn = SubscriptionsConnector(secret_data=secret_data) + # + # subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + # subscription_info = self.convert_nested_dictionary(subscription_obj) + # + # web_pubsub_services = web_pubsub_service_conn.list_by_subscription() + # + # for web_pubsub_service in web_pubsub_services: + # + # try: + # web_pubsub_service_dict = self.convert_nested_dictionary( + # web_pubsub_service + # ) + # web_pubsub_service_id = web_pubsub_service_dict["id"] + # resource_group_name = self.get_resource_group_from_id( + # web_pubsub_service_id + # ) + # resource_name = web_pubsub_service_dict["name"] + # + # web_pubsub_hubs = web_pubsub_service_conn.list_hubs( + # resource_group_name=resource_group_name, resource_name=resource_name + # ) + # + # web_pubsub_hubs_dict = [ + # self.convert_nested_dictionary(hub) for hub in web_pubsub_hubs + # ] + # + # for web_pubsub_hub_dict in web_pubsub_hubs_dict: + # + # web_pubsub_hub_id = web_pubsub_hub_dict["id"] + # resource_group_name = self.get_resource_group_from_id(web_pubsub_hub_id) + # web_pubsub_hub_dict.update( + # { + # "tenant_id": secret_data["tenant_id"], + # "location": web_pubsub_service_dict["location"], + # "resource_group": resource_group_name, + # "subscription_id": subscription_info["subscription_id"], + # "subscription_name": subscription_info["display_name"], + # "azure_monitor": {"resource_id": web_pubsub_hub_id}, + # "web_pubsub_svc_name": self.get_web_pubsub_name_from_id( + # web_pubsub_hub_id + # ), + # "web_pubsub_hub_evnet_handler_count_display": len( + # web_pubsub_hub_dict.get("properties", {}).get( + # "event_handlers", [] + # ) + # ), + # } + # ) + # + # cloud_services.append( + # make_cloud_service( + # name=web_pubsub_hub_dict["name"], + # cloud_service_type=self.cloud_service_type, + # cloud_service_group=self.cloud_service_group, + # provider=self.provider, + # data=web_pubsub_hub_dict, + # account=web_pubsub_hub_dict["subscription_id"], + # region_code=web_pubsub_hub_dict["location"], + # reference=self.make_reference(web_pubsub_hub_dict.get("id")), + # tags=web_pubsub_hub_dict.get("tags", {}), + # data_format="dict" + # ) + # ) + # + # except Exception as e: + # _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + # error_responses.append( + # make_error_response( + # error=e, + # provider=self.provider, + # cloud_service_group=self.cloud_service_group, + # cloud_service_type=self.cloud_service_type, + # ) + # ) + # + # return cloud_services, error_responses + # + # @staticmethod + # def get_web_pubsub_name_from_id(dict_id): + # svc_name = dict_id.split("/")[-3] + # return svc_name diff --git a/src/plugin/manager/web_pub_sub_service/service_manager.py b/src/plugin/manager/web_pub_sub_service/service_manager.py new file mode 100644 index 00000000..96046699 --- /dev/null +++ b/src/plugin/manager/web_pub_sub_service/service_manager.py @@ -0,0 +1,207 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.web_pub_sub_service.web_pubsub_service_connector import WebPubSubServiceConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager +from plugin.manager.web_pub_sub_service.hub_manager import WebPubSubHubManager + +_LOGGER = logging.getLogger(__name__) + + +class WebPubSubServiceManager(AzureBaseManager): + cloud_service_group = "WebPubSubService" + cloud_service_type = "Service" + service_code = "/Microsoft.SignalRService/WebPubSub" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Application Integration"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-web-pubsub-service.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + web_pubsub_service_conn = WebPubSubServiceConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + web_pubsub_services = web_pubsub_service_conn.list_by_subscription() + + for web_pubsub_service in web_pubsub_services: + + try: + web_pubsub_service_dict = self.convert_nested_dictionary( + web_pubsub_service + ) + web_pubsub_service_id = web_pubsub_service_dict["id"] + resource_group_name = self.get_resource_group_from_id( + web_pubsub_service_id + ) + resource_name = web_pubsub_service_dict["name"] + + # Update data info in Container Instance's Raw Data + + # Make private endpoint name + if private_endpoints := web_pubsub_service_dict.get( + "private_endpoint_connections", [] + ): + for private_endpoint in private_endpoints: + private_endpoint["private_endpoint"][ + "private_endpoint_name_display" + ] = self.get_resource_name_from_id( + private_endpoint["private_endpoint"]["id"] + ) + + # Collect Web PubSub Hub resource + web_pubsub_hubs = web_pubsub_service_conn.list_hubs( + resource_group_name=resource_group_name, resource_name=resource_name + ) + web_pubsub_hubs_dict = [ + self.convert_nested_dictionary(hub) for hub in web_pubsub_hubs + ] + + _hub_responses, _hub_errors = self._collect_web_pubsub_hub( + web_pubsub_hubs_dict, + subscription_info, + web_pubsub_service_dict["location"], + secret_data["tenant_id"] + ) + + cloud_services.extend(_hub_responses) + error_responses.extend(_hub_errors) + + # Add Web PubSub Key info in data + # web_pubsub_key = web_pubsub_service_conn.list_keys( + # resource_group_name=resource_group_name, resource_name=resource_name + # ) + # web_pubsub_key = {} + # if web_pubsub_key: + # web_pubsub_service_dict["web_pubsub_key"] = ( + # self.convert_nested_dictionary(web_pubsub_key) + # ) + + web_pubsub_service_dict.update( + { + "resource_group": resource_group_name, + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": web_pubsub_service_id}, + "web_pubsub_hubs": web_pubsub_hubs_dict, + "web_pubsub_hub_count_display": len(web_pubsub_hubs_dict), + } + ) + + cloud_services.append( + make_cloud_service( + name=resource_name, + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=web_pubsub_service_dict, + account=web_pubsub_service_dict["subscription_id"], + region_code=web_pubsub_service_dict["location"], + reference=self.make_reference(web_pubsub_service_dict.get("id")), + tags=web_pubsub_service_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def _collect_web_pubsub_hub( + self, web_pubsub_hubs_dict, subscription_info, location, tenant_id + ): + cloud_services = [] + error_responses = [] + + web_pubsub_hub_manager = WebPubSubHubManager() + + for web_pubsub_hub_dict in web_pubsub_hubs_dict: + + try: + web_pubsub_hub_id = web_pubsub_hub_dict["id"] + resource_group_name = self.get_resource_group_from_id(web_pubsub_hub_id) + + web_pubsub_hub_dict.update( + { + "tenant_id": tenant_id, + "location": location, + "resource_group": resource_group_name, + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": web_pubsub_hub_id}, + "web_pubsub_svc_name": self.get_web_pubsub_name_from_id( + web_pubsub_hub_id + ), + "web_pubsub_hub_evnet_handler_count_display": len( + web_pubsub_hub_dict.get("properties", {}).get( + "event_handlers", [] + ) + ), + } + ) + + cloud_services.append( + make_cloud_service( + name=web_pubsub_hub_dict["name"], + cloud_service_type=web_pubsub_hub_manager.cloud_service_type, + cloud_service_group=web_pubsub_hub_manager.cloud_service_group, + provider=self.provider, + data=web_pubsub_hub_dict, + account=web_pubsub_hub_dict["subscription_id"], + region_code=web_pubsub_hub_dict["location"], + reference=self.make_reference(web_pubsub_hub_dict.get("id")), + tags=web_pubsub_hub_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + @staticmethod + def get_resource_name_from_id(dict_id): + resource_name = dict_id.split("/")[-1] + return resource_name + + @staticmethod + def get_web_pubsub_name_from_id(dict_id): + svc_name = dict_id.split("/")[-3] + return svc_name diff --git a/src/plugin/metadata/web_pub_sub_service/hub.yaml b/src/plugin/metadata/web_pub_sub_service/hub.yaml new file mode 100644 index 00000000..a6c98282 --- /dev/null +++ b/src/plugin/metadata/web_pub_sub_service/hub.yaml @@ -0,0 +1,84 @@ +search: + fields: + - Anonymous Connect: data.properties.anonymous_connect_policy + - Event Handlers count: data.web_pubsub_hub_evnet_handler_count_display + data_type: integer + - Web SubSub Service: data.web_pubsub_svc_name + - Subscription Name: data.subscription_name + - Subscription ID: account + - Resource Group: data.resource_group + - Location: data.location + + + +table: + sort: + key: data.id + desc: false + fields: + - Anonymous Connect: data.properties.anonymous_connect_policy + type: enum + enums: + - allow: indigo.500 + type: badge + - deny: coral.600 + type: badge + - Event Handlers count: data.web_pubsub_hub_evnet_handler_count_display + - Web SubSub Service: data.web_pubsub_svc_name + - Subscription Name: data.subscription_name + - Subscription ID: account + - Resource Group: data.resource_group + - Location: data.location + + + +tabs.0: + name: Web PubSub Hub + type: item + fields: + - Hub name: name + - Resource ID: data.id + - Resource Group: data.resource_group + - Subscription: data.subscription_name + - Subscription ID: account + - Region: data.location + - Anonymous Connect: data.properties.anonymous_connect_policy + type: enum + enums: + - allow: indigo.500 + type: badge + - deny: coral.600 + type: badge + - EventHandler count: data.web_pubsub_hub_evnet_handler_count_display + + + +tabs.1: + name: Event Handlers + type: table + root_path: data.properties.event_handlers + fields: + - Url template: url_template + - User events: user_event_pattern + - System events: system_events + type: list + options: + delimiter: ', ' + - Authentication: auth.type + + + +tabs.2: + name: System data + type: item + fields: + - Created at: created_at + source_type: iso8601 + type: datetime + - Created by: created_by + - Created by type: created_by_type + - Last modified at: last_modified_at + source_type: iso8601 + type: datetime + - Last modified by: last_modified_by + - Last modified by type: last_modified_by_type \ No newline at end of file diff --git a/src/plugin/metadata/web_pubsub_service/servuce.yaml b/src/plugin/metadata/web_pub_sub_service/service.yaml similarity index 56% rename from src/plugin/metadata/web_pubsub_service/servuce.yaml rename to src/plugin/metadata/web_pub_sub_service/service.yaml index 74eec186..8814f742 100644 --- a/src/plugin/metadata/web_pubsub_service/servuce.yaml +++ b/src/plugin/metadata/web_pub_sub_service/service.yaml @@ -6,9 +6,12 @@ search: - Resource Group: data.resource_group - Location: data.location - Hub count: data.web_pubsub_hub_count_display + data_type: integer - SKU: data.sku.tier - Unit: data.sku.capacity + data_type: integer - Version: data.version + data_type: float - Host name: data.host_name - Host name prefix: data.host_name_prefix - Public IP: data.external_ip @@ -178,6 +181,143 @@ tabs.2: - Anonymous Connect: properties.anonymous_connect_policy type: enum enums: + - allow: indigo.500 + type: badge + - deny: coral.600 + type: badge + - Event Handlers: properties.event_handlers.url_template + type: list + options: + delimiter: '
' +tabs.3: + name: Public access + type: table + fields: + - Public network access: data.public_network_access + type: enum + enums: + - Enabled: indigo.500 + type: badge + - Disabled: coral.600 + type: badge + + + +tabs.4: + name: Private access + items: + - name: Private endpoint connections + type: table + root_path: data.private_endpoint_connections + fields: + - Connection name: name + - Connection state: private_link_service_connection_state.status + type: enum + enums: + - Approved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Pending: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Disconnected: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Rejected: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Private Endpoint: private_endpoint.private_endpoint_name_display + - Description: private_link_service_connection_state.status + - Group ids: group_ids + type: list + options: + delimiter: '
' + - Provisioning state: provisioning_state + - name: Shared private endpoints + type: table + root_path: data.shared_private_link_resources + fields: + - Name: name + - Private link resource ID: private_link_resource_id + - Group ID: group_id + - Connection state: status + type: enum + enums: + - Approved: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Pending: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Disconnected: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Rejected: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Description: request_message + - Provisioning state: provisioning_state + + + +tabs.5: + name: Access control rules + items: + - name: Default action + type: item + fields: + - Default action: data.network_ac_ls.default_action + type: enum + enums: + - Enabled: indigo.500 + type: badge + - Disabled: coral.600 + type: badge + - name: Public network + type: item + fields: + - Allow: data.network_ac_ls.public_network.allow + type: list + options: + delimiter: ', ' + - name: Private endpoint connections + type: table + root_path: data.network_ac_ls.private_endpoints + fields: + - Connection name: name + - Allow: allow + type: list + options: + delimiter: ', ' + + + +tabs.6: + name: System data + type: item + fields: + - Created at: data.system_data.created_at + source_type: iso8601 + type: datetime + - Created by: data.system_data.created_by + - Created by type: data.system_data.created_by_type + - Last modified at: data.system_data.last_modified_at + source_type: iso8601 + type: datetime + - Last modified by: data.system_data.last_modified_by + - Last modified by type: data.system_data.last_modified_by_type \ No newline at end of file diff --git a/src/plugin/metrics/WebPubSubService/Hub/hub_count.yaml b/src/plugin/metrics/WebPubSubService/Hub/hub_count.yaml new file mode 100644 index 00000000..197bde1d --- /dev/null +++ b/src/plugin/metrics/WebPubSubService/Hub/hub_count.yaml @@ -0,0 +1,31 @@ +--- +metric_id: metric-azure-web-pub-sub-service-hub +name: Hub Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.WebPubSubService.Hub +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-web-pub-sub-service-hub +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/WebPubSubService/Hub/namespace.yaml b/src/plugin/metrics/WebPubSubService/Hub/namespace.yaml new file mode 100644 index 00000000..52dfc59a --- /dev/null +++ b/src/plugin/metrics/WebPubSubService/Hub/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-web-pub-sub-service-hub +name: WebPubSubService/Hub +resource_type: inventory.CloudService:azure.WebPubSubService.Hub +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-web-pubsub-service.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/WebPubSubService/Service/namespace.yaml b/src/plugin/metrics/WebPubSubService/Service/namespace.yaml new file mode 100644 index 00000000..c4465194 --- /dev/null +++ b/src/plugin/metrics/WebPubSubService/Service/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-web-pub-sub-service-service +name: WebPubSubService/Service +resource_type: inventory.CloudService:azure.WebPubSubService.Service +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-web-pubsub-service.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/WebPubSubService/Service/service_count.yaml b/src/plugin/metrics/WebPubSubService/Service/service_count.yaml new file mode 100644 index 00000000..77dada5f --- /dev/null +++ b/src/plugin/metrics/WebPubSubService/Service/service_count.yaml @@ -0,0 +1,34 @@ +--- +metric_id: metric-azure-web-pub-sub-service-service +name: Service Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.WebPubSubService.Service +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.sku.name + name: Sku name + - key: data.sku.tier + name: Sku Tier + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + default: true + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-web-pub-sub-service-service +version: '1.0' \ No newline at end of file From 0130585649ed9ffd3c1d5e72f87d6cc4966548cb Mon Sep 17 00:00:00 2001 From: lhhyung Date: Mon, 5 Aug 2024 15:17:44 +0900 Subject: [PATCH 19/35] feat: Implement KeyVaults Collector --- src/plugin/connector/base.py | 7 + src/plugin/connector/key_vaults/__init__.py | 0 .../key_vaults/key_vaults_connector.py | 46 ++++ src/plugin/manager/__init__.py | 1 + src/plugin/manager/key_vaults/__init__.py | 1 + .../manager/key_vaults/instance_manager.py | 232 ++++++++++++++++++ src/plugin/metadata/key_vaults/instance.yaml | 203 +++++++++++++++ .../Instance/certificates_count.yaml | 31 +++ .../KeyVaults/Instance/credentials_count.yaml | 31 +++ .../KeyVaults/Instance/instance_count.yaml | 32 +++ .../metrics/KeyVaults/Instance/key_count.yaml | 31 +++ .../metrics/KeyVaults/Instance/namespace.yaml | 8 + .../KeyVaults/Instance/secret_count.yaml | 31 +++ 13 files changed, 654 insertions(+) create mode 100644 src/plugin/connector/key_vaults/__init__.py create mode 100644 src/plugin/connector/key_vaults/key_vaults_connector.py create mode 100644 src/plugin/manager/key_vaults/__init__.py create mode 100644 src/plugin/manager/key_vaults/instance_manager.py create mode 100644 src/plugin/metadata/key_vaults/instance.yaml create mode 100644 src/plugin/metrics/KeyVaults/Instance/certificates_count.yaml create mode 100644 src/plugin/metrics/KeyVaults/Instance/credentials_count.yaml create mode 100644 src/plugin/metrics/KeyVaults/Instance/instance_count.yaml create mode 100644 src/plugin/metrics/KeyVaults/Instance/key_count.yaml create mode 100644 src/plugin/metrics/KeyVaults/Instance/namespace.yaml create mode 100644 src/plugin/metrics/KeyVaults/Instance/secret_count.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index 63639892..fd1a67b2 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -13,6 +13,9 @@ from azure.mgmt.cosmosdb import CosmosDBManagementClient from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient from azure.mgmt.webpubsub import WebPubSubManagementClient +from azure.mgmt.keyvault import KeyVaultManagementClient +from azure.mgmt.rdbms.mysql import MySQLManagementClient + from spaceone.core.connector import BaseConnector @@ -34,6 +37,8 @@ def __init__(self, *args, **kwargs): self.cosmosdb_client = None self.postgre_sql_client = None self.web_pubsub_service_client = None + self.key_vault_client = None + self.mysql_client = None def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -56,6 +61,8 @@ def set_connect(self, secret_data: dict): self.cosmosdb_client = CosmosDBManagementClient(credential=credential, subscription_id=subscription_id) self.postgre_sql_client = PostgreSQLManagementClient(credential=credential, subscription_id=subscription_id) self.web_pubsub_service_client = WebPubSubManagementClient(credential=credential, subscription_id=subscription_id) + self.key_vault_client = KeyVaultManagementClient(credential=credential, subscription_id=subscription_id) + self.mysql_client = MySQLManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/key_vaults/__init__.py b/src/plugin/connector/key_vaults/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/key_vaults/key_vaults_connector.py b/src/plugin/connector/key_vaults/key_vaults_connector.py new file mode 100644 index 00000000..5ca9b1bd --- /dev/null +++ b/src/plugin/connector/key_vaults/key_vaults_connector.py @@ -0,0 +1,46 @@ +import logging + +from plugin.connector.base import AzureBaseConnector +from azure.keyvault.secrets import SecretClient +from azure.keyvault.certificates import CertificateClient +from azure.identity import DefaultAzureCredential + +_LOGGER = logging.getLogger("spaceone") + + +class KeyVaultsConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.set_connect(kwargs.get("secret_data")) + # self.key_vault_secret_client = None + # self.key_vault_certificate_client = None + + def init_key_vault_secret_client(self, subscription_id, vault_uri): + credential = DefaultAzureCredential() + key_vault_secret_client = SecretClient( + credential=credential, subscription_id=subscription_id, vault_url=vault_uri + ) + return key_vault_secret_client + + def init_key_vault_certificate_client(self, subscription_id, vault_uri): + credential = DefaultAzureCredential() + key_vault_certificate_client = CertificateClient( + credential=credential, subscription_id=subscription_id, vault_url=vault_uri + ) + return key_vault_certificate_client + + def list_all_key_vaults(self): + return self.key_vault_client.vaults.list_by_subscription() + + def get_key_vaults(self): + return self.key_vault_client.vaults.get() + + def list_keys(self, resource_group_name, vault_name): + return self.key_vault_client.keys.list( + resource_group_name=resource_group_name, vault_name=vault_name + ) + + def list_secrets(self): + # return self.key_vault_secrets_client.list_properties_of_secrets() + return self.key_vault_client.secrets.list() \ No newline at end of file diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 6fbee67c..b992326e 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -14,3 +14,4 @@ from .cosmos_db import * from .postgre_sql_servers import * from .web_pub_sub_service import * +from .key_vaults import * diff --git a/src/plugin/manager/key_vaults/__init__.py b/src/plugin/manager/key_vaults/__init__.py new file mode 100644 index 00000000..26e1d194 --- /dev/null +++ b/src/plugin/manager/key_vaults/__init__.py @@ -0,0 +1 @@ +from .instance_manager import KeyVaultsManager diff --git a/src/plugin/manager/key_vaults/instance_manager.py b/src/plugin/manager/key_vaults/instance_manager.py new file mode 100644 index 00000000..449d76ca --- /dev/null +++ b/src/plugin/manager/key_vaults/instance_manager.py @@ -0,0 +1,232 @@ +import logging + +import azure.core.exceptions + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.key_vaults.key_vaults_connector import KeyVaultsConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class KeyVaultsManager(AzureBaseManager): + cloud_service_group = "KeyVaults" + cloud_service_type = "Instance" + service_code = "/Microsoft.KeyVault/vaults" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Security"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-key-vault.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + key_vaults_conn = KeyVaultsConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + key_vaults_obj_list = key_vaults_conn.list_all_key_vaults() + + for key_vault in key_vaults_obj_list: + + try: + key_vault_dict = self.convert_nested_dictionary(key_vault) + key_vault_id = key_vault_dict["id"] + + key_vault_dict = self.update_tenant_id_from_secret_data( + key_vault_dict, secret_data + ) + + key_vault_dict.update( + { + "resource_group": self.get_resource_group_from_id( + key_vault_id + ), # parse resource_group from ID + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": key_vault_id}, + } + ) + + resource_group_name = key_vault_dict.get("resource_group", "") + subscription_id = key_vault_dict.get("subscription_id", "") + + # Get list of keys, secrets + if key_vault_dict.get("properties", {}).get("vault_uri") is not None: + vault_name = key_vault_dict["name"] + vault_uri = key_vault_dict["properties"]["vault_uri"] + + keys = self.list_keys( + key_vaults_conn, resource_group_name, vault_name + ) + + secrets, secrets_permissions_display = self.list_secrets( + key_vaults_conn, subscription_id, vault_uri + ) + + ( + certificates, + certificates_permissions_display, + ) = self.list_certificates( + key_vaults_conn, subscription_id, vault_uri + ) + + key_vault_dict.update( + { + "keys": keys, + "secrets": secrets, + "certificates": certificates, + "key_count": len(keys), + "secret_count": len(secrets), + "certificate_count": len(certificates), + "total_credentials_count": len(keys) + + len(secrets) + + len(certificates), + "keys_permissions_description_display": "Microsoft.KeyVault/vaults/read", + "secrets_permissions_description_display": secrets_permissions_display, + "certificates_permissions_description_display": certificates_permissions_display, + } + ) + + # Get name of private connection from ID + if ( + key_vault_dict.get("properties", {}).get( + "private_endpoint_connections" + ) + is not None + ): + key_vault_dict["properties"].update( + { + "private_endpoint_connections": self.get_private_endpoint_name( + key_vault_dict["properties"][ + "private_endpoint_connections" + ] + ) + } + ) + + # Change purge protection to user-friendly word + if ( + key_vault_dict.get("properties", {}).get("enable_purge_protection") + is not None + ): + key_vault_dict["properties"].update( + { + "enable_purge_protection_str": "Disabled" + if key_vault_dict["properties"]["enable_purge_protection"] + is False + else "Enabled" + } + ) + if sku := key_vault_dict.get("properties", {}).get("sku"): + key_vault_dict["sku"] = sku + + self.set_region_code(key_vault_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=key_vault_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=key_vault_dict, + account=secret_data["subscription_id"], + instance_type=key_vault_dict["properties"]["sku"]["name"], + region_code=key_vault_dict["location"], + reference=self.make_reference(key_vault_dict.get("id")), + tags=key_vault_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def list_keys(self, key_vault_conn, resource_group_name, vault_name): + keys = [] + keys_obj_list = key_vault_conn.list_keys( + resource_group_name=resource_group_name, vault_name=vault_name + ) + + if keys_obj_list: + for key in keys_obj_list: + key_dict = self.convert_nested_dictionary(key) + keys.append(key_dict) + return keys + + def list_secrets(self, key_vault_conn, subscription_id, vault_uri): + secrets = [] + permissions_display = "Microsoft.KeyVault/vaults/secrets/read, Microsoft.KeyVault/vaults/secrets/readMetadata/action" + + try: + key_vault_secret_client = key_vault_conn.init_key_vault_secret_client( + subscription_id=subscription_id, vault_uri=vault_uri + ) + + secrets_obj_list = key_vault_secret_client.list_properties_of_secrets() + + if secrets_obj_list: + for secret in secrets_obj_list: + secret_dict = self.convert_nested_dictionary(secret) + secrets.append(secret_dict) + except azure.core.exceptions.HttpResponseError as e: + _LOGGER.error(f"[list_secrets] {e}", exc_info=True) + permissions_display = "If you want to see the secretes list, please grant 'List' permission(Microsoft.KeyVault/vaults/secrets/read, Microsoft.KeyVault/vaults/secrets/readMetadata/action) to the service principal. or assign built-in role KeyVault Reader to the service principal.(https://learn.microsoft.com/en-us/azure/key-vault/general/rbac-guide?tabs=azure-cli#azure-built-in-roles-for-key-vault-data-plane-operations)" + return secrets, permissions_display + + def list_certificates(self, key_vault_conn, subscription_id, vault_uri): + certificates = [] + permissions_display = "Microsoft.KeyVault/vaults/secrets/readMetadata/action, Microsoft.KeyVault/vaults/certificates/read" + try: + key_vault_certificate_client = ( + key_vault_conn.init_key_vault_certificate_client( + subscription_id=subscription_id, vault_uri=vault_uri + ) + ) + + certificate_obj_list = ( + key_vault_certificate_client.list_properties_of_certificates() + ) + + if certificate_obj_list: + for certificate in certificate_obj_list: + secret_dict = self.convert_nested_dictionary(certificate) + certificates.append(secret_dict) + except azure.core.exceptions.HttpResponseError as e: + _LOGGER.error(f"[list_secrets] {e}", exc_info=True) + permissions_display = "If you want to see the secretes list, please grant 'List' permission(Microsoft.KeyVault/vaults/secrets/read, Microsoft.KeyVault/vaults/secrets/readMetadata/action) to the service principal. or assign built-in role 'KeyVault Reader' to the service principal.(https://learn.microsoft.com/en-us/azure/key-vault/general/rbac-guide?tabs=azure-cli#azure-built-in-roles-for-key-vault-data-plane-operations)" + + return certificates, permissions_display + + @staticmethod + def get_private_endpoint_name(private_endpoint_connections): + for private_endpoint in private_endpoint_connections: + private_endpoint.update({"name": private_endpoint["id"].split("/")[10]}) + return private_endpoint_connections diff --git a/src/plugin/metadata/key_vaults/instance.yaml b/src/plugin/metadata/key_vaults/instance.yaml new file mode 100644 index 00000000..2cddf66e --- /dev/null +++ b/src/plugin/metadata/key_vaults/instance.yaml @@ -0,0 +1,203 @@ +search: + fields: + - Type: instance_type + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Public IP Address: data.public_ip_addresses.name + - Vault URI: data.properties.vault_uri + - SKU (Pricing Tier): data.sku.name + - Directory ID: data.properties.tenant_id + - Soft-delete: data.properties.enable_soft_delete + - Purge Protection: data.properties.enable_purge_protection + - Key Name: data.keys.name + - Key Type: data.keys.type + - Key Location: data.keys.location + - Key Status: data.keys.attributes.enabled + - Key Expiration Date: data.keys.attributes.expires + - Key Creation Date: data.keys.attributes.created + - Key URI: data.keys.key_uri + - Enable for Azure VM Deployment: data.properties.enabled_for_deployment + - Enable for Disk Encryption: data.properties.enabled_for_disk_encryption + - Enable for Template Deployment: data.properties.enabled_for_template_deployment + - Enable RBAC Authorization: data.properties.enable_rbac_authorization + - Private Endpoint Connection Name: data.properties.private_endpoint_connections.name + - Private Endpoint Connection State: data.properties.private_endpoint_connections.private_link_service_connection_state.status + - Private Endpoint ID: data.properties.private_endpoint_connections.private_endpoint.id + + + +table: + sort: + key: data.id + desc: false + fields: + - Type: instance_type + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: account + - Public IP Address: data.public_ip_addresses.name + is_optional: true + - Vault URI: data.properties.vault_uri + is_optional: true + - SKU (Pricing Tier): data.sku.name + is_optional: true + - Directory ID: data.properties.tenant_id + is_optional: true + - Soft-delete: data.properties.enable_soft_delete + is_optional: true + - Purge Protection: data.properties.enable_purge_protection + is_optional: true + - Key Name: data.keys.name + is_optional: true + - Key Type: data.keys.type + is_optional: true + - Key Location: data.keys.location + is_optional: true + - Key Status: data.keys.attributes.enabled + is_optional: true + - Key Expiration Date: data.keys.attributes.expires + source_type: iso8601 + type: datetime + is_optional: true + - Key Creation Date: data.keys.attributes.created + source_type: iso8601 + type: datetime + is_optional: true + - Key URI: data.keys.key_uri + is_optional: true + - Enable for Azure VM Deployment: data.properties.enabled_for_deployment + is_optional: true + - Enable for Disk Encryption: data.properties.enabled_for_disk_encryption + is_optional: true + - Enable for Template Deployment: data.properties.enabled_for_template_deployment + is_optional: true + - Enable RBAC Authorization: data.properties.enable_rbac_authorization + is_optional: true + - Private Connection Name: data.properties.private_endpoint_connections.name + is_optional: true + - Private Connection State: data.properties.private_endpoint_connections.private_link_service_connection_state.status + is_optional: true + - Private Endpoint ID: data.properties.private_endpoint_connections.private_endpoint.id + is_optional: true + + + +tabs.0: + name: Key Vault + type: item + fields: + - Name: name + - Resource ID: data.id + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - Vault URI: data.properties.vault_uri + - Sku (Pricing Tier): instance_type + - Directory ID: data.properties.tenant_id + - Soft-delete: data.properties.enable_soft_delete + - Purge Protection: data.properties.enable_purge_protection_str + - Total Credentials Count: data.total_credentials_count + - Keys Count: data.key_count + - Secrets Count: data.secret_count + - Certificates Count: data.certificate_count + + + +tabs.1: + name: Permissions description + type: item + fields: + - Keys: data.keys_permissions_description_display + - Secrets: data.secrets_permissions_description_display + - Certificates: data.certificates_permissions_description_display + + + +tabs.2: + name: Keys + type: query-search-table + root_path: data.keys + fields: + - Name: name + - Type: instance_type + - Location: location + - Status: attributes.enabled + - Expiration Date: attributes.expires + source_type: iso8601 + type: datetime + - Creation Date: attributes.created + source_type: iso8601 + type: datetime + - Key URI: key_uri + + + +tabs.3: + name: Secrets + type: query-search-table + root_path: data.secrets + fields: + - ID: _id + - Type: _content_type + - Status: _attributes.enabled + - Updated Date: _attributes.updated + source_type: iso8601 + type: datetime + - Creation Date: _attributes.created + source_type: iso8601 + type: datetime + - Recoverable Days: _attributes.recoverable_days + + + +tabs.4: + name: Certificates + type: query-search-table + root_path: data.certificates + fields: + - ID: _id + - Status: _attributes.enabled + - Updated Date: _attributes.updated + source_type: iso8601 + type: datetime + - Creation Date: _attributes.created + source_type: iso8601 + type: datetime + - Recoverable Days: _attributes.recoverable_days + + + +tabs.5: + name: Access Policies + type: item + fields: + - Enable for Azure VM Deployment: data.properties.enabled_for_deployment + - Enable for Disk Encryption: data.properties.enabled_for_disk_encryption + - Enable for Template Deployment: data.properties.enabled_for_template_deployment + - Enable RBAC Authorization: data.properties.enable_rbac_authorization + + + +tabs.6: + name: Private Endpoint Connections + type: query-search-table + root_path: data.properties.private_endpoint_connections + fields: + - Connection Name: name + - Connection State: private_link_service_connection_state.status + - Provisioning State: provisioning_state + type: enum + enums: + - Succeeded: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - RegisteringDns: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Private Endpoint: private_endpoint.id \ No newline at end of file diff --git a/src/plugin/metrics/KeyVaults/Instance/certificates_count.yaml b/src/plugin/metrics/KeyVaults/Instance/certificates_count.yaml new file mode 100644 index 00000000..7a400a02 --- /dev/null +++ b/src/plugin/metrics/KeyVaults/Instance/certificates_count.yaml @@ -0,0 +1,31 @@ +--- +metric_id: metric-azure-kvs-instance-certificate-count +name: Certificate Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.KeyVaults.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku.name + name: Sku Name + - key: data.properties.provisioning_state + name: Provisioning State + fields: + value: + key: data.certificate_count + operator: sum +unit: Count +namespace_id: ns-azure-key-vaults-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/KeyVaults/Instance/credentials_count.yaml b/src/plugin/metrics/KeyVaults/Instance/credentials_count.yaml new file mode 100644 index 00000000..a21492ad --- /dev/null +++ b/src/plugin/metrics/KeyVaults/Instance/credentials_count.yaml @@ -0,0 +1,31 @@ +--- +metric_id: metric-azure-kvs-instance-credentials-count +name: Credentials Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.KeyVaults.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku.name + name: Sku Name + - key: data.properties.provisioning_state + name: Provisioning State + fields: + value: + key: data.total_credentials_count + operator: sum +unit: Count +namespace_id: ns-azure-key-vaults-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/KeyVaults/Instance/instance_count.yaml b/src/plugin/metrics/KeyVaults/Instance/instance_count.yaml new file mode 100644 index 00000000..42e987fb --- /dev/null +++ b/src/plugin/metrics/KeyVaults/Instance/instance_count.yaml @@ -0,0 +1,32 @@ +--- +metric_id: metric-azure-kvs-instance-count +name: Instance Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.KeyVaults.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku.name + name: Sku Name + - key: data.properties.provisioning_state + name: Provisioning State + - key: data.system_data.created_by + name: Created By + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-key-vaults-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/KeyVaults/Instance/key_count.yaml b/src/plugin/metrics/KeyVaults/Instance/key_count.yaml new file mode 100644 index 00000000..7b547101 --- /dev/null +++ b/src/plugin/metrics/KeyVaults/Instance/key_count.yaml @@ -0,0 +1,31 @@ +--- +metric_id: metric-azure-kvs-instance-key-count +name: Key Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.KeyVaults.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku.name + name: Sku Name + - key: data.properties.provisioning_state + name: Provisioning State + fields: + value: + key: data.key_count + operator: count +unit: Count +namespace_id: ns-azure-key-vaults-instance +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/KeyVaults/Instance/namespace.yaml b/src/plugin/metrics/KeyVaults/Instance/namespace.yaml new file mode 100644 index 00000000..06748e76 --- /dev/null +++ b/src/plugin/metrics/KeyVaults/Instance/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-key-vaults-instance +name: KeyVaults/Instance +resource_type: inventory.CloudService:azure.KeyVaults.Instance +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-key-vault.svg +version: '1.0' \ No newline at end of file diff --git a/src/plugin/metrics/KeyVaults/Instance/secret_count.yaml b/src/plugin/metrics/KeyVaults/Instance/secret_count.yaml new file mode 100644 index 00000000..079a74f9 --- /dev/null +++ b/src/plugin/metrics/KeyVaults/Instance/secret_count.yaml @@ -0,0 +1,31 @@ +--- +metric_id: metric-azure-kvs-instance-secret-count +name: Secret Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.KeyVaults.Instance +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.sku.name + name: Sku Name + - key: data.properties.provisioning_state + name: Provisioning State + fields: + value: + key: data.secret_count + operator: count +unit: Count +namespace_id: ns-azure-key-vaults-instance +version: '1.0' \ No newline at end of file From ae615073aa1e177c9622e0dfa84bfd4cae88c9cb Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 7 Aug 2024 17:58:05 +0900 Subject: [PATCH 20/35] feat: Implement MySQL Single Servers --- .../connector/my_sql_servers/__init__.py | 0 .../my_sql_servers/mysql_servers_connector.py | 21 ++ src/plugin/manager/__init__.py | 1 + .../manager/cosmos_db/instance_manager.py | 3 +- .../manager/key_vaults/instance_manager.py | 2 +- .../load_balancers/instance_manager.py | 2 +- src/plugin/manager/my_sql_servers/__init__.py | 1 + .../manager/my_sql_servers/server_manager.py | 154 ++++++++++++++ .../web_pub_sub_service/hub_manager.py | 88 -------- .../metadata/my_sql_servers/server.yaml | 191 ++++++++++++++++++ .../metadata/sql_databases/database.yaml | 6 + src/plugin/metadata/sql_servers/server.yaml | 3 + .../metadata/storage_accounts/instance.yaml | 6 + .../metadata/web_pub_sub_service/service.yaml | 4 + .../MySQLServers/Server/namespace.yaml | 8 + .../MySQLServers/Server/server_count.yaml | 29 +++ 16 files changed, 428 insertions(+), 91 deletions(-) create mode 100644 src/plugin/connector/my_sql_servers/__init__.py create mode 100644 src/plugin/connector/my_sql_servers/mysql_servers_connector.py create mode 100644 src/plugin/manager/my_sql_servers/__init__.py create mode 100644 src/plugin/manager/my_sql_servers/server_manager.py create mode 100644 src/plugin/metadata/my_sql_servers/server.yaml create mode 100644 src/plugin/metrics/MySQLServers/Server/namespace.yaml create mode 100644 src/plugin/metrics/MySQLServers/Server/server_count.yaml diff --git a/src/plugin/connector/my_sql_servers/__init__.py b/src/plugin/connector/my_sql_servers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/plugin/connector/my_sql_servers/mysql_servers_connector.py b/src/plugin/connector/my_sql_servers/mysql_servers_connector.py new file mode 100644 index 00000000..39afe6a3 --- /dev/null +++ b/src/plugin/connector/my_sql_servers/mysql_servers_connector.py @@ -0,0 +1,21 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class MySQLServersConnector(AzureBaseConnector): + def __init__(self, secret_data=None, **kwargs): + super().__init__(**kwargs) + + self.set_connect(secret_data) + + def list_servers(self): + return self.mysql_client.servers.list() + + def list_firewall_rules_by_server(self, resource_group_name, server_name): + return self.mysql_client.firewall_rules.list_by_server(resource_group_name=resource_group_name, server_name=server_name) + + def list_server_parameters(self, resource_group_name, server_name): + return self.mysql_client.server_parameters._list_update_configurations_initial(resource_group_name=resource_group_name, server_name=server_name, value=[]) \ No newline at end of file diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index b992326e..9e808ded 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -15,3 +15,4 @@ from .postgre_sql_servers import * from .web_pub_sub_service import * from .key_vaults import * +# from .my_sql_servers import * diff --git a/src/plugin/manager/cosmos_db/instance_manager.py b/src/plugin/manager/cosmos_db/instance_manager.py index d27b87d7..1acaacf7 100644 --- a/src/plugin/manager/cosmos_db/instance_manager.py +++ b/src/plugin/manager/cosmos_db/instance_manager.py @@ -63,7 +63,7 @@ def create_cloud_service(self, options, secret_data, schema): cosmos_db_account_dict["id"] ), "subscription_id": subscription_info["subscription_id"], - "subscription_name": subscription_info["subscription_name"], + "subscription_name": subscription_info["display_name"], "azure_monitor": {"resource_id": cosmos_db_account_id}, } ) @@ -142,6 +142,7 @@ def create_cloud_service(self, options, secret_data, schema): provider=self.provider, data=cosmos_db_account_dict, account=secret_data["subscription_id"], + instance_type=cosmos_db_account_dict["database_account_offer_type"], region_code=cosmos_db_account_dict["location"], reference=self.make_reference(cosmos_db_account_dict.get("id")), # launched_at=cosmos_db_account_dict.system_data.created_at, diff --git a/src/plugin/manager/key_vaults/instance_manager.py b/src/plugin/manager/key_vaults/instance_manager.py index 449d76ca..a6fcd6ad 100644 --- a/src/plugin/manager/key_vaults/instance_manager.py +++ b/src/plugin/manager/key_vaults/instance_manager.py @@ -131,7 +131,7 @@ def create_cloud_service(self, options, secret_data, schema): { "enable_purge_protection_str": "Disabled" if key_vault_dict["properties"]["enable_purge_protection"] - is False + is False else "Enabled" } ) diff --git a/src/plugin/manager/load_balancers/instance_manager.py b/src/plugin/manager/load_balancers/instance_manager.py index 3671573a..2daad824 100644 --- a/src/plugin/manager/load_balancers/instance_manager.py +++ b/src/plugin/manager/load_balancers/instance_manager.py @@ -225,7 +225,7 @@ def create_cloud_service(self, options, secret_data, schema): provider=self.provider, data=load_balancer_dict, account=load_balancer_dict["subscription_id"], - instance_type=load_balancer_dict["sku"]["tier"], + instance_type=load_balancer_dict["sku"]["name"], region_code=load_balancer_dict["location"], reference=self.make_reference(load_balancer_dict.get("id")), tags=load_balancer_dict.get("tags", {}), diff --git a/src/plugin/manager/my_sql_servers/__init__.py b/src/plugin/manager/my_sql_servers/__init__.py new file mode 100644 index 00000000..ce17838c --- /dev/null +++ b/src/plugin/manager/my_sql_servers/__init__.py @@ -0,0 +1 @@ +from .server_manager import MySQLServersManager diff --git a/src/plugin/manager/my_sql_servers/server_manager.py b/src/plugin/manager/my_sql_servers/server_manager.py new file mode 100644 index 00000000..3748051d --- /dev/null +++ b/src/plugin/manager/my_sql_servers/server_manager.py @@ -0,0 +1,154 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.my_sql_servers.mysql_servers_connector import MySQLServersConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class MySQLServersManager(AzureBaseManager): + cloud_service_group = "MySQLServers" + cloud_service_type = "Server" + service_code = "/Microsoft.DBforMySQL/servers" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Database"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-mysql-servers.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + mysql_servers_conn = MySQLServersConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + mysql_servers_obj_list = mysql_servers_conn.list_servers() + + for mysql_server in mysql_servers_obj_list: + + try: + mysql_server_dict = self.convert_nested_dictionary(mysql_server) + mysql_server_id = mysql_server_dict["id"] + + mysql_server_dict.update( + { + "resource_group": self.get_resource_group_from_id( + mysql_server_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": mysql_server_id}, + } + ) + + if mysql_server_dict.get("name") is not None: + resource_group = mysql_server_dict.get("resource_group", "") + server_name = mysql_server_dict["name"] + mysql_server_dict.update( + { + "firewall_rules": self.get_firewall_rules_by_server( + mysql_servers_conn, resource_group, server_name + ), + } + ) + + if mysql_server_dict.get("firewall_rules") is not None: + mysql_server_dict.update( + { + "allow_azure_services_access": self.get_azure_service_access( + mysql_server_dict["firewall_rules"] + ) + } + ) + + if mysql_server_dict.get("storage_profile") is not None: + mysql_server_dict["storage_profile"].update( + { + "storage_gb": self.get_storage_gb( + mysql_server_dict["storage_profile"].get( + "storage_mb", "" + ) + ) + } + ) + + self.set_region_code(mysql_server_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=mysql_server_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=mysql_server_dict, + account=secret_data["subscription_id"], + instance_type=mysql_server_dict["sku"]["tier"], + region_code=mysql_server_dict["location"], + reference=self.make_reference(mysql_server_dict.get("id")), + tags=mysql_server_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_firewall_rules_by_server( + self, mysql_servers_conn, resource_group, server_name + ): + firewall_rules = [] + firewall_rules_obj = mysql_servers_conn.list_firewall_rules_by_server( + resource_group_name=resource_group, server_name=server_name + ) + for firewall_rule in firewall_rules_obj: + firewall_dict = self.convert_nested_dictionary(firewall_rule) + firewall_rules.append(firewall_dict) + + return firewall_rules + + @staticmethod + def get_azure_service_access(firewall_rules): + firewall_rule_name_list = [] + + for firewall_rule in firewall_rules: + if firewall_rule.get("name") is not None: + firewall_rule_name_list.append(firewall_rule["name"]) + + if "AllowAllWindowsAzureIps" in firewall_rule_name_list: + return True + + return False + + @staticmethod + def get_storage_gb(storage_mb): + if storage_mb: + storage_gb = int(storage_mb / 1024) + return storage_gb diff --git a/src/plugin/manager/web_pub_sub_service/hub_manager.py b/src/plugin/manager/web_pub_sub_service/hub_manager.py index 486e73b2..81694ed6 100644 --- a/src/plugin/manager/web_pub_sub_service/hub_manager.py +++ b/src/plugin/manager/web_pub_sub_service/hub_manager.py @@ -35,91 +35,3 @@ def create_cloud_service(self, options, secret_data, schema): error_responses = [] return cloud_services, error_responses - - # def create_cloud_service(self, options, secret_data, schema): - # cloud_services = [] - # error_responses = [] - # - # web_pubsub_service_conn = WebPubSubServiceConnector(secret_data=secret_data) - # subscription_conn = SubscriptionsConnector(secret_data=secret_data) - # - # subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) - # subscription_info = self.convert_nested_dictionary(subscription_obj) - # - # web_pubsub_services = web_pubsub_service_conn.list_by_subscription() - # - # for web_pubsub_service in web_pubsub_services: - # - # try: - # web_pubsub_service_dict = self.convert_nested_dictionary( - # web_pubsub_service - # ) - # web_pubsub_service_id = web_pubsub_service_dict["id"] - # resource_group_name = self.get_resource_group_from_id( - # web_pubsub_service_id - # ) - # resource_name = web_pubsub_service_dict["name"] - # - # web_pubsub_hubs = web_pubsub_service_conn.list_hubs( - # resource_group_name=resource_group_name, resource_name=resource_name - # ) - # - # web_pubsub_hubs_dict = [ - # self.convert_nested_dictionary(hub) for hub in web_pubsub_hubs - # ] - # - # for web_pubsub_hub_dict in web_pubsub_hubs_dict: - # - # web_pubsub_hub_id = web_pubsub_hub_dict["id"] - # resource_group_name = self.get_resource_group_from_id(web_pubsub_hub_id) - # web_pubsub_hub_dict.update( - # { - # "tenant_id": secret_data["tenant_id"], - # "location": web_pubsub_service_dict["location"], - # "resource_group": resource_group_name, - # "subscription_id": subscription_info["subscription_id"], - # "subscription_name": subscription_info["display_name"], - # "azure_monitor": {"resource_id": web_pubsub_hub_id}, - # "web_pubsub_svc_name": self.get_web_pubsub_name_from_id( - # web_pubsub_hub_id - # ), - # "web_pubsub_hub_evnet_handler_count_display": len( - # web_pubsub_hub_dict.get("properties", {}).get( - # "event_handlers", [] - # ) - # ), - # } - # ) - # - # cloud_services.append( - # make_cloud_service( - # name=web_pubsub_hub_dict["name"], - # cloud_service_type=self.cloud_service_type, - # cloud_service_group=self.cloud_service_group, - # provider=self.provider, - # data=web_pubsub_hub_dict, - # account=web_pubsub_hub_dict["subscription_id"], - # region_code=web_pubsub_hub_dict["location"], - # reference=self.make_reference(web_pubsub_hub_dict.get("id")), - # tags=web_pubsub_hub_dict.get("tags", {}), - # data_format="dict" - # ) - # ) - # - # except Exception as e: - # _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) - # error_responses.append( - # make_error_response( - # error=e, - # provider=self.provider, - # cloud_service_group=self.cloud_service_group, - # cloud_service_type=self.cloud_service_type, - # ) - # ) - # - # return cloud_services, error_responses - # - # @staticmethod - # def get_web_pubsub_name_from_id(dict_id): - # svc_name = dict_id.split("/")[-3] - # return svc_name diff --git a/src/plugin/metadata/my_sql_servers/server.yaml b/src/plugin/metadata/my_sql_servers/server.yaml new file mode 100644 index 00000000..de539864 --- /dev/null +++ b/src/plugin/metadata/my_sql_servers/server.yaml @@ -0,0 +1,191 @@ +search: + fields: + - Type: instance_type + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Server Admin Login Name: data.administrator_login + - MySQL Version: data.version + - Performance Configuration (Tier): instance_type + - Performance Configuration (Name): data.sku.name + - SSL Enforce Status: data.ssl_enforcement + - Firewall Rule Name: data.firewall_rules.name + - Firewall Rule Start IP: data.firewall_rules.start_ip_address + - Firewall Rule End IP: data.firewall_rules.end_ip_address + - Allow Access To Azure Services: data.allow_azure_services_access + - Enforce SSL Connection: data.ssl_enforcement + - Minimum TLS Version: data.minimal_tls_version + - Compute Generation: data.sku.family + - vCore: data.sku.capacity + data_type: integer + - Storage: data.storage_profile.storage_gb + data_type: integer + - Backup Retention Period: data.storage_profile.backup_retention_days + + + +table: + sort: + key: data.id + desc: false + fields: + - Type: instance_type + - Status: data.user_visible_state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Inaccessible: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: account + - Server Admin Login Name: data.administrator_login + is_optional: true + - MySQL Version: data.version + is_optional: true + - Performance Configuration (Tier): instance_type + is_optional: true + - Performance Configuration (Name): data.sku.name + is_optional: true + - SSL Enforce Status: data.ssl_enforcement + is_optional: true + - Firewall Rule Name: data.firewall_rules.name + is_optional: true + - Firewall Rule Start IP: data.firewall_rules.start_ip_address + is_optional: true + - Firewall Rule End IP: data.firewall_rules.end_ip_address + is_optional: true + - Allow Access To Azure Services: data.allow_azure_services_access + is_optional: true + - Enforce SSL Connection: data.ssl_enforcement + is_optional: true + - Minimum TLS Version: data.minimal_tls_version + is_optional: true + - Compute Generation: data.sku.family + is_optional: true + - vCore: data.sku.capacity + is_optional: true + - Storage: data.storage_profile.storage_gb + is_optional: true + - Backup Retention Period: data.storage_profile.backup_retention_days + is_optional: true + + + +tabs.0: + name: MySQL Server + type: item + fields: + - Name: name + - Server Name: data.fully_qualified_domain_name + - Type: instance_type + - Status: data.user_visible_state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Inaccessible: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - Server Admin Login Name: data.administrator_login + - MySQL Version: data.version + - Performance Configuration (Tier): data.sku.tier + - Performance Configuration (Name): data.sku.name + - SSL Enforce Status: data.ssl_enforcement + + + +tabs.1: + name: Connection Security + items: + - name: Firewall Rules + type: table + root_path: data.firewall_rules + fields: + - Firewall Rule Name: name + - Start IP: start_ip_address + - End IP: end_ip_address + - name: MySQL Server + type: item + fields: + - Allow Access To Azure Services: data.allow_azure_services_access + - Enforce SSL Connection: data.ssl_enforcement + - Minimum TLS Version: data.minimal_tls_version + + + +tabs.2: + name: MySQL Parameters + type: table + fields: + - Allow Access To Azure Services: data.allow_azure_services_access + - Enforce SSL Connection: data.ssl_enforcement + - Minimum TLS Version: data.minimal_tls_version + + + +tabs.3: + name: Pricing Tier + type: item + fields: + - Tier: data.sku.tier + - Compute Generation: data.sku.family + - vCore: data.sku.capacity + - Storage: data.storage_profile.storage_gb + - Storage Auto-Growth: data.storage_profile.storage_autogrow + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Geo Redundant Backup: data.storage_profile.geo_redundant_backup + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Backup Retention Period: data.storage_profile.backup_retention_days \ No newline at end of file diff --git a/src/plugin/metadata/sql_databases/database.yaml b/src/plugin/metadata/sql_databases/database.yaml index 0d881bcf..f8c689cf 100644 --- a/src/plugin/metadata/sql_databases/database.yaml +++ b/src/plugin/metadata/sql_databases/database.yaml @@ -112,14 +112,17 @@ table: - Disabled: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - Paused: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - Shutdown: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - EmergencyMode: text_color: red.500 @@ -260,14 +263,17 @@ tabs.0: - Disabled: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - Paused: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - Shutdown: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - EmergencyMode: text_color: red.500 diff --git a/src/plugin/metadata/sql_servers/server.yaml b/src/plugin/metadata/sql_servers/server.yaml index 8d0dda9c..275ec578 100644 --- a/src/plugin/metadata/sql_servers/server.yaml +++ b/src/plugin/metadata/sql_servers/server.yaml @@ -316,14 +316,17 @@ tabs.4: - Disabled: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - Paused: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - Shutdown: icon_image: ic_circle-filled icon_color: gray.400 + text_color: gray.400 type: state - EmergencyMode: text_color: red.500 diff --git a/src/plugin/metadata/storage_accounts/instance.yaml b/src/plugin/metadata/storage_accounts/instance.yaml index 0a8939cf..7ae10c50 100644 --- a/src/plugin/metadata/storage_accounts/instance.yaml +++ b/src/plugin/metadata/storage_accounts/instance.yaml @@ -78,8 +78,14 @@ table: - Virtual Network: data.network_acls.virtual_networks is_optional: true - Firewall Address Range: data.network_acls.firewall_address_range + type: list + options: + delimiter: ', ' is_optional: true - Resource Instances: data.network_acls.resource_access_rules_display + type: list + options: + delimiter: ', ' is_optional: true - Exceptions: data.network_acls.bypass is_optional: true diff --git a/src/plugin/metadata/web_pub_sub_service/service.yaml b/src/plugin/metadata/web_pub_sub_service/service.yaml index 8814f742..8b8c60ab 100644 --- a/src/plugin/metadata/web_pub_sub_service/service.yaml +++ b/src/plugin/metadata/web_pub_sub_service/service.yaml @@ -69,6 +69,8 @@ table: icon_color: red.500 type: state - Unknown: + icon_image: ic_circle-filled + icon_color: gray.400 text_color: gray.400 type: state - Subscription Name: data.subscription_name @@ -136,6 +138,8 @@ tabs.0: icon_color: red.500 type: state - Unknown: + icon_image: ic_circle-filled + icon_color: gray.400 text_color: gray.400 type: state - Resource ID: data.id diff --git a/src/plugin/metrics/MySQLServers/Server/namespace.yaml b/src/plugin/metrics/MySQLServers/Server/namespace.yaml new file mode 100644 index 00000000..fc075c5b --- /dev/null +++ b/src/plugin/metrics/MySQLServers/Server/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-mysql-servers-server +name: MySQLServers/Server +resource_type: inventory.CloudService:azure.MySQLServers.Server +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-mysql-servers.svg +version: '1.0' diff --git a/src/plugin/metrics/MySQLServers/Server/server_count.yaml b/src/plugin/metrics/MySQLServers/Server/server_count.yaml new file mode 100644 index 00000000..852f3834 --- /dev/null +++ b/src/plugin/metrics/MySQLServers/Server/server_count.yaml @@ -0,0 +1,29 @@ +--- +metric_id: metric-azure-mysql-servers-server-count +name: Server Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.MySQLServers.Server +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-mysql-servers-server +version: '1.0' \ No newline at end of file From d334b9c98ad31170b52b379d400bddfc0754ba4d Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 8 Aug 2024 18:31:51 +0900 Subject: [PATCH 21/35] fix: Fix Disks, NAT Gateways data fields default value --- .../container_instances/container_manager.py | 6 +++ src/plugin/manager/disks/disk_manager.py | 2 + .../manager/nat_gateways/instance_manager.py | 44 +++++++++++++++++++ .../metadata/nat_gateways/instance.yaml | 2 +- src/plugin/metadata/sql_servers/server.yaml | 32 ++++++++++---- 5 files changed, 77 insertions(+), 9 deletions(-) diff --git a/src/plugin/manager/container_instances/container_manager.py b/src/plugin/manager/container_instances/container_manager.py index 4ae51b4c..d3953423 100644 --- a/src/plugin/manager/container_instances/container_manager.py +++ b/src/plugin/manager/container_instances/container_manager.py @@ -83,6 +83,12 @@ def create_cloud_service(self, options, secret_data, schema): container_instance_dict["volume_count_display"] = len( container_instance_dict["volumes"] ) + else: + for container in container_instance_dict["containers"]: + container["volume_mount_count_display"] = 0 + + container_instance_dict["volume_count_display"] = 0 + container_instance_dict = self.update_tenant_id_from_secret_data( container_instance_dict, secret_data diff --git a/src/plugin/manager/disks/disk_manager.py b/src/plugin/manager/disks/disk_manager.py index 1ed2f620..18174644 100644 --- a/src/plugin/manager/disks/disk_manager.py +++ b/src/plugin/manager/disks/disk_manager.py @@ -93,6 +93,8 @@ def create_cloud_service(self, options, secret_data, schema): max_shares = disk_dict.get("max_shares") if max_shares is not None and max_shares > 0: disk_dict.update({"enable_shared_disk_display": True}) + else: + disk_dict.update({"enable_shared_disk_display": False}) if disk_dict.get("bursting_enabled") is None: disk_dict["bursting_enabled"] = False diff --git a/src/plugin/manager/nat_gateways/instance_manager.py b/src/plugin/manager/nat_gateways/instance_manager.py index 5a6f49c0..a6df374a 100644 --- a/src/plugin/manager/nat_gateways/instance_manager.py +++ b/src/plugin/manager/nat_gateways/instance_manager.py @@ -96,6 +96,44 @@ def create_cloud_service(self, options, secret_data, schema): nat_gateway_dict["public_ip_addresses"] = pip_list + else: + nat_gateway_dict.update( + { + "public_ip_addresses_count": 0 + } + ) + + if nat_gateway_dict.get("public_ip_prefixes") is not None: + nat_gateway_dict.update( + { + "public_ip_prefixes_count": len( + nat_gateway_dict["public_ip_addresses"] + ) + } + ) + + # Get Public IP Address Dictionary + if not nat_gateway_dict["public_ip_prefixes"]: + break + + pip_list = [] + + for pip in nat_gateway_dict["public_ip_prefixes"]: + public_ip_prefixes_id = pip["id"] + pip_dict = self.get_public_ip_prefixes_dict( + nat_gateways_conn, public_ip_prefixes_id + ) + pip_list.append(pip_dict) + + nat_gateway_dict["public_ip_prefixes"] = pip_list + + else: + nat_gateway_dict.update( + { + "public_ip_prefixes_count": 0 + } + ) + if nat_gateway_dict.get("subnets") is not None: nat_gateway_dict.update( { @@ -105,6 +143,12 @@ def create_cloud_service(self, options, secret_data, schema): "subnets_count": len(nat_gateway_dict["subnets"]), } ) + else: + nat_gateway_dict.update( + { + "subnets_count": 0 + } + ) self.set_region_code(nat_gateway_dict["location"]) diff --git a/src/plugin/metadata/nat_gateways/instance.yaml b/src/plugin/metadata/nat_gateways/instance.yaml index 582e8be3..ad2e2db0 100644 --- a/src/plugin/metadata/nat_gateways/instance.yaml +++ b/src/plugin/metadata/nat_gateways/instance.yaml @@ -25,7 +25,7 @@ table: - Subscription Name: data.subscription_name - Subscription ID: account - Subnets (count): data.subnets_count - - Public IP Addresses (count): data.public_ip_prefixes_count + - Public IP Addresses (count): data.public_ip_addresses_count - Public IP Prefixes (count): data.public_ip_prefixes_count - Public IP Name (optional): data.public_ip_addresses.name is_optional: true diff --git a/src/plugin/metadata/sql_servers/server.yaml b/src/plugin/metadata/sql_servers/server.yaml index 275ec578..1bf996c7 100644 --- a/src/plugin/metadata/sql_servers/server.yaml +++ b/src/plugin/metadata/sql_servers/server.yaml @@ -18,13 +18,13 @@ search: - Backup Earliest PITR Restore Point (UTC): data.databases.earliest_restore_date type: datetime - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id - - '# of SQL DBs': number_of_databases_display + - '# of SQL DBs': number_of_databases data_type: integer - Elastic Pool Name: data.elastic_pools.name - Elastic Pool Resource Group: data.elastic_pools.resource_group_display - Per DB Settings: data.elastic_pools.per_db_settings_display - Pricing Tier: data.elastic_pools.pricing_tier_display - - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases_display + - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases data_type: integer - Elastic Pool Unit: data.elastic_pools.unit_display - Elastic Pool Server Name: data.elastic_pools.server_name_display @@ -104,7 +104,7 @@ table: is_optional: true - Backup Available LTR backups: data.databases.long_term_retention_backup_resource_id is_optional: true - - '# of SQL DBs': data.number_of_databases_display + - '# of SQL DBs': data.number_of_databases is_optional: true - Elastic Pool Name: data.elastic_pools.name is_optional: true @@ -114,7 +114,7 @@ table: is_optional: true - Pricing Tier: data.elastic_pools.pricing_tier_display is_optional: true - - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases_display + - 'Elastic Pool # of DBs': data.elastic_pools.number_of_databases is_optional: true - Elastic Pool Unit: data.elastic_pools.unit_display is_optional: true @@ -380,7 +380,7 @@ tabs.5: - Resource Group: resource_group_display - Per DB Settings: per_db_settings_display - Pricing Tier: pricing_tier_display - - '# of SQL DBs': number_of_databases_display + - '# of SQL DBs': number_of_databases - Unit: unit_display - Status: state type: enum @@ -427,6 +427,22 @@ tabs.6: tabs.7: + name: Deleted Databases + type: table + root_path: data.deleted_databases + fields: + - Database: database_name + - Deletion Time (UTC): deletion_date + source_type: iso8601 + type: datetime + - Creation Time (UTC): creation_date + source_type: iso8601 + type: datetime + - Edition Time (UTC): edition + + + +tabs.8: name: Firewalls and Network items: - name: Network @@ -488,7 +504,7 @@ tabs.7: -tabs.8: +tabs.9: name: Private Endpoint Connections type: table root_path: data.private_endpoint_connections @@ -500,7 +516,7 @@ tabs.8: -tabs.9: +tabs.10: name: Transparent Data Encryption type: table root_path: data.encryption_protectors @@ -512,7 +528,7 @@ tabs.9: -tabs.10: +tabs.11: name: Tuning Options type: table root_path: data.server_automatic_tuning.options From 37528db1717da08f36e995a711b077d91e2d265b Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 9 Aug 2024 13:46:51 +0900 Subject: [PATCH 22/35] feat: Add unix timestamp to iso8601 method --- .../manager/key_vaults/instance_manager.py | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/plugin/manager/key_vaults/instance_manager.py b/src/plugin/manager/key_vaults/instance_manager.py index a6fcd6ad..fd53caa8 100644 --- a/src/plugin/manager/key_vaults/instance_manager.py +++ b/src/plugin/manager/key_vaults/instance_manager.py @@ -1,4 +1,6 @@ import logging +import datetime +from typing import Union import azure.core.exceptions @@ -77,6 +79,14 @@ def create_cloud_service(self, options, secret_data, schema): key_vaults_conn, resource_group_name, vault_name ) + for key in keys: + key["attributes"].update( + { + "created": self.timestamp_to_iso8601(key["attributes"]["created"]), + "updated": self.timestamp_to_iso8601(key["attributes"]["updated"]), + } + ) + secrets, secrets_permissions_display = self.list_secrets( key_vaults_conn, subscription_id, vault_uri ) @@ -123,18 +133,21 @@ def create_cloud_service(self, options, secret_data, schema): ) # Change purge protection to user-friendly word + key_vault_dict["properties"].update( + { + "enable_purge_protection_str": "Disabled" + } + ) if ( key_vault_dict.get("properties", {}).get("enable_purge_protection") is not None ): - key_vault_dict["properties"].update( - { - "enable_purge_protection_str": "Disabled" - if key_vault_dict["properties"]["enable_purge_protection"] - is False - else "Enabled" - } - ) + if key_vault_dict["properties"]["enable_purge_protection"]: + key_vault_dict["properties"].update( + { + "enable_purge_protection_str": "Enabled" + } + ) if sku := key_vault_dict.get("properties", {}).get("sku"): key_vault_dict["sku"] = sku @@ -230,3 +243,11 @@ def get_private_endpoint_name(private_endpoint_connections): for private_endpoint in private_endpoint_connections: private_endpoint.update({"name": private_endpoint["id"].split("/")[10]}) return private_endpoint_connections + + @staticmethod + def timestamp_to_iso8601(timestamp: int) -> Union[str, None]: + if isinstance(timestamp, int): + dt = datetime.datetime.utcfromtimestamp(timestamp) + return f"{dt.isoformat(timespec='milliseconds')}Z" + + return None From db2bcc806b19251f6483fb7d6adaf2641b9dacfd Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 9 Aug 2024 13:48:13 +0900 Subject: [PATCH 23/35] fix: Fix Web PubSub Service metadata --- src/plugin/metadata/web_pub_sub_service/hub.yaml | 1 + src/plugin/metadata/web_pub_sub_service/service.yaml | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugin/metadata/web_pub_sub_service/hub.yaml b/src/plugin/metadata/web_pub_sub_service/hub.yaml index a6c98282..b5bd62b9 100644 --- a/src/plugin/metadata/web_pub_sub_service/hub.yaml +++ b/src/plugin/metadata/web_pub_sub_service/hub.yaml @@ -71,6 +71,7 @@ tabs.1: tabs.2: name: System data type: item + root_path: data.system_data fields: - Created at: created_at source_type: iso8601 diff --git a/src/plugin/metadata/web_pub_sub_service/service.yaml b/src/plugin/metadata/web_pub_sub_service/service.yaml index 8b8c60ab..e185d5e5 100644 --- a/src/plugin/metadata/web_pub_sub_service/service.yaml +++ b/src/plugin/metadata/web_pub_sub_service/service.yaml @@ -75,19 +75,25 @@ table: type: state - Subscription Name: data.subscription_name - Subscription ID: account + is_optional: true - Resource Group: data.resource_group - Location: data.location - Hub count: data.web_pubsub_hub_count_display - SKU: data.sku.tier - Unit: data.sku.capacity - Version: data.version + is_optional: true - Host name: data.host_name - Host name prefix: data.host_name_prefix + is_optional: true - Public IP: data.external_ip - Public access: data.public_network_access - Public port: data.public_port + is_optional: true - Server port: data.server_port + is_optional: true - TLS: data.tls.client_cert_enabled + is_optional: true @@ -198,7 +204,7 @@ tabs.2: tabs.3: name: Public access - type: table + type: item fields: - Public network access: data.public_network_access type: enum @@ -288,9 +294,9 @@ tabs.5: - Default action: data.network_ac_ls.default_action type: enum enums: - - Enabled: indigo.500 + - Allow: indigo.500 type: badge - - Disabled: coral.600 + - Deny: coral.600 type: badge - name: Public network type: item From 0afadc02dca73c5f4340e35fae88256f7cab56a1 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 9 Aug 2024 14:19:48 +0900 Subject: [PATCH 24/35] fix: Fix Storage Accounts metadata in Blob size display unit --- src/plugin/metadata/storage_accounts/instance.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugin/metadata/storage_accounts/instance.yaml b/src/plugin/metadata/storage_accounts/instance.yaml index 7ae10c50..ef19380c 100644 --- a/src/plugin/metadata/storage_accounts/instance.yaml +++ b/src/plugin/metadata/storage_accounts/instance.yaml @@ -52,7 +52,7 @@ table: - Container count: data.container_count_display - Blob count: data.blob_count_display - Blob total size: data.blob_size_display - display_unit: GB + display_unit: MB source_unit: BYTES type: size - Resource Group: data.resource_group @@ -148,7 +148,7 @@ tabs.0: - Container count: data.container_count_display - Blob count: data.blob_count_display - Blob total size: data.blob_size_display - display_unit: GB + display_unit: MB source_unit: BYTES type: size From b2e89c231177e33ec07748b4593d9fe4fa4eb1ac Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 9 Aug 2024 14:33:13 +0900 Subject: [PATCH 25/35] fix: Fix VMScaleSets metadata in "Size" type deleted --- src/plugin/metadata/vm_scale_sets/scale_set.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/plugin/metadata/vm_scale_sets/scale_set.yaml b/src/plugin/metadata/vm_scale_sets/scale_set.yaml index b7f87e7b..bc80a5b3 100644 --- a/src/plugin/metadata/vm_scale_sets/scale_set.yaml +++ b/src/plugin/metadata/vm_scale_sets/scale_set.yaml @@ -192,9 +192,6 @@ tabs.4: - Image Reference: data.virtual_machine_profile.storage_profile.image_reference_display - Storage Account Type: data.virtual_machine_profile.storage_profile.os_disk.managed_disk.storage_account_type - Size: data.virtual_machine_profile.storage_profile.os_disk.disk_size_gb - display_unit: GB - source_unit: BYTES - type: size - Host Caching: data.virtual_machine_profile.storage_profile.os_disk.caching - name: Data Disks type: simple-table @@ -203,9 +200,6 @@ tabs.4: - Name: name - Storage Type: managed_disk.storage_type - Size: disk_size_gb - display_unit: GB - source_unit: BYTES - type: size - Max IOPS: disk_iops_read_write - MAX Throughput(MBps): disk_m_bps_read_write - Encryption: disk_encryption_set.id From f3c4b3de102f19403810147b39c1fddfc3db6fb1 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Mon, 12 Aug 2024 17:41:14 +0900 Subject: [PATCH 26/35] fix: Fix VMScaleSets metadata in "Size" source_unit --- src/plugin/metadata/vm_scale_sets/scale_set.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugin/metadata/vm_scale_sets/scale_set.yaml b/src/plugin/metadata/vm_scale_sets/scale_set.yaml index bc80a5b3..e5795291 100644 --- a/src/plugin/metadata/vm_scale_sets/scale_set.yaml +++ b/src/plugin/metadata/vm_scale_sets/scale_set.yaml @@ -200,6 +200,9 @@ tabs.4: - Name: name - Storage Type: managed_disk.storage_type - Size: disk_size_gb + display_unit: GB + source_unit: GB + type: size - Max IOPS: disk_iops_read_write - MAX Throughput(MBps): disk_m_bps_read_write - Encryption: disk_encryption_set.id From 05e0d4f17f77071118856dbc6e941a6799abcd85 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Mon, 12 Aug 2024 17:43:09 +0900 Subject: [PATCH 27/35] feat: Implement Virtual Machines Manager --- src/plugin/manager/__init__.py | 3 +- .../manager/virtual_machines/__init__.py | 8 + .../manager/virtual_machines/disk_manager.py | 88 ++++ .../virtual_machines/instance_manager.py | 245 +++++++++ .../virtual_machines/load_balancer_manager.py | 106 ++++ .../network_security_group_manager.py | 210 ++++++++ .../manager/virtual_machines/nic_manager.py | 123 +++++ .../manager/virtual_machines/vm_manager.py | 413 +++++++++++++++ .../manager/virtual_machines/vnet_manager.py | 61 +++ .../metadata/virtual_machines/instance.yaml | 479 ++++++++++++++++++ 10 files changed, 1735 insertions(+), 1 deletion(-) create mode 100644 src/plugin/manager/virtual_machines/disk_manager.py create mode 100644 src/plugin/manager/virtual_machines/instance_manager.py create mode 100644 src/plugin/manager/virtual_machines/load_balancer_manager.py create mode 100644 src/plugin/manager/virtual_machines/network_security_group_manager.py create mode 100644 src/plugin/manager/virtual_machines/nic_manager.py create mode 100644 src/plugin/manager/virtual_machines/vm_manager.py create mode 100644 src/plugin/manager/virtual_machines/vnet_manager.py create mode 100644 src/plugin/metadata/virtual_machines/instance.yaml diff --git a/src/plugin/manager/__init__.py b/src/plugin/manager/__init__.py index 9e808ded..893cd79d 100644 --- a/src/plugin/manager/__init__.py +++ b/src/plugin/manager/__init__.py @@ -15,4 +15,5 @@ from .postgre_sql_servers import * from .web_pub_sub_service import * from .key_vaults import * -# from .my_sql_servers import * +from .my_sql_servers import * +from .virtual_machines import * diff --git a/src/plugin/manager/virtual_machines/__init__.py b/src/plugin/manager/virtual_machines/__init__.py index e69de29b..11b1bdda 100644 --- a/src/plugin/manager/virtual_machines/__init__.py +++ b/src/plugin/manager/virtual_machines/__init__.py @@ -0,0 +1,8 @@ +from plugin.manager.virtual_machines.disk_manager import VirtualMachineDiskManager +from plugin.manager.virtual_machines.load_balancer_manager import VirtualMachineLoadBalancerManager +from plugin.manager.virtual_machines.network_security_group_manager import VirtualMachineNetworkSecurityGroupManager +from plugin.manager.virtual_machines.nic_manager import VirtualMachineNICManager +from plugin.manager.virtual_machines.vm_manager import VirtualMachineVmManager +from plugin.manager.virtual_machines.vnet_manager import VirtualMachineVNetManager + +from .instance_manager import VirtualMachinesManager diff --git a/src/plugin/manager/virtual_machines/disk_manager.py b/src/plugin/manager/virtual_machines/disk_manager.py new file mode 100644 index 00000000..a53f5dec --- /dev/null +++ b/src/plugin/manager/virtual_machines/disk_manager.py @@ -0,0 +1,88 @@ +class VirtualMachineDiskManager: + def get_disk_info(self, vm, list_disks): + ''' + disk_data = { + "device_index": 0, + "device": "", + "disk_type": "disk", + "size": 100, + "tags": { + "disk_name": "", + "caching": "None" | "ReadOnly" | "ReadWrite" + "storage_account_type": "Standard_LRS" | "Premium_LRS" | "StandardSSD_LRS" | "UltraSSD_LRS" + "disk_encryption_set": "PMK" | "CMK" + "iops": 60, + "throughput_mbps": 200 + } + } + ''' + + disk_data = [] + index = 0 + + os_disk = vm.storage_profile.os_disk + volume_data = self.get_volume_data(os_disk, list_disks, index) + volume_data.update({ + 'disk_type': 'os_disk' + }) + disk_data.append(volume_data) + index += 1 + + data_disks = vm.storage_profile.data_disks + if data_disks: + for data_disk in data_disks: + volume_data_sub = self.get_volume_data(data_disk, list_disks, index) + volume_data_sub.update({ + 'disk_type': 'data_disk' + }) + disk_data.append(volume_data_sub) + index += 1 + + return disk_data + + def get_volume_data(self, disk, list_disks, index): + volume_data = { + 'device_index': index, + 'size': disk.disk_size_gb * 1073741824 if disk.disk_size_gb is not None else 0, + 'tags': { + 'disk_name': disk.name if disk.name is not None else '', + 'caching': disk.caching if disk.caching is not None else '', + } + } + + if getattr(disk, 'managed_disk') and disk.managed_disk is not None: + encryption = self.get_disk_encryption(disk) + volume_data['tags'].update({'disk_encryption_set': encryption}) + if disk.managed_disk.id is not None: + volume_data['tags'].update({'disk_id': disk.managed_disk.id}) + if disk.managed_disk.storage_account_type is not None: + volume_data['tags'].update({'storage_account_type': disk.managed_disk.storage_account_type}) + + map_disk = self.get_mapping_disk_info(disk, list_disks) + + if map_disk: + volume_data['tags'].update({ + 'iops': map_disk.disk_iops_read_write, + 'throughput_mbps': map_disk.disk_m_bps_read_write + }) + return volume_data + + @staticmethod + def get_mapping_disk_info(disk, list_disks): + if list_disks: + list_disks = [] + + if getattr(disk, 'managed_disk') and disk.managed_disk: + disk_name = disk.managed_disk.id.split('/')[-1] + for disk_info in list_disks: + if disk_info.name == disk_name: + return disk_info + + return None + + @staticmethod + def get_disk_encryption(disk): + if disk.managed_disk.disk_encryption_set: + return 'CMK' + else: + return 'PMK' diff --git a/src/plugin/manager/virtual_machines/instance_manager.py b/src/plugin/manager/virtual_machines/instance_manager.py new file mode 100644 index 00000000..3e243b0f --- /dev/null +++ b/src/plugin/manager/virtual_machines/instance_manager.py @@ -0,0 +1,245 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.virtual_machines.virtual_machines_connector import VirtualMachinesConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.virtual_machines import ( + VirtualMachineDiskManager, + VirtualMachineLoadBalancerManager, + VirtualMachineNetworkSecurityGroupManager, + VirtualMachineNICManager, + VirtualMachineVmManager, + VirtualMachineVNetManager, +) +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class VirtualMachinesManager(AzureBaseManager): + cloud_service_group = "VirtualMachines" + cloud_service_type = "Instance" + service_code = "/Microsoft.Compute/virtualMachines" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Compute", "Server"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-vm.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + vm_conn = VirtualMachinesConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + # call all managers + vm_manager = VirtualMachineVmManager(vm_conn=vm_conn) + disk_manager = VirtualMachineDiskManager() + load_balancer_manager = VirtualMachineLoadBalancerManager() + network_security_group_manager = VirtualMachineNetworkSecurityGroupManager() + nic_manager = VirtualMachineNICManager() + vnet_manager = VirtualMachineVNetManager() + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + subscription_data = { + "subscription_id": secret_data["subscription_id"], + "subscription_name": subscription_info["display_name"], + "tenant_id": subscription_info["tenant_id"], + } + + vms = list(vm_conn.list_all_vms()) + resource_groups = list(vm_conn.list_resource_groups()) + load_balancers = list(vm_conn.list_load_balancers()) + network_security_groups = list(vm_conn.list_network_security_groups()) + network_interfaces = list(vm_conn.list_network_interfaces()) + disks = list(vm_conn.list_disks()) + public_ip_addresses = list(vm_conn.list_public_ip_addresses()) + virtual_networks = list(vm_conn.list_virtual_networks()) + skus = list(vm_conn.list_skus()) + + for vm in vms: + try: + vnet_data = None + subnet_data = None + lb_vos = [] + + resource_group, resource_group_name = self.get_resource_info_in_vm( + vm, resource_groups + ) + skus_dict = self.get_skus_resource(skus) + + disk_vos = disk_manager.get_disk_info(vm, disks) + nic_vos, primary_ip = nic_manager.get_nic_info( + vm, network_interfaces, public_ip_addresses, virtual_networks + ) + + vm_resource = vm_manager.get_vm_info( + vm, + disk_vos, + nic_vos, + resource_group, + subscription_data["subscription_id"], + network_security_groups, + primary_ip, + skus_dict, + ) + + if load_balancers is not None: + lb_vos = load_balancer_manager.get_load_balancer_info( + vm, load_balancers, public_ip_addresses + ) + + nsg_vos = ( + network_security_group_manager.get_network_security_group_info( + vm, network_security_groups, network_interfaces + ) + ) + + nic_name = vm.network_profile.network_interfaces[0].id.split("/")[-1] + + if nic_name is not None: + vnet_subnet_dict = vnet_manager.get_vnet_subnet_info( + nic_name, network_interfaces, virtual_networks + ) + + if vnet_subnet_dict.get("vnet_info"): + vnet_data = vnet_subnet_dict["vnet_info"] + + if vnet_subnet_dict.get("subnet_info"): + subnet_data = vnet_subnet_dict["subnet_info"] + + vm_resource.update({"tags": self.get_tags(vm.tags)}) + + resource_id = f'/subscriptions/{subscription_data["subscription_id"]}/resourceGroups/{resource_group_name}/providers/Microsoft.Compute/virtualMachines/{vm_resource["name"]}' + + # update vm_resource data + vm_resource["data"].update( + { + "tenant_id": subscription_data["tenant_id"], + "subscription_name": subscription_data["subscription_name"], + "subscription_id": subscription_data["subscription_id"], + "resource_group": resource_group_name, + } + ) + + vm_resource["data"].update( + { + "load_balancer": lb_vos, + "security_group": nsg_vos, + "vnet": vnet_data, + "subnet": subnet_data, + "azure_monitor": {"resource_id": resource_id}, + "activity_log": {"resource_uri": resource_id}, + } + ) + + vm_resource["data"]["compute"]["account"] = subscription_data[ + "subscription_name" + ] + + self.set_region_code(vm_resource["region_code"]) + + cloud_services.append( + make_cloud_service( + name=vm_resource["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=vm_resource, + account=subscription_data["subscription_id"], + instance_type=vm_resource["data"]["compute"]["instance_type"], + region_code=vm_resource["region_code"], + reference=self.make_reference( + vm_resource["data"]["compute"]["instance_id"], + f"https://portal.azure.com/#@.onmicrosoft.com/resource/subscriptions/{subscription_data['subscription_id']}/resourceGroups/{resource_group_name}/providers/Microsoft.Compute/virtualMachines/{vm_resource['data']['compute']['instance_name']}/overview" + ), + tags=vm.tags, + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + @staticmethod + def get_tags(tags): + tags_result = [] + if tags: + for k, v in tags.items(): + tags_result.append({"key": k, "value": v}) + + return tags_result + + @staticmethod + def get_resource_info_in_vm(vm, resource_groups): + for rg in resource_groups: + vm_info = vm.id.split("/") + for info in vm_info: + if info == rg.name.upper(): + resource_group = rg + resource_group_name = rg.name + return resource_group, resource_group_name + + @staticmethod + def get_resources_in_resource_group(resources, resource_group_name): + infos = [] + for resource in resources: + id_info = resource.id.split("/") + for info in id_info: + if info == resource_group_name.upper(): + infos.append(resource) + return infos + + @staticmethod + def get_skus_resource(skus): + skus_dict = {} + for sku in skus: + if sku.resource_type == "virtualMachines": + location = sku.locations[0].lower() + if location not in skus_dict: + skus_dict[location] = [] + info = {} + # get sku information for discriminating Instance type + info.update( + { + "resource_type": sku.resource_type, + "name": sku.name, + "tier": sku.tier, + "size": sku.size, + "family": sku.family, + } + ) + + # get cpu and memory information + for capa in sku.capabilities: + if capa.name == "vCPUs": + info["core"] = capa.value + elif capa.name == "MemoryGB": + info["memory"] = capa.value + skus_dict[location].append(info) + + return skus_dict diff --git a/src/plugin/manager/virtual_machines/load_balancer_manager.py b/src/plugin/manager/virtual_machines/load_balancer_manager.py new file mode 100644 index 00000000..ff4699c4 --- /dev/null +++ b/src/plugin/manager/virtual_machines/load_balancer_manager.py @@ -0,0 +1,106 @@ +class VirtualMachineLoadBalancerManager: + def get_load_balancer_info(self, vm, load_balancers, public_ip_addresses): + """ + lb_data = { + "type" = "application" | "network", + "endpoint" = "", + "port" = [] + "name" = "" + "protocol" = [] + "scheme" = "internet-facing" | "internal" + "tags" = { + "lb_id" = "" + } + } + """ + + lb_data = [] + match_load_balancers = self.get_load_balancers_from_nic( + vm.network_profile.network_interfaces, load_balancers + ) + + for match_load_balancer in match_load_balancers: + ports, protocols = self.get_lb_port_protocol(match_load_balancer) + load_balancer_data = { + "type": "network", + "scheme": self.get_lb_scheme(match_load_balancer), + "endpoint": self.get_lb_endpoint( + match_load_balancer, public_ip_addresses + ), + "port": ports, + "name": match_load_balancer.name, + "protocol": protocols, + "tags": {"lb_id": match_load_balancer.id}, + } + lb_data.append(load_balancer_data) + + return lb_data + + def get_lb_endpoint(self, match_load_balancer, public_ip_addresses): + frontend_ip_configurations = match_load_balancer.frontend_ip_configurations + + if public_ip_addresses: + public_ip_addresses = [] + + if frontend_ip_configurations: + frontend_ip_configurations = [] + + if self.get_lb_scheme(match_load_balancer) == "internet-facing": + for ip in frontend_ip_configurations: + public_ip_address_name = ip.public_ip_address.id.split("/")[-1] + for pub_ip in public_ip_addresses: + if public_ip_address_name == pub_ip.name: + return pub_ip.ip_address + + elif self.get_lb_scheme(match_load_balancer) == "internal": + for ip in frontend_ip_configurations: + return ip.private_ip_address + + return "" + + @staticmethod + def get_load_balancers_from_nic(network_interfaces, load_balancers): + match_load_balancers = [] + + if network_interfaces: + network_interfaces = [] + + if load_balancers: + load_balancers = [] + + vm_nics = [] + for nic in network_interfaces: + vm_nics.append(nic.id.split("/")[-1]) + + for vm_nic in vm_nics: + for lb in load_balancers: + if lb.backend_address_pools: + for be in lb.backend_address_pools: + if be.backend_ip_configurations: + for ip_conf in be.backend_ip_configurations: + nic_name = ip_conf.id.split("/")[-3] + if nic_name == vm_nic: + match_load_balancers.append(lb) + + return match_load_balancers + + @staticmethod + def get_lb_scheme(match_load_balancer): + frontend_ip_configurations = match_load_balancer.frontend_ip_configurations + for fe_ip_conf in frontend_ip_configurations: + if fe_ip_conf.public_ip_address: + return "internet-facing" + else: + return "internal" + + @staticmethod + def get_lb_port_protocol(match_load_balancer): + ports = [] + protocols = [] + lb_rules = match_load_balancer.load_balancing_rules + if lb_rules: + for lbr in lb_rules: + ports.append(lbr.frontend_port) + protocols.append(lbr.protocol.upper()) + + return ports, protocols \ No newline at end of file diff --git a/src/plugin/manager/virtual_machines/network_security_group_manager.py b/src/plugin/manager/virtual_machines/network_security_group_manager.py new file mode 100644 index 00000000..567337d2 --- /dev/null +++ b/src/plugin/manager/virtual_machines/network_security_group_manager.py @@ -0,0 +1,210 @@ +class VirtualMachineNetworkSecurityGroupManager: + def get_network_security_group_info( + self, vm, network_security_groups, network_interfaces + ): + """ + nsg_data = { + "protocol" = "", + "remote" = "", + "remote_cidr" = "", + "remote_id" = "", + "security_group_name" = "", + "security_group_id" = "", + "description" = "", + "direction" = "inbound" | "outbound", + "port_range_min" = 0, + "port_range_max" = 0, + "port" = "", + "priority" = 0 + } + """ + + nsg_data = [] + + network_security_groups_data = [] + + if ( + getattr(vm.network_profile, "network_interfaces") + and vm.network_profile.network_interfaces + ): + vm_network_interfaces = vm.network_profile.network_interfaces + else: + vm_network_interfaces = [] + + match_network_security_groups = self.get_network_security_group_from_nic( + vm_network_interfaces, network_interfaces, network_security_groups + ) + for network_security_group in match_network_security_groups: + sg_id = network_security_group.id + + security_rules = network_security_group.security_rules + security_data = self.get_nsg_security_rules(security_rules, sg_id) + network_security_groups_data.extend(security_data) + + default_security_rules = network_security_group.default_security_rules + default_security_data = self.get_nsg_security_rules( + default_security_rules, sg_id + ) + network_security_groups_data.extend(default_security_data) + + for nsg in network_security_groups_data: + nsg_data.append(nsg) + + return nsg_data + + def get_nsg_security_rules(self, security_rules, sg_id): + result = [] + for s_rule in security_rules: + security_rule_data = { + "protocol": self.get_nsg_protocol(s_rule.protocol), + "remote_id": s_rule.id, + "security_group_name": s_rule.id.split("/")[-3], + "description": s_rule.description, + "direction": s_rule.direction.lower(), + "priority": s_rule.priority, + "security_group_id": sg_id, + "action": s_rule.access.lower(), + } + + remote_data = self.get_nsg_remote(s_rule) + security_rule_data.update(remote_data) + port_data = self.get_nsg_port(s_rule) + security_rule_data.update(port_data) + + result.append(security_rule_data) + + return result + + @staticmethod + def get_nsg_protocol(protocol): + if protocol == "*": + return "ALL" + return protocol + + @staticmethod + def get_network_security_group_from_nic( + vm_network_interfaces, network_interfaces, network_security_groups + ): + nsgs = [] + for vm_nic in vm_network_interfaces: + vm_nic_name = vm_nic.id.split("/")[-1] + for nic in network_interfaces: + if vm_nic_name == nic.name: + if ( + getattr(nic, "network_security_group") + and nic.network_security_group + ): + nsg_name = nic.network_security_group.id.split("/")[-1] + for nsg in network_security_groups: + if nsg.name == nsg_name: + nsgs.append(nsg) + break + break + + return nsgs + + @staticmethod + def get_nsg_remote(s_rule): + remote_result = {} + if s_rule.source_address_prefix is not None: + if "/" in s_rule.source_address_prefix: + remote_result.update( + { + "remote": s_rule.source_address_prefix, + "remote_cidr": s_rule.source_address_prefix, + } + ) + elif s_rule.source_address_prefix == "*": + remote_result.update({"remote": "*", "remote_cidr": "*"}) + else: + remote_result.update({"remote": s_rule.source_address_prefix}) + + else: + address_prefixes = s_rule.source_address_prefixes + remote = "" + + if address_prefixes: + for prfx in address_prefixes: + remote += prfx + remote += ", " + + remote = remote[:-2] + + remote_result.update({"remote": remote, "remote_cidr": remote}) + + if len(remote_result) > 0: + return remote_result + + return None + + @staticmethod + def get_nsg_port(s_rule): + port_result = {} + + if ( + getattr(s_rule, "destination_port_range") + and s_rule.destination_port_range is not None + ): + if "-" in s_rule.destination_port_range: + port_min = s_rule.destination_port_range.split("-")[0] + port_max = s_rule.destination_port_range.split("-")[1] + port_result.update( + { + "port_range_min": port_min, + "port_range_max": port_max, + "port": s_rule.destination_port_range, + } + ) + elif s_rule.destination_port_range == "*": + port_result.update( + {"port_range_min": 0, "port_range_max": 0, "port": "*"} + ) + else: + port_result.update( + { + "port_range_min": s_rule.destination_port_range, + "port_range_max": s_rule.destination_port_range, + "port": s_rule.destination_port_range, + } + ) + else: + if ( + getattr(s_rule, "destination_port_ranges") + and s_rule.destination_port_ranges + ): + port_ranges = s_rule.destination_port_ranges + if not port_ranges: + port_ranges = [] + + port_min = 0 + port_max = 0 + all_port = "" + ports = [] + + for port in port_ranges: + if "-" in port: # ex. ['33-55'] + for i in port.split("-"): + ports.append(i) + else: # ex. ['8080'] + ports.append(port) + + ports = list(map(int, ports)) # Change to int list + + if ports: + port_min = min(ports) + port_max = max(ports) + + all_port = ", ".join(map(str, ports)) # Update string + + port_result.update( + { + "port_range_min": port_min, + "port_range_max": port_max, + "port": all_port, + } + ) + + if len(port_result) > 0: + return port_result + + return None \ No newline at end of file diff --git a/src/plugin/manager/virtual_machines/nic_manager.py b/src/plugin/manager/virtual_machines/nic_manager.py new file mode 100644 index 00000000..08b6cf90 --- /dev/null +++ b/src/plugin/manager/virtual_machines/nic_manager.py @@ -0,0 +1,123 @@ +class VirtualMachineNICManager: + def get_nic_info( + self, vm, network_interfaces, public_ip_addresses, virtual_networks + ): + """ + nic_data = { + "device_index": 0, + "device": "", + "nic_type": "", + "ip_addresses": [], + "cidr": "", + "mac_address": "", + "public_ip_address": "", + "tags": { + "nic_id": "" + } + } + """ + + nic_data = [] + index = 0 + + vm_network_interfaces = vm.network_profile.network_interfaces + + if vm_network_interfaces is None: + vm_network_interfaces = [] + + match_network_interfaces = self.get_network_interfaces( + vm_network_interfaces, network_interfaces + ) + + for vm_nic in match_network_interfaces: + ip_configurations = self.get_ip_configurations(vm_nic) + + network_data = { + "device_index": index, + "cidr": self.get_nic_cidr(ip_configurations, virtual_networks), + "ip_addresses": self.get_nic_ip_addresses(ip_configurations), + "mac_address": vm_nic.mac_address, + "public_ip_address": self.get_nic_public_ip_addresses( + ip_configurations, public_ip_addresses + ), + "tags": self.get_tags(vm_nic), + } + + primary_ip = self.get_primary_ip_addresses( + self.get_ip_configurations(vm_nic) + ) + + index += 1 + nic_data.append(network_data) + + return nic_data, primary_ip + + @staticmethod + def get_nic_public_ip_addresses(ip_configurations, public_ip_addresses): + for ip_conf in ip_configurations: + if getattr(ip_conf, "public_ip_address") and ip_conf.public_ip_address: + ip_name = ip_conf.public_ip_address.id.split("/")[-1] + for pub_ip in public_ip_addresses: + if ip_name == pub_ip.name: + return pub_ip.ip_address + + return None + + @staticmethod + def get_nic_cidr(ip_configurations, virtual_networks): + if ip_configurations: + subnet_name = ip_configurations[0].subnet.id.split("/")[-1] + for vnet in virtual_networks: + for subnet in vnet.subnets: + if subnet_name == subnet.name: + return subnet.address_prefix + + return None + + @staticmethod + def get_nic_ip_addresses(ip_configurations): + ip_addresses = [] + for ip_conf in ip_configurations: + ip_addresses.append(ip_conf.private_ip_address) + + if ip_addresses: + return ip_addresses + + return None + + @staticmethod + def get_primary_ip_addresses(ip_configurations): + result = {} + for ip_conf in ip_configurations: + result.update({ip_conf.private_ip_address: ip_conf.primary}) + + return result + + @staticmethod + def get_ip_configurations(vm_nic): + result = [] + if getattr(vm_nic, "ip_configurations") and vm_nic.ip_configurations: + for ip in vm_nic.ip_configurations: + result.append(ip) + + return result + + @staticmethod + def get_tags(vm_nic): + return { + "name": vm_nic.name, + "etag": vm_nic.etag, + "enable_accelerated_networking": vm_nic.enable_accelerated_networking, + "enable_ip_forwarding": vm_nic.enable_ip_forwarding, + } + + @staticmethod + def get_network_interfaces(vm_network_interfaces, network_interfaces): + result = [] + for vm_nic in vm_network_interfaces: + for nic in network_interfaces: + if vm_nic.id.split("/")[-1] == nic.name: + result.append(nic) + break + + return result diff --git a/src/plugin/manager/virtual_machines/vm_manager.py b/src/plugin/manager/virtual_machines/vm_manager.py new file mode 100644 index 00000000..779f6593 --- /dev/null +++ b/src/plugin/manager/virtual_machines/vm_manager.py @@ -0,0 +1,413 @@ +from plugin.connector.virtual_machines.virtual_machines_connector import VirtualMachinesConnector + + +class VirtualMachineVmManager: + def __init__(self, vm_conn): + self.vm_conn: VirtualMachinesConnector = vm_conn + + def get_vm_info(self, vm, disks, nics, resource_group, subscription, network_security_groups, primary_ip, + skus_dict): + ''' + server_data = { + "name": "" + "ip_addresses": [], + "data": { + "primary_ip_address": "", + "os": { + "os_distro": "", + "os_arch": "", + "os_details": "", + "os_type": "LINUX" | "WINDOWS" + }, + "azure": { + "boot_diagnostics": "true" | "false", + "ultra_ssd_enabled": "true" | "false", + "write_accelerator_enabled": "true" | "false", + "priority": "Regular" | "Low" | "Spot", + "tags": { + "key": "", + "value": "" + }, + }, + "hardware": { + "core": 0, + "memory": 0 + }, + "compute": { + "keypair": "", + "availability_zone": "", + "instance_state": "", + "instance_type": "", + "launched_at": "datetime", + "instance_id": "", + "instance_name": "", + "security_groups": [ + { + "id": "", + "name": "", + "display": "" + }, + ... + ], + "image": "", + "account": "", + "tags": { + "id": "" + } + }, + "nics": [ + { nics_info }, + ... + ], + "disks": [ + { disk_info }, + ... + ] + } + } + ''' + + resource_group_name = resource_group.name + + vm_dict = self.get_vm_dict(vm, nics) + os_data = self.get_os_data(vm.storage_profile) + azure_data = self.get_azure_data(vm) + compute_data = self.get_compute_data(vm, resource_group_name, network_security_groups, subscription) + resource_group_data = self.get_resource_group_data(resource_group) + hardware_data = self.get_hardware_data(vm, skus_dict, compute_data) + + vm_dict.update({ + 'data': { + 'os': os_data, + 'hardware': hardware_data, + 'azure': azure_data, + 'compute': compute_data, + 'resource_group': resource_group_data, + 'disks': disks, + 'nics': nics, + 'primary_ip_address': self.get_primary_ip_address(primary_ip) + } + }) + + return vm_dict + + def get_vm_dict(self, vm, nic_vos): + vm_data = { + 'name': vm.name, + 'region_code': vm.location, + 'ip_addresses': self.get_ip_addresses(nic_vos), + } + return vm_data + + def get_os_data(self, vm_storage_profile): + if vm_storage_profile.image_reference is not None: + try: + os_type = self.get_os_type(vm_storage_profile.os_disk) + image_reference = vm_storage_profile.image_reference + offer = vm_storage_profile.image_reference.offer + + if os_type and offer is not None: + try: + os_data = { + 'os_distro': self.get_os_distro(os_type, offer), + 'details': self.get_os_details(image_reference), + 'os_type': os_type + } + return os_data + + except Exception as e: + print(f'[ERROR: GET OS Distro Data]: {e}') + + except Exception as e: + print(f'[ERROR: GET OS Data]: {e}') + + def get_compute_data(self, vm, resource_group_name, network_security_groups, subscription_id): + vm_info = self.vm_conn.get_vm(resource_group_name, vm.name) + compute_data = { + # 'keypair': self.get_keypair(vm.os_profile.linux_configuration), + 'keypair': '', # TODO: not implemented yet + 'instance_state': self.get_instance_state(vm_info.instance_view.statuses), + 'instance_type': vm.hardware_profile.vm_size, + 'launched_at': self.get_launched_time(vm_info.instance_view.statuses), + 'instance_id': vm.id, + 'instance_name': vm.name, + 'security_groups': self.get_security_groups(vm.network_profile.network_interfaces, network_security_groups), + 'image': self.get_image_detail(vm.location, vm.storage_profile.image_reference, subscription_id), + 'tags': { + 'vm_id': vm.vm_id + } + } + + if vm.zones: + compute_data.update({ + 'az': f'{vm.location}-{vm.zones[0]}' + }) + else: + compute_data.update({ + 'az': vm.location + }) + + return compute_data + + def get_azure_data(self, vm): + azure_data = { + 'ultra_ssd_enabled': self.get_ultra_ssd_enabled(vm.additional_capabilities), + 'write_accelerator_enabled': self.get_write_accelerator_enabled(vm.storage_profile.os_disk), + 'priority': self.get_vm_priority(vm), + 'tags': self.get_tags(vm.tags) + } + + if getattr(vm, 'diagnostics_profile') and getattr(vm.diagnostics_profile, + "boot_diagnostics") and vm.diagnostics_profile.boot_diagnostics: + azure_data.update({ + 'boot_diagnostics': self.get_boot_diagnostics(vm.diagnostics_profile.boot_diagnostics) + }) + + return azure_data + + def get_vm_size(self, location): + return self.vm_conn.list_virtual_machine_sizes(location) + + @staticmethod + def get_hardware_data(vm, skus_dict, compute_data): + """ + skus_dict = [ + { + 'memory': '0.75', + 'family': 'basicAFamily', + 'name': 'Basic_A0', + 'resource_type': 'virtualMachines', + 'size': 'A0', + 'tier': 'Basic', + 'core': '1'}, + }, + ] + """ + + location = vm.location.lower() + instance_type = compute_data["instance_type"] + + hardware_data = [] + for sku in skus_dict[location]: + if sku['name'] == instance_type: + hardware_data = sku + return hardware_data + + def get_os_distro(self, os_type, offer): + return self.extract_os_distro(os_type, offer) + + @staticmethod + def get_write_accelerator_enabled(os_disk): + if hasattr(os_disk.write_accelerator_enabled, 'os_disk.write_accelerator_enabled'): + return os_disk.write_accelerator_enabled + return False + + @staticmethod + def get_boot_diagnostics(boot_diagnostics): + if hasattr(boot_diagnostics.enabled, 'boot_diagnostics.enabled'): + return boot_diagnostics.enabled + return True + + @staticmethod + def get_keypair(linux_configuration): + if hasattr(linux_configuration, 'ssh') and linux_configuration.ssh: + key = linux_configuration.ssh.public_keys[0] + + return key.path.split('/')[2] + return "" + + @staticmethod + def get_ip_addresses(nic_vos): + ip_addrs = [] + for nic_vo in nic_vos: + ip_addrs.extend(nic_vo.get("ip_addresses")) + + if nic_vo["public_ip_address"]: + ip_addrs.append(nic_vo.get("public_ip_address")) + + return list(set(ip_addrs)) + + @staticmethod + def get_primary_ip_address(primary_ip): + for key, value in primary_ip.items(): + if value: + return key + + return '' + + @staticmethod + def get_vm_priority(vm): + if hasattr(vm, 'priority') and vm.priority: + return vm.priority + else: + return 'Regular' + + @staticmethod + def get_vm_hardware_info(list_sizes, size): + result = {} + for list_size in list_sizes: + if list_size.name == size: + result.update({ + 'core': list_size.number_of_cores, + 'memory': round(float(list_size.memory_in_mb / 1024), 2) + }) + break + + return result + + @staticmethod + def get_security_groups(vm_network_interfaces, network_security_groups): + security_groups = [] + nic_names = [] + + if vm_network_interfaces is None: + vm_network_interfaces = [] + + for vm_nic in vm_network_interfaces: + nic_name = vm_nic.id.split('/')[-1] + nic_names.append(nic_name) + + for nsg in network_security_groups: + network_interfaces = nsg.network_interfaces + if network_interfaces: + for nic in network_interfaces: + nic_name2 = nic.id.split('/')[-1] + for nic_name in nic_names: + if nic_name == nic_name2: + nsg_data = { + 'display': nsg.name, + 'id': nsg.id, + 'name': nsg.name + } + security_groups.append(nsg_data) + break + break + if len(security_groups) > 0: + return security_groups + return None + + @staticmethod + def get_launched_time(statuses): + if statuses is None: + statuses = [] + + for status in statuses: + if status.display_status == 'Provisioning succeeded': + return status.time.isoformat() + + return None + + @staticmethod + def get_instance_state(statuses): + try: + if statuses: + return statuses[-1].code.split('/')[-1].upper() + except Exception: + pass + + return None + + @staticmethod + def get_resource_group_data(resource_group): + resource_group_data = { + 'resource_group_name': resource_group.name, + 'resource_group_id': resource_group.id + } + return resource_group_data + + @staticmethod + def get_ultra_ssd_enabled(additional_capabilities): + if additional_capabilities: + return additional_capabilities.ultra_ssd_enabled + else: + return False + + @staticmethod + def get_os_type(os_disk): + if os_disk.os_type is not None: + return os_disk.os_type.upper() + + @staticmethod + def extract_os_distro(os_type, offer): + if offer is not None and os_type is not None: + try: + offer.lower() + + if os_type == 'LINUX': + os_map = { + 'suse': 'suse', + 'rhel': 'redhat', + 'centos': 'centos', + 'cent': 'centos', + 'fedora': 'fedora', + 'ubuntu': 'ubuntu', + 'ubuntuserver': 'ubuntu', + 'oracle': 'oraclelinux', + 'oraclelinux': 'oraclelinux', + 'debian': 'debian' + } + + for key in os_map: + if key in offer: + return os_map[key] + + return 'linux' + + elif os_type == 'WINDOWS': + os_distro_string = None + offer_splits = offer.split('-') + + version_cmps = ['2016', '2019', '2012'] + + for cmp in version_cmps: + if cmp in offer_splits: + os_distro_string = f'win{cmp}' + + if os_distro_string is not None and 'R2_RTM' in offer_splits: + os_distro_string = f'{os_distro_string}r2' + + if os_distro_string is None: + os_distro_string = 'windows' + + return os_distro_string + + except Exception as e: + print(f'[ERROR: Cannot extract os distro info]: {e}') + + @staticmethod + def get_os_details(image_reference): + if image_reference: + publisher = image_reference.publisher + offer = image_reference.offer + sku = image_reference.sku + if publisher and offer and sku: + os_details = f'{publisher}, {offer}, {sku}' + return os_details + + return None + + @staticmethod + def get_image_detail(location, image_reference, subscription_id): + publisher = getattr(image_reference, "publisher", None) + offer = getattr(image_reference, "offer", None) + sku = getattr(image_reference, "sku", None) + version = getattr(image_reference, "exact_version", None) + + if publisher and offer and sku and version: + image_detail = f'/Subscriptions/{subscription_id}/Providers/Microsoft.Compute/Locations/{location}' \ + f'/Publishers/{publisher}/ArtifactTypes/VMImage/Offers/{offer}/Skus/{sku}/Versions/{version}' + return image_detail + + return None + + @staticmethod + def get_tags(tags): + tags_result = [] + if tags: + for k, v in tags.items(): + tags_result.append({ + 'key': k, + 'value': v + }) + + return tags_result diff --git a/src/plugin/manager/virtual_machines/vnet_manager.py b/src/plugin/manager/virtual_machines/vnet_manager.py new file mode 100644 index 00000000..0b673c3c --- /dev/null +++ b/src/plugin/manager/virtual_machines/vnet_manager.py @@ -0,0 +1,61 @@ +class VirtualMachineVNetManager: + def get_vnet_subnet_info(self, nic_name, network_interfaces, virtual_networks): + ''' + vnet_subnet_dict = { + "vnet_info": vnet_data, + "subnet_info": subnet_data + } + ''' + vnet_info_dict = {} + + for nic in network_interfaces: + if nic.name == nic_name: + vnet_name = nic.ip_configurations[0].subnet.id.split('/')[-3] + + if vnet_name is not None and len(virtual_networks) > 0: + for vnet in virtual_networks: + if vnet.name == vnet_name: + subnet_info = self.convert_subnet_info(vnet.subnets[0]) # Get attached subnets + vnet_info = self.convert_vnet_info(vnet) + if subnet_info is not None: + vnet_info_dict['subnet_info'] = subnet_info + if vnet_info is not None: + vnet_info_dict['vnet_info'] = vnet_info + + return vnet_info_dict + + @staticmethod + def convert_vnet_info(vnet): + ''' + vnet_data = { + "vnet_id" = "", + "vnet_name" = "", + "cidr" = "" + } + ''' + + vnet_data = { + 'vnet_id': vnet.id, + 'vnet_name': vnet.name, + 'cidr': vnet.address_space.address_prefixes[0] + } + + return vnet_data + + @staticmethod + def convert_subnet_info(subnet): + ''' + subnet_data = { + "subnet_name": "", + "subnet_id": "", + "cidr": "" + } + ''' + + subnet_data = { + 'subnet_name': subnet.name, + 'subnet_id': subnet.id, + 'cidr': subnet.address_prefix + } + + return subnet_data diff --git a/src/plugin/metadata/virtual_machines/instance.yaml b/src/plugin/metadata/virtual_machines/instance.yaml new file mode 100644 index 00000000..300e3459 --- /dev/null +++ b/src/plugin/metadata/virtual_machines/instance.yaml @@ -0,0 +1,479 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription.subscription_name + - Resource Group: data.resource_group.resource_group_name + - IP Address: ip_addresses + - Instance ID: data.compute.instance_id + - Instance State: data.compute.instance_state + - Instance Type: data.compute.instance_type + - Key Pair: data.compute.keypair + - Image: data.compute.image + - Availability Zone: data.compute.az + - OS Type: data.os.os_type + - OS Architecture: data.os.os_arch + - MAC Address: data.nics.mac_address + - Public IP Address: data.nics.public_ip_address + - Public DNS: data.nics.tags.public_dns + - VNet ID: data.vnet.vnet_id + - VNet Name: data.vnet.vnet_name + - Subnet ID: data.subnet.subnet_id + - Subnet Name: data.subnet.subnet_name + - ELB Name: data.load_balancer.name + - ELB DNS: data.load_balancer.endpoint + - Auto Scaling Group: data.auto_scaling_group.name + - Core: data.hardware.core + data_type: integer + - Memory: data.hardware.memory + data_type: float + - Management State: state + - Cloud Service Group: cloud_service_group + - Cloud Service Type: cloud_service_type + - Service Account: collection_info.service_accounts + - Launched: data.launched_at + + + +table: + sort: + key: data.id + desc: false + fields: + - Instance State: data.compute.instance_state + type: enum + enums: + - RUNNING: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - PENDING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - REBOOTING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - SHUTTING-DOWN: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - STOPPING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - STARTING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - PROVISIONING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - STAGING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - DEALLOCATING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - REPAIRING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - STOPPED: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - DEALLOCATED: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - SUSPENDED: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - TERMINATED: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Cloud Service ID: cloud_service_id + is_optional: true + - Instance Type: data.compute.instance_type + - Core: data.hardware.core + - Memory: data.hardware.memory + - Instance ID: data.compute.instance_id + is_optional: true + - Key Pair: data.compute.keypair + is_optional: true + - Image: data.compute.image + is_optional: true + - Availability Zone: data.compute.az + - OS Type: data.os.os_type + is_optional: true + - OS: data.os.os_distro + - OS Architecture: data.os.os_arch + is_optional: true + - Primary IP: data.primary_ip_address + - Public DNS: data.nics + type: list + options: + sub_key: tags.public_dns + is_optional: true + - Public IP: data.nics + type: list + options: + sub_key: public_ip_address + is_optional: true + - All IP: ip_addresses + is_optional: true + - MAC Address: data.nics.mac_address + is_optional: true + - CIDR: data.vnet.cidr + is_optional: true + - VNet ID: data.vnet.vnet_id + is_optional: true + - VNet Name: data.vnet.vnet_name + is_optional: true + - Subnet ID: data.subnet.subnet_id + is_optional: true + - Subnet Name: data.subnet.subnet_name + is_optional: true + - Load Balancer Name: data.load_balancer.name + is_optional: true + - Load Balancer DNS: data.load_balancer.endpoint + is_optional: true + - Ultra SSD Enabled: data.azure.ultra_ssd_enabled + is_optional: true + - Write Accelerator Enabled: data.azure.write_accelerator_enabled + is_optional: true + - Boot Diagnostics: data.azure.boot_diagnostics + is_optional: true + - Priority: data.azure.priority + is_optional: true + - Auto Scaling Group: data.auto_scaling_group.name + is_optional: true + - CPU Utilization: data.monitoring.cpu.utilization.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Memory Usage: data.monitoring.memory.usage.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Disk Read IOPS: data.monitoring.disk.read_iops.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Disk Write IOPS: data.monitoring.disk.write_iops.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Disk Read Throughput: data.monitoring.disk.read_throughput.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Disk Write Throughput: data.monitoring.disk.write_throughput.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Network Received PPS: data.monitoring.network.received_pps.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Network Send PPS: data.monitoring.network.sent_pps.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Network Received Throughput: data.monitoring.network.received_throughput.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - Network Sent Throughput: data.monitoring.network.sent_throughput.avg + default: 0 + is_optional: true + field_description: (Daily Average) + - CPU Utilization: data.monitoring.cpu.utilization.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Memory Usage: data.monitoring.memory.usage.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Disk Read IOPS: data.monitoring.disk.read_iops.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Disk Write IOPS: data.monitoring.disk.write_iops.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Disk Read Throughput: data.monitoring.disk.read_throughput.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Disk Write Throughput: data.monitoring.disk.write_throughput.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Network Received PPS: data.monitoring.network.received_pps.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Network Send PPS: data.monitoring.network.sent_pps.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Network Received Throughput: data.monitoring.network.received_throughput.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Network Sent Throughput: data.monitoring.network.sent_throughput.max + default: 0 + is_optional: true + field_description: (Daily Max) + - Subscription ID: account + - Launched: launched_at + is_optional: true + + + +tabs.0: + name: Azure VM + items: + - name: Virtual Machine + type: item + fields: + - Resource ID: data.compute.instance_id + - VM ID: data.compute.tags.vm_id + - VM State: data.compute.instance_state + type: enum + enums: + - RUNNING: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - STARTING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - DEALLOCATING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - STOPPING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - DEALLOCATING: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - STOPPED: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - DEALLOCATED: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Instance Type: data.compute.instance_type + - Image: data.compute.image + - Azure Priority: data.azure.priority + type: enum + enums: + - Regular: indigo.500 + type: badge + - Low: coral.600 + type: badge + - Spot: peacock.600 + type: badge + - Region: region_code + - Availability Zone: data.compute.az + - Key Pair: data.compute.keypair + - Ultra SSD Enabled: data.azure.ultra_ssd_enabled + type: enum + enums: + - 'true': indigo.500 + type: badge + - 'false': coral.600 + type: badge + - Write Accelerator Enabled: data.azure.write_accelerator_enabled + type: enum + enums: + - 'true': indigo.500 + type: badge + - 'false': coral.600 + type: badge + - Boot Diagnostics: data.azure.boot_diagnostics + type: enum + enums: + - 'true': indigo.500 + type: badge + - 'false': coral.600 + type: badge + - Public IP: data.nics + type: list + options: + sub_key: public_ip_address + delimiter: '
' + - Security Groups: data.compute.security_groups + type: list + options: + sub_key: display + delimiter: '
' + - Launched At: data.compute.launched_at + - name: Virtual Network + type: item + fields: + - VNet ID: data.vnet.vnet_id + - VNet Name: data.vnet.vnet_name + - Subnet ID: data.subnet.subnet_id + - Subnet Name: data.subnet.subnet_name + - name: Operating System + type: item + fields: + - OS Type: data.os.os_type + translation_id: PAGE_SCHEMA.OS_TYPE + - OS Distribution: data.os.os_distro + translation_id: PAGE_SCHEMA.OS_DISTRO + - OS Architecture: data.os.os_arch + translation_id: PAGE_SCHEMA.OS_ARCH + - OS Version Details: data.os.details + translation_id: PAGE_SCHEMA.OS_DETAILS + - OS License: data.os.os_license + translation_id: PAGE_SCHEMA.OS_LICENSE + - name: Hardware + type: item + fields: + - Core: data.hardware.core + translation_id: PAGE_SCHEMA.CPU_CORE + - Memory: data.hardware.memory + translation_id: PAGE_SCHEMA.MEMORY + + + +tabs.1: + name: Disk + type: table + root_path: data.disks + fields: + - Index: device_index + - Name: tags.disk_name + - Size: size + - Disk ID: tags.disk_id + - Storage Account Type: tags.storage_Account_type + - IOPS: tags.iops + - Throughput (mbps): tags.throughput_mbps + - Encryption Set: tags.disk_encryption_set + - Caching: tags.caching + + + +tabs.2: + name: NIC + type: table + root_path: data.nics + fields: + - Index: device_index + - Name: tags.name + - IP Addresses: ip_addresses + type: list + options: + delimiter: '
' + - Public IP: public_ip_address + - MAC Address: mac_address + - CIDR: cidr + - etag: tags.etag + - Enable Accelerated Networking: tags.enable_accelerated_networking + type: enum + enums: + - 'true': indigo.500 + type: badge + - 'false': coral.600 + type: badge + - Enable IP Forwarding: tags.enable_ip_forwarding + type: enum + enums: + - 'true': indigo.500 + type: badge + - 'false': coral.600 + type: badge + + + +tabs.3: + name: Network Security Groups + type: table + root_path: data.security_group + fields: + - Direction: direction + type: enum + enums: + - inbound: indigo.500 + type: badge + - outbound: coral.600 + type: badge + - Name: security_group_name + - Protocol: protocol + type: enum + enums: + - ALL: primary + type: badge + - TCP: indigo.500 + type: badge + - UDP: coral.600 + type: badge + - ICMP: peacock.500 + type: badge + - Port Range: port + - Remote: remote + - Priority: priority + - Action: action + type: enum + enums: + - allow: indigo.500 + type: badge + - deny: coral.600 + type: badge + - Description: description + + + +tabs.4: + name: Load Balancer + type: table + root_path: data.load_balancer + fields: + - Name: name + - Endpoint: endpoint + - Type: type + type: enum + enums: + - network: indigo.500 + type: badge + - application: coral.600 + type: badge + - Protocol: protocol + type: list + options: + delimiter: '
' + - Port: port + type: list + options: + delimiter: '
' + - Scheme: scheme + type: enum + enums: + - internet-facing: indigo.500 + type: badge + - internal: coral.600 + type: badge \ No newline at end of file From e69b089c9df0ec7482eb1185ca7cb558192a9264 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Mon, 12 Aug 2024 17:52:43 +0900 Subject: [PATCH 28/35] feat: Add Postgre SQL Servers Metadata --- .../metadata/postgre_sql_servers/server.yaml | 131 +++++++++++++----- 1 file changed, 93 insertions(+), 38 deletions(-) diff --git a/src/plugin/metadata/postgre_sql_servers/server.yaml b/src/plugin/metadata/postgre_sql_servers/server.yaml index 3b8e7176..46885faf 100644 --- a/src/plugin/metadata/postgre_sql_servers/server.yaml +++ b/src/plugin/metadata/postgre_sql_servers/server.yaml @@ -162,12 +162,83 @@ tabs.0: tabs.1: name: Connection Security - type: item + items: + - name: Connection Security + type: item + fields: + - Public Network Access: data.public_network_access + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - SSL Enforcement: data.ssl_enforcement + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - TLS Setting: data.minimal_tls_version + - name: Firewall Rules + type: simple-table + root_path: data.firewall_rules + fields: + - Firewall Rule Name: name + - Start IP: start_ip_address + - End IP: end_ip_address + - name: VNET Rules + type: simple-table + root_path: data.virtual_network_rules + fields: + - Rule Name: name + - Virtual Network: virtual_network_name_display + - Subnet: subnet_name + - Endpoint Status: state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - InProgress: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Deleting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Initializing: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Unknown: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + + +tabs.2: + name: Replicas + type: simple-table + root_path: data.replicas fields: - - Public Network Access: data.public_network_access + - Name: name + - Location: location + - Status: user_visible_state type: enum enums: - - Enabled: + - Ready: icon_image: ic_circle-filled icon_color: green.500 type: state @@ -175,60 +246,44 @@ tabs.1: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - SSL Enforcement: data.ssl_enforcement - type: enum - enums: - - Enabled: + - Dropping: icon_image: ic_circle-filled - icon_color: green.500 + icon_color: yellow.500 type: state - - Disabled: + - Inaccessible: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - TLS Setting: data.minimal_tls_version -tabs.2: - name: Firewall Rules +tabs.3: + name: Active Directory Admin type: simple-table - root_path: data.firewall_rules + root_path: data.server_administrators fields: - - Firewall Rule Name: name - - Start IP: start_ip_address - - End IP: end_ip_address + - Name: name + - Login: login + - SID: sid + - Tenant ID: tenant_id -tabs.3: - name: VNET Rules - type: simple-table - root_path: data.virtual_network_rules +tabs.4: + name: Pricing Tier + type: item fields: - - Rule Name: name - - Virtual Network: virtual_network_name_display - - Subnet: subnet_name - - Endpoint Status: state + - Compute Generation: data.sku.name + - vCore: data.sku.capacity + - Storage Auto Grow: data.storage_profile.storage_autogrow type: enum enums: - - Ready: - icon_image: ic_circle-filled - icon_color: green.500 - type: state - - InProgress: + - Enabled: icon_image: ic_circle-filled icon_color: green.500 type: state - - Deleting: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state - - Initializing: + - Disabled: icon_image: ic_circle-filled icon_color: yellow.500 type: state - - Unknown: - icon_image: ic_circle-filled - icon_color: yellow.500 - type: state \ No newline at end of file + - Backup Retention Period (Days): data.storage_profile.backup_retention_days \ No newline at end of file From eef5e013f4b11edd7722dff2d23fd61087c03aac Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 14 Aug 2024 11:43:09 +0900 Subject: [PATCH 29/35] feat: Implement MySQL Servers FlexibleServer type --- src/plugin/connector/base.py | 4 + .../mysql_flexible_servers_connector.py | 18 ++ src/plugin/manager/my_sql_servers/__init__.py | 1 + .../my_sql_servers/flexible_server_manager.py | 138 ++++++++++ src/plugin/metadata/disks/disk.yaml | 8 + .../my_sql_servers/flexible_server.yaml | 249 ++++++++++++++++++ .../metadata/my_sql_servers/server.yaml | 1 + .../metadata/virtual_machines/instance.yaml | 2 +- .../FlexibleServer/namespace.yaml | 8 + .../FlexibleServer/server_count.yaml | 29 ++ 10 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 src/plugin/connector/my_sql_servers/mysql_flexible_servers_connector.py create mode 100644 src/plugin/manager/my_sql_servers/flexible_server_manager.py create mode 100644 src/plugin/metadata/my_sql_servers/flexible_server.yaml create mode 100644 src/plugin/metrics/MySQLServers/FlexibleServer/namespace.yaml create mode 100644 src/plugin/metrics/MySQLServers/FlexibleServer/server_count.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index fd1a67b2..a6c4feb4 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -15,6 +15,7 @@ from azure.mgmt.webpubsub import WebPubSubManagementClient from azure.mgmt.keyvault import KeyVaultManagementClient from azure.mgmt.rdbms.mysql import MySQLManagementClient +from azure.mgmt.rdbms.mysql_flexibleservers import MySQLManagementClient as MySQLFlexibleManagementClient from spaceone.core.connector import BaseConnector @@ -39,6 +40,8 @@ def __init__(self, *args, **kwargs): self.web_pubsub_service_client = None self.key_vault_client = None self.mysql_client = None + self.mysql_flexible_client = None + def set_connect(self, secret_data: dict): subscription_id = secret_data['subscription_id'] @@ -63,6 +66,7 @@ def set_connect(self, secret_data: dict): self.web_pubsub_service_client = WebPubSubManagementClient(credential=credential, subscription_id=subscription_id) self.key_vault_client = KeyVaultManagementClient(credential=credential, subscription_id=subscription_id) self.mysql_client = MySQLManagementClient(credential=credential, subscription_id=subscription_id) + self.mysql_flexible_client = MySQLFlexibleManagementClient(credential=credential, subscription_id=subscription_id) def get_connector(self, cloud_service_group: str, cloud_service_type: str): pass diff --git a/src/plugin/connector/my_sql_servers/mysql_flexible_servers_connector.py b/src/plugin/connector/my_sql_servers/mysql_flexible_servers_connector.py new file mode 100644 index 00000000..4ab8a2df --- /dev/null +++ b/src/plugin/connector/my_sql_servers/mysql_flexible_servers_connector.py @@ -0,0 +1,18 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class MySQLFlexibleServersConnector(AzureBaseConnector): + def __init__(self, secret_data=None, **kwargs): + super().__init__(**kwargs) + + self.set_connect(secret_data) + + def list_flexible_servers(self): + return self.mysql_flexible_client.servers.list() + + def list_firewall_rules_by_server(self, resource_group_name, server_name): + return self.mysql_flexible_client.firewall_rules.list_by_server(resource_group_name=resource_group_name, server_name=server_name) \ No newline at end of file diff --git a/src/plugin/manager/my_sql_servers/__init__.py b/src/plugin/manager/my_sql_servers/__init__.py index ce17838c..a383d3a3 100644 --- a/src/plugin/manager/my_sql_servers/__init__.py +++ b/src/plugin/manager/my_sql_servers/__init__.py @@ -1 +1,2 @@ from .server_manager import MySQLServersManager +from .flexible_server_manager import MySQLFlexibleServersManager diff --git a/src/plugin/manager/my_sql_servers/flexible_server_manager.py b/src/plugin/manager/my_sql_servers/flexible_server_manager.py new file mode 100644 index 00000000..489e0b3a --- /dev/null +++ b/src/plugin/manager/my_sql_servers/flexible_server_manager.py @@ -0,0 +1,138 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.my_sql_servers.mysql_flexible_servers_connector import MySQLFlexibleServersConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class MySQLFlexibleServersManager(AzureBaseManager): + cloud_service_group = "MySQLServers" + cloud_service_type = "FlexibleServer" + service_code = "/Microsoft.DBforMySQL/flexibleServers" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Database"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-mysql-servers.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + mysql_flexible_servers_conn = MySQLFlexibleServersConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + mysql_flexible_servers_obj_list = mysql_flexible_servers_conn.list_flexible_servers() + + for mysql_flexible_server in mysql_flexible_servers_obj_list: + + try: + mysql_flexible_server_dict = self.convert_nested_dictionary(mysql_flexible_server) + mysql_flexible_server_id = mysql_flexible_server_dict["id"] + + mysql_flexible_server_dict.update( + { + "resource_group": self.get_resource_group_from_id( + mysql_flexible_server_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": mysql_flexible_server_id}, + } + ) + + if mysql_flexible_server_dict.get("name") is not None: + resource_group = mysql_flexible_server_dict.get("resource_group", "") + server_name = mysql_flexible_server_dict.get("name") + mysql_flexible_server_dict.update( + { + "firewall_rules": self.get_firewall_rules_by_server( + mysql_flexible_servers_conn, resource_group, server_name + ), + } + ) + + if mysql_flexible_server_dict.get("firewall_rules") is not None: + mysql_flexible_server_dict.update( + { + "allow_azure_services_access": self.get_azure_service_access( + mysql_flexible_server_dict["firewall_rules"] + ) + } + ) + + self.set_region_code(mysql_flexible_server_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=mysql_flexible_server_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=mysql_flexible_server_dict, + account=secret_data["subscription_id"], + instance_type=mysql_flexible_server_dict["sku"]["tier"], + region_code=mysql_flexible_server_dict["location"], + reference=self.make_reference(mysql_flexible_server_dict.get("id")), + tags=mysql_flexible_server_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def get_firewall_rules_by_server( + self, mysql_flexible_servers_conn, resource_group, server_name + ): + firewall_rules = [] + firewall_rule_obj = mysql_flexible_servers_conn.list_firewall_rules_by_server( + resource_group_name=resource_group, server_name=server_name + ) + + for firewall_rule in firewall_rule_obj: + firewall_dict = self.convert_nested_dictionary(firewall_rule) + firewall_rules.append(firewall_dict) + + return firewall_rules + + @staticmethod + def get_azure_service_access(firewall_rules): + firewall_rule_name_list = [] + + for firewall_rule in firewall_rules: + if firewall_rule.get("name") is not None: + firewall_rule_name_list.append(firewall_rule["name"]) + + if "AllowAllWindowsAzureIps" in firewall_rule_name_list: + return True + + return False diff --git a/src/plugin/metadata/disks/disk.yaml b/src/plugin/metadata/disks/disk.yaml index d681ba88..fbc3342c 100644 --- a/src/plugin/metadata/disks/disk.yaml +++ b/src/plugin/metadata/disks/disk.yaml @@ -19,6 +19,8 @@ search: - Time Created: data.time_created data_type: datetime + + table: sort: key: data.id @@ -76,6 +78,8 @@ table: - Time Created: data.time_created is_optional: true + + tabs.0: name: Disks type: item @@ -130,6 +134,8 @@ tabs.0: source_type: iso8601 type: datetime + + tabs.1: name: Configuration items: @@ -146,6 +152,8 @@ tabs.1: source_type: iso8601 type: datetime + + tabs.2: name: Networking type: item diff --git a/src/plugin/metadata/my_sql_servers/flexible_server.yaml b/src/plugin/metadata/my_sql_servers/flexible_server.yaml new file mode 100644 index 00000000..81122cd5 --- /dev/null +++ b/src/plugin/metadata/my_sql_servers/flexible_server.yaml @@ -0,0 +1,249 @@ +search: + fields: + - Type: instance_type + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Server Admin Login Name: data.administrator_login + - MySQL Version: data.version + - Zone: data.availability_zone + - High Availability Mode: data.high_availability.mode + - High Availability State: data.high_availability.state + - Performance Configuration (Tier): instance_type + - Performance Configuration (Name): data.sku.name + - Firewall Rule Name: data.firewall_rules.name + - Firewall Rule Start IP: data.firewall_rules.start_ip_address + - Firewall Rule End IP: data.firewall_rules.end_ip_address + - Allow Access To Azure Services: data.allow_azure_services_access + - Storage: data.storage.storage_size_gb + data_type: integer + - Backup Retention Period: data.backup.backup_retention_days + + + +table: + sort: + key: data.id + desc: false + fields: + - Type: instance_type + - Status: data.state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Starting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopped: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - High Availability Mode: data.high_availability.mode + - High Availability State: data.high_availability.state + is_optional: true + - Resource Group: data.resource_group + - Location: data.location + - Subscription Name: data.subscription_name + - Subscription ID: account + is_optional: true + - Server Admin Login Name: data.administrator_login + is_optional: true + - MySQL Version: data.version + is_optional: true + - Zone: data.availability_zone + is_optional: true + - Performance Configuration (Tier): data.sku.tier + is_optional: true + - Performance Configuration (Name): data.sku.name + is_optional: true + - Firewall Rule Name: data.firewall_rules.name + is_optional: true + - Firewall Rule Start IP: data.firewall_rules.start_ip_address + is_optional: true + - Firewall Rule End IP: data.firewall_rules.end_ip_address + is_optional: true + - Allow Access To Azure Services: data.allow_azure_services_access + is_optional: true + - Storage: data.storage.storage_size_gb + display_unit: GB + source_unit: GB + type: size + is_optional: true + - Backup Retention Period: data.backup.backup_retention_days + is_optional: true + + + +tabs.0: + name: MySQL Server + type: item + fields: + - Name: name + - Server Name: data.fully_qualified_domain_name + - Type: instance_type + - Status: data.user_visible_state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Starting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopped: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - Server Admin Login Name: data.administrator_login + - Performance Configuration (Tier): data.sku.tier + - Performance Configuration (Name): data.sku.name + - Storage: data.storage.storage_size_gb + display_unit: GB + source_unit: GB + type: size + is_optional: true + - MySQL Version: data.version + - Zone: data.availability_zone + + + +tabs.1: + name: Compute & Storage + items: + - name: Compute + type: item + fields: + - Compute Tier: data.sku.tier + - Compute Size: data.sku.name + - name: Storage + type: item + fields: + - Storage Size: data.storage.storage_size_gb + display_unit: GB + source_unit: GB + type: size + - Storage Auto-growth: data.storage.auto_grow + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - name: High Availability + type: item + fields: + - High Availability State: data.high_availability.state + type: enum + enums: + - Healthy: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - CreatingStandby: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - RemovingStandby: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - FailOver: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - NotEnabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - High Availability Mode: data.high_availability.mode + - name: Backup + type: item + fields: + - Backup Retention Period (Days): data.backup.backup_retention_days + - Geo Redundant Backup: data.backup.geo_redundant_backup + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + + + +tabs.2: + name: Networking + items: + - name: Public Network Access + type: items + fields: + - Public Network Access: data.network.public_network_access + type: enum + enums: + - Enabled: indigo.500 + type: badge + - Disabled: coral.600 + type: badge + - name: Firewall Rules + type: table + root_path: data.firewall_rules + fields: + - Firewall rule Name: name + - Start IP: start_ip_address + - End IP: end_ip_address \ No newline at end of file diff --git a/src/plugin/metadata/my_sql_servers/server.yaml b/src/plugin/metadata/my_sql_servers/server.yaml index de539864..a27fc6e3 100644 --- a/src/plugin/metadata/my_sql_servers/server.yaml +++ b/src/plugin/metadata/my_sql_servers/server.yaml @@ -56,6 +56,7 @@ table: - Location: data.location - Subscription Name: data.subscription_name - Subscription ID: account + is_optional: true - Server Admin Login Name: data.administrator_login is_optional: true - MySQL Version: data.version diff --git a/src/plugin/metadata/virtual_machines/instance.yaml b/src/plugin/metadata/virtual_machines/instance.yaml index 300e3459..b97be5fc 100644 --- a/src/plugin/metadata/virtual_machines/instance.yaml +++ b/src/plugin/metadata/virtual_machines/instance.yaml @@ -426,7 +426,7 @@ tabs.3: - Protocol: protocol type: enum enums: - - ALL: primary + - ALL: violet.600 type: badge - TCP: indigo.500 type: badge diff --git a/src/plugin/metrics/MySQLServers/FlexibleServer/namespace.yaml b/src/plugin/metrics/MySQLServers/FlexibleServer/namespace.yaml new file mode 100644 index 00000000..fc075c5b --- /dev/null +++ b/src/plugin/metrics/MySQLServers/FlexibleServer/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-mysql-servers-server +name: MySQLServers/Server +resource_type: inventory.CloudService:azure.MySQLServers.Server +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-mysql-servers.svg +version: '1.0' diff --git a/src/plugin/metrics/MySQLServers/FlexibleServer/server_count.yaml b/src/plugin/metrics/MySQLServers/FlexibleServer/server_count.yaml new file mode 100644 index 00000000..852f3834 --- /dev/null +++ b/src/plugin/metrics/MySQLServers/FlexibleServer/server_count.yaml @@ -0,0 +1,29 @@ +--- +metric_id: metric-azure-mysql-servers-server-count +name: Server Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.MySQLServers.Server +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-mysql-servers-server +version: '1.0' \ No newline at end of file From 3b93ae2317e92d5dd963c281e38d37b38ac6b527 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Wed, 14 Aug 2024 18:13:21 +0900 Subject: [PATCH 30/35] feat: Implement PostgreSQL Servers FlexibleServer type --- src/plugin/connector/base.py | 3 + .../postgresql_flexible_servers_connector.py | 19 ++ .../my_sql_servers/flexible_server_manager.py | 2 +- .../manager/postgre_sql_servers/__init__.py | 1 + .../flexible_server_manager.py | 124 ++++++++++ .../postgre_sql_servers/server_manager.py | 2 +- .../my_sql_servers/flexible_server.yaml | 6 +- .../postgre_sql_servers/flexible_server.yaml | 221 ++++++++++++++++++ .../FlexibleServer/namespace.yaml | 8 + .../FlexibleServer/server_count.yaml | 29 +++ 10 files changed, 410 insertions(+), 5 deletions(-) create mode 100644 src/plugin/connector/postgre_sql_servers/postgresql_flexible_servers_connector.py create mode 100644 src/plugin/manager/postgre_sql_servers/flexible_server_manager.py create mode 100644 src/plugin/metadata/postgre_sql_servers/flexible_server.yaml create mode 100644 src/plugin/metrics/PostgreSQLServers/FlexibleServer/namespace.yaml create mode 100644 src/plugin/metrics/PostgreSQLServers/FlexibleServer/server_count.yaml diff --git a/src/plugin/connector/base.py b/src/plugin/connector/base.py index a6c4feb4..9c859acc 100644 --- a/src/plugin/connector/base.py +++ b/src/plugin/connector/base.py @@ -12,6 +12,7 @@ from azure.mgmt.storage import StorageManagementClient from azure.mgmt.cosmosdb import CosmosDBManagementClient from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient +from azure.mgmt.rdbms.postgresql_flexibleservers import PostgreSQLManagementClient as PostgreSQLFlexibleManagementClient from azure.mgmt.webpubsub import WebPubSubManagementClient from azure.mgmt.keyvault import KeyVaultManagementClient from azure.mgmt.rdbms.mysql import MySQLManagementClient @@ -37,6 +38,7 @@ def __init__(self, *args, **kwargs): self.storage_client = None self.cosmosdb_client = None self.postgre_sql_client = None + self.postgre_sql_flexible_client = None self.web_pubsub_service_client = None self.key_vault_client = None self.mysql_client = None @@ -63,6 +65,7 @@ def set_connect(self, secret_data: dict): self.storage_client = StorageManagementClient(credential=credential, subscription_id=subscription_id) self.cosmosdb_client = CosmosDBManagementClient(credential=credential, subscription_id=subscription_id) self.postgre_sql_client = PostgreSQLManagementClient(credential=credential, subscription_id=subscription_id) + self.postgre_sql_flexible_client = PostgreSQLFlexibleManagementClient(credential=credential, subscription_id=subscription_id) self.web_pubsub_service_client = WebPubSubManagementClient(credential=credential, subscription_id=subscription_id) self.key_vault_client = KeyVaultManagementClient(credential=credential, subscription_id=subscription_id) self.mysql_client = MySQLManagementClient(credential=credential, subscription_id=subscription_id) diff --git a/src/plugin/connector/postgre_sql_servers/postgresql_flexible_servers_connector.py b/src/plugin/connector/postgre_sql_servers/postgresql_flexible_servers_connector.py new file mode 100644 index 00000000..f61d1449 --- /dev/null +++ b/src/plugin/connector/postgre_sql_servers/postgresql_flexible_servers_connector.py @@ -0,0 +1,19 @@ +import logging + +from plugin.connector.base import AzureBaseConnector + +_LOGGER = logging.getLogger("spaceone") + + +class PostgreSQLFlexibleServersConnector(AzureBaseConnector): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.set_connect(kwargs.get("secret_data")) + + def list_flexible_servers(self): + return self.postgre_sql_flexible_client.servers.list() + + def list_firewall_rules_by_server(self, resource_group_name, server_name): + return self.postgre_sql_flexible_client.firewall_rules.list_by_server( + resource_group_name=resource_group_name, server_name=server_name + ) \ No newline at end of file diff --git a/src/plugin/manager/my_sql_servers/flexible_server_manager.py b/src/plugin/manager/my_sql_servers/flexible_server_manager.py index 489e0b3a..ab96db68 100644 --- a/src/plugin/manager/my_sql_servers/flexible_server_manager.py +++ b/src/plugin/manager/my_sql_servers/flexible_server_manager.py @@ -89,7 +89,7 @@ def create_cloud_service(self, options, secret_data, schema): provider=self.provider, data=mysql_flexible_server_dict, account=secret_data["subscription_id"], - instance_type=mysql_flexible_server_dict["sku"]["tier"], + instance_type="Azure DB for MySQL Flexible Server", region_code=mysql_flexible_server_dict["location"], reference=self.make_reference(mysql_flexible_server_dict.get("id")), tags=mysql_flexible_server_dict.get("tags", {}), diff --git a/src/plugin/manager/postgre_sql_servers/__init__.py b/src/plugin/manager/postgre_sql_servers/__init__.py index 19ed5a5d..e693aa6d 100644 --- a/src/plugin/manager/postgre_sql_servers/__init__.py +++ b/src/plugin/manager/postgre_sql_servers/__init__.py @@ -1 +1,2 @@ from .server_manager import PostgreSQLServersManager +from .flexible_server_manager import PostgreSQLFlexibleServersManager diff --git a/src/plugin/manager/postgre_sql_servers/flexible_server_manager.py b/src/plugin/manager/postgre_sql_servers/flexible_server_manager.py new file mode 100644 index 00000000..80b30232 --- /dev/null +++ b/src/plugin/manager/postgre_sql_servers/flexible_server_manager.py @@ -0,0 +1,124 @@ +import logging + +from spaceone.inventory.plugin.collector.lib import * + +from plugin.conf.cloud_service_conf import ICON_URL +from plugin.connector.postgre_sql_servers.postgresql_flexible_servers_connector import PostgreSQLFlexibleServersConnector +from plugin.connector.subscriptions.subscriptions_connector import SubscriptionsConnector +from plugin.manager.base import AzureBaseManager + +_LOGGER = logging.getLogger(__name__) + + +class PostgreSQLFlexibleServersManager(AzureBaseManager): + cloud_service_group = "PostgreSQLServers" + cloud_service_type = "FlexibleServer" + service_code = "/Microsoft.DBforPostgreSQL/flexibleServers" + + def create_cloud_service_type(self): + return make_cloud_service_type( + name=self.cloud_service_type, + group=self.cloud_service_group, + provider=self.provider, + service_code=self.service_code, + metadata_path=self.get_metadata_path(), + is_primary=True, + is_major=True, + labels=["Database"], + tags={ + "spaceone:icon": f"{ICON_URL}/azure-sql-postgresql-server.svg" + } + ) + + def create_cloud_service(self, options, secret_data, schema): + cloud_services = [] + error_responses = [] + + postgre_sql_flexible_servers_conn = PostgreSQLFlexibleServersConnector(secret_data=secret_data) + subscription_conn = SubscriptionsConnector(secret_data=secret_data) + + subscription_obj = subscription_conn.get_subscription(secret_data["subscription_id"]) + subscription_info = self.convert_nested_dictionary(subscription_obj) + + postgre_sql_flexible_servers = postgre_sql_flexible_servers_conn.list_flexible_servers() + + for postgre_sql_flexible_server in postgre_sql_flexible_servers: + + try: + postgre_sql_flexible_server_dict = self.convert_nested_dictionary( + postgre_sql_flexible_server + ) + postgre_sql_flexible_server_id = postgre_sql_flexible_server_dict["id"] + + postgre_sql_flexible_server_dict = self.update_tenant_id_from_secret_data( + postgre_sql_flexible_server_dict, secret_data + ) + + postgre_sql_flexible_server_dict.update( + { + "resource_group": self.get_resource_group_from_id( + postgre_sql_flexible_server_id + ), + "subscription_id": subscription_info["subscription_id"], + "subscription_name": subscription_info["display_name"], + "azure_monitor": {"resource_id": postgre_sql_flexible_server_id}, + } + ) + + if postgre_sql_flexible_server_dict.get("name") is not None: + resource_group = postgre_sql_flexible_server_dict["resource_group"] + server_name = postgre_sql_flexible_server_dict["name"] + postgre_sql_flexible_server_dict.update( + { + "firewall_rules": self.list_firewall_rules_by_server( + postgre_sql_flexible_servers_conn, resource_group, server_name + ), + } + ) + + self.set_region_code(postgre_sql_flexible_server_dict["location"]) + + cloud_services.append( + make_cloud_service( + name=postgre_sql_flexible_server_dict["name"], + cloud_service_type=self.cloud_service_type, + cloud_service_group=self.cloud_service_group, + provider=self.provider, + data=postgre_sql_flexible_server_dict, + account=secret_data["subscription_id"], + instance_type="Azure DB for PostgreSQL Flexible Server", + instance_size=float(postgre_sql_flexible_server_dict["storage"]["storage_size_gb"]), + region_code=postgre_sql_flexible_server_dict["location"], + reference=self.make_reference(postgre_sql_flexible_server_dict.get("id")), + tags=postgre_sql_flexible_server_dict.get("tags", {}), + data_format="dict" + ) + ) + + except Exception as e: + _LOGGER.error(f"[create_cloud_service] Error {self.service} {e}", exc_info=True) + error_responses.append( + make_error_response( + error=e, + provider=self.provider, + cloud_service_group=self.cloud_service_group, + cloud_service_type=self.cloud_service_type, + ) + ) + + return cloud_services, error_responses + + def list_firewall_rules_by_server(self, postgresql_conn, resource_group, name): + firewall_rules = [] + firewall_rules_obj = postgresql_conn.list_firewall_rules_by_server( + resource_group_name=resource_group, server_name=name + ) + + for firewall_rule in firewall_rules_obj: + firewall_rule_dict = self.convert_nested_dictionary(firewall_rule) + firewall_rules.append(firewall_rule_dict) + + return firewall_rules + + + diff --git a/src/plugin/manager/postgre_sql_servers/server_manager.py b/src/plugin/manager/postgre_sql_servers/server_manager.py index 8e887474..c1ca280d 100644 --- a/src/plugin/manager/postgre_sql_servers/server_manager.py +++ b/src/plugin/manager/postgre_sql_servers/server_manager.py @@ -97,7 +97,7 @@ def create_cloud_service(self, options, secret_data, schema): data=postgre_sql_server_dict, account=secret_data["subscription_id"], instance_type=postgre_sql_server_dict["sku"]["tier"], - instance_size=float(postgre_sql_server_dict["max_size_gb"]), + instance_size=float(postgre_sql_server_dict["storage_profile"]["max_size_gb"]), region_code=postgre_sql_server_dict["location"], reference=self.make_reference(postgre_sql_server_dict.get("id")), tags=postgre_sql_server_dict.get("tags", {}), diff --git a/src/plugin/metadata/my_sql_servers/flexible_server.yaml b/src/plugin/metadata/my_sql_servers/flexible_server.yaml index 81122cd5..e8e65d5c 100644 --- a/src/plugin/metadata/my_sql_servers/flexible_server.yaml +++ b/src/plugin/metadata/my_sql_servers/flexible_server.yaml @@ -18,7 +18,7 @@ search: - Allow Access To Azure Services: data.allow_azure_services_access - Storage: data.storage.storage_size_gb data_type: integer - - Backup Retention Period: data.backup.backup_retention_days + - Backup Retention Period (Days): data.backup.backup_retention_days @@ -92,7 +92,7 @@ table: source_unit: GB type: size is_optional: true - - Backup Retention Period: data.backup.backup_retention_days + - Backup Retention Period (Days): data.backup.backup_retention_days is_optional: true @@ -104,7 +104,7 @@ tabs.0: - Name: name - Server Name: data.fully_qualified_domain_name - Type: instance_type - - Status: data.user_visible_state + - Status: data.state type: enum enums: - Ready: diff --git a/src/plugin/metadata/postgre_sql_servers/flexible_server.yaml b/src/plugin/metadata/postgre_sql_servers/flexible_server.yaml new file mode 100644 index 00000000..f5f2927b --- /dev/null +++ b/src/plugin/metadata/postgre_sql_servers/flexible_server.yaml @@ -0,0 +1,221 @@ +search: + fields: + - Subscription ID: account + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group + - Location: data.location + - Server Name: data.fully_qualified_domain_name + - Server Admin Login Name: data.administrator_login + - PostgreSQL Version: data.version + - Zone: data.availability_zone + - High Availability Mode: data.high_availability.mode + - High Availability State: data.high_availability.state + - Performance Configuration (Tier): instance_type + - Performance Configuration (Name): data.sku.name + - Public Network Access: data.network.public_network_access + - Firewall Rule Name: data.firewall_rules.name + - Firewall Rule Start IP: data.firewall_rules.start_ip_address + - Firewall Rule End IP: data.firewall_rules.end_ip_address + - Storage Size: data.storage.storage_size_gb + data_type: integer + - Backup Retention Period (Days): data.backup.backup_retention_days + + + +table: + sort: + key: data.id + desc: false + fields: + - Type: instance_type + - Status: data.state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Starting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopped: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Resource Group: data.resource_group + is_optional: true + - Location: data.location + is_optional: true + - Subscription Name: data.subscription_name + is_optional: true + - Subscription ID: account + is_optional: true + - Server Name: data.fully_qualified_domain_name + is_optional: true + - Server Admin Login Name: data.administrator_login + is_optional: true + - PostgreSQL Version: data.version + is_optional: true + - Zone: data.availability_zone + is_optional: true + - Performance Configuration (Tier): instance_type + is_optional: true + - Performance Configuration (Name): data.sku.name + is_optional: true + - Public Network Access: data.network.public_network_access + is_optional: true + - Firewall Rule Name: data.firewall_rules.name + is_optional: true + - Firewall Rule Start IP: data.firewall_rules.start_ip_address + is_optional: true + - Firewall Rule End IP: data.firewall_rules.end_ip_address + is_optional: true + - Compute Generation: data.sku.name + is_optional: true + - Compute Tier: data.sku.tier + is_optional: true + - Storage Size: data.storage.storage_size_gb + display_unit: GB + source_unit: GB + type: size + is_optional: true + - Backup Retention Period (Days): data.backup.backup_retention_days + is_optional: true + + + +tabs.0: + name: PostgreSQL Servers + type: item + fields: + - Name: name + - Server Name: data.fully_qualified_domain_name + - Type: instance_type + - Status: data.state + type: enum + enums: + - Ready: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Starting: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Updating: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Dropping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopping: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - Stopped: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - Resource Group: data.resource_group + - Location: data.location + - Subscription: data.subscription_name + - Subscription ID: account + - Server Admin Login Name: data.administrator_login + - Performance Configuration (Tier): data.sku.tier + - Performance Configuration (Name): data.sku.name + - Storage Size: data.storage.storage_size_gb + display_unit: GB + source_unit: GB + type: size + is_optional: true + - PostgreSQL Version: data.version + - Zone: data.availability_zone + + + +tabs.1: + name: Compute & Storage + items: + - name: Compute + type: item + fields: + - Compute Tier: data.sku.tier + - Compute Size: data.sku.name + - name: Storage + type: item + fields: + - Storage Size: data.storage.storage_size_gb + display_unit: GB + source_unit: GB + type: size + - name: High Availability + type: item + fields: + - High Availability State: data.high_availability.state + type: enum + enums: + - Healthy: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - CreatingStandby: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - RemovingStandby: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state + - FailOver: + text_color: red.500 + icon_image: ic_circle-filled + icon_color: red.500 + type: state + - NotEnabled: + icon_image: ic_circle-filled + icon_color: gray.400 + text_color: gray.400 + type: state + - High Availability Mode: data.high_availability.mode + - name: Backup + type: item + fields: + - Backup Retention Period (Days): data.backup.backup_retention_days + - Geo Redundant Backup: data.backup.geo_redundant_backup + type: enum + enums: + - Enabled: + icon_image: ic_circle-filled + icon_color: green.500 + type: state + - Disabled: + icon_image: ic_circle-filled + icon_color: yellow.500 + type: state diff --git a/src/plugin/metrics/PostgreSQLServers/FlexibleServer/namespace.yaml b/src/plugin/metrics/PostgreSQLServers/FlexibleServer/namespace.yaml new file mode 100644 index 00000000..cd6ff421 --- /dev/null +++ b/src/plugin/metrics/PostgreSQLServers/FlexibleServer/namespace.yaml @@ -0,0 +1,8 @@ +--- +namespace_id: ns-azure-postgresql-servers-server +name: PostgreSQL/Server +resource_type: inventory.CloudService:azure.PostgreSQLServers.Server +group: azure +category: ASSET +icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/azure/azure-sql-postgresql-server.svg +version: '1.0' diff --git a/src/plugin/metrics/PostgreSQLServers/FlexibleServer/server_count.yaml b/src/plugin/metrics/PostgreSQLServers/FlexibleServer/server_count.yaml new file mode 100644 index 00000000..2b3cee47 --- /dev/null +++ b/src/plugin/metrics/PostgreSQLServers/FlexibleServer/server_count.yaml @@ -0,0 +1,29 @@ +--- +metric_id: metric-azure-postgersql-servers-server-count +name: Server Count +metric_type: GAUGE +resource_type: inventory.CloudService:azure.PostgreSQLServers.Server +query_options: + group_by: + - key: region_code + name: Region + reference: + resource_type: inventory.Region + reference_key: region_code + - key: data.tenant_id + name: Tenant ID + - key: data.subscription_name + name: Subscription Name + - key: account + name: Subscription ID + - key: data.resource_group + name: Resource Group + - key: data.provisioning_state + name: Provisioning State + default: true + fields: + value: + operator: count +unit: Count +namespace_id: ns-azure-postgresql-servers-server +version: '1.0' \ No newline at end of file From d39dfbdbff87668b957e7f887b0a54b8a986af39 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Fri, 16 Aug 2024 11:51:59 +0900 Subject: [PATCH 31/35] feat: Add version_display to PostgreSQL Servers FlexibleServer type --- .../postgre_sql_servers/flexible_server_manager.py | 9 ++++++++- .../metadata/postgre_sql_servers/flexible_server.yaml | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugin/manager/postgre_sql_servers/flexible_server_manager.py b/src/plugin/manager/postgre_sql_servers/flexible_server_manager.py index 80b30232..07e45930 100644 --- a/src/plugin/manager/postgre_sql_servers/flexible_server_manager.py +++ b/src/plugin/manager/postgre_sql_servers/flexible_server_manager.py @@ -62,6 +62,10 @@ def create_cloud_service(self, options, secret_data, schema): "subscription_id": subscription_info["subscription_id"], "subscription_name": subscription_info["display_name"], "azure_monitor": {"resource_id": postgre_sql_flexible_server_id}, + "version_display": self.get_version_display( + postgre_sql_flexible_server_dict.get("version"), + postgre_sql_flexible_server_dict.get("minor_version"), + ) } ) @@ -120,5 +124,8 @@ def list_firewall_rules_by_server(self, postgresql_conn, resource_group, name): return firewall_rules - + @staticmethod + def get_version_display(version, minor_version): + version_display = f"{version}.{minor_version}" + return version_display diff --git a/src/plugin/metadata/postgre_sql_servers/flexible_server.yaml b/src/plugin/metadata/postgre_sql_servers/flexible_server.yaml index f5f2927b..eb474f07 100644 --- a/src/plugin/metadata/postgre_sql_servers/flexible_server.yaml +++ b/src/plugin/metadata/postgre_sql_servers/flexible_server.yaml @@ -6,7 +6,7 @@ search: - Location: data.location - Server Name: data.fully_qualified_domain_name - Server Admin Login Name: data.administrator_login - - PostgreSQL Version: data.version + - PostgreSQL Version: data.version_display - Zone: data.availability_zone - High Availability Mode: data.high_availability.mode - High Availability State: data.high_availability.state @@ -73,7 +73,7 @@ table: is_optional: true - Server Admin Login Name: data.administrator_login is_optional: true - - PostgreSQL Version: data.version + - PostgreSQL Version: data.version_display is_optional: true - Zone: data.availability_zone is_optional: true @@ -155,7 +155,7 @@ tabs.0: source_unit: GB type: size is_optional: true - - PostgreSQL Version: data.version + - PostgreSQL Version: data.version_display - Zone: data.availability_zone From 29d8a41493da26b81b8bce2dca502acb852ed99b Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 22 Aug 2024 16:21:17 +0900 Subject: [PATCH 32/35] fix: Fix Virtual Machines metadata --- .../metadata/virtual_machines/instance.yaml | 206 +++++++++--------- 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/src/plugin/metadata/virtual_machines/instance.yaml b/src/plugin/metadata/virtual_machines/instance.yaml index b97be5fc..92fa93de 100644 --- a/src/plugin/metadata/virtual_machines/instance.yaml +++ b/src/plugin/metadata/virtual_machines/instance.yaml @@ -1,45 +1,45 @@ search: fields: - Subscription ID: account - - Subscription Name: data.subscription.subscription_name - - Resource Group: data.resource_group.resource_group_name - - IP Address: ip_addresses - - Instance ID: data.compute.instance_id - - Instance State: data.compute.instance_state - - Instance Type: data.compute.instance_type - - Key Pair: data.compute.keypair - - Image: data.compute.image - - Availability Zone: data.compute.az - - OS Type: data.os.os_type - - OS Architecture: data.os.os_arch - - MAC Address: data.nics.mac_address - - Public IP Address: data.nics.public_ip_address - - Public DNS: data.nics.tags.public_dns - - VNet ID: data.vnet.vnet_id - - VNet Name: data.vnet.vnet_name - - Subnet ID: data.subnet.subnet_id - - Subnet Name: data.subnet.subnet_name - - ELB Name: data.load_balancer.name - - ELB DNS: data.load_balancer.endpoint - - Auto Scaling Group: data.auto_scaling_group.name - - Core: data.hardware.core + - Subscription Name: data.data.subscription_name + - Resource Group: data.data.resource_group.resource_group_name + - IP Address: data.ip_addresses + - Instance ID: data.data.compute.instance_id + - Instance State: data.data.compute.instance_state + - Instance Type: data.data.compute.instance_type + - Key Pair: data.data.compute.keypair + - Image: data.data.compute.image + - Availability Zone: data.data.compute.az + - OS Type: data.data.os.os_type + - OS Architecture: data.data.os.os_arch + - MAC Address: data.data.nics.mac_address + - Public IP Address: data.data.nics.public_ip_address + - Public DNS: data.data.nics.tags.public_dns + - VNet ID: data.data.vnet.vnet_id + - VNet Name: data.data.vnet.vnet_name + - Subnet ID: data.data.subnet.subnet_id + - Subnet Name: data.data.subnet.subnet_name + - ELB Name: data.data.load_balancer.name + - ELB DNS: data.data.load_balancer.endpoint + - Auto Scaling Group: data.data.auto_scaling_group.name + - Core: data.data.hardware.core data_type: integer - - Memory: data.hardware.memory + - Memory: data.data.hardware.memory data_type: float - Management State: state - Cloud Service Group: cloud_service_group - Cloud Service Type: cloud_service_type - Service Account: collection_info.service_accounts - - Launched: data.launched_at + - Launched: data.data.compute.launched_at table: sort: - key: data.id + key: data.activity_log.resource_uri desc: false fields: - - Instance State: data.compute.instance_state + - Instance State: data.data.compute.instance_state type: enum enums: - RUNNING: @@ -104,142 +104,142 @@ table: type: state - Cloud Service ID: cloud_service_id is_optional: true - - Instance Type: data.compute.instance_type - - Core: data.hardware.core - - Memory: data.hardware.memory - - Instance ID: data.compute.instance_id + - Instance Type: data.data.compute.instance_type + - Core: data.data.hardware.core + - Memory: data.data.hardware.memory + - Instance ID: data.data.compute.instance_id is_optional: true - - Key Pair: data.compute.keypair + - Key Pair: data.data.compute.keypair is_optional: true - - Image: data.compute.image + - Image: data.data.compute.image is_optional: true - - Availability Zone: data.compute.az - - OS Type: data.os.os_type + - Availability Zone: data.data.compute.az + - OS Type: data.data.os.os_type is_optional: true - - OS: data.os.os_distro - - OS Architecture: data.os.os_arch + - OS: data.data.os.os_distro + - OS Architecture: data.data.os.os_arch is_optional: true - - Primary IP: data.primary_ip_address - - Public DNS: data.nics + - Primary IP: data.data.primary_ip_address + - Public DNS: data.data.nics type: list options: sub_key: tags.public_dns is_optional: true - - Public IP: data.nics + - Public IP: data.data.nics type: list options: sub_key: public_ip_address is_optional: true - - All IP: ip_addresses + - All IP: data.ip_addresses is_optional: true - - MAC Address: data.nics.mac_address + - MAC Address: data.data.nics.mac_address is_optional: true - - CIDR: data.vnet.cidr + - CIDR: data.data.vnet.cidr is_optional: true - - VNet ID: data.vnet.vnet_id + - VNet ID: data.data.vnet.vnet_id is_optional: true - - VNet Name: data.vnet.vnet_name + - VNet Name: data.data.vnet.vnet_name is_optional: true - - Subnet ID: data.subnet.subnet_id + - Subnet ID: data.data.subnet.subnet_id is_optional: true - - Subnet Name: data.subnet.subnet_name + - Subnet Name: data.data.subnet.subnet_name is_optional: true - - Load Balancer Name: data.load_balancer.name + - Load Balancer Name: data.data.load_balancer.name is_optional: true - - Load Balancer DNS: data.load_balancer.endpoint + - Load Balancer DNS: data.data.load_balancer.endpoint is_optional: true - - Ultra SSD Enabled: data.azure.ultra_ssd_enabled + - Ultra SSD Enabled: data.data.azure.ultra_ssd_enabled is_optional: true - - Write Accelerator Enabled: data.azure.write_accelerator_enabled + - Write Accelerator Enabled: data.data.azure.write_accelerator_enabled is_optional: true - - Boot Diagnostics: data.azure.boot_diagnostics + - Boot Diagnostics: data.data.azure.boot_diagnostics is_optional: true - - Priority: data.azure.priority + - Priority: data.data.azure.priority is_optional: true - - Auto Scaling Group: data.auto_scaling_group.name + - Auto Scaling Group: data.data.auto_scaling_group.name is_optional: true - - CPU Utilization: data.monitoring.cpu.utilization.avg + - CPU Utilization: data.data.monitoring.cpu.utilization.avg default: 0 is_optional: true field_description: (Daily Average) - - Memory Usage: data.monitoring.memory.usage.avg + - Memory Usage: data.data.monitoring.memory.usage.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Read IOPS: data.monitoring.disk.read_iops.avg + - Disk Read IOPS: data.data.monitoring.disk.read_iops.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Write IOPS: data.monitoring.disk.write_iops.avg + - Disk Write IOPS: data.data.monitoring.disk.write_iops.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Read Throughput: data.monitoring.disk.read_throughput.avg + - Disk Read Throughput: data.data.monitoring.disk.read_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Write Throughput: data.monitoring.disk.write_throughput.avg + - Disk Write Throughput: data.data.monitoring.disk.write_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Received PPS: data.monitoring.network.received_pps.avg + - Network Received PPS: data.data.monitoring.network.received_pps.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Send PPS: data.monitoring.network.sent_pps.avg + - Network Send PPS: data.data.monitoring.network.sent_pps.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Received Throughput: data.monitoring.network.received_throughput.avg + - Network Received Throughput: data.data.monitoring.network.received_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Sent Throughput: data.monitoring.network.sent_throughput.avg + - Network Sent Throughput: data.data.monitoring.network.sent_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - CPU Utilization: data.monitoring.cpu.utilization.max + - CPU Utilization: data.data.monitoring.cpu.utilization.max default: 0 is_optional: true field_description: (Daily Max) - - Memory Usage: data.monitoring.memory.usage.max + - Memory Usage: data.data.monitoring.memory.usage.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Read IOPS: data.monitoring.disk.read_iops.max + - Disk Read IOPS: data.data.monitoring.disk.read_iops.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Write IOPS: data.monitoring.disk.write_iops.max + - Disk Write IOPS: data.data.monitoring.disk.write_iops.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Read Throughput: data.monitoring.disk.read_throughput.max + - Disk Read Throughput: data.data.monitoring.disk.read_throughput.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Write Throughput: data.monitoring.disk.write_throughput.max + - Disk Write Throughput: data.data.monitoring.disk.write_throughput.max default: 0 is_optional: true field_description: (Daily Max) - - Network Received PPS: data.monitoring.network.received_pps.max + - Network Received PPS: data.data.monitoring.network.received_pps.max default: 0 is_optional: true field_description: (Daily Max) - - Network Send PPS: data.monitoring.network.sent_pps.max + - Network Send PPS: data.data.monitoring.network.sent_pps.max default: 0 is_optional: true field_description: (Daily Max) - - Network Received Throughput: data.monitoring.network.received_throughput.max + - Network Received Throughput: data.data.monitoring.network.received_throughput.max default: 0 is_optional: true field_description: (Daily Max) - - Network Sent Throughput: data.monitoring.network.sent_throughput.max + - Network Sent Throughput: data.data.monitoring.network.sent_throughput.max default: 0 is_optional: true field_description: (Daily Max) - Subscription ID: account - - Launched: launched_at + - Launched: data.data.compute.launched_at is_optional: true @@ -250,9 +250,9 @@ tabs.0: - name: Virtual Machine type: item fields: - - Resource ID: data.compute.instance_id - - VM ID: data.compute.tags.vm_id - - VM State: data.compute.instance_state + - Resource ID: data.data.compute.instance_id + - VM ID: data.data.compute.tags.vm_id + - VM State: data.data.compute.instance_state type: enum enums: - RUNNING: @@ -285,9 +285,9 @@ tabs.0: icon_color: gray.400 text_color: gray.400 type: state - - Instance Type: data.compute.instance_type - - Image: data.compute.image - - Azure Priority: data.azure.priority + - Instance Type: data.data.compute.instance_type + - Image: data.data.compute.image + - Azure Priority: data.data.azure.priority type: enum enums: - Regular: indigo.500 @@ -297,66 +297,66 @@ tabs.0: - Spot: peacock.600 type: badge - Region: region_code - - Availability Zone: data.compute.az - - Key Pair: data.compute.keypair - - Ultra SSD Enabled: data.azure.ultra_ssd_enabled + - Availability Zone: data.data.compute.az + - Key Pair: data.data.compute.keypair + - Ultra SSD Enabled: data.data.azure.ultra_ssd_enabled type: enum enums: - 'true': indigo.500 type: badge - 'false': coral.600 type: badge - - Write Accelerator Enabled: data.azure.write_accelerator_enabled + - Write Accelerator Enabled: data.data.azure.write_accelerator_enabled type: enum enums: - 'true': indigo.500 type: badge - 'false': coral.600 type: badge - - Boot Diagnostics: data.azure.boot_diagnostics + - Boot Diagnostics: data.data.azure.boot_diagnostics type: enum enums: - 'true': indigo.500 type: badge - 'false': coral.600 type: badge - - Public IP: data.nics + - Public IP: data.data.nics type: list options: sub_key: public_ip_address delimiter: '
' - - Security Groups: data.compute.security_groups + - Security Groups: data.data.compute.security_groups type: list options: sub_key: display delimiter: '
' - - Launched At: data.compute.launched_at + - Launched At: data.data.compute.launched_at - name: Virtual Network type: item fields: - - VNet ID: data.vnet.vnet_id - - VNet Name: data.vnet.vnet_name - - Subnet ID: data.subnet.subnet_id - - Subnet Name: data.subnet.subnet_name + - VNet ID: data.data.vnet.vnet_id + - VNet Name: data.data.vnet.vnet_name + - Subnet ID: data.data.subnet.subnet_id + - Subnet Name: data.data.subnet.subnet_name - name: Operating System type: item fields: - - OS Type: data.os.os_type + - OS Type: data.data.os.os_type translation_id: PAGE_SCHEMA.OS_TYPE - - OS Distribution: data.os.os_distro + - OS Distribution: data.data.os.os_distro translation_id: PAGE_SCHEMA.OS_DISTRO - - OS Architecture: data.os.os_arch + - OS Architecture: data.data.os.os_arch translation_id: PAGE_SCHEMA.OS_ARCH - - OS Version Details: data.os.details + - OS Version Details: data.data.os.details translation_id: PAGE_SCHEMA.OS_DETAILS - - OS License: data.os.os_license + - OS License: data.data.os.os_license translation_id: PAGE_SCHEMA.OS_LICENSE - name: Hardware type: item fields: - - Core: data.hardware.core + - Core: data.data.hardware.core translation_id: PAGE_SCHEMA.CPU_CORE - - Memory: data.hardware.memory + - Memory: data.data.hardware.memory translation_id: PAGE_SCHEMA.MEMORY @@ -364,7 +364,7 @@ tabs.0: tabs.1: name: Disk type: table - root_path: data.disks + root_path: data.data.disks fields: - Index: device_index - Name: tags.disk_name @@ -381,7 +381,7 @@ tabs.1: tabs.2: name: NIC type: table - root_path: data.nics + root_path: data.data.nics fields: - Index: device_index - Name: tags.name @@ -413,7 +413,7 @@ tabs.2: tabs.3: name: Network Security Groups type: table - root_path: data.security_group + root_path: data.data.security_group fields: - Direction: direction type: enum @@ -451,7 +451,7 @@ tabs.3: tabs.4: name: Load Balancer type: table - root_path: data.load_balancer + root_path: data.data.load_balancer fields: - Name: name - Endpoint: endpoint From ce889c0325ace89122d40b6f1b243df1f646072f Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 22 Aug 2024 18:55:26 +0900 Subject: [PATCH 33/35] build: modify dockerfile python package build step --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 85bb345c..04ab1239 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ ENV SRC_DIR /tmp/src COPY pkg/*.txt ${PKG_DIR}/ RUN pip install --upgrade pip && \ pip install --upgrade -r ${PKG_DIR}/pip_requirements.txt && \ - pip install --upgrade spaceone-api spaceone-inventory==2.0.dev216 + pip install --upgrade spaceone-api spaceone-inventory COPY src ${SRC_DIR} From 6ccf14670366fd929842a9be7741f2448cdb4ff8 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 22 Aug 2024 18:56:12 +0900 Subject: [PATCH 34/35] fix: fix virtual machines metadata --- .../metadata/virtual_machines/instance.yaml | 204 +++++++++--------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/src/plugin/metadata/virtual_machines/instance.yaml b/src/plugin/metadata/virtual_machines/instance.yaml index 92fa93de..30d0e6b4 100644 --- a/src/plugin/metadata/virtual_machines/instance.yaml +++ b/src/plugin/metadata/virtual_machines/instance.yaml @@ -1,36 +1,36 @@ search: fields: - Subscription ID: account - - Subscription Name: data.data.subscription_name - - Resource Group: data.data.resource_group.resource_group_name + - Subscription Name: data.subscription_name + - Resource Group: data.resource_group.resource_group_name - IP Address: data.ip_addresses - - Instance ID: data.data.compute.instance_id - - Instance State: data.data.compute.instance_state - - Instance Type: data.data.compute.instance_type - - Key Pair: data.data.compute.keypair - - Image: data.data.compute.image - - Availability Zone: data.data.compute.az - - OS Type: data.data.os.os_type - - OS Architecture: data.data.os.os_arch - - MAC Address: data.data.nics.mac_address - - Public IP Address: data.data.nics.public_ip_address - - Public DNS: data.data.nics.tags.public_dns - - VNet ID: data.data.vnet.vnet_id - - VNet Name: data.data.vnet.vnet_name - - Subnet ID: data.data.subnet.subnet_id - - Subnet Name: data.data.subnet.subnet_name - - ELB Name: data.data.load_balancer.name - - ELB DNS: data.data.load_balancer.endpoint - - Auto Scaling Group: data.data.auto_scaling_group.name - - Core: data.data.hardware.core + - Instance ID: data.compute.instance_id + - Instance State: data.compute.instance_state + - Instance Type: data.compute.instance_type + - Key Pair: data.compute.keypair + - Image: data.compute.image + - Availability Zone: data.compute.az + - OS Type: data.os.os_type + - OS Architecture: data.os.os_arch + - MAC Address: data.nics.mac_address + - Public IP Address: data.nics.public_ip_address + - Public DNS: data.nics.tags.public_dns + - VNet ID: data.vnet.vnet_id + - VNet Name: data.vnet.vnet_name + - Subnet ID: data.subnet.subnet_id + - Subnet Name: data.subnet.subnet_name + - ELB Name: data.load_balancer.name + - ELB DNS: data.load_balancer.endpoint + - Auto Scaling Group: data.auto_scaling_group.name + - Core: data.hardware.core data_type: integer - - Memory: data.data.hardware.memory + - Memory: data.hardware.memory data_type: float - Management State: state - Cloud Service Group: cloud_service_group - Cloud Service Type: cloud_service_type - Service Account: collection_info.service_accounts - - Launched: data.data.compute.launched_at + - Launched: data.launched_at @@ -39,7 +39,7 @@ table: key: data.activity_log.resource_uri desc: false fields: - - Instance State: data.data.compute.instance_state + - Instance State: data.compute.instance_state type: enum enums: - RUNNING: @@ -104,142 +104,142 @@ table: type: state - Cloud Service ID: cloud_service_id is_optional: true - - Instance Type: data.data.compute.instance_type - - Core: data.data.hardware.core - - Memory: data.data.hardware.memory - - Instance ID: data.data.compute.instance_id + - Instance Type: data.compute.instance_type + - Core: data.hardware.core + - Memory: data.hardware.memory + - Instance ID: data.compute.instance_id is_optional: true - - Key Pair: data.data.compute.keypair + - Key Pair: data.compute.keypair is_optional: true - - Image: data.data.compute.image + - Image: data.compute.image is_optional: true - - Availability Zone: data.data.compute.az - - OS Type: data.data.os.os_type + - Availability Zone: data.compute.az + - OS Type: data.os.os_type is_optional: true - - OS: data.data.os.os_distro - - OS Architecture: data.data.os.os_arch + - OS: data.os.os_distro + - OS Architecture: data.os.os_arch is_optional: true - - Primary IP: data.data.primary_ip_address - - Public DNS: data.data.nics + - Primary IP: data.primary_ip_address + - Public DNS: data.nics type: list options: - sub_key: tags.public_dns + sub_key: tags.name is_optional: true - - Public IP: data.data.nics + - Public IP: data.nics type: list options: sub_key: public_ip_address is_optional: true - - All IP: data.ip_addresses + - All IP: ip_addresses is_optional: true - - MAC Address: data.data.nics.mac_address + - MAC Address: data.nics.mac_address is_optional: true - - CIDR: data.data.vnet.cidr + - CIDR: data.vnet.cidr is_optional: true - - VNet ID: data.data.vnet.vnet_id + - VNet ID: data.vnet.vnet_id is_optional: true - - VNet Name: data.data.vnet.vnet_name + - VNet Name: data.vnet.vnet_name is_optional: true - - Subnet ID: data.data.subnet.subnet_id + - Subnet ID: data.subnet.subnet_id is_optional: true - - Subnet Name: data.data.subnet.subnet_name + - Subnet Name: data.subnet.subnet_name is_optional: true - - Load Balancer Name: data.data.load_balancer.name + - Load Balancer Name: data.load_balancer.name is_optional: true - - Load Balancer DNS: data.data.load_balancer.endpoint + - Load Balancer DNS: data.load_balancer.endpoint is_optional: true - - Ultra SSD Enabled: data.data.azure.ultra_ssd_enabled + - Ultra SSD Enabled: data.azure.ultra_ssd_enabled is_optional: true - - Write Accelerator Enabled: data.data.azure.write_accelerator_enabled + - Write Accelerator Enabled: data.azure.write_accelerator_enabled is_optional: true - - Boot Diagnostics: data.data.azure.boot_diagnostics + - Boot Diagnostics: data.azure.boot_diagnostics is_optional: true - - Priority: data.data.azure.priority + - Priority: data.azure.priority is_optional: true - - Auto Scaling Group: data.data.auto_scaling_group.name + - Auto Scaling Group: data.auto_scaling_group.name is_optional: true - - CPU Utilization: data.data.monitoring.cpu.utilization.avg + - CPU Utilization: data.monitoring.cpu.utilization.avg default: 0 is_optional: true field_description: (Daily Average) - - Memory Usage: data.data.monitoring.memory.usage.avg + - Memory Usage: data.monitoring.memory.usage.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Read IOPS: data.data.monitoring.disk.read_iops.avg + - Disk Read IOPS: data.monitoring.disk.read_iops.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Write IOPS: data.data.monitoring.disk.write_iops.avg + - Disk Write IOPS: data.monitoring.disk.write_iops.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Read Throughput: data.data.monitoring.disk.read_throughput.avg + - Disk Read Throughput: data.monitoring.disk.read_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - Disk Write Throughput: data.data.monitoring.disk.write_throughput.avg + - Disk Write Throughput: data.monitoring.disk.write_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Received PPS: data.data.monitoring.network.received_pps.avg + - Network Received PPS: data.monitoring.network.received_pps.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Send PPS: data.data.monitoring.network.sent_pps.avg + - Network Send PPS: data.monitoring.network.sent_pps.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Received Throughput: data.data.monitoring.network.received_throughput.avg + - Network Received Throughput: data.monitoring.network.received_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - Network Sent Throughput: data.data.monitoring.network.sent_throughput.avg + - Network Sent Throughput: data.monitoring.network.sent_throughput.avg default: 0 is_optional: true field_description: (Daily Average) - - CPU Utilization: data.data.monitoring.cpu.utilization.max + - CPU Utilization: data.monitoring.cpu.utilization.max default: 0 is_optional: true field_description: (Daily Max) - - Memory Usage: data.data.monitoring.memory.usage.max + - Memory Usage: data.monitoring.memory.usage.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Read IOPS: data.data.monitoring.disk.read_iops.max + - Disk Read IOPS: data.monitoring.disk.read_iops.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Write IOPS: data.data.monitoring.disk.write_iops.max + - Disk Write IOPS: data.monitoring.disk.write_iops.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Read Throughput: data.data.monitoring.disk.read_throughput.max + - Disk Read Throughput: data.monitoring.disk.read_throughput.max default: 0 is_optional: true field_description: (Daily Max) - - Disk Write Throughput: data.data.monitoring.disk.write_throughput.max + - Disk Write Throughput: data.monitoring.disk.write_throughput.max default: 0 is_optional: true field_description: (Daily Max) - - Network Received PPS: data.data.monitoring.network.received_pps.max + - Network Received PPS: data.monitoring.network.received_pps.max default: 0 is_optional: true field_description: (Daily Max) - - Network Send PPS: data.data.monitoring.network.sent_pps.max + - Network Send PPS: data.monitoring.network.sent_pps.max default: 0 is_optional: true field_description: (Daily Max) - - Network Received Throughput: data.data.monitoring.network.received_throughput.max + - Network Received Throughput: data.monitoring.network.received_throughput.max default: 0 is_optional: true field_description: (Daily Max) - - Network Sent Throughput: data.data.monitoring.network.sent_throughput.max + - Network Sent Throughput: data.monitoring.network.sent_throughput.max default: 0 is_optional: true field_description: (Daily Max) - Subscription ID: account - - Launched: data.data.compute.launched_at + - Launched: launched_at is_optional: true @@ -250,9 +250,9 @@ tabs.0: - name: Virtual Machine type: item fields: - - Resource ID: data.data.compute.instance_id - - VM ID: data.data.compute.tags.vm_id - - VM State: data.data.compute.instance_state + - Resource ID: data.compute.instance_id + - VM ID: data.compute.tags.vm_id + - VM State: data.compute.instance_state type: enum enums: - RUNNING: @@ -285,9 +285,9 @@ tabs.0: icon_color: gray.400 text_color: gray.400 type: state - - Instance Type: data.data.compute.instance_type - - Image: data.data.compute.image - - Azure Priority: data.data.azure.priority + - Instance Type: data.compute.instance_type + - Image: data.compute.image + - Azure Priority: data.azure.priority type: enum enums: - Regular: indigo.500 @@ -297,66 +297,66 @@ tabs.0: - Spot: peacock.600 type: badge - Region: region_code - - Availability Zone: data.data.compute.az - - Key Pair: data.data.compute.keypair - - Ultra SSD Enabled: data.data.azure.ultra_ssd_enabled + - Availability Zone: data.compute.az + - Key Pair: data.compute.keypair + - Ultra SSD Enabled: data.azure.ultra_ssd_enabled type: enum enums: - 'true': indigo.500 type: badge - 'false': coral.600 type: badge - - Write Accelerator Enabled: data.data.azure.write_accelerator_enabled + - Write Accelerator Enabled: data.azure.write_accelerator_enabled type: enum enums: - 'true': indigo.500 type: badge - 'false': coral.600 type: badge - - Boot Diagnostics: data.data.azure.boot_diagnostics + - Boot Diagnostics: data.azure.boot_diagnostics type: enum enums: - 'true': indigo.500 type: badge - 'false': coral.600 type: badge - - Public IP: data.data.nics + - Public IP: data.nics type: list options: sub_key: public_ip_address delimiter: '
' - - Security Groups: data.data.compute.security_groups + - Security Groups: data.compute.security_groups type: list options: sub_key: display delimiter: '
' - - Launched At: data.data.compute.launched_at + - Launched At: data.compute.launched_at - name: Virtual Network type: item fields: - - VNet ID: data.data.vnet.vnet_id - - VNet Name: data.data.vnet.vnet_name - - Subnet ID: data.data.subnet.subnet_id - - Subnet Name: data.data.subnet.subnet_name + - VNet ID: data.vnet.vnet_id + - VNet Name: data.vnet.vnet_name + - Subnet ID: data.subnet.subnet_id + - Subnet Name: data.subnet.subnet_name - name: Operating System type: item fields: - - OS Type: data.data.os.os_type + - OS Type: data.os.os_type translation_id: PAGE_SCHEMA.OS_TYPE - - OS Distribution: data.data.os.os_distro + - OS Distribution: data.os.os_distro translation_id: PAGE_SCHEMA.OS_DISTRO - - OS Architecture: data.data.os.os_arch + - OS Architecture: data.os.os_arch translation_id: PAGE_SCHEMA.OS_ARCH - - OS Version Details: data.data.os.details + - OS Version Details: data.os.details translation_id: PAGE_SCHEMA.OS_DETAILS - - OS License: data.data.os.os_license + - OS License: data.os.os_license translation_id: PAGE_SCHEMA.OS_LICENSE - name: Hardware type: item fields: - - Core: data.data.hardware.core + - Core: data.hardware.core translation_id: PAGE_SCHEMA.CPU_CORE - - Memory: data.data.hardware.memory + - Memory: data.hardware.memory translation_id: PAGE_SCHEMA.MEMORY @@ -364,7 +364,7 @@ tabs.0: tabs.1: name: Disk type: table - root_path: data.data.disks + root_path: data.disks fields: - Index: device_index - Name: tags.disk_name @@ -381,7 +381,7 @@ tabs.1: tabs.2: name: NIC type: table - root_path: data.data.nics + root_path: data.nics fields: - Index: device_index - Name: tags.name @@ -413,7 +413,7 @@ tabs.2: tabs.3: name: Network Security Groups type: table - root_path: data.data.security_group + root_path: data.security_group fields: - Direction: direction type: enum @@ -451,7 +451,7 @@ tabs.3: tabs.4: name: Load Balancer type: table - root_path: data.data.load_balancer + root_path: data.load_balancer fields: - Name: name - Endpoint: endpoint From c0443cdc792482cba75cf8a1829574775ed8a66e Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 22 Aug 2024 18:57:03 +0900 Subject: [PATCH 35/35] fix: fix virtual machines response data --- src/plugin/manager/virtual_machines/instance_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugin/manager/virtual_machines/instance_manager.py b/src/plugin/manager/virtual_machines/instance_manager.py index 3e243b0f..ba648f8a 100644 --- a/src/plugin/manager/virtual_machines/instance_manager.py +++ b/src/plugin/manager/virtual_machines/instance_manager.py @@ -159,15 +159,16 @@ def create_cloud_service(self, options, secret_data, schema): cloud_service_type=self.cloud_service_type, cloud_service_group=self.cloud_service_group, provider=self.provider, - data=vm_resource, + data=vm_resource["data"], account=subscription_data["subscription_id"], instance_type=vm_resource["data"]["compute"]["instance_type"], + ip_addresses=vm_resource["ip_addresses"], region_code=vm_resource["region_code"], reference=self.make_reference( vm_resource["data"]["compute"]["instance_id"], f"https://portal.azure.com/#@.onmicrosoft.com/resource/subscriptions/{subscription_data['subscription_id']}/resourceGroups/{resource_group_name}/providers/Microsoft.Compute/virtualMachines/{vm_resource['data']['compute']['instance_name']}/overview" ), - tags=vm.tags, + tags=vm_resource["tags"], data_format="dict" ) )