def attach(env): """Map an existing vlmc Image to a block device This function maps an existing vlmc Image to a block device e.g. /dev/xsegbd{X} and returns the device path. If the mapping already exists, it returns the corresponding device path. """ name = env.get("name") # Check if the mapping already exists d_id = vlmc.is_mapped(name) if d_id is not None: sys.stderr.write("The mapping exists for %s\n" % name) # The mapping exists. Return it. sys.stdout.write("%s" % str(DEVICE_PREFIX + str(d_id))) return 0 # The mapping doesn't exist. Create it. d_id = vlmc.map_volume(name=name) # The device was successfully mapped. Return it. #maybe assert (d_id == vlmc.is_mapped(name) sys.stdout.write("%s" % str(DEVICE_PREFIX + str(d_id))) sys.stderr.write("Create the mapping for %s\n" % name) return 0
def detach(env): """Unmap a vlmc device from the Image it is mapped to This function unmaps an vlmc device from the Image it is mapped to. It is idempotent if the mapping doesn't exist at all. """ name = env.get("name") #try: # Check if the mapping already exists d_id = vlmc.is_mapped(name) if d_id is not None: # The mapping exists. Unmap the vlmc device. vlmc.unmap_volume(name=str(DEVICE_PREFIX + str(d_id))) #assert(vlmc.is_mapped(name) == None) return 0
def detach(env): """Unmap a vlmc device from the Image it is mapped to This function unmaps an vlmc device from the Image it is mapped to. It is idempotent if the mapping doesn't exist at all. """ name = env.get("name") #try: # Check if the mapping already exists d_id = vlmc.is_mapped(name) if d_id: # The mapping exists. Unmap the vlmc device. vlmc.unmap_volume(name=str(DEVICE_PREFIX + str(d_id))) #assert(vlmc.is_mapped(name) == None) return 0