コード例 #1
0
func (i *importer) machinePortsOps(m description.Machine) []txn.Op {
	var result []txn.Op
	machineId := m.Id()

	for _, ports := range m.NetworkPorts() {
		networkName := ports.NetworkName()
		doc := &portsDoc{
			MachineID:   machineId,
			NetworkName: networkName,
		}
		for _, opened := range ports.OpenPorts() {
			doc.Ports = append(doc.Ports, PortRange{
				UnitName: opened.UnitName(),
				FromPort: opened.FromPort(),
				ToPort:   opened.ToPort(),
				Protocol: opened.Protocol(),
			})
		}
		result = append(result, txn.Op{
			C:      openedPortsC,
			Id:     portsGlobalKey(machineId, networkName),
			Assert: txn.DocMissing,
			Insert: doc,
		})
	}

	return result
}