// Subnets can only be deleted if there are no instance-ips or floating-ips associated
// with the subnet.
func (m *NetworkManagerImpl) updateSubnetConfig(network *types.VirtualNetwork, prefix string) error {
	prefixList, err := m.NetworkIPPrefixList(network)
	if err != nil {
		glog.Fatal(err)
	}
	add := true
	for _, pfx := range prefixList {
		if pfx == prefix {
			add = false
			continue
		}

		ipRefs, err := network.GetInstanceIpBackRefs()
		if err != nil {
			glog.Error(err)
			continue
		}

		// TODO: filter the IP addresses associated with the subnet that we are
		// attempting to delete.
		if len(ipRefs) > 0 {
			glog.Warningf(
				"network %s %s is stale but there are %d instance-ips present",
				network.GetName(), pfx, len(ipRefs))
			continue
		}

		pool, err := m.LookupFloatingIpPool(network)
		if err == nil {
			floatRefs, err := pool.GetFloatingIps()
			if err != nil {
				glog.Error(err)
				continue
			}
			// TODO: filter the floating-ips associated with the subnet that we
			// are attempting to delete.
			if len(floatRefs) > 0 {
				glog.Warningf(
					"network %s %s is stale but there are %d floating-ip addresses present",
					network.GetName(), pfx, len(floatRefs))
				continue
			}
		}

		err = config.RemoveSubnet(m.client, network, pfx)
		if err != nil {
			glog.Error(err)
		}
	}
	if add {
		_, err := config.AddSubnet(m.client, network, m.config.PublicSubnet)
		if err != nil {
			glog.Error(err)
		}
		return err
	}
	return nil
}