This is method is handling two separate cases 1) multi_nic and 2) no
multi_nice. Since it's pretty long, I think it's a good canidate to be broken
up into two smaller methods, something like:
def inject_network_info_multi_nic(self, instance, network_info):
# multi-nic stuff here
return networks
def inject_network_info_default(self, instance):
# old code here
return networks
If possible, it's a good idea to have the inject_network_info stuff continue
to return `networks`; this is more consistent and allows you to make the
simplification noted above.
Looks like there's an opportunity to DRY up the code a bit. Looks like both
multi-nic and default both do something like
for network in networks:
try: self.write_to_xenstore(vm_ref, location, mapping['location'])
except KeyError:
# catch KeyError for domid if instance isn't running
pass
Nice work, Trey. Here are my thoughts so far (mostly style stuff):
> 9 + def spawn(self, instance, network_info=None):
Not exposed from xenapi_conn.py?
Are all virt-drivers going to accept a network_info=None kwarg?
> 25 + if network_info is not None: network_ info(instance, network_info) vifs(instance, [nw for (nw, mapping) in network_info]) network_ info(instance) vifs(instance, networks)
> 26 + self.inject_
> 27 + self.create_
> 28 + else:
> 29 + # TODO(tr3buchet) - goes away with multi-nic
> 30 + networks = self.inject_
> 31 + self.create_
It seems like we should be able to simplify all of that to:
networks = self.inject_ network_ info(instance, network_info) create_ vifs(instance, networks)
self.
Assuming `inject_ network_ info` returns `networks` correctly for both the
network_info=None and network_info!=None cases.
> def inject_ network_ info(self, instance, network_info=None):
This is method is handling two separate cases 1) multi_nic and 2) no
multi_nice. Since it's pretty long, I think it's a good canidate to be broken
up into two smaller methods, something like:
def inject_ network_ info(self, instance, network_info=None):
networks = self.inject_ network_ info_multi_ nic(self, instance, network_info)
networks = self.inject_ network_ info_default( self, instance)
if network_info:
else:
return networks
def inject_ network_ info_multi_ nic(self, instance, network_info):
# multi-nic stuff here
return networks
def inject_ network_ info_default( self, instance):
# old code here
return networks
If possible, it's a good idea to have the inject_network_info stuff continue
to return `networks`; this is more consistent and allows you to make the
simplification noted above.
> 59 + self.write_ to_param_ xenstore( vm_ref, {location: mapping})
Syntax error. {'location': mapping}
> 61 + self.write_ to_xenstore( vm_ref, location, 'location' ])
> 62 + mapping[
Appears misaligned. Seems like we have to 'accepted' conventions here:
1. Line-up with the first arg write_to_ xenstore( vm_ref, location,
mapping[ 'location' ])
self.
2. +1 level hanging indent write_to_ xenstore( vm_ref, location,
mapping[ 'location' ])
self.
OR
self. write_to_ xenstore( 'location' ])
vm_ref, location, mapping[
Looks like there's an opportunity to DRY up the code a bit. Looks like both
multi-nic and default both do something like
for network in networks:
self. write_to_ xenstore( vm_ref, location,
mapping[ 'location' ])
try:
except KeyError:
# catch KeyError for domid if instance isn't running
pass
There should be a way of extracting that out.