Commit d4117a72 authored by Apollon Oikonomopoulos's avatar Apollon Oikonomopoulos Committed by Iustin Pop
Browse files

Modify instance client to support networks



Add --no-conflicts-check option.
Modify instance query methods to return nic's network info.
Signed-off-by: default avatarApollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a5ad5e58
......@@ -2467,6 +2467,7 @@ def GenericInstanceCreate(mode, opts, args):
disks=disks,
disk_template=opts.disk_template,
nics=nics,
conflicts_check=opts.conflicts_check,
pnode=pnode, snode=snode,
ip_check=opts.ip_check,
name_check=opts.name_check,
......
......@@ -220,6 +220,7 @@ def ListInstances(opts, args):
fmtoverride = dict.fromkeys(["tags", "disk.sizes", "nic.macs", "nic.ips",
"nic.modes", "nic.links", "nic.bridges",
"nic.networks",
"snodes", "snodes.group", "snodes.group.uuid"],
(lambda value: ",".join(str(item)
for item in value),
......@@ -1177,9 +1178,10 @@ def ShowInstanceConfig(opts, args):
FormatParameterDict(buf, instance["be_instance"], be_actual, level=2)
# TODO(ganeti 2.7) rework the NICs as well
buf.write(" - NICs:\n")
for idx, (ip, mac, mode, link) in enumerate(instance["nics"]):
buf.write(" - nic/%d: MAC: %s, IP: %s, mode: %s, link: %s\n" %
(idx, mac, ip, mode, link))
for idx, (ip, mac, mode, link, network) in enumerate(instance["nics"]):
buf.write(" - nic/%d: MAC: %s, IP: %s,"
" mode: %s, link: %s, network: %s\n" %
(idx, mac, ip, mode, link, network))
buf.write(" Disk template: %s\n" % instance["disk_template"])
buf.write(" Disks:\n")
......
......@@ -1550,6 +1550,20 @@ def _GetInstNic(index, cb):
return fn
def _GetInstNicNetwork(ctx, _, nic): # pylint: disable=W0613
"""Get a NIC's Network.
@type ctx: L{InstanceQueryData}
@type nic: L{objects.NIC}
@param nic: NIC object
"""
if nic.network is None:
return _FS_UNAVAIL
else:
return nic.network
def _GetInstNicIp(ctx, _, nic): # pylint: disable=W0613
"""Get a NIC's IP address.
......@@ -1661,6 +1675,9 @@ def _GetInstanceNetworkFields():
(_MakeField("nic.bridges", "NIC_bridges", QFT_OTHER,
"List containing each network interface's bridge"),
IQ_CONFIG, 0, _GetInstAllNicBridges),
(_MakeField("nic.networks", "NIC_networks", QFT_OTHER,
"List containing each interface's network"), IQ_CONFIG, 0,
lambda ctx, inst: [nic.network for nic in inst.nics]),
]
# NICs by number
......@@ -1682,6 +1699,9 @@ def _GetInstanceNetworkFields():
(_MakeField("nic.bridge/%s" % i, "NicBridge/%s" % i, QFT_TEXT,
"Bridge of %s network interface" % numtext),
IQ_CONFIG, 0, _GetInstNic(i, _GetInstNicBridge)),
(_MakeField("nic.network/%s" % i, "NicNetwork/%s" % i, QFT_TEXT,
"Network of %s network interface" % numtext),
IQ_CONFIG, 0, _GetInstNic(i, _GetInstNicNetwork)),
])
aliases = [
......@@ -1691,6 +1711,7 @@ def _GetInstanceNetworkFields():
("bridge", "nic.bridge/0"),
("nic_mode", "nic.mode/0"),
("nic_link", "nic.link/0"),
("nic_network", "nic.network/0"),
]
return (fields, aliases)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment