Revision cbe4a0a5 lib/rpc.py
b/lib/rpc.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
35 | 35 |
import base64 |
36 | 36 |
import pycurl |
37 | 37 |
import threading |
38 |
import copy |
|
38 | 39 |
|
39 | 40 |
from ganeti import utils |
40 | 41 |
from ganeti import objects |
... | ... | |
666 | 667 |
rpc_defs.ED_INST_DICT: self._InstDict, |
667 | 668 |
rpc_defs.ED_INST_DICT_HVP_BEP_DP: self._InstDictHvpBepDp, |
668 | 669 |
rpc_defs.ED_INST_DICT_OSP_DP: self._InstDictOspDp, |
670 |
rpc_defs.ED_NIC_DICT: self._NicDict, |
|
669 | 671 |
|
670 | 672 |
# Encoders annotating disk parameters |
671 | 673 |
rpc_defs.ED_DISKS_DICT_DP: self._DisksDictDP, |
... | ... | |
691 | 693 |
_generated_rpc.RpcClientDnsOnly.__init__(self) |
692 | 694 |
_generated_rpc.RpcClientDefault.__init__(self) |
693 | 695 |
|
696 |
def _NicDict(self, nic): |
|
697 |
"""Convert the given nic to a dict and encapsulate netinfo |
|
698 |
|
|
699 |
""" |
|
700 |
n = copy.deepcopy(nic) |
|
701 |
if n.network: |
|
702 |
net_uuid = self._cfg.LookupNetwork(n.network) |
|
703 |
if net_uuid: |
|
704 |
nobj = self._cfg.GetNetwork(net_uuid) |
|
705 |
n.netinfo = objects.Network.ToDict(nobj) |
|
706 |
return n.ToDict() |
|
707 |
|
|
694 | 708 |
def _InstDict(self, instance, hvp=None, bep=None, osp=None): |
695 | 709 |
"""Convert the given instance to a dict. |
696 | 710 |
|
... | ... | |
721 | 735 |
idict["osparams"] = cluster.SimpleFillOS(instance.os, instance.osparams) |
722 | 736 |
if osp is not None: |
723 | 737 |
idict["osparams"].update(osp) |
738 |
idict["disks"] = self._DisksDictDP((instance.disks, instance)) |
|
724 | 739 |
for nic in idict["nics"]: |
725 | 740 |
nic["nicparams"] = objects.FillDict( |
726 | 741 |
cluster.nicparams[constants.PP_DEFAULT], |
727 | 742 |
nic["nicparams"]) |
728 |
idict["disks"] = self._DisksDictDP((instance.disks, instance)) |
|
743 |
network = nic.get("network", None) |
|
744 |
if network: |
|
745 |
net_uuid = self._cfg.LookupNetwork(network) |
|
746 |
if net_uuid: |
|
747 |
nobj = self._cfg.GetNetwork(net_uuid) |
|
748 |
nic["netinfo"] = objects.Network.ToDict(nobj) |
|
729 | 749 |
return idict |
730 | 750 |
|
731 | 751 |
def _InstDictHvpBepDp(self, (instance, hvp, bep)): |
Also available in: Unified diff