From b059209105927d881264a111a4921e7aa5da93f1 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 27 Nov 2023 15:30:49 +0400 Subject: [PATCH] fix: Added EdgeType args to c_in_graph method --- .../azure/resoto_plugin_azure/collector.py | 1 - .../resoto_plugin_azure/resource/compute.py | 39 +++++--- .../resoto_plugin_azure/resource/network.py | 97 +++++++++++-------- 3 files changed, 77 insertions(+), 60 deletions(-) diff --git a/plugins/azure/resoto_plugin_azure/collector.py b/plugins/azure/resoto_plugin_azure/collector.py index c4502f611c..8806143e9a 100644 --- a/plugins/azure/resoto_plugin_azure/collector.py +++ b/plugins/azure/resoto_plugin_azure/collector.py @@ -65,7 +65,6 @@ def collect(self) -> None: # collect all regional resources for location in locations: self.collect_resource_list(location.safe_name, builder.with_location(location), regional_resources) - # wait for all work to finish queue.wait_for_submitted_work() # connect nodes diff --git a/plugins/azure/resoto_plugin_azure/resource/compute.py b/plugins/azure/resoto_plugin_azure/resource/compute.py index af02e6648f..fbdffb7130 100644 --- a/plugins/azure/resoto_plugin_azure/resource/compute.py +++ b/plugins/azure/resoto_plugin_azure/resource/compute.py @@ -31,6 +31,7 @@ BaseAutoScalingGroup, InstanceStatus, ModelReference, + EdgeType, ) @@ -89,10 +90,12 @@ class AzureAvailabilitySet(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if placement_group_id := self.proximity_placement_group: - builder.add_edge(self, clazz=AzureProximityPlacementGroup, id=placement_group_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureProximityPlacementGroup, id=placement_group_id + ) if virtual_machines := self.virtual_machines_availability: for vm_id in virtual_machines: - builder.add_edge(self, clazz=AzureVirtualMachine, id=vm_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachine, id=vm_id) @define(eq=False, slots=False) @@ -140,7 +143,7 @@ class AzureCapacityReservationGroup(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if virtual_machines := self.virtual_machines_associated: for vm_id in virtual_machines: - builder.add_edge(self, clazz=AzureVirtualMachine, id=vm_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachine, id=vm_id) @define(eq=False, slots=False) @@ -717,9 +720,9 @@ class AzureDisk(AzureResource, BaseVolume): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if disk_id := self.id: - builder.add_edge(self, clazz=AzureDiskAccess, id=disk_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDiskAccess, id=disk_id) if (disk_encryption := self.disk_encryption) and (disk_en_set_id := disk_encryption.disk_encryption_set_id): - builder.add_edge(self, clazz=AzureDiskEncryptionSet, id=disk_en_set_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDiskEncryptionSet, id=disk_en_set_id) @define(eq=False, slots=False) @@ -1099,7 +1102,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vmsss := self.virtual_machine_scale_sets: for vmss in vmsss: if vmss_id := vmss.id: - builder.add_edge(self, clazz=AzureVirtualMachineScaleSet, id=vmss_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachineScaleSet, id=vmss_id) @define(eq=False, slots=False) @@ -1752,7 +1755,7 @@ class AzureRestorePointCollection(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if (source_id := self.source) and (vm_id := source_id.id): - builder.add_edge(self, clazz=AzureVirtualMachine, id=vm_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachine, id=vm_id) @define(eq=False, slots=False) @@ -1855,7 +1858,7 @@ class AzureSnapshot(AzureResource, BaseSnapshot): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if (disk_data := self.creation_data) and (disk_id := disk_data.source_resource_id): - builder.add_edge(self, clazz=AzureDisk, id=disk_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDisk, id=disk_id) @define(eq=False, slots=False) @@ -2608,14 +2611,16 @@ class AzureVirtualMachine(AzureResource, BaseInstance): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if placement_group_id := self.proximity_placement_group: - builder.add_edge(self, clazz=AzureProximityPlacementGroup, id=placement_group_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureProximityPlacementGroup, id=placement_group_id + ) if ( (sp := self.virtual_machine_storage_profile) and (image_ref := sp.image_reference) and (image_reference_id := image_ref.id) ): - builder.add_edge(self, clazz=AzureImage, id=image_reference_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureImage, id=image_reference_id) if ( (sp := self.virtual_machine_storage_profile) @@ -2623,27 +2628,27 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: and (managed := disk.managed_disk) and (managed_disk_id := managed.id) ): - builder.add_edge(self, clazz=AzureDisk, id=managed_disk_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDisk, id=managed_disk_id) if (vm_network_profile := self.virtual_machine_network_profile) and ( ni_cofigurations := vm_network_profile.network_interface_configurations ): for ni_configuration in ni_cofigurations: if nsg_id := ni_configuration.network_security_group: - builder.add_edge(self, clazz=AzureNetworkSecurityGroup, id=nsg_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkSecurityGroup, id=nsg_id) if ip_configurations := ni_configuration.ip_configurations: for ip_configuration in ip_configurations: if subnet_id := ip_configuration.subnet: - builder.add_edge(self, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id) if lbbap_id := ip_configuration.load_balancer_backend_address_pools: - builder.add_edge(self, clazz=AzureLoadBalancer, id=lbbap_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureLoadBalancer, id=lbbap_id) if (vm_network_profile := self.virtual_machine_network_profile) and ( network_interfaces := vm_network_profile.network_interfaces ): for network_interface in network_interfaces: if ni_id := network_interface.id: - builder.add_edge(self, clazz=AzureNetworkInterface, id=ni_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkInterface, id=ni_id) @define(eq=False, slots=False) @@ -3167,7 +3172,9 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if baps := ip_config.load_balancer_backend_address_pools: for bap in baps: if bap_id := bap: - builder.add_edge(self, clazz=AzureLoadBalancer, id=bap_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureLoadBalancer, id=bap_id + ) @define(eq=False, slots=False) diff --git a/plugins/azure/resoto_plugin_azure/resource/network.py b/plugins/azure/resoto_plugin_azure/resource/network.py index 23f9602ca5..a02713f98f 100644 --- a/plugins/azure/resoto_plugin_azure/resource/network.py +++ b/plugins/azure/resoto_plugin_azure/resource/network.py @@ -20,6 +20,7 @@ BaseNetwork, BasePeeringConnection, ModelReference, + EdgeType, ) from resotolib.json_bender import Bender, S, Bend, ForallBend, K, AsInt, StringToUnitNumber from resotolib.types import Json @@ -1113,17 +1114,19 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_conf in ip_confs: if subnet := ip_conf.subnet: vn_id = extract_vn_id(subnet) - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) if firewall_policy := self.firewall_policy: - builder.add_edge(self, clazz=AzureWebApplicationFirewallPolicy, id=firewall_policy) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureWebApplicationFirewallPolicy, id=firewall_policy + ) if pl_configurations := self.private_link_configurations: for pl_configuration in pl_configurations: if ip_configurations := pl_configuration.link_ip_configurations: for ip_configuration in ip_configurations: if subnet_id := ip_configuration.subnet: - builder.add_edge(self, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id) vn_id = extract_vn_id(subnet_id) - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) @define(eq=False, slots=False) @@ -1495,12 +1498,12 @@ class AzureFirewall(AzureResource, BaseFirewall): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if policy_id := self.firewall_policy: - builder.add_edge(self, clazz=AzureFirewallPolicy, id=policy_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureFirewallPolicy, id=policy_id) if ip_confs := self.firewall_ip_configurations: for ip_conf in ip_confs: if subnet := ip_conf.subnet: vn_id = extract_vn_id(subnet) - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) if rule_collections := self.application_rule_collections: for rule_collection in rule_collections: if rules := rule_collection.rules: @@ -1508,9 +1511,11 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: fqdn_tags = rule.fqdn_tags if fqdn_tags: for fqdn_tag_id in fqdn_tags: - builder.add_edge(self, clazz=AzureFirewallFqdnTag, id=fqdn_tag_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureFirewallFqdnTag, id=fqdn_tag_id + ) if vh_id := self.virtual_hub: - builder.add_edge(self, clazz=AzureVirtualHub, id=vh_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualHub, id=vh_id) @define(eq=False, slots=False) @@ -1651,13 +1656,13 @@ class AzureBastionHost(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vn_id := self.virtual_network: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) if ip_configurations := self.bastion_host_ip_configurations: for ip_configuration in ip_configurations: if subnet_id := ip_configuration.subnet: - builder.add_edge(self, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id) if p_ip_address := ip_configuration.public_ip_address: - builder.add_edge(self, clazz=AzurePublicIPAddress, id=p_ip_address) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzurePublicIPAddress, id=p_ip_address) @define(eq=False, slots=False) @@ -1720,7 +1725,7 @@ class AzureCustomIpPrefix(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vn_address := self.cidr: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_address) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_address) @define(eq=False, slots=False) @@ -1760,10 +1765,10 @@ class AzureDdosProtectionPlan(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vns := self.virtual_networks: for vn_id in vns: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) if p_ip_addresses := self.public_ip_addresses: for p_ip_address in p_ip_addresses: - builder.add_edge(self, clazz=AzurePublicIPAddress, id=p_ip_address) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzurePublicIPAddress, id=p_ip_address) @define(eq=False, slots=False) @@ -2240,9 +2245,9 @@ class AzurePublicIPAddress(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if p_ip_prefix_id := self.public_ip_prefix: - builder.add_edge(self, clazz=AzurePublicIPPrefix, id=p_ip_prefix_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzurePublicIPPrefix, id=p_ip_prefix_id) if (nat_gateway := self.nat_gateway) and (nat_gateway_id := nat_gateway.id): - builder.add_edge(self, clazz=AzureNatGateway, id=nat_gateway_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNatGateway, id=nat_gateway_id) @define(eq=False, slots=False) @@ -2791,15 +2796,15 @@ class AzureNetworkInterface(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if dscp_config_id := self.dscp_configuration: - builder.add_edge(self, clazz=AzureDscpConfiguration, id=dscp_config_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureDscpConfiguration, id=dscp_config_id) if tap_configs := self.tap_configurations: for tap_config in tap_configs: if vn_tap_id := tap_config.id: - builder.add_edge(self, clazz=AzureVirtualNetworkTap, id=vn_tap_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetworkTap, id=vn_tap_id) if nsg_id := self._network_security_group: - builder.add_edge(self, clazz=AzureNetworkSecurityGroup, id=nsg_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNetworkSecurityGroup, id=nsg_id) if p_l_service_id := self.private_link_service: - builder.add_edge(self, clazz=AzurePrivateLinkService, id=p_l_service_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzurePrivateLinkService, id=p_l_service_id) @define(eq=False, slots=False) @@ -2861,7 +2866,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_conf in ip_confs: if (subnet := ip_conf.subnet) and (subnet_id := subnet.id): vn_id = extract_vn_id(subnet_id) - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) @define(eq=False, slots=False) @@ -3153,7 +3158,7 @@ def collect_ids_and_names() -> None: def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if route_port_id := self.express_route_port: - builder.add_edge(self, clazz=AzureExpressRoutePort, id=route_port_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureExpressRoutePort, id=route_port_id) if ( (provider_properties := self.service_provider_properties) and (location_name := provider_properties.peering_location) @@ -3162,13 +3167,15 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for info in names_and_ids: erplocation, erplocation_id = info if erplocation == location_name: - builder.add_edge(self, clazz=AzureExpressRoutePortsLocation, id=erplocation_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureExpressRoutePortsLocation, id=erplocation_id + ) if c_peerings := self.circuit_peerings: for c_peering in c_peerings: if p_address := c_peering.primary_peer_address_prefix: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=p_address) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=p_address) if s_address := c_peering.secondary_peer_address_prefix: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=s_address) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=s_address) @define(eq=False, slots=False) @@ -3791,9 +3798,9 @@ class AzureIpAllocation(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vn_id := self.virtual_network: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) if subnet_id := self.subnet: - builder.add_edge(self, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id) @define(eq=False, slots=False) @@ -3857,7 +3864,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: vn_ips, vn_id = info for vn_address in vn_ips: if ip_address == vn_address: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) @define(eq=False, slots=False) @@ -4140,13 +4147,13 @@ class AzureLoadBalancer(AzureResource, BaseLoadBalancer): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vns := self.backends: for vn_id in vns: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) if baps := self.backend_address_pools: for bap in baps: if lbbas := bap.load_balancer_backend_addresses: for lbba in lbbas: if subnet_id := lbba.subnet: - builder.add_edge(self, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id) @define(eq=False, slots=False) @@ -4282,7 +4289,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for ip_configuration in ip_configurations: if subnet := ip_configuration.subnet: vn_id = extract_vn_id(subnet) - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) if (container_ni_ids := container.container_network_interfaces) and ( ni_ids_and_vm_ids := self._network_interfaces_and_vm_ids @@ -4291,7 +4298,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for info in ni_ids_and_vm_ids: network_interface_id, vm_id = info if ni_id == network_interface_id: - builder.add_edge(self, clazz=AzureVirtualMachine, id=vm_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualMachine, id=vm_id) @define(eq=False, slots=False) @@ -4446,11 +4453,13 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for info in vendors: vendor_name, nvasku_id = info if vendor_name == nva_vendor: - builder.add_edge(self, clazz=AzureNetworkVirtualApplianceSku, id=nvasku_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzureNetworkVirtualApplianceSku, id=nvasku_id + ) if virtual_appliances := self.virtual_appliance_nics: for va in virtual_appliances: if private_address := va.private_ip_address: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=private_address) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=private_address) @define(eq=False, slots=False) @@ -4546,7 +4555,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: for info in vns_info: vn_location, vn_id = info if vn_location == nw_location: - builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualNetwork, id=vn_id) @define(eq=False, slots=False) @@ -4699,7 +4708,7 @@ class AzureP2SVpnGateway(AzureResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vh_id := self.virtual_hub: - builder.add_edge(self, clazz=AzureVirtualHub, id=vh_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualHub, id=vh_id) @define(eq=False, slots=False) @@ -5029,17 +5038,19 @@ def collect_ip_info() -> None: def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if er_gateway_id := self.express_route_gateway: - builder.add_edge(self, clazz=AzureExpressRouteGateway, id=er_gateway_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureExpressRouteGateway, id=er_gateway_id) if vpn_gateway_id := self.vpn_gateway: - builder.add_edge(self, clazz=AzureVpnGateway, id=vpn_gateway_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVpnGateway, id=vpn_gateway_id) if vw_id := self.virtual_wan: - builder.add_edge(self, clazz=AzureVirtualWAN, id=vw_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualWAN, id=vw_id) if (ip_config_ids := self.ip_configuration_ids) and (p_ip_a_and_ip_conf_ids := self._p_ip_addresses_ip_c_ids): for ip_config_id in ip_config_ids: for info in p_ip_a_and_ip_conf_ids: p_ip_address_id, collected_ip_conf_id = info if ip_config_id == collected_ip_conf_id: - builder.add_edge(self, clazz=AzurePublicIPAddress, id=p_ip_address_id) + builder.add_edge( + self, edge_type=EdgeType.default, clazz=AzurePublicIPAddress, id=p_ip_address_id + ) @define(eq=False, slots=False) @@ -5175,9 +5186,9 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if subnets := self.subnets: for subnet in subnets: if subnet_id := subnet.id: - builder.add_edge(self, clazz=AzureSubnet, id=subnet_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id) if nat_gateway_id := subnet.nat_gateway: - builder.add_edge(self, clazz=AzureNatGateway, id=nat_gateway_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureNatGateway, id=nat_gateway_id) @define(eq=False, slots=False) @@ -5763,7 +5774,7 @@ class AzureVpnSite(AzureResource, BasePeeringConnection): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if vw_id := self.virtual_wan: - builder.add_edge(self, clazz=AzureVirtualWAN, id=vw_id) + builder.add_edge(self, edge_type=EdgeType.default, clazz=AzureVirtualWAN, id=vw_id) @define(eq=False, slots=False)