Revision 5a672c30 lib/bdev.py

b/lib/bdev.py
1079 1079
    # pyparsing setup
1080 1080
    lbrace = pyp.Literal("{").suppress()
1081 1081
    rbrace = pyp.Literal("}").suppress()
1082
    lbracket = pyp.Literal("[").suppress()
1083
    rbracket = pyp.Literal("]").suppress()
1082 1084
    semi = pyp.Literal(";").suppress()
1085
    colon = pyp.Literal(":").suppress()
1083 1086
    # this also converts the value to an int
1084 1087
    number = pyp.Word(pyp.nums).setParseAction(lambda s, l, t: int(t[0]))
1085 1088

  
......
1092 1095
    # value types
1093 1096
    value = pyp.Word(pyp.alphanums + '_-/.:')
1094 1097
    quoted = dbl_quote + pyp.CharsNotIn('"') + dbl_quote
1095
    addr_type = (pyp.Optional(pyp.Literal("ipv4")).suppress() +
1096
                 pyp.Optional(pyp.Literal("ipv6")).suppress())
1097
    addr_port = (addr_type + pyp.Word(pyp.nums + '.') +
1098
                 pyp.Literal(':').suppress() + number)
1098
    ipv4_addr = (pyp.Optional(pyp.Literal("ipv4")).suppress() +
1099
                 pyp.Word(pyp.nums + ".") + colon + number)
1100
    ipv6_addr = (pyp.Optional(pyp.Literal("ipv6")).suppress() +
1101
                 pyp.Optional(lbracket) + pyp.Word(pyp.hexnums + ":") +
1102
                 pyp.Optional(rbracket) + colon + number)
1099 1103
    # meta device, extended syntax
1100
    meta_value = ((value ^ quoted) + pyp.Literal('[').suppress() +
1101
                  number + pyp.Word(']').suppress())
1104
    meta_value = ((value ^ quoted) + lbracket + number + rbracket)
1102 1105
    # device name, extended syntax
1103 1106
    device_value = pyp.Literal("minor").suppress() + number
1104 1107

  
1105 1108
    # a statement
1106 1109
    stmt = (~rbrace + keyword + ~lbrace +
1107
            pyp.Optional(addr_port ^ value ^ quoted ^ meta_value ^
1110
            pyp.Optional(ipv4_addr ^ ipv6_addr ^ value ^ quoted ^ meta_value ^
1108 1111
                         device_value) +
1109 1112
            pyp.Optional(defa) + semi +
1110 1113
            pyp.Optional(pyp.restOfLine).suppress())
......
1280 1283
    # about its peer.
1281 1284
    cls._SetMinorSyncSpeed(minor, constants.SYNC_SPEED)
1282 1285

  
1286
    if utils.IsValidIP6(lhost):
1287
      if not utils.IsValidIP6(rhost):
1288
        _ThrowError("drbd%d: can't connect ip %s to ip %s" %
1289
                    (minor, lhost, rhost))
1290
      family = "ipv6"
1291
    elif utils.IsValidIP4(lhost):
1292
      if not utils.IsValidIP4(rhost):
1293
        _ThrowError("drbd%d: can't connect ip %s to ip %s" %
1294
                    (minor, lhost, rhost))
1295
      family = "ipv4"
1296
    else:
1297
      _ThrowError("drbd%d: Invalid ip %s" % (minor, lhost))
1298

  
1283 1299
    args = ["drbdsetup", cls._DevPath(minor), "net",
1284
            "%s:%s" % (lhost, lport), "%s:%s" % (rhost, rport), protocol,
1300
            "%s:%s:%s" % (family, lhost, lport),
1301
            "%s:%s:%s" % (family, rhost, rport), protocol,
1285 1302
            "-A", "discard-zero-changes",
1286 1303
            "-B", "consensus",
1287 1304
            "--create-device",

Also available in: Unified diff