# Buggy code
def get_vm_details(resource_group_name, vm_name):
    result = get_instance_view(resource_group_name, vm_name)
    network_client = get_mgmt_service_client(ResourceType.MGMT_NETWORK)
    public_ips = []
    fqdns = []
    private_ips = []
    mac_addresses = []
    # pylint: disable=line-too-long,no-member
    for nic_ref in result.network_profile.network_interfaces:
        nic_parts = parse_resource_id(nic_ref.id)
        nic = network_client.network_interfaces.get(
            nic_parts["resource_group"], nic_parts["name"]
        )
        if nic.mac_address:
            mac_addresses.append(nic.mac_address)
        for ip_configuration in nic.ip_configurations:
            private_ips.append(ip_configuration.private_ip_address)
            if ip_configuration.public_ip_address:
                res = parse_resource_id(ip_configuration.public_ip_address.id)
                public_ip_info = network_client.public_ip_addresses.get(
                    res["resource_group"], res["name"]
                )
                if public_ip_info.ip_address:
                    public_ips.append(public_ip_info.ip_address)
                if public_ip_info.dns_settings:
                    fqdns.append(public_ip_info.dns_settings.fqdn)

    setattr(
        result,
        "power_state",
        ",".join(
            [
                s.display_status
                for s in result.instance_view.statuses
                if s.code.startswith("PowerState/")
            ]
        ),
    )
    setattr(result, "public_ips", ",".join(public_ips))
    setattr(result, "fqdns", ",".join(fqdns))
    setattr(result, "private_ips", ",".join(private_ips))
    setattr(result, "mac_addresses", ",".join(mac_addresses))
    del (
        result.instance_view
    )  # we don't need other instance_view info as people won't care
    return result


# Traceback (TypeError)
$ az vm list -d (or az vm show -n v6linux -g summer -d)

sequence item 1: expected string or Unicode, NoneType found
Traceback (most recent call last):
File "/home/snobu/lib/azure-cli/local/lib/python2.7/site-packages/azure/cli/main.py", line 36, in main
cmd_result = APPLICATION.execute(args)
File "/home/snobu/lib/azure-cli/local/lib/python2.7/site-packages/azure/cli/core/application.py", line 211, in execute
result = expanded_arg.func(params)
File "/home/snobu/lib/azure-cli/local/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 351, in __call__
return self.handler(*args, **kwargs)
File "/home/snobu/lib/azure-cli/local/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 550, in _execute_command
reraise(*sys.exc_info())
File "/home/snobu/lib/azure-cli/local/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 527, in _execute_command
result = op(client, **kwargs) if client else op(**kwargs)
File "/home/snobu/lib/azure-cli/local/lib/python2.7/site-packages/azure/cli/command_modules/vm/custom.py", line 160, in list_vm
return [get_vm_details(_parse_rg_name(v.id)[0], v.name) for v in vm_list]
File "/home/snobu/lib/azure-cli/local/lib/python2.7/site-packages/azure/cli/command_modules/vm/custom.py", line 197, in get_vm_details
setattr(result, 'private_ips', ','.join(private_ips))
TypeError: sequence item 1: expected string or Unicode, NoneType found

# Fixed code
def get_vm_details(resource_group_name, vm_name):
    result = get_instance_view(resource_group_name, vm_name)
    network_client = get_mgmt_service_client(ResourceType.MGMT_NETWORK)
    public_ips = []
    fqdns = []
    private_ips = []
    mac_addresses = []
    # pylint: disable=line-too-long,no-member
    for nic_ref in result.network_profile.network_interfaces:
        nic_parts = parse_resource_id(nic_ref.id)
        nic = network_client.network_interfaces.get(
            nic_parts["resource_group"], nic_parts["name"]
        )
        if nic.mac_address:
            mac_addresses.append(nic.mac_address)
        for ip_configuration in nic.ip_configurations:
            if ip_configuration.private_ip_address:
                private_ips.append(ip_configuration.private_ip_address)
            if ip_configuration.public_ip_address:
                res = parse_resource_id(ip_configuration.public_ip_address.id)
                public_ip_info = network_client.public_ip_addresses.get(
                    res["resource_group"], res["name"]
                )
                if public_ip_info.ip_address:
                    public_ips.append(public_ip_info.ip_address)
                if public_ip_info.dns_settings:
                    fqdns.append(public_ip_info.dns_settings.fqdn)

    setattr(
        result,
        "power_state",
        ",".join(
            [
                s.display_status
                for s in result.instance_view.statuses
                if s.code.startswith("PowerState/")
            ]
        ),
    )
    setattr(result, "public_ips", ",".join(public_ips))
    setattr(result, "fqdns", ",".join(fqdns))
    setattr(result, "private_ips", ",".join(private_ips))
    setattr(result, "mac_addresses", ",".join(mac_addresses))
    del (
        result.instance_view
    )  # we don't need other instance_view info as people won't care
    return result