857
857
what VMHelper.lookup(session, instance.name) will find (ex: rescue)
859
859
logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref)
862
# this function raises if vm_ref is not a vm_opaque_ref
863
self._session.get_xenapi().VM.get_record(vm_ref)
865
vm_ref = VMHelper.lookup(self._session, instance.name)
867
for (network, info) in network_info:
868
location = 'vm-data/networking/%s' % info['mac'].replace(':', '')
869
self.write_to_param_xenstore(vm_ref, {location: info})
871
# TODO(tr3buchet): fix function call after refactor
872
#self.write_to_xenstore(vm_ref, location, info)
873
self._make_plugin_call('xenstore.py', 'write_record', instance,
874
location, {'value': json.dumps(info)},
877
# catch KeyError for domid if instance isn't running
860
#TODO: do something here!!!!!!
861
agent_driver_name = FLAGS.xenapi_guest_agent_driver
862
agent_driver = utils.import_object(agent_driver_name)
863
agent_driver.inject_network_info(self, instance, network_info, vm_ref)
880
865
def create_vifs(self, vm_ref, network_info):
881
866
"""Creates vifs for an instance."""
1069
def add_to_param_xenstore(self, instance_or_vm, key, val):
1054
def add_to_param_xenstore(self, instance_or_vm, key, val, json_dump=True):
1071
1056
Takes a key/value pair and adds it to the xenstore parameter
1072
1057
record for the given vm instance. If the key exists in xenstore,
1075
1060
vm_ref = self._get_vm_opaque_ref(instance_or_vm)
1076
1061
self.remove_from_param_xenstore(instance_or_vm, key)
1077
jsonval = json.dumps(val)
1063
val = json.dumps(val)
1078
1064
self._session.call_xenapi_request('VM.add_to_xenstore_data',
1079
(vm_ref, key, jsonval))
1081
def write_to_param_xenstore(self, instance_or_vm, mapping):
1067
def write_to_param_xenstore(self, instance_or_vm, mapping, json_dump=True):
1083
1069
Takes a dict and writes each key/value pair to the xenstore
1084
1070
parameter record for the given vm instance. Any existing data for
1085
1071
those keys is overwritten.
1087
1073
for k, v in mapping.iteritems():
1088
self.add_to_param_xenstore(instance_or_vm, k, v)
1074
self.add_to_param_xenstore(instance_or_vm, k, v, json_dump)
1090
1076
def remove_from_param_xenstore(self, instance_or_vm, key_or_keys):