コード例 #1
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_server(req, db, context, server_id):
    server = find_server(db, context, server_id);

    name = get_input(req, 'name')
    if name:
        server.name = name
    
    owner_id = get_input(req, 'owner')
    if owner_id:
        owner = find_user(db, context, owner_id)
        server.owner = owner_id
        server.dept = owner.dept_id

    db.add(server)
    db.commit()

    action = get_input(req, 'action') 
    if action:
        if action == 'start':
            return start_server(server)
        elif action == 'stop':
            return stop_server(server)
        elif action == 'suspend':
            return suspend_server(server)
        elif action == 'resume':
            return resume_server(server)
        elif action == 'get_console':
            return get_console(req, db, server)
        elif action == 'take_snapshot':
            return take_snapshot(req, db, context, server)
        else:
            raise UnsupportedOperationError(action)
コード例 #2
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_server(req, db, context, server_id):
    server = find_server(db, context, server_id)

    name = get_input(req, 'name')
    if name:
        server.name = name

    owner_id = get_input(req, 'owner')
    if owner_id:
        owner = find_user(db, context, owner_id)
        server.owner = owner_id
        server.dept = owner.dept_id

    db.add(server)
    db.commit()

    action = get_input(req, 'action')
    if action:
        if action == 'start':
            return start_server(server)
        elif action == 'stop':
            return stop_server(server)
        elif action == 'suspend':
            return suspend_server(server)
        elif action == 'resume':
            return resume_server(server)
        elif action == 'get_console':
            return get_console(req, db, server)
        elif action == 'take_snapshot':
            return take_snapshot(req, db, context, server)
        else:
            raise UnsupportedOperationError(action)
コード例 #3
0
def get_data(req, db, context, data_type):
    if data_type not in supported_datatype:
        raise MonitorDataTypeNotSupportedError(data_type)

    host = get_required_input(req, 'hostname')

    from_time = get_input(req, "from_time")
    if from_time == None or from_time == '':
        from_time = (get_current_time() - 600) * 1000  # 缺省查询10分钟的数据
    else:
        from_time = int(from_time)

    to_time = get_input(req, "to_time")
    if to_time == None or to_time == '':
        to_time = get_current_time() * 1000
    else:
        to_time = int(to_time)

    interval = get_input(req, "interval")
    if interval == None or interval == '':
        interval = 60 * 1000  # 缺省间隔1分钟
    else:
        interval = int(interval)

    if data_type == "cpu":
        return get_cpu_data(host, from_time, to_time, interval)
    elif data_type == "memory":
        return get_memory_data(host, from_time, to_time, interval)
    elif data_type == "load":
        return get_load_data(host, from_time, to_time, interval)
コード例 #4
0
ファイル: monitor.py プロジェクト: jiangwu1911/jwu_cloud_api
def get_data(req, db, context, data_type):
    if data_type not in supported_datatype:
        raise MonitorDataTypeNotSupportedError(data_type)     

    host = get_required_input(req, 'hostname')

    from_time = get_input(req, "from_time")
    if from_time==None or from_time=='':
        from_time = (get_current_time() - 600) * 1000      # 缺省查询10分钟的数据
    else: 
        from_time = int(from_time)

    to_time = get_input(req, "to_time")
    if to_time==None or to_time=='':
        to_time = get_current_time() * 1000              
    else: 
        to_time = int(to_time)

    interval = get_input(req, "interval")
    if interval==None or interval=='':
        interval = 60 * 1000                                # 缺省间隔1分钟
    else:
        interval = int(interval)

    if data_type == "cpu":
        return get_cpu_data(host, from_time, to_time, interval)
    elif data_type == "memory":
        return get_memory_data(host, from_time, to_time, interval)
    elif data_type == "load":
        return get_load_data(host, from_time, to_time, interval)
コード例 #5
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def create_flavor(req, db, context):
    name = get_required_input(req, 'name')
    vcpus = get_required_input(req, 'vcpus')
    ram = get_required_input(req, 'ram')
    disk = get_required_input(req, 'disk')
    ephemeral = get_input(req, 'ephemeral') 
    swap = get_input(req, 'swap')

    flavor = admin_nova_client().flavors.create(name, ram, vcpus, disk,
                                              flavorid='auto', 
                                              ephemeral=ephemeral,
                                              swap=swap,
                                              is_public=True)
    return {'flavor': flavor.to_dict()}
コード例 #6
0
ファイル: snapshot.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_snapshot(req, db, context, id):
    snapshot = find_snapshot(db, context, id);

    name = get_input(req, 'name')
    if name:
        snapshot.name = name

    owner_id = get_input(req, 'owner')
    if owner_id:
        owner = find_user(db, context, owner_id)
        snapshot.owner = owner_id
        snapshot.dept = owner.dept_id

    db.add(snapshot)
    db.commit()
コード例 #7
0
def update_snapshot(req, db, context, id):
    snapshot = find_snapshot(db, context, id)

    name = get_input(req, 'name')
    if name:
        snapshot.name = name

    owner_id = get_input(req, 'owner')
    if owner_id:
        owner = find_user(db, context, owner_id)
        snapshot.owner = owner_id
        snapshot.dept = owner.dept_id

    db.add(snapshot)
    db.commit()
コード例 #8
0
def list_hypervisor(req, db, context):
    action = get_input(req, "action")
    if action == "stats":
        return hopervisor_stats(db, context)
    else:
        results = admin_nova_client().hypervisors.list()
        return obj_array_to_json(results, "hypervisors")
コード例 #9
0
def list_hypervisor(req, db, context):
    action = get_input(req, 'action')
    if action == 'stats':
        return hopervisor_stats(db, context)
    else:
        results = admin_nova_client().hypervisors.list()
        return obj_array_to_json(results, 'hypervisors')
コード例 #10
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def create_flavor(req, db, context):
    name = get_required_input(req, 'name')
    vcpus = get_required_input(req, 'vcpus')
    ram = get_required_input(req, 'ram')
    disk = get_required_input(req, 'disk')
    ephemeral = get_input(req, 'ephemeral')
    swap = get_input(req, 'swap')

    flavor = admin_nova_client().flavors.create(name,
                                                ram,
                                                vcpus,
                                                disk,
                                                flavorid='auto',
                                                ephemeral=ephemeral,
                                                swap=swap,
                                                is_public=True)
    return {'flavor': flavor.to_dict()}
コード例 #11
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def get_console(req, db, server):
    console_type = get_input(req, 'console_type');
    if console_type==None or console_type=='':
        console_type = 'novnc'

    ret = nova_client().servers.get_vnc_console(server.instance_id,
                                                console_type)
    server.console_url = ret['console']['url']
    db.add(server)
    db.commit()
    return ret
コード例 #12
0
ファイル: image.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_image(req, db, context, image_id):
    image = find_image(db, context, image_id)
    if image == None:
        raise ImageNotFoundError(image_id)

    name = get_input(req, 'name')
    if name:
        image.name = name

    db.add(image)
    db.commit()
コード例 #13
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def get_console(req, db, server):
    console_type = get_input(req, 'console_type')
    if console_type == None or console_type == '':
        console_type = 'novnc'

    ret = nova_client().servers.get_vnc_console(server.instance_id,
                                                console_type)
    server.console_url = ret['console']['url']
    db.add(server)
    db.commit()
    return ret
コード例 #14
0
ファイル: image.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_image(req, db, context, image_id):
    image = find_image(db, context, image_id)
    if image == None:
        raise ImageNotFoundError(image_id)

    name = get_input(req, 'name')
    if name:
        image.name = name

    db.add(image)
    db.commit()
コード例 #15
0
ファイル: volume.py プロジェクト: jiangwu1911/jwu_cloud_api
def attach(req, db, context, volume):
    server_id = get_required_input(req, 'server_id')
    device = get_input(req, 'device')
    server = find_server(db, context, server_id)

    nova_client().volumes.create_server_volume(server.instance_id,
                                               volume.volume_id, device)
    volume.status = 'attaching'
    volume.owner = server.owner
    db.add(volume)
    db.commit()
コード例 #16
0
ファイル: volume.py プロジェクト: jiangwu1911/jwu_cloud_api
def attach(req, db, context, volume):
    server_id = get_required_input(req, 'server_id')
    device = get_input(req, 'device')
    server = find_server(db, context, server_id)

    nova_client().volumes.create_server_volume(server.instance_id,
                                             volume.volume_id,
                                             device)
    volume.status = 'attaching'
    volume.owner = server.owner
    db.add(volume)
    db.commit()
コード例 #17
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_flavor(req, db, context, flavor_id):
    name = get_input(req, 'name')
    vcpus = get_input(req, 'vcpus')
    ram = get_input(req, 'ram')
    disk = get_input(req, 'disk')
    ephemeral = get_input(req, 'ephemeral')
    swap = get_input(req, 'swap')

    f = nova_client().flavors.get(flavor_id)

    if name==None or name=='':
        name = f.name
    if vcpus==None or name=='':
        vcpus = f.vcpus
    if ram==None or ram=='':
        ram = f.ram
    if disk==None or disk=='':
        disk = f.disk
    if ephemeral==None or ephemeral=='':
        ephemeral = f.ephemeral
    if swap==None or swap=='':
        swap = f.swap
        if swap == '':
            swap = 0

    admin_nova_client().flavors.delete(flavor_id)
        
    flavor = admin_nova_client().flavors.create(name, int(ram), int(vcpus), int(disk),
                                              flavorid=flavor_id,
                                              ephemeral=int(ephemeral),
                                              swap=int(swap),
                                              is_public=True)
    return {'flavor': flavor.to_dict()}
コード例 #18
0
ファイル: volume.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_volume(req, db, context, id):
    volume = find_volume(db, context, id);

    name = get_input(req, 'name')
    if name:
        volume.name = name

    owner_id = get_input(req, 'owner')
    if owner_id:
        owner = find_user(db, context, owner_id)
        volume.owner = owner_id
        volume.dept = owner.dept_id

    db.add(volume)
    db.commit()

    action = get_input(req, 'action')
    if action:
        if action == 'attach':
            return attach(req, db, context, volume)
        elif action == 'detach':
            return detach(req, db, context, volume)
        else:
            raise UnsupportedOperationError(action)
コード例 #19
0
ファイル: volume.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_volume(req, db, context, id):
    volume = find_volume(db, context, id)

    name = get_input(req, 'name')
    if name:
        volume.name = name

    owner_id = get_input(req, 'owner')
    if owner_id:
        owner = find_user(db, context, owner_id)
        volume.owner = owner_id
        volume.dept = owner.dept_id

    db.add(volume)
    db.commit()

    action = get_input(req, 'action')
    if action:
        if action == 'attach':
            return attach(req, db, context, volume)
        elif action == 'detach':
            return detach(req, db, context, volume)
        else:
            raise UnsupportedOperationError(action)
コード例 #20
0
ファイル: server.py プロジェクト: jiangwu1911/jwu_cloud_api
def update_flavor(req, db, context, flavor_id):
    name = get_input(req, 'name')
    vcpus = get_input(req, 'vcpus')
    ram = get_input(req, 'ram')
    disk = get_input(req, 'disk')
    ephemeral = get_input(req, 'ephemeral')
    swap = get_input(req, 'swap')

    f = nova_client().flavors.get(flavor_id)

    if name == None or name == '':
        name = f.name
    if vcpus == None or name == '':
        vcpus = f.vcpus
    if ram == None or ram == '':
        ram = f.ram
    if disk == None or disk == '':
        disk = f.disk
    if ephemeral == None or ephemeral == '':
        ephemeral = f.ephemeral
    if swap == None or swap == '':
        swap = f.swap
        if swap == '':
            swap = 0

    admin_nova_client().flavors.delete(flavor_id)

    flavor = admin_nova_client().flavors.create(name,
                                                int(ram),
                                                int(vcpus),
                                                int(disk),
                                                flavorid=flavor_id,
                                                ephemeral=int(ephemeral),
                                                swap=int(swap),
                                                is_public=True)
    return {'flavor': flavor.to_dict()}