~chad.smith/charms/precise/block-storage-broker/trunk

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Chad Smith
  • Date: 2014-02-07 02:11:11 UTC
  • Revision ID: chad.smith@canonical.com-20140207021111-fcf5lyl9wq6hjgt7
allow optional volume_label specfied in request-volume interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
    """Attach a nova device to the C{instance-id} requested by the relation
56
56
 
57
57
    Optionally the relation can specify:
58
 
        - C{volume-id} to attach an existing volume
 
58
        - C{volume-label} the label to set on the created volume
 
59
        - C{volume-id} to attach an existing volume-id or volume-name
59
60
        - C{size} to request a specific volume size
60
61
    """
61
62
    import nova_util
62
63
    instance_id = hookenv.relation_get('instance-id')
 
64
    volume_label = hookenv.relation_get('volume-label')
63
65
    if not instance_id:
64
66
        hookenv.log("Waiting for relation to define instance-id", INFO)
65
67
        return
66
68
    volume_id = hookenv.relation_get('volume-id')  # optional
67
69
    size = hookenv.relation_get('size')            # optional
68
70
    device_path = nova_util.attach_nova_volume(
69
 
        instance_id=instance_id, volume_id=volume_id, size=size)
 
71
        instance_id=instance_id, volume_id=volume_id, size=size,
 
72
        volume_label=volume_label)
70
73
 
71
74
    # Volume is attached, send the path back to the remote storage unit
72
75
    hookenv.relation_set(relation_settings={"block-device-path": device_path})