Revision 08b079e2 snf-cyclades-app/synnefo/api/servers.py

b/snf-cyclades-app/synnefo/api/servers.py
107 107
    else:
108 108
        return method_not_allowed(request)
109 109

  
110

  
111 110
def nic_to_dict(nic):
112 111
    network = nic.network
113 112
    network_id = str(network.id) if not network.public else 'public'
114
    d = {'id': network_id, 'name': network.name, 'mac': nic.mac}
113
    ipv4 = nic.ipv4 if nic.ipv4 else None
114
    ipv6 = nic.ipv6 if nic.ipv6 else None
115

  
116
    d = {'id': util.construct_nic_id(nic), 'network_id': network_id, 'mac_address': nic.mac, 'ipv4': ipv4, 'ipv6': ipv6}
115 117
    if nic.firewall_profile:
116 118
        d['firewallProfile'] = nic.firewall_profile
117
    if nic.ipv4 or nic.ipv6:
118
        d['values'] = []
119
        if nic.ipv4:
120
            d['values'].append({'version': 4, 'addr': nic.ipv4})
121
        if nic.ipv6:
122
            d['values'].append({'version': 6, 'addr': nic.ipv6})
123 119
    return d
124 120

  
125 121

  
......
139 135
        if metadata:
140 136
            d['metadata'] = {'values': metadata}
141 137

  
142
        addresses = [nic_to_dict(nic) for nic in vm.nics.all()]
143
        if addresses:
144
            d['addresses'] = {'values': addresses}
138
        attachments = [nic_to_dict(nic) for nic in vm.nics.all()]
139
        if attachments:
140
            d['attachments'] = {'values': attachments}
145 141
    return d
146 142

  
147 143

  

Also available in: Unified diff