Пример #1
0
/** Create a Virtual Machine in the specified pool
	@param name 	The name of the new Virtual Machine
	@param ip		The IP address to assign the VM
	@param asset	Asset tag to use (VM UUID)
	@param osInfo	Operating System information (to be stored as a comment)
	@param taglist	Array of tags to use for this new object
	@param poolID	Virtual Machine pool to parent this object to
*/
function createVMInPool($name, $ip, $asset, $osInfo, $taglist, $poolID, $vmTypeID)
{
    // make sure there's no duplicates
    if (getSearchResultByField('RackObject', array('id'), 'name', $name, '', 2)) {
        return FALSE;
    }
    // commitAddObject ($new_name, $new_label, $new_type_id, $new_asset_no, $taglist = array())
    $newObject = commitAddObject($name, $name, $vmTypeID, $asset, $taglist);
    // add IP address to new object
    if (!empty($ip)) {
        bindIpToObject(ip_parse($ip), $newObject, 'eth0', 'regular');
    }
    // add OS info to new object
    if (!empty($osInfo)) {
        usePreparedUpdateBlade('Object', array('comment' => $osInfo), array('id' => $newObject));
    }
    // set container
    //commitLinkEntities($parent_entity_type, $parent_entity_id, $child_entity_type, $child_entity_id);
    commitLinkEntities("object", $poolID, "object", $newObject);
}
Пример #2
0
function getObjectNATSearchResults($what)
{
    $ret = array();
    $ifaces = getSearchResultByField('IPv4NAT', array('object_id', 'description'), 'description', $what, 'object_id');
    foreach ($ifaces as $row) {
        $ret[$row['object_id']]['id'] = $row['object_id'];
        $ret[$row['object_id']]['by_nat'][] = $row['description'];
    }
    return $ret;
}
Пример #3
0
function renderVLANInfo($vlan_ck)
{
    global $vtoptions, $nextorder;
    $vlan = getVLANInfo($vlan_ck);
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
    echo '<tr><td colspan=2 align=center><h1>' . formatVLANAsRichText($vlan) . '</h1></td></tr>';
    echo "<tr><td class=pcleft width='50%'>";
    startPortlet('summary');
    echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>";
    echo "<tr><th width='50%' class=tdright>Domain:</th><td class=tdleft>";
    echo niftyString($vlan['domain_descr'], 0) . '</td></tr>';
    echo "<tr><th width='50%' class=tdright>VLAN ID:</th><td class=tdleft>{$vlan['vlan_id']}</td></tr>";
    if (strlen($vlan['vlan_descr'])) {
        echo "<tr><th width='50%' class=tdright>Description:</th><td class=tdleft>" . niftyString($vlan['vlan_descr'], 0) . "</td></tr>";
    }
    echo "<tr><th width='50%' class=tdright>Propagation:</th><td class=tdleft>" . $vtoptions[$vlan['vlan_prop']] . "</td></tr>";
    $others = getSearchResultByField('VLANDescription', array('domain_id'), 'vlan_id', $vlan['vlan_id'], 'domain_id', 1);
    foreach ($others as $other) {
        if ($other['domain_id'] != $vlan['domain_id']) {
            echo '<tr><th class=tdright>Counterpart:</th><td class=tdleft>' . formatVLANAsHyperlink(getVLANInfo("{$other['domain_id']}-{$vlan['vlan_id']}")) . '</td></tr>';
        }
    }
    echo '</table>';
    finishPortlet();
    if (0 == count($vlan['ipv4nets']) + count($vlan['ipv6nets'])) {
        startPortlet('no networks');
    } else {
        startPortlet('networks (' . (count($vlan['ipv4nets']) + count($vlan['ipv6nets'])) . ')');
        $order = 'odd';
        echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
        echo '<tr><th>';
        printImageHREF('net');
        echo '</th><th>';
        printImageHREF('text');
        echo '</th></tr>';
        foreach (array('ipv4net', 'ipv6net') as $nettype) {
            foreach ($vlan[$nettype . 's'] as $netid) {
                $net = spotEntity($nettype, $netid);
                #echo "<tr class=row_${order}><td>";
                echo '<tr><td>';
                renderCell($net);
                echo '</td><td>' . (mb_strlen($net['comment']) ? niftyString($net['comment']) : '&nbsp;');
                echo '</td></tr>';
                $order = $nextorder[$order];
            }
        }
        echo '</table>';
    }
    finishPortlet();
    $confports = getVLANConfiguredPorts($vlan_ck);
    // get non-switch device list
    $foreign_devices = array();
    foreach ($confports as $switch_id => $portlist) {
        $object = spotEntity('object', $switch_id);
        foreach ($portlist as $port_name) {
            if ($portinfo = getPortinfoByName($object, $port_name)) {
                if ($portinfo['linked'] && !isset($confports[$portinfo['remote_object_id']])) {
                    $foreign_devices[$portinfo['remote_object_id']][] = $portinfo;
                }
            }
        }
    }
    if (!empty($foreign_devices)) {
        startPortlet("Non-switch devices");
        echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>";
        echo '<tr><th>device</th><th>ports</th></tr>';
        $order = 'odd';
        foreach ($foreign_devices as $cell_id => $ports) {
            echo "<tr class=row_{$order} valign=top><td>";
            $cell = spotEntity('object', $cell_id);
            renderCell($cell);
            echo "</td><td><ul>";
            foreach ($ports as $portinfo) {
                echo "<li>" . formatPortLink($portinfo['remote_object_id'], NULL, $portinfo['remote_id'], $portinfo['remote_name']) . ' &mdash; ' . formatPort($portinfo) . "</li>";
            }
            echo "</ul></td></tr>";
            $order = $nextorder[$order];
        }
        echo '</table>';
        finishPortlet();
    }
    echo '</td><td class=pcright>';
    if (!count($confports)) {
        startPortlet('no ports');
    } else {
        startPortlet('Switch ports (' . count($confports) . ')');
        global $nextorder;
        $order = 'odd';
        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
        echo '<tr><th>switch</th><th>ports</th></tr>';
        foreach ($confports as $switch_id => $portlist) {
            usort_portlist($portlist);
            echo "<tr class=row_{$order} valign=top><td>";
            $object = spotEntity('object', $switch_id);
            renderCell($object);
            echo '</td><td class=tdleft><ul>';
            foreach ($portlist as $port_name) {
                echo '<li>';
                if ($portinfo = getPortinfoByName($object, $port_name)) {
                    echo formatPortLink($object['id'], NULL, $portinfo['id'], $portinfo['name']);
                } else {
                    echo $port_name;
                }
                echo '</li>';
            }
            echo '</ul></td></tr>';
            $order = $nextorder[$order];
        }
        echo '</table>';
    }
    finishPortlet();
    echo '</td></tr></table>';
}
Пример #4
0
function renderVLANInfo($vlan_ck)
{
    global $vtoptions, $nextorder;
    $vlan = getVLANInfo($vlan_ck);
    $group_members = getDomainGroupMembers($vlan['domain_id']);
    // list of VLANs to display linked nets and ports from.
    // If domain is a group master, this list contains all
    // the counterpart vlans from domain group members.
    // If domain is a group member, the list contains one
    // counterpart vlan from the domain master.
    $group_ck_list = array();
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
    echo '<tr><td colspan=2 align=center><h1>' . formatVLANAsRichText($vlan) . '</h1></td></tr>';
    echo "<tr><td class=pcleft width='50%'>";
    $summary = array();
    $summary['Domain'] = stringForTD($vlan['domain_descr'], 0);
    $summary['VLAN ID'] = $vlan['vlan_id'];
    if (strlen($vlan['vlan_descr'])) {
        $summary['Description'] = stringForTD($vlan['vlan_descr'], 0);
    }
    $summary['Propagation'] = $vtoptions[$vlan['vlan_prop']];
    $others = getSearchResultByField('VLANDescription', array('domain_id'), 'vlan_id', $vlan['vlan_id'], 'domain_id', 1);
    $counterparts = array();
    $group_counterparts = array();
    $domain_list = getVLANDomainOptions();
    foreach ($others as $other) {
        if ($other['domain_id'] != $vlan['domain_id']) {
            $counterpart_ck = "{$other['domain_id']}-{$vlan['vlan_id']}";
            $counterpart_vlan = getVlanRow($counterpart_ck);
            $counterpart_link = mkA($domain_list[$counterpart_vlan['domain_id']] . ': ' . $counterpart_vlan['vlan_descr'], 'vlan', $counterpart_ck);
            if ($counterpart_vlan['domain_id'] == $vlan['domain_group_id'] or in_array($counterpart_vlan['domain_id'], $group_members)) {
                $group_ck_list[$counterpart_ck] = $counterpart_vlan;
                $group_counterparts[] = $counterpart_link;
            } elseif ($vlan['domain_group_id'] and $counterpart_vlan['domain_group_id'] == $vlan['domain_group_id']) {
                $group_counterparts[] = $counterpart_link;
            } else {
                $counterparts[] = $counterpart_link;
            }
        }
    }
    if ($group_counterparts) {
        $group_id = $vlan['domain_group_id'] ? $vlan['domain_group_id'] : $vlan['domain_id'];
        $summary[$domain_list[$group_id] . ' counterparts'] = implode('<br>', $group_counterparts);
    }
    if ($counterparts) {
        $summary['Counterparts'] = implode('<br>', $counterparts);
    }
    renderEntitySummary($vlan, 'summary', $summary);
    $networks = array();
    $net_vlan_list = array($vlan);
    foreach (array_keys($group_ck_list) as $grouped_ck) {
        $net_vlan_list[] = getVLANInfo($grouped_ck);
    }
    foreach ($net_vlan_list as $net_vlan) {
        foreach (array('ipv4net' => 'ipv4nets', 'ipv6net' => 'ipv6nets') as $realm => $key) {
            foreach ($net_vlan[$key] as $net_id) {
                $networks["{$realm}-{$net_id}"] = spotEntity($realm, $net_id);
            }
        }
    }
    if (0 == count($networks)) {
        startPortlet('no networks');
    } else {
        startPortlet('networks (' . count($networks) . ')');
        $order = 'odd';
        echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
        echo '<tr><th>';
        printImageHREF('net');
        echo '</th><th>';
        printImageHREF('text');
        echo '</th></tr>';
        foreach ($networks as $net) {
            echo '<tr><td>';
            renderCell($net);
            echo '</td><td>' . stringForTD($net['comment']);
            echo '</td></tr>';
            $order = $nextorder[$order];
        }
        echo '</table>';
    }
    finishPortlet();
    $confports = getVLANConfiguredPorts($vlan_ck);
    foreach (array_keys($group_ck_list) as $grouped_ck) {
        $confports += getVLANConfiguredPorts($grouped_ck);
    }
    if ($vlan['domain_group_id']) {
        // we should find configured port on master's members
        // even if master domain itself does not have such VLAN
        $master_ck = $vlan['domain_group_id'] . '-' . $vlan['vlan_id'];
        if (!isset($group_ck_list[$master_ck])) {
            $confports += getVLANConfiguredPorts($master_ck);
        }
    }
    // get non-switch device list
    $foreign_devices = array();
    foreach ($confports as $switch_id => $portlist) {
        $object = spotEntity('object', $switch_id);
        foreach ($portlist as $port_name) {
            if ($portinfo = getPortinfoByName($object, $port_name)) {
                if ($portinfo['linked'] && !isset($confports[$portinfo['remote_object_id']])) {
                    $foreign_devices[$portinfo['remote_object_id']][] = $portinfo;
                }
            }
        }
    }
    if (!empty($foreign_devices)) {
        startPortlet("Non-switch devices");
        echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>";
        echo '<tr><th>device</th><th>ports</th></tr>';
        $order = 'odd';
        foreach ($foreign_devices as $cell_id => $ports) {
            echo "<tr class=row_{$order} valign=top><td>";
            $cell = spotEntity('object', $cell_id);
            renderCell($cell);
            echo "</td><td><ul>";
            foreach ($ports as $portinfo) {
                echo "<li>" . formatPortLink($portinfo['remote_object_id'], NULL, $portinfo['remote_id'], $portinfo['remote_name']) . ' &mdash; ' . formatPort($portinfo) . "</li>";
            }
            echo "</ul></td></tr>";
            $order = $nextorder[$order];
        }
        echo '</table>';
        finishPortlet();
    }
    echo '</td><td class=pcright>';
    if (!count($confports)) {
        startPortlet('no ports');
    } else {
        startPortlet('Switch ports (' . count($confports) . ')');
        global $nextorder;
        $order = 'odd';
        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
        echo '<tr><th>switch</th><th>ports</th></tr>';
        foreach ($confports as $switch_id => $portlist) {
            usort_portlist($portlist);
            echo "<tr class=row_{$order} valign=top><td>";
            $object = spotEntity('object', $switch_id);
            renderCell($object);
            echo '</td><td class=tdleft><ul>';
            foreach ($portlist as $port_name) {
                echo '<li>';
                if ($portinfo = getPortinfoByName($object, $port_name)) {
                    echo formatPortLink($object['id'], NULL, $portinfo['id'], $portinfo['name']);
                    if ($portinfo['linked']) {
                        echo ' &mdash; ' . formatPortLink($portinfo['remote_object_id'], $portinfo['remote_object_name'], $portinfo['remote_id'], NULL);
                    }
                } else {
                    echo $port_name;
                }
                echo '</li>';
            }
            echo '</ul></td></tr>';
            $order = $nextorder[$order];
        }
        echo '</table>';
    }
    finishPortlet();
    echo '</td></tr></table>';
}
Пример #5
0
function ImportTab()
{
    global $nextorder;
    global $Version;
    global $taglist;
    ?>

  <style type='text/css'>
  tr.has_problems 
  {
    background-color: #ffa0a0;
  }
  </style>

  <!--Legend-->
  <table align=right>
  <tr class=trerror><td colspan=2>Unknown object</td></tr>
  <tr><td class=row_even>Existing </td><td class=row_odd> object</td></tr>
  </table>

  <center><h1>Import yaml objects </h1><h2>from /yamls/</h2></center>
<?php 
    startPortlet();
    echo "<table with=90% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>";
    echo "<form method=post name=ImportObject action='?module=redirect&page=depot&tab=yaml_import&op=RunImport'>";
    echo "<tr valign=top><th>Assign tags</th><th align=center>Name</th><th align=center>Import ?</th></tr>";
    // taglist on display - left handed
    echo "<tr valign=top><td rowspan=\"0\">";
    renderNewEntityTags('object');
    echo "</td></tr>";
    $order = 'odd';
    # Find and read loop through all .yaml files in the yaml directory.
    //  if ($handle = opendir('./yamls/'))
    if ($files = scandir('./yamls/')) {
        //    while (false !== ($file = readdir($handle)))
        foreach ($files as $file) {
            # Since puppet names the files $FQDN.yaml, we don't have to inspect the file during the first run.
            if (preg_match('/\\.yaml/', $file)) {
                $name = preg_replace('/\\.yaml/', '', $file);
                # Do a search on the row 'name' passing the one name, and retrieving the ID.
                $object = getSearchResultByField('RackObject', array('id'), 'name', $name, '', 2);
                if ($object) {
                    $url = makeHref(array('page' => 'object', 'tab' => 'default', 'object_id' => $object[0]['id']));
                    echo "<tr class=row_{$order}><td align=left><a href=\"{$url}\">" . $name . "</a></td>\n";
                } else {
                    echo "<tr class=trerror><td align=left>" . $name . "</td>\n";
                }
                echo "<td align=center> <input type=checkbox name=objectname[] value={$name}></td></tr>\n";
                $order = $nextorder[$order];
            }
        }
    }
    // tags ?
    //  echo "<tr><td rowspan=\"0\">";
    //  renderNewEntityTags('object');
    //  echo "</td></tr>";
    echo "<tr><td align=left><font size=1em color=gray>version {$Version}</font></td><td align=right><input type=submit name=got_very_fast_data value='Import selected items'></td><td></td></tr></table></td></tr>";
    echo "</form>";
    echo "</table>";
    finishPortlet();
}