~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/virt/vmwareapi/vm_util.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-08-09 10:12:27 UTC
  • mfrom: (1.1.74)
  • Revision ID: package-import@ubuntu.com-20130809101227-4n60fzcgra8dzk3d
Tags: 1:2013.1.3-0ubuntu1
* Resynchronize with stable/grizzly (89c7ee4) (LP: #1210447):
  - [8e6edd2] Bump stable/grizzly next version to 2013.1.3
  - [61fc529] attach quantum security group to an existing vm failed
    LP: 1189059
  - [60774bd] nova-compute fails to start if quantum is down LP: 1186357
  - [8e6d4b6] asymmetric routes in nova network with external gateway and
    routing_source_ip LP: 1182143
  - [8849413] Failed VM's not set to error state on exception LP: 1182056
  - [ef10eee] Double healing of info_cache with cells LP: 1180304
  - [7422d83] Can't log into  VM after powervm is resized LP: 1169848
  - [49ab0e8] stack trace when instance_actions extension can not find
    instance in GET LP: 1182867
  - [e71247c] nova service-list returns illegal result with non db service
    heartbeat LP: 1168861
  - [3f60606] Volume IO usage gets reset to 0 after a reboot / crash
    LP: 1169097
  - [19c443b] unused method  list_interfaces in vmware driver can be removed
    LP: 1187251
  - [a8dab9f] No cleanup done when file transfer fails with powervm driver
    LP: 1173017
  - [fc98015] nova consoleauth depends on Conductor Service LP: 1186123
  - [1066418] VMware drivers are no longer passing quantum port-id to
    vCenter LP: 1183452
  - [b92075c] nova net-list fails on empty list with Quantum backend
    LP: 1189976
  - [3ba31f2] Create VM with no networks with Quantum Gives SecurityGroups
    Exception LP: 1191044
  - [89150b2] Periodic ValueErrors when using qpid LP: 1185465
  - [0e0d615] Libvirt pre-Grizzly instances cannot be block migrated
    LP: 1185588
  - [27960ef] ZMQ ipc socket file is created using un-sanitized network
    input LP: 1122763
  - [265b868] cannot block migrate old style instances libvirt complains
    LP: 1175286
  - [008a68a] code logical error exists in vmwareapi vif.py  LP: 1177635
  - [378c045] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [48ddffe] Reboot of compute node breaks VMs with volumes LP: 1188326
  - [f427f01] Missing dashes from console-log LP: 1194032
  - [78ebf1a] network-create returns an internal error when network
    conflicts LP: 1158075
  - [767c850] Instance nics are reorder after reboot LP: 1187092
  - [0b45996] instance directory naming update to use uuid  LP: 1186944
  - [06cfad5] Disassociate failed dhcp fixed ip in deallocate_for_instance()
    method LP: 1180766
  - [cbcdfc5] Allow confirm_resize action on an instance in 'deleting'
    status LP: 1189391
  - [2563c44] aggregate_get_by_host returns aggregates from other hosts
    LP: 1201277
  - [109f3a9] nova libvirt driver requires iscsi initiator name regardless
    of using it in volume drivers LP: 1007084
  - [7f1c336] Host is always set to None in get_instance_nw_info(...)
    LP: 1194178
  - [1cf30a3] nova boot with colume should fail if the volume is already
    attached to another instance LP: 1166770
  - [9cb9361] Aggregate metadata filtering by key returns unrelated metadata
    LP: 1201283
  - [a61872b] Need clean up  ftp transfer faiure  in powervm driver
    LP: 1188884
  - [91bcd15] Race can cause soft deleted instance to be erased by mistake
    LP: 1186243
  - [c57fded] Nova fails to create a security group rule if ::0/0 is used as
    cidr LP: 1199943
  - [c698dd3] VMwareESXDriver and VMwareVCDriver report incorrect stat
    LP: 1180779
  - [e572faf] novnc fails when amqp_rpc_single_reply_queue=True LP: 1193031
  - [34ddd27] eventlet.monkey_patch() for spice and vnc proxy
  - [864837f] hypervisor_hostname not updated on evacuate LP: 1198284
  - [756a772] libvirt migrate/resize on shared storage can cause data loss
    LP: 1177247
  - [889b215] nova live-migration of volume-backed VM fails because of image
    is None LP: 1199811
  - [60712a4] VNC console does not work with VCDriver LP: 1178369
  - [e0aa0f5] metadata service throws error 500 when compute_driver is not
    set LP: 1184641
  - [340d337] Instance IP addresses are re-used even when previous instance
    could not be powered off LP: 1180178
  - [8247dc8] Resource limit circumvention in Nova private flavors
    (CVE-2013-2256) LP: 1194093
  - [bd7e467] Denial of Service in Nova network source security groups
    (CVE-2013-4185) LP: 1184041
  - [c3fddb7] Resize a VM when a volume is attached fails LP: 1190364
  - [01edbaa] Hyper-V versions before 2012 are not properly recognized
    LP: 1203059
  - [b18818a] driver libvirt doesn't honor vif quota LP: 1185030
  - [798984d] config drive not visible to windows LP: 1155842
  - [d18ceb1] nova live-migration failed due to exception.MigrationError
    LP: 1171526
  - [1934dbc] vmware Hyper for nova vnc console url parameters error
    LP: 1172177
  - [89c7ee4] [OSSA 2013-023] Potential unsafe XML usage (CVE-2013-4179,
    CVE-2013-4202) LP: 1190229
* debian/rules: Clean new setuptools-git cruft.
* debian/control: Update Vcs fields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
"""
21
21
 
22
22
import copy
 
23
 
23
24
from nova import exception
24
25
from nova.virt.vmwareapi import vim_util
25
26
 
47
48
                       vif_infos, os_type="otherGuest"):
48
49
    """Builds the VM Create spec."""
49
50
    config_spec = client_factory.create('ns0:VirtualMachineConfigSpec')
50
 
    config_spec.name = instance['name']
 
51
    config_spec.name = instance['uuid']
51
52
    config_spec.guestId = os_type
52
53
 
53
54
    vm_file_info = client_factory.create('ns0:VirtualMachineFileInfo')
126
127
    network_spec = client_factory.create('ns0:VirtualDeviceConfigSpec')
127
128
    network_spec.operation = "add"
128
129
 
129
 
    # Get the recommended card type for the VM based on the guest OS of the VM
130
 
    net_device = client_factory.create('ns0:VirtualPCNet32')
 
130
    # Keep compatible with other Hyper vif model parameter.
 
131
    if vif_info['vif_model'] == "e1000":
 
132
        vif_info['vif_model'] = "VirtualE1000"
 
133
 
 
134
    vif = 'ns0:' + vif_info['vif_model']
 
135
    net_device = client_factory.create(vif)
131
136
 
132
137
    # NOTE(asomya): Only works on ESXi if the portgroup binding is set to
133
138
    # ephemeral. Invalid configuration if set to static and the NIC does
499
504
    return None
500
505
 
501
506
 
 
507
def get_vm_ref_from_uuid(session, instance_uuid):
 
508
    """Get reference to the VM with the uuid specified."""
 
509
    vms = session._call_method(vim_util, "get_objects",
 
510
                "VirtualMachine", ["name"])
 
511
    for vm in vms:
 
512
        if vm.propSet[0].val == instance_uuid:
 
513
            return vm.obj
 
514
 
 
515
 
 
516
def get_vm_ref(session, instance):
 
517
    """Get reference to the VM through uuid or vm name."""
 
518
    vm_ref = get_vm_ref_from_uuid(session, instance['uuid'])
 
519
    if not vm_ref:
 
520
        vm_ref = get_vm_ref_from_name(session, instance['name'])
 
521
    if vm_ref is None:
 
522
        raise exception.InstanceNotFound(instance_id=instance['uuid'])
 
523
    return vm_ref
 
524
 
 
525
 
 
526
def get_host_ref_from_id(session, host_id, property_list=None):
 
527
    """Get a host reference object for a host_id string."""
 
528
 
 
529
    if property_list is None:
 
530
        property_list = ['name']
 
531
 
 
532
    host_refs = session._call_method(
 
533
                    vim_util, "get_objects",
 
534
                    "HostSystem", property_list)
 
535
 
 
536
    for ref in host_refs:
 
537
        if ref.obj.value == host_id:
 
538
            return ref
 
539
 
 
540
 
 
541
def get_host_id_from_vm_ref(session, vm_ref):
 
542
    """
 
543
    This method allows you to find the managed object
 
544
    ID of the host running a VM. Since vMotion can
 
545
    change the value, you should not presume that this
 
546
    is a value that you can cache for very long and
 
547
    should be prepared to allow for it to change.
 
548
 
 
549
    :param session: a vSphere API connection
 
550
    :param vm_ref: a reference object to the running VM
 
551
    :return: the host_id running the virtual machine
 
552
    """
 
553
 
 
554
    # to prevent typographical errors below
 
555
    property_name = 'runtime.host'
 
556
 
 
557
    # a property collector in VMware vSphere Management API
 
558
    # is a set of local representations of remote values.
 
559
    # property_set here, is a local representation of the
 
560
    # properties we are querying for.
 
561
    property_set = session._call_method(
 
562
            vim_util, "get_object_properties",
 
563
            None, vm_ref, vm_ref._type, [property_name])
 
564
 
 
565
    prop = property_from_property_set(
 
566
        property_name, property_set)
 
567
 
 
568
    if prop is not None:
 
569
        prop = prop.val.value
 
570
    else:
 
571
        # reaching here represents an impossible state
 
572
        raise RuntimeError(
 
573
            "Virtual Machine %s exists without a runtime.host!"
 
574
            % (vm_ref))
 
575
 
 
576
    return prop
 
577
 
 
578
 
 
579
def property_from_property_set(property_name, property_set):
 
580
    '''
 
581
    Use this method to filter property collector results.
 
582
 
 
583
    Because network traffic is expensive, multiple
 
584
    VMwareAPI calls will sometimes pile-up properties
 
585
    to be collected. That means results may contain
 
586
    many different values for multiple purposes.
 
587
 
 
588
    This helper will filter a list for a single result
 
589
    and filter the properties of that result to find
 
590
    the single value of whatever type resides in that
 
591
    result. This could be a ManagedObjectReference ID
 
592
    or a complex value.
 
593
 
 
594
    :param property_name: name of property you want
 
595
    :param property_set: all results from query
 
596
    :return: the value of the property.
 
597
    '''
 
598
 
 
599
    for prop in property_set:
 
600
        p = _property_from_propSet(prop.propSet, property_name)
 
601
        if p is not None:
 
602
            return p
 
603
 
 
604
 
 
605
def _property_from_propSet(propSet, name='name'):
 
606
    for p in propSet:
 
607
        if p.name == name:
 
608
            return p
 
609
 
 
610
 
 
611
def get_host_ref_for_vm(session, instance, props):
 
612
    """Get the ESXi host running a VM by its name."""
 
613
 
 
614
    vm_ref = get_vm_ref(session, instance)
 
615
    host_id = get_host_id_from_vm_ref(session, vm_ref)
 
616
    return get_host_ref_from_id(session, host_id, props)
 
617
 
 
618
 
 
619
def get_host_name_for_vm(session, instance):
 
620
    """Get the ESXi host running a VM by its name."""
 
621
    host_ref = get_host_ref_for_vm(session, instance, ['name'])
 
622
    return get_host_name_from_host_ref(host_ref)
 
623
 
 
624
 
 
625
def get_host_name_from_host_ref(host_ref):
 
626
    p = _property_from_propSet(host_ref.propSet)
 
627
    if p is not None:
 
628
        return p.val
 
629
 
 
630
 
502
631
def get_cluster_ref_from_name(session, cluster_name):
503
632
    """Get reference to the cluster with the name specified."""
504
633
    cls = session._call_method(vim_util, "get_objects",