Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azure] [feat] Add new relationships between network resources #1838

Merged
merged 17 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion plugins/azure/resoto_plugin_azure/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 67 additions & 3 deletions plugins/azure/resoto_plugin_azure/resource/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
AzurePrincipalidClientid,
AzurePrivateLinkServiceConnectionState,
)
from resoto_plugin_azure.resource.network import (
AzureNetworkSecurityGroup,
AzureSubnet,
AzureNetworkInterface,
AzureLoadBalancer,
)
from resotolib.json_bender import Bender, S, Bend, MapEnum, ForallBend, K, F
from resotolib.types import Json
from resotolib.baseresources import (
Expand Down Expand Up @@ -353,7 +359,7 @@ class AzureComputeOperationValue(AzureResource):
expect_array=True,
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": K(None),
"id": S("name"),
"tags": S("tags", default={}),
"name": S("name"),
"ctime": K(None),
Expand Down Expand Up @@ -1065,6 +1071,9 @@ class AzureProximityPlacementGroup(AzureResource):
access_path="value",
expect_array=True,
)
reference_kinds: ClassVar[ModelReference] = {
"successors": {"default": ["azure_virtual_machine_scale_set"]},
}
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
"tags": S("tags", default={}),
Expand All @@ -1089,6 +1098,12 @@ class AzureProximityPlacementGroup(AzureResource):
virtual_machine_scale_sets: Optional[List[AzureSubResourceWithColocationStatus]] = field(default=None, metadata={'description': 'A list of references to all virtual machine scale sets in the proximity placement group.'}) # fmt: skip
virtual_machines_status: Optional[List[AzureSubResourceWithColocationStatus]] = field(default=None, metadata={'description': 'A list of references to all virtual machines in the proximity placement group.'}) # fmt: skip

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, edge_type=EdgeType.default, clazz=AzureVirtualMachineScaleSet, id=vmss_id)


@define(eq=False, slots=False)
class AzureResourceSkuCapacity:
Expand Down Expand Up @@ -2505,7 +2520,17 @@ class AzureVirtualMachine(AzureResource, BaseInstance):
expect_array=True,
)
reference_kinds: ClassVar[ModelReference] = {
"successors": {"default": ["azure_proximity_placement_group", "azure_image", "azure_disk"]},
"successors": {
"default": [
"azure_proximity_placement_group",
1101-1 marked this conversation as resolved.
Show resolved Hide resolved
"azure_image",
"azure_disk",
"azure_network_security_group",
"azure_subnet",
1101-1 marked this conversation as resolved.
Show resolved Hide resolved
"azure_network_interface",
"azure_load_balancer",
1101-1 marked this conversation as resolved.
Show resolved Hide resolved
]
},
}
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
Expand Down Expand Up @@ -2605,6 +2630,26 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
):
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, 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, edge_type=EdgeType.default, clazz=AzureSubnet, id=subnet_id)
if lbbap_id := ip_configuration.load_balancer_backend_address_pools:
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, edge_type=EdgeType.default, clazz=AzureNetworkInterface, id=ni_id)


@define(eq=False, slots=False)
class AzureRollingUpgradePolicy:
Expand Down Expand Up @@ -3054,6 +3099,9 @@ class AzureVirtualMachineScaleSet(AzureResource, BaseAutoScalingGroup):
access_path="value",
expect_array=True,
)
reference_kinds: ClassVar[ModelReference] = {
"predecessors": {"default": ["azure_load_balancer"]},
}
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
"tags": S("tags", default={}),
Expand Down Expand Up @@ -3112,6 +3160,22 @@ class AzureVirtualMachineScaleSet(AzureResource, BaseAutoScalingGroup):
virtual_machine_profile: Optional[AzureVirtualMachineScaleSetVMProfile] = field(default=None, metadata={'description': 'Describes a virtual machine scale set virtual machine profile.'}) # fmt: skip
zone_balance: Optional[bool] = field(default=None, metadata={'description': 'Whether to force strictly even virtual machine distribution cross x-zones in case there is zone outage. Zonebalance property can only be set if the zones property of the scale set contains more than one zone. If there are no zones or only one zone specified, then zonebalance property should not be set.'}) # fmt: skip

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
if (
(vm_profile := self.virtual_machine_profile)
and (net_profile := vm_profile.network_profile)
and (net_i_configs := net_profile.network_interface_configurations)
):
for net_i_config in net_i_configs:
if ip_configs := net_i_config.ip_configurations:
for ip_config in ip_configs:
if baps := ip_config.load_balancer_backend_address_pools:
for bap in baps:
if bap_id := bap:
builder.add_edge(
self, edge_type=EdgeType.default, clazz=AzureLoadBalancer, id=bap_id
1101-1 marked this conversation as resolved.
Show resolved Hide resolved
)


@define(eq=False, slots=False)
class AzureVirtualMachineSize(AzureResource, BaseInstanceType):
Expand All @@ -3126,7 +3190,7 @@ class AzureVirtualMachineSize(AzureResource, BaseInstanceType):
expect_array=True,
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
"id": S("name"),
"tags": S("tags", default={}),
"name": S("name"),
"ctime": K(None),
Expand Down
Loading
Loading