Exemplo n.º 1
0
/**
 * activates a lab (deploys to a host)
 *
 * @api
 *
 * @param   int $lab_id lab id
 *
 * @return  bool                    on success TRUE/FALSE
 */
function ace_lab_activate($lab_id)
{
    # only if user has no active labs (i.e. must deactivate other labs first)
    $user_id = ace_lab_get_user_id($lab_id);
    $user_lab_table = ace_user_get_lab_table($user_id);
    $another_user_lab_is_active = FALSE;
    foreach ($user_lab_table as $lab) {
        if ($lab['state'] == 1) {
            $another_user_lab_is_active = TRUE;
        }
    }
    if (!$another_user_lab_is_active) {
        # determine best host, and update lab record
        $host_id = ace_db_get_best_host();
        if (is_numeric($host_id)) {
            # set lab as activated in db
            $db_success = ace_db_lab_set_state($lab_id, TRUE);
            # this lab was inactive, and was successfully activated
            $activated = $db_success;
            # update lab record with host_id
            ace_db_lab_set_host_id($lab_id, $host_id);
            # construct lab on host
            $net_table = ace_db_lab_get_network_table($lab_id);
            foreach ($net_table as $net) {
                # create (define) each network
                ace_virt_network_create($net['id']);
                # start each network if marked active in db
                if ($net['state'] == 1) {
                    ace_virt_network_activate($net['id']);
                }
            }
            $vol_table = ace_db_lab_get_volume_table($lab_id);
            foreach ($vol_table as $vol) {
                # create each volume
                ace_virt_volume_create($vol['id']);
            }
            $vm_table = ace_db_lab_get_vm_table($lab_id);
            foreach ($vm_table as $vm) {
                # create (define) each vm
                ace_virt_vm_create($vm['id']);
                $vm_cdrom_table = ace_db_vm_get_cdrom_table($vm['id']);
                foreach ($vm_cdrom_table as $vm_cdrom) {
                    ace_virt_vm_attach_cdrom($vm['id'], $vm_cdrom['instance']);
                    if ($vm_cdrom['volume_id'] != NULL) {
                        ace_virt_vm_cdrom_insert_media($vm['id'], $vm_cdrom['instance'], $vm_cdrom['volume_id']);
                    }
                }
                $vm_disk_table = ace_db_vm_get_disk_table($vm['id']);
                foreach ($vm_disk_table as $vm_disk) {
                    ace_virt_vm_attach_disk($vm['id'], $vm_disk['instance'], $vm_disk['volume_id']);
                }
                $vm_nic_table = ace_db_vm_get_nic_table($vm['id']);
                foreach ($vm_nic_table as $vm_nic) {
                    $vm_nic_mac_address = ace_gen_convert_int2mac($vm_nic['mac_index']);
                    ace_virt_vm_attach_nic($vm['id'], $vm_nic['instance'], $vm_nic_mac_address);
                    ace_virt_vm_nic_connect_network($vm['id'], $vm_nic['instance'], $vm_nic['network_id']);
                }
                # set each vm state
                if ($vm['state'] == 1) {
                    ace_vm_activate($vm['id']);
                }
            }
        } else {
            $activated = FALSE;
        }
    } else {
        $activated = FALSE;
    }
    return $activated;
}
Exemplo n.º 2
0
/**
 * fetch mac address assigned to a vm nic instance for a given vm id
 *
 * @param   int $vm_id           vm id
 * @param   int $vm_nic_instance vm nic instance
 *
 * @return  string|bool         vm nic mac address | FALSE on error
 */
function ace_db_vm_nic_get_mac_address($vm_id, $vm_nic_instance)
{
    $sql = "SELECT mac_index\n            FROM vnic\n            WHERE vm_id={$vm_id}\n              AND instance={$vm_nic_instance}";
    $db_result = ace_db_query($sql);
    if ($db_result->row_count > 0) {
        $mac_index = $db_result->table[0]['mac_index'];
        $mac_address = ace_gen_convert_int2mac($mac_index);
        $return = $mac_address;
    } else {
        $return = FALSE;
    }
    return $return;
}
Exemplo n.º 3
0
     //                <th>#</th>
     //                <th>Mac</th>
     //                <th>Net</th>
     //            </tr>';
     $table = '<table class="element_table">';
     foreach ($vm_nics as $vm_nic) {
         $html_link_class = '';
         if ($lab_state) {
             $vm_nic_link_state = ace_vm_nic_get_link_state($vm_id, $vm_nic['instance']);
             $html_link_class = $vm_nic_link_state ? 'active' : 'inactive';
         }
         $table .= '<tr class="' . $html_link_class . '">';
         $table .= '<td><input name="vm_nic_instance" value="' . $vm_nic['instance'] . '" type="radio" /></td>';
         //$table .= '<td>nic' . $vm_nic['instance'] . '</td>';
         $table .= '<td align="center">' . $vm_nic['instance'] . '</td>';
         $table .= '<td align="center" style="font-size: 60%">' . ace_gen_convert_int2mac($vm_nic['mac_index']) . '</td>';
         $table .= '<td align="center">' . ace_network_get_display_name_by_id($vm_nic['network_id']) . '</td>';
         $table .= '</tr>';
     }
     $table .= '</table>';
     $html_vm_nic_radios = $table;
 }
 $html_vm_snapshot_radios = NULL;
 for ($vm_snapshot_instance = 0; $vm_snapshot_instance < $num_vm_snapshots; $vm_snapshot_instance++) {
     $html_vm_snapshot_radios .= '<input name="vm_snapshot_instance" value="' . $vm_snapshot_instance . '" type="radio" />';
     $tz_set = date_default_timezone_set('America/New_York');
     $html_vm_snapshot_radios .= date("Y-m-d H:i", $vm_snapshots[$vm_snapshot_instance]) . '<br/>';
 }
 switch ($vm['profile']) {
     case 'linux':
         $vm_profile = 'Linux';