Ejemplo n.º 1
0
def main():
    args = parser.parse_args()
    initiator = utils.get_initiator()
    client = utils.build_cinder(args)

    volumes = client.volumes.list(True)
    if args.list:
        for vol in volumes:
            if vol.status == 'in-use':
                print("Name: '%(name)s' %(id)s Size:%(size)sG Type:%(type)s " %
                      {'name': vol.name, 'id': vol.id, 'size': vol.size,
                       'type': vol.volume_type})

        sys.exit(0)

    for vol in volumes:
        if vol.status == 'in-use' and vol.id == args.volume:
            LOG.debug("id = %s", vol.id)
            conn = client.volumes.initialize_connection(vol, initiator)
            LOG.debug("conn = %s", conn)
            sys.exit(-1)
            b = connector.InitiatorConnector.factory(
                conn['driver_volume_type'], 'sudo',
                use_multipath=initiator['multipath'])
            LOG.debug("call resize for %s", conn)
            new_size = b.extend_volume(conn['data'])
            LOG.debug("New size for device = %s" %
                      new_size)
Ejemplo n.º 2
0
def main():
    setup_logging()
    args = parser.parse_args()
    CONF([], project='brick_volume',
         default_config_files=['/etc/cinder/cinder.conf'])
    client = utils.build_cinder(args)
    initiator = utils.get_initiator()

    volumes = client.volumes.list(True)
    if args.list:
        for vol in volumes:
            if (vol.status == 'available'):
                print("Name: '%(name)s' %(id)s Size:%(size)sG Type:%(type)s " %
                      {'name': vol.name, 'id': vol.id, 'size': vol.size,
                       'type': vol.volume_type})

        sys.exit(0)

    for vol in volumes:
        if (vol.status == 'available' and
                vol.id == args.volume):
            context = cinder_ctxt.get_admin_context()
            vol_handle = attach_volume(context, client, vol, initiator)
            try:
                if args.oper == 'w':
                    write_data(vol_handle['path'], args.data)
                else:
                    read_data(vol_handle['path'])
            finally:
                detach_volume(context, client, vol,
                              vol_handle['path'], initiator)
Ejemplo n.º 3
0
def main():
    """The main."""
    args = parser.parse_args()
    initiator = utils.get_initiator()
    client = utils.build_cinder(args)

    volumes = client.volumes.list(True)
    if args.list:
        for vol in volumes:
            if vol.status == 'in-use':
                print("Name: '%(name)s' %(id)s Size:%(size)sG Type:%(type)s " %
                      {'name': vol.name, 'id': vol.id, 'size': vol.size,
                       'type': vol.volume_type})

        sys.exit(0)

    info = dict()
    volume = client.volumes.get(args.volume)
    info['id'] = volume._info['id']
    info['encrypted'] = volume._info['encrypted']
    info['multiattach'] = volume._info['multiattach']
    info['status'] = volume._info['status']
    info['host'] = volume._info['os-vol-host-attr:host']
    info['size'] = volume._info['size']
    info['volume_type'] = volume._info['volume_type']
    info['attachments'] = volume._info['attachments']
    # info.update(volume._info)
    info.pop('links', None)

    # now fetch the volume paths
    if volume.status == 'in-use':
        conn = client.volumes.initialize_connection(volume, initiator)
        b = connector.InitiatorConnector.factory(
            conn['driver_volume_type'], 'sudo',
            use_multipath=initiator['multipath'])
        info['system-paths'] = b.get_volume_paths(conn['data'])

    utils.print_dict(info, value_align='l', disable_unicode=True)