Skip to content

Commit

Permalink
fix: Fixed tests and relationships of ALB resource
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 committed Nov 26, 2023
1 parent 0827cb6 commit 5648a4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 41 deletions.
17 changes: 17 additions & 0 deletions plugins/azure/resoto_plugin_azure/resource/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3094,6 +3094,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 @@ -3152,6 +3155,20 @@ 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, clazz=AzureLoadBalancer, id=bap_id)


@define(eq=False, slots=False)
class AzureVirtualMachineSize(AzureResource, BaseInstanceType):
Expand Down
40 changes: 0 additions & 40 deletions plugins/azure/resoto_plugin_azure/resource/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4096,7 +4096,6 @@ class AzureLoadBalancer(AzureResource, BaseLoadBalancer):
)
reference_kinds: ClassVar[ModelReference] = {
"predecessors": {"default": ["azure_virtual_network", "azure_subnet"]},
"successors": {"default": ["azure_virtual_machine_scale_set"]},
}
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
Expand All @@ -4119,9 +4118,6 @@ class AzureLoadBalancer(AzureResource, BaseLoadBalancer):
"resource_guid": S("properties", "resourceGuid"),
"azure_sku": S("sku") >> Bend(AzureSku.mapping),
"lb_type": S("type"),
"public_ip_address": S(
"properties", "frontendIPConfigurations", "properties", "publicIPAddress", "properties", "ipAddress"
),
"backends": S("properties", "backendAddressPools")
>> ForallBend(AzureBackendAddressPool.mapping)
>> ForallBend(S("virtual_network", default=[])),
Expand All @@ -4140,49 +4136,13 @@ class AzureLoadBalancer(AzureResource, BaseLoadBalancer):
provisioning_state: Optional[str] = field(default=None, metadata={'description': 'The current provisioning state.'}) # fmt: skip
resource_guid: Optional[str] = field(default=None, metadata={'description': 'The resource GUID property of the load balancer resource.'}) # fmt: skip
azure_sku: Optional[AzureSku] = field(default=None, metadata={"description": "SKU of a load balancer."})
_vmss_and_lb_ids: Optional[List[Tuple[str, str]]] = None

def post_process(self, graph_builder: GraphBuilder, source: Json) -> None:
def collect_vmss_ids() -> None:
resources_api_spec = AzureApiSpec(
service="compute",
version="2023-07-01",
path="/subscriptions/{subscriptionId}/providers/Microsoft.Network/virtualMachineScaleSets",
path_parameters=["subscriptionId"],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)

self._vmss_and_lb_ids = [
(backend_address_pool["id"], resource["id"])
for resource in graph_builder.client.list(resources_api_spec)
for vm_profile in [resource.get("properties", {}).get("virtualMachineProfile", {})]
if isinstance(vm_profile, dict)
for nic_config in vm_profile.get("networkProfile", {}).get("networkInterfaceConfigurations", [])
for ip_config in nic_config.get("properties", {}).get("ipConfigurations", [])
for backend_address_pool in ip_config.get("properties", {}).get("loadBalancerBackendAddressPools", [])
]

graph_builder.submit_work(collect_vmss_ids)

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
# Import placed inside the method due to circular import error resolution
from resoto_plugin_azure.resource.compute import ( # pylint: disable=import-outside-toplevel
AzureVirtualMachineScaleSet,
)

if vns := self.backends:
for vn_id in vns:
builder.add_edge(self, clazz=AzureVirtualNetwork, id=vn_id)
if baps := self.backend_address_pools:
for bap in baps:
if bap_id := bap.id:
if vmsss_info := self._vmss_and_lb_ids:
for info in vmsss_info:
r_bap_id, vmss_id = info
if r_bap_id == bap_id:
builder.add_edge(self, clazz=AzureVirtualMachineScaleSet, id=vmss_id)
if lbbas := bap.load_balancer_backend_addresses:
for lbba in lbbas:
if subnet_id := lbba.subnet:
Expand Down
4 changes: 3 additions & 1 deletion resotolib/resotolib/baseresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,9 @@ class BaseNetworkQuota(BaseQuota):

@define(eq=False, slots=False)
class BaseFirewall(BaseResource):
kind: ClassVar[str] = "network"
kind: ClassVar[str] = "firewall"
kind_display: ClassVar[str] = "Firewall"
kind_description: ClassVar[str] = "A firewall."
metadata: ClassVar[Dict[str, Any]] = {"icon": "firewall", "group": "networking"}


Expand Down

0 comments on commit 5648a4d

Please sign in to comment.