def _get_vm_network_data(instance: NovaServer, api: OSApi,
                         mgmt_net_id) -> List[VmDetailsNetworkInterface]:
    network_interfaces = []
    for interface in instance.interface_list():
        net_dict = api.get_network_dict(id=interface.net_id)
        net_name = net_dict["name"]
        private_ip = get_private_ip(instance, net_name)
        is_primary_and_predefined = mgmt_net_id == interface.net_id
        public_ip = get_floating_ip(instance)

        network_data = [
            VmDetailsProperty("IP", private_ip),
            VmDetailsProperty("MAC Address", interface.mac_addr),
            VmDetailsProperty("VLAN Name", net_name, hidden=True),
        ]
        if public_ip:
            network_data.append(VmDetailsProperty("Floating IP", public_ip))

        current_interface = VmDetailsNetworkInterface(
            interfaceId=interface.mac_addr,
            networkId=net_dict["provider:segmentation_id"],
            isPrimary=is_primary_and_predefined,
            isPredefined=is_primary_and_predefined,
            networkData=network_data,
            privateIpAddress=private_ip,
            publicIpAddress=public_ip,
        )
        network_interfaces.append(current_interface)
    return sorted(network_interfaces, key=lambda x: x.networkId)
Ejemplo n.º 2
0
    def _prepare_vm_network_data(self, virtual_machine, resource_group_name):
        """Prepare VM Network data.

        :param virtual_machine:
        :param str resource_group_name:
        :return:
        """
        vm_network_interfaces = []
        for network_interface in virtual_machine.network_profile.network_interfaces:
            interface_name = get_name_from_resource_id(network_interface.id)
            interface = self.get_vm_network(
                interface_name=interface_name,
                resource_group_name=resource_group_name)

            ip_configuration = interface.ip_configurations[0]
            private_ip_addr = ip_configuration.private_ip_address

            network_data = [
                VmDetailsProperty(key="IP",
                                  value=ip_configuration.private_ip_address),
                VmDetailsProperty(key="MAC Address",
                                  value=interface.mac_address),
            ]

            subnet_name = ip_configuration.subnet.id.split("/")[-1]

            if ip_configuration.public_ip_address:
                public_ip = self.get_vm_network_public_ip(
                    interface_name=interface_name,
                    resource_group_name=resource_group_name,
                )
                network_data.extend([
                    VmDetailsProperty(key="Public IP",
                                      value=public_ip.ip_address),
                    VmDetailsProperty(
                        key="Public IP Type",
                        value=public_ip.public_ip_allocation_method,
                    ),
                ])

                public_ip_addr = public_ip.ip_address
            else:
                public_ip_addr = ""

            vm_network_interface = VmDetailsNetworkInterface(
                interfaceId=interface.resource_guid,
                networkId=subnet_name,
                isPrimary=interface.primary,
                networkData=network_data,
                privateIpAddress=private_ip_addr,
                publicIpAddress=public_ip_addr,
            )

            vm_network_interfaces.append(vm_network_interface)

        return vm_network_interfaces
Ejemplo n.º 3
0
    def _prepare_gallery_vm_instance_data(self, virtual_machine):
        """Prepare custom VM instance data.

        :param virtual_machine:
        :return:
        """
        image_resource_id = virtual_machine.storage_profile.image_reference.id
        image_name = self._parse_image_name(resource_id=image_resource_id)
        resource_group = self._parse_resource_group_name(
            resource_id=image_resource_id)

        return [
            VmDetailsProperty(key="Image", value=image_name),
            VmDetailsProperty(key="Image Resource Group",
                              value=resource_group),
        ] + self._prepare_common_vm_instance_data(
            virtual_machine=virtual_machine)
Ejemplo n.º 4
0
    def _get_vm_instance_data(self, services, deployment, deployed_app):
        """Get VM instance data.

        :param List[V1Service] services:
        :param ubernetes.client.AppsV1beta1Deployment deployment:
        :param DeployedAppResource deployed_app:
        :return:
        """
        internal_service, external_service = self._get_internal_external_services_set(
            services)

        data = [
            VmDetailsProperty(key="Image", value=self._get_image(deployment)),
            VmDetailsProperty(key="Replicas",
                              value=self._get_replicas(deployment,
                                                       deployed_app)),
            VmDetailsProperty(key="Ready Replicas",
                              value=self._get_ready_replicas(deployment)),
            VmDetailsProperty(key="Internal IP",
                              value=self.get_internal_ip(internal_service)),
            VmDetailsProperty(key="Internal Ports",
                              value=self._get_service_ports(internal_service)),
            VmDetailsProperty(key="External IP",
                              value=self.get_external_ip(external_service)),
            VmDetailsProperty(
                key="External Ports",
                value=self._get_external_service_ports(external_service),
            ),
        ]

        return data
Ejemplo n.º 5
0
    def _prepare_common_vm_instance_data(virtual_machine):
        """Prepare commnon VM instance data.

        :param virtual_machine:
        :return:
        """
        disk_type = ("HDD" if virtual_machine.storage_profile.os_disk.
                     managed_disk.storage_account_type
                     == StorageAccountTypes.standard_lrs else "SSD")

        return [
            VmDetailsProperty(key="VM Size",
                              value=virtual_machine.hardware_profile.vm_size),
            VmDetailsProperty(
                key="Operating System",
                value=virtual_machine.storage_profile.os_disk.os_type.name,
            ),
            VmDetailsProperty(key="Disk Type", value=disk_type),
        ]
Ejemplo n.º 6
0
    def _prepare_marketplace_vm_instance_data(self, virtual_machine):
        """Prepare marketplace VM instance data.

        :param virtual_machine:
        :return:
        """
        return [
            VmDetailsProperty(
                key="Image Publisher",
                value=virtual_machine.storage_profile.image_reference.
                publisher,
            ),
            VmDetailsProperty(
                key="Image Offer",
                value=virtual_machine.storage_profile.image_reference.offer,
            ),
            VmDetailsProperty(
                key="Image SKU",
                value=virtual_machine.storage_profile.image_reference.sku,
            ),
        ] + self._prepare_common_vm_instance_data(
            virtual_machine=virtual_machine)
def _get_vm_instance_data(instance: NovaServer,
                          api: OSApi) -> List[VmDetailsProperty]:
    image = api.get_image_from_instance(instance)
    flavor = api.get_flavor_from_instance(instance)
    available_zone = getattr(instance, "OS-EXT-AZ:availability_zone")
    return [
        VmDetailsProperty("Image", image.name),
        VmDetailsProperty("Flavor", flavor.name),
        VmDetailsProperty("Availability Zone", available_zone),
        VmDetailsProperty("CPU", f"{flavor.vcpus} vCPU"),
        VmDetailsProperty("Memory", f"{flavor.ram} GB"),
        VmDetailsProperty("Disk Size", f"{flavor.disk} GB"),
    ]