Example #1
0
def test_add_task():
    global imageA
    global imageB
    global test_taskA
    global test_taskB
    from corecluster.cache.task import Task

    assert imageA.last_task == None
    assert imageB.last_task == None

    test_taskA = Task()
    test_taskA.type = 'queue_a'
    test_taskA.state = 'not active'
    test_taskA.action = 'test_action'
    test_taskA.append_to([imageA, imageB])

    assert test_taskA.blockers == []

    test_taskB = Task()
    test_taskB.type = 'queue_b'
    test_taskB.state = 'not active'
    test_taskB.action = 'test_action'
    test_taskB.append_to([imageA, imageB])

    assert test_taskB.blockers == [
        test_taskA.cache_key(), test_taskA.cache_key()
    ]
Example #2
0
def start(context, network_id, gateway_ip):
    """
    Start DHCP server(s) in isolated network.
    :param network_id: Isolated network, which should be connected with new VPN server
    :param gateway_ip: Gateway ip for isolated network.
    """

    network = Subnet.get(context.user_id, network_id)

    if network.network_pool.mode != 'isolated':
        raise CoreException('network_not_isolated')

    network.set_prop('gateway', gateway_ip)
    network.save()

    if network.get_prop('dhcp_running', False):
        task = Task()
        task.type = 'dhcp'
        task.action = 'stop_dhcp'
        task.append_to([network], broadcast=True)

    task = Task()
    task.type = 'dhcp'
    task.action = 'start_dhcp'
    task.append_to([network])
Example #3
0
def delete(context, vpn_id):
    """ Delete vpn network """
    vpn = VPN.get(context.user_id, vpn_id)

    task = Task()
    task.type = 'vpn'
    task.action = 'delete'
    task.append_to([vpn], broadcast=True)
Example #4
0
def test_add_task():
    global imageA
    global imageB
    global test_taskA
    from corecluster.cache.task import Task

    test_taskA = Task()
    test_taskA.type = 'test_task'
    test_taskA.state = 'not active'
    test_taskA.action = 'test_action'
    test_taskA.append_to([imageA, imageB])
Example #5
0
def test_add_second_task():
    global imageA
    global test_taskB
    from corecluster.cache.task import Task

    test_taskB = Task()
    test_taskB.type = 'test_task'
    test_taskB.state = 'not active'
    test_taskB.action = 'test_action'

    # New task is assigned only to imageA
    test_taskB.append_to([imageA])
Example #6
0
def stop(context, network_id):
    """
    Stop DHCP servers in network
    """
    network = Subnet.get(context.user_id, network_id)
    if network.network_pool.mode != 'isolated':
        raise CoreException('network_not_isolated')

    task = Task()
    task.type = 'dhcp'
    task.action = 'stop_dhcp'
    task.append_to([network], broadcast=True)
Example #7
0
def stop(context, network_id):
    """
    Stop DHCP servers in network
    """
    network = Subnet.get(context.user_id, network_id)
    if network.network_pool.mode != 'isolated':
        raise CoreException('network_not_isolated')

    task = Task()
    task.type = 'dhcp'
    task.action = 'stop_dhcp'
    task.append_to([network], broadcast=True)
def test_add_task():
    global imageA
    global test_taskA
    from corecluster.cache.task import Task

    assert imageA.last_task == None

    test_taskA = Task()
    test_taskA.type = 'queue_a'
    test_taskA.state = 'not active'
    test_taskA.action = 'test_action'
    test_taskA.append_to([imageA])

    assert test_taskA.blockers == []
Example #9
0
def test_append_third_task():
    # Append next task to empty queue
    global imageA
    global imageB
    global test_taskC

    from corecluster.cache.task import Task
    from corecluster.models.core import Image

    test_taskC = Task()
    test_taskC.type = 'test_task'
    test_taskC.state = 'not active'
    test_taskC.action = 'test_action'

    # New task is assigned only to imageA
    test_taskC.append_to([imageA])

    img_a = Image.objects.get(pk=imageA.id)

    assert img_a.last_task == test_taskC.cache_key()
Example #10
0
def start(context, network_id, gateway_ip):
    """
    Start DHCP server(s) in isolated network.
    :param network_id: Isolated network, which should be connected with new VPN server
    :param gateway_ip: Gateway ip for isolated network.
    """

    network = Subnet.get(context.user_id, network_id)
    if network.network_pool.mode != 'isolated':
        raise CoreException('network_not_isolated')

    network.set_prop('gateway', gateway_ip)
    network.save()

    if network.get_prop('dhcp_running', False):
        task = Task()
        task.type = 'dhcp'
        task.action = 'stop_dhcp'
        task.append_to([network], broadcast=True)

    task = Task()
    task.type = 'dhcp'
    task.action = 'start_dhcp'
    task.append_to([network])
Example #11
0
def create(context, name, network_id):
    """
    Create new vpn server attached to isolated network. There is no dhcp
    :param name: Network name
    :param network_id: Isolated network, which should be connected with new VPN server
    """

    network = Subnet.get(context.user_id, network_id)
    if network.network_pool.mode != 'isolated':
        raise CoreException('network_not_isolated')

    vpn = VPN()
    vpn.state = 'init'
    vpn.name = name
    vpn.network = Subnet.get(context.user_id, network_id)
    vpn.user_id = context.user_id
    vpn.save()

    task = Task()
    task.type = 'vpn'
    task.action = 'create'
    task.append_to([vpn, network])

    return vpn.to_dict
Example #12
0
def attach_configdrive(context, userdata_id, vm_id):
    userdata = UserData.get(context.user_id, userdata_id)
    vm = VM.get(context.user_id, vm_id)

    system.call(['mkdir', '-p', '/tmp/configdrive_' + userdata.id + '/openstack/latest/'])
    ud = open('/tmp/configdrive_' + userdata.id + '/openstack/latest/user_data', 'w')
    ud.write(userdata.data)
    ud.close()

    # Detailed instruction: https://coreos.com/os/docs/latest/config-drive.html
    #TODO: Convert to: http://serverfault.com/questions/43634/how-to-mount-external-vfat-drive-as-user
    system.call(['genisoimage', '-R', '-V', 'config-2', '-o', '/tmp/configdrive_' + userdata.id + '.img', '/tmp/configdrive_' + userdata.id])
    system.call(['rm', '-rf', '/tmp/configdrive_' + userdata.id])
    system.call(['qemu-img', 'convert', '-f', 'raw', '-O', 'qcow2', '/tmp/configdrive_' + userdata.id + '.img', '/tmp/configdrive_' + userdata.id + '.qcow2'])
    system.call(['rm', '-rf', '/tmp/configdrive_' + userdata.id + '.img'])

    image = Image.create(name='CoreTalk ConfigDrive',
                         description='UserData: %s, VM: %s' % (userdata.id, vm.id),
                         access='private',
                         format='qcow2',
                         size=os.stat('/tmp/configdrive_' + userdata.id + '.qcow2').st_size,
                         type='permanent',
                         disk_controller='virtio',
                         user=vm.user)
    image.save()

    create_img = Task()
    create_img.user_id = context.user_id
    create_img.type = 'image'
    create_img.action = 'create'
    create_img.append_to([vm, image, image.storage])

    chunk = DataChunk()
    contents = open('/tmp/configdrive_' + userdata.id + '.qcow2').read(image.size)
    chunk.data = base64.b64encode(contents)
    chunk.offset = 0
    chunk.image_id = image.id
    chunk.type = 'upload'
    chunk.save()

    upload_data = Task()
    upload_data.user_id = context.user_id
    upload_data.type = 'image'
    upload_data.action = 'upload_data'
    upload_data.set_all_props({'offset': 0,
                               'size': image.size,
                               'chunk_id': chunk.cache_key()})
    upload_data.append_to([image, vm])

    attach_img = Task()
    attach_img.user_id = context.user_id
    attach_img.type = 'image'
    attach_img.action = 'attach'
    attach_img.append_to([vm, image])