~renukaapte/nova/iscsi-refactor-minor

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/vmops.py

  • Committer: Salvatore Orlando
  • Date: 2011-05-06 09:58:57 UTC
  • Revision ID: salvatore.orlando@eu.citrix.com-20110506095857-qgtlzb6mwt8hc3aw
IP Injection for windows using XenServer tools

Show diffs side-by-side

added added

removed removed

Lines of Context:
857
857
        what VMHelper.lookup(session, instance.name) will find (ex: rescue)
858
858
        """
859
859
        logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref)
860
 
 
861
 
        if 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)
864
 
        else:
865
 
            vm_ref = VMHelper.lookup(self._session, instance.name)
866
 
 
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})
870
 
            try:
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)},
875
 
                                       vm_ref)
876
 
            except KeyError:
877
 
                # catch KeyError for domid if instance isn't running
878
 
                pass
 
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)
879
864
 
880
865
    def create_vifs(self, vm_ref, network_info):
881
866
        """Creates vifs for an instance."""
1066
1051
                ret[key] = raw
1067
1052
        return ret
1068
1053
 
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):
1070
1055
        """
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,
1074
1059
        """
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)
 
1062
        if json_dump:
 
1063
            val = json.dumps(val)
1078
1064
        self._session.call_xenapi_request('VM.add_to_xenstore_data',
1079
 
                                          (vm_ref, key, jsonval))
 
1065
                                          (vm_ref, key, val))
1080
1066
 
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):
1082
1068
        """
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.
1086
1072
        """
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)
1089
1075
 
1090
1076
    def remove_from_param_xenstore(self, instance_or_vm, key_or_keys):
1091
1077
        """