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] Filter virtual machine sizes #1852

Merged
merged 7 commits into from Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/azure/resoto_plugin_azure/azure_client.py
Expand Up @@ -153,7 +153,7 @@ def _call(self, spec: AzureApiSpec, **kwargs: Any) -> List[Json]:
if lookup_map.get(param, None) is not None:
path_map[param] = lookup_map[param]
else:
raise ValueError(f"Param {param} in lookup_map does not found")
raise KeyError(f"Param {param} in lookup_map does not found")
1101-1 marked this conversation as resolved.
Show resolved Hide resolved

# Construct parameters
params = case_insensitive_dict()
Expand All @@ -163,7 +163,7 @@ def _call(self, spec: AzureApiSpec, **kwargs: Any) -> List[Json]:
if lookup_map.get(param, None) is not None:
params[param] = ser.query(param, lookup_map[param], "str") # type: ignore # noqa: E501
else:
raise ValueError(f"Param {param} in lookup_map does not found")
raise KeyError(f"Param {param} in lookup_map does not found")
1101-1 marked this conversation as resolved.
Show resolved Hide resolved

# Construct url
path = spec.path.format_map(path_map)
Expand Down
34 changes: 23 additions & 11 deletions plugins/azure/resoto_plugin_azure/resource/compute.py
Expand Up @@ -2578,6 +2578,7 @@ class AzureVirtualMachine(AzureResource, BaseInstance):
"user_data": S("properties", "userData"),
"virtual_machine_scale_set": S("properties", "virtualMachineScaleSet", "id"),
"vm_id": S("properties", "vmId"),
"location": S("location"),
"instance_type": S("properties", "hardwareProfile", "vmSize"),
"instance_status": S("properties", "provisioningState")
>> MapEnum(InstanceStatusMapping, default=InstanceStatus.UNKNOWN),
Expand Down Expand Up @@ -2612,6 +2613,27 @@ class AzureVirtualMachine(AzureResource, BaseInstance):
user_data: Optional[str] = field(default=None, metadata={'description': 'Userdata for the vm, which must be base-64 encoded. Customer should not pass any secrets in here. Minimum api-version: 2021-03-01.'}) # fmt: skip
virtual_machine_scale_set: Optional[str] = field(default=None, metadata={"description": ""})
vm_id: Optional[str] = field(default=None, metadata={'description': 'Specifies the vm unique id which is a 128-bits identifier that is encoded and stored in all azure iaas vms smbios and can be read using platform bios commands.'}) # fmt: skip
location: Optional[str] = field(default=None, metadata={"description": "Resource location."})

def post_process(self, graph_builder: GraphBuilder, source: Json) -> None:
def collect_vms_size() -> None:
api_spec = AzureApiSpec(
service="compute",
version="2023-03-01",
path="/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/vmSizes",
path_parameters=["subscriptionId", "location"],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)
hardware_profile_name = self.instance_type if self.instance_type else ""
location = self.location if self.location else ""
items = [
r for r in graph_builder.client.list(api_spec, location=location) if r["name"] == hardware_profile_name
]
AzureVirtualMachineSize.collect(items, graph_builder)

1101-1 marked this conversation as resolved.
Show resolved Hide resolved
graph_builder.submit_work(collect_vms_size)

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
if placement_group_id := self.proximity_placement_group:
Expand Down Expand Up @@ -3201,17 +3223,8 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
@define(eq=False, slots=False)
class AzureVirtualMachineSize(AzureResource, BaseInstanceType):
kind: ClassVar[str] = "azure_virtual_machine_size"
api_spec: ClassVar[AzureApiSpec] = AzureApiSpec(
service="compute",
version="2023-03-01",
path="/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/vmSizes",
path_parameters=["location", "subscriptionId"],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("name"),
"id": K(None),
"tags": S("tags", default={}),
"name": S("name"),
"ctime": K(None),
Expand Down Expand Up @@ -3251,5 +3264,4 @@ class AzureVirtualMachineSize(AzureResource, BaseInstanceType):
AzureSshPublicKeyResource,
AzureVirtualMachine,
AzureVirtualMachineScaleSet,
AzureVirtualMachineSize,
]
25 changes: 0 additions & 25 deletions plugins/azure/resoto_plugin_azure/resource/network.py
Expand Up @@ -1168,30 +1168,6 @@ class AzureApplicationGatewayFirewallRuleSet(AzureResource):
tiers: Optional[List[str]] = field(default=None, metadata={'description': 'Tier of an application gateway that support the rule set.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureAutoApprovedPrivateLinkService(AzureResource):
kind: ClassVar[str] = "azure_auto_approved_private_link_service"
api_spec: ClassVar[AzureApiSpec] = AzureApiSpec(
service="network",
version="2023-05-01",
path="/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/autoApprovedPrivateLinkServices",
path_parameters=["location", "subscriptionId"],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("privateLinkService"),
"tags": S("tags", default={}),
"name": K(None),
"ctime": K(None),
"mtime": K(None),
"atime": K(None),
"private_link_service_id": S("privateLinkService"),
}
private_link_service_id: Optional[str] = field(default=None, metadata={'description': 'The id of the private link service resource.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureAvailableServiceAlias(AzureResource):
kind: ClassVar[str] = "azure_available_service_alias"
Expand Down Expand Up @@ -6019,7 +5995,6 @@ class AzureWebApplicationFirewallPolicy(AzureResource):
resources: List[Type[AzureResource]] = [
AzureApplicationGateway,
AzureApplicationGatewayFirewallRuleSet,
AzureAutoApprovedPrivateLinkService,
AzureAvailableServiceAlias,
AzureFirewall,
AzureFirewallFqdnTag,
Expand Down
4 changes: 2 additions & 2 deletions plugins/azure/test/collector_test.py
Expand Up @@ -15,5 +15,5 @@ def test_collect(
) -> None:
collector = AzureSubscriptionCollector(config, Cloud(id="azure"), azure_subscription, credentials, core_feedback)
collector.collect()
assert len(collector.graph.nodes) == 471
assert len(collector.graph.edges) == 524
assert len(collector.graph.nodes) == 416
assert len(collector.graph.edges) == 469
12 changes: 0 additions & 12 deletions plugins/azure/test/compute_test.py
Expand Up @@ -146,18 +146,6 @@ def test_scale_set(builder: GraphBuilder) -> None:
assert len(collected) == 1


def test_virtual_machine_size(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureVirtualMachineSize, builder)
assert len(collected) == 2


def test_virtual_machine_size_resources(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureVirtualMachineSize, builder)[0]
assert collected.instance_type == "Standard_A1_V2"
assert collected.instance_cores == 1.0
assert collected.instance_memory == 2.0


def test_snapshot(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureSnapshot, builder)
assert len(collected) == 2
Expand Down
5 changes: 0 additions & 5 deletions plugins/azure/test/network_test.py
Expand Up @@ -25,11 +25,6 @@ def test_application_gateway_web_application_firewall_policy(builder: GraphBuild
assert len(collected) == 1


def test_auto_approved_private_link_service(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureAutoApprovedPrivateLinkService, builder)
assert len(collected) == 3


def test_available_service_alias(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureAvailableServiceAlias, builder)
assert len(collected) == 2
Expand Down