示例#1
0
def get_by_id(id):
    nova = commons.nova_client(request.args.get('key'))
    servers = nova.servers.list(search_opts={'id': id})
    if servers and len(servers):
        return mappers.server_to_view(servers[0]), 201
    else:
        return errors.http_notfound()
示例#2
0
def get_by_id(id):
    glance = commons.glance_client(request.args.get('key'))
    images = glance.images.list(filters={'id': id})
    if not images or not len(images):
        return errors.http_notfound()
    image = images[0]
    return jsonify(mappers.image_to_view(image)), 201
示例#3
0
def get_by_id(id):
    neutron = commons.neutron_client(request.args.get('key'))
    networks = neutron.list_networks(id=id)
    if networks and len(networks):
        return jsonify(mappers.network_to_view(networks[0]))
    else:
        return errors.http_notfound()
示例#4
0
def detach(id):
    cinder = commons.cinder_client(request.args.get('key'))
    volumes = cinder.volumes.list(search_opts={'id': id})
    if not volumes or not len(volumes):
        return errors.http_notfound()
    volume = volumes[0]
    cinder.volumes.detach(volume)
    return jsonify(success=True)
示例#5
0
def shelve(id):
    nova = commons.nova_client(request.args.get('key'))
    server = nova.servers.find(id=id)
    if server:
        server.shelve()
        return jsonify(success=True)
    else:
        return errors.http_notfound()
示例#6
0
def get_by_id(id):
    cinder = commons.cinder_client(request.args.get('key'))
    volumes = cinder.volumes.list(search_opts={'id': id})
    if volumes and len(volumes):
        print(dir(volumes[0]))
        print(volumes[0].attachments)
        return jsonify(mappers.volume_to_view(volumes[0])), 201
    else:
        return errors.http_notfound()
示例#7
0
def get_diagnostics_by_id(id):
    nova = commons.nova_client(request.args.get('key'))
    servers = nova.servers.list(search_opts={'id': id})
    if servers and len(servers):
        server = servers[0]
        response, diagnostics = server.diagnostics()
        return jsonify(diagnostics)
    else:
        return errors.http_notfound()
示例#8
0
def attach(id):
    cinder = commons.cinder_client(request.args.get('key'))
    volumes = cinder.volumes.list(search_opts={'id': id})
    if not volumes or not len(volumes):
        return errors.http_notfound()
    volume = volumes[0]
    cinder.volumes.attach(volume,
                          request.json['server'],
                          mountpoint=request.json['mountpoint'])
    return jsonify(success=True)
示例#9
0
def get():
    neutron = commons.neutron_client(request.args.get('key'))
    kwargs = {}
    name = request.args.get('name')
    if name:
        kwargs['name'] = name
    networks = neutron.list_networks(**kwargs)
    if networks and networks['networks']:
        return jsonify(
            list(
                map(lambda network: mappers.network_to_view(network),
                    networks['networks']))), 201
    else:
        return errors.http_notfound()
示例#10
0
def get_by_id(id):
    nova = commons.nova_client(request.args.get('key'))
    flavor = nova.flavors.find(id=id)
    if not flavor:
        return errors.http_notfound()
    return jsonify(mappers.flavor_to_view(flavor)), 201