コード例 #1
0
ファイル: conn.php プロジェクト: quickpacket/noclayer
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('dev', 'Device id', 'required|min_length[1]|max_length[20]');
         $val->add_field('type', 'Input or output', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             $power = Model_Device_Power::find()->where('deviceID', $val->validated('dev'))->get_one();
             if ($power) {
                 $type = $val->validated('type');
                 $out = array('status' => 'ok', 'cables' => array(), 'ports' => array());
                 $sockets = $power->socket;
                 foreach ($sockets as $socket) {
                     if ($type == 1 && $socket->type == 2) {
                         array_push($out['ports'], array('id' => $socket->id));
                     }
                     if ($type == 2 && $socket->type == 1) {
                         array_push($out['ports'], array('id' => $socket->id));
                     }
                 }
                 $cabels = Model_Cable::find()->where('dev1', $power->deviceID)->where('type', 2)->or_where('dev2', $power->deviceID)->where('type', 2)->get();
                 //$out['ports']=$ports;
                 foreach ($cabels as $cab) {
                     array_push($out['cables'], array('id' => $cab->id, 'dev1' => $cab->dev1, 'port1' => $cab->port1, 'dev2' => $cab->dev2, 'port2' => $cab->port2, 'name1' => $cab->name1, 'name2' => $cab->name2));
                 }
             } else {
                 $out = array('status' => 'nop');
             }
             echo json_encode($out);
         }
     }
 }
コード例 #2
0
ファイル: pdu.php プロジェクト: quickpacket/noclayer
 public function action_new()
 {
     $out = 0;
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('rack', 'rack id', 'required|min_length[1]|max_length[20]');
         $val->add_field('p', 'position left|right', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             $rack = Model_Rack::find($val->validated('rack'));
             if ($rack) {
                 $size = $rack->size;
                 //left or right side pdu
                 if ($val->validated('p') == 'l') {
                     $m = 1;
                 } else {
                     $m = 2;
                 }
                 $devs = Model_Device::find()->where('rack', $rack->id)->where('cat', 4)->where('meta_default_data', $m)->get();
                 $pos = $this->empty_space($devs, $rack->size);
                 if ($pos >= 0) {
                     $props = array('hostname' => 'vertical pdu', 'type' => 0, 'cat' => 4, 'rack' => $rack->id, 'rack_pos' => 0, 'rack_units' => 0, 'parent_device' => 0, 'meta_default_data' => $m, 'meta_update_time' => time(), 'meta_update_user' => $this->user);
                     //print_r($props);
                     $dev = new Model_Device($props);
                     $dev->save();
                     $this->add_device_default_fields($dev);
                     $power = Model_Device_Power::find()->where('deviceID', $dev->id)->get_one();
                     $this->tmpl = false;
                     $power->pos = $pos;
                     $power->input = 1;
                     $power->output = 8;
                     $power->save();
                     for ($i = 1; $i <= 7; $i++) {
                         $prop = array('powerID' => $power->id, 'conn_type' => 1, 'type' => 2);
                         if ($this->tmpl) {
                             $socket = new Model_Device_Template_Pdu_Socket($prop);
                         } else {
                             $socket = new Model_Device_Power_Socket($prop);
                         }
                         $socket->save();
                     }
                     $out = array('id' => $power->id, 'ru' => 8, 'pos' => $pos, 'devid' => $dev->id, 'name' => $dev->hostname, 'parent_device' => 0, 'out' => $power['output'], 'cur' => $power['current']);
                 }
             }
         }
     }
     echo json_encode(array('data' => $out));
 }
コード例 #3
0
ファイル: user.php プロジェクト: quickpacket/noclayer
 private function add_server($pos, $rack, $user, $sw, $macs, $pdu)
 {
     $pduid = $pdu['id'];
     $sockets = $pdu['sockets'];
     $hostnames = array("", "", "", "", "", "", "", "", "", "akcp-sp2", "c1-activedirectory-1", "c1-activedirectory-2", "c1-activedirectory-3", "c1-dns-1", "c1-dns-2", "c1-dns-3", "c1-dns-4", "c1-exchange-1", "c1-exchange-2", "c1-exchange-3", "c1-exchange-4", "c1-linux-1", "c1-linux-2", "c1-linux-3", "c1-linux-4", "c1-linux-5", "c1-mysql-1", "c1-mysql-2", "c1-mysql-3", "c1-mysql-4", "c1-web-1", "c1-web-2", "c1-web-3", "c1-web-4", "c1-windows-1", "c1-windows-2", "c1-windows-3", "c1-windows-4", "c1-windows-5", "c1-windows-6", "c2-exchange-3", "c2-exchange-4", "c2-mysql-1", "c2-mysql-2", "c2-web-1", "c2-windows-1", "c2_windows-2", "c3-linux-1", "c3-linux-2", "c3-linux-3", "c3-linux-4", "c3-windows-1", "c3-windows-2", "c3-windows-3", "fujitsu-tx-s2", "knuerr-diview", "knuerr-rmsII", "messpc", "sensatronics-e4", "sensatronics-em1", "sensatronics-senturion");
     $props = array('hostname' => $hostnames[$pos], 'type' => 0, 'cat' => 1, 'rack' => $rack->id, 'rack_pos' => $pos, 'rack_units' => 1, 'parent_device' => 0, 'meta_default_data' => 0, 'meta_update_time' => time(), 'meta_update_user' => $user);
     //print_r($props);
     $server = new Model_Device($props);
     $server->save();
     $this->net_type = 1;
     $this->add_device_default_fields($server);
     $network = Model_Device_Network::find()->where('deviceID', $server->id)->get_one();
     $network->nics = 2;
     $network->save();
     for ($i = 0; $i <= 1; $i++) {
         $prop = array('networkID' => $network->id, 'nic_name' => '', 'ipv4' => '192.168.8.' . $i, 'ipv6' => '', 'conn_type' => 1, 'conn_speed' => 3, 'type' => 1);
         $ip = new Model_Network_Ip($prop);
         $ip->save();
     }
     //add cabel
     $props = array('dev1' => $sw, 'port1' => $macs[$pos - 9], 'dev2' => $server->id, 'port2' => $ip->id, 'name1' => $pos - 9, 'name2' => 2, 'type' => 1, 'meta_update_time' => time(), 'meta_update_user' => $user);
     $cable = new Model_Cable($props);
     $cable->save();
     $power = Model_Device_Power::find()->where('deviceID', $server->id)->get_one();
     $powsockets = $power->socket;
     foreach ($powsockets as $sock) {
         $n = $pos - 9;
         $props = array('dev1' => $pduid, 'port1' => $sockets[38 - $n], 'dev2' => $server->id, 'port2' => $sock->id, 'name1' => $pos - 9, 'name2' => 1, 'type' => 2, 'meta_update_time' => time(), 'meta_update_user' => $user);
         $cable = new Model_Cable($props);
         $cable->save();
     }
     /*
     
     
     $props=Array(
     		'dev1'=>$sw,
     		'port1'=>$macs[$pos-9],
     		'dev2'=>$server->id,
     		'port2'=>$ip->id,
     		'name1'=>$pos-9,
     		'name2'=>1,
     		'type'=>2,
     		'meta_update_time'=>time(),
     		'meta_update_user'=>$user
     );
     $cable=new Model_Cable($props);
     $cable->save();
     */
     return $server;
 }
コード例 #4
0
ファイル: fieldset.php プロジェクト: quickpacket/noclayer
 public function save($cascade = null, $use_transtation = false)
 {
     parent::save();
     if ($this->get('type') == 'hdd') {
         if (!$this->get('hdd')) {
             $props = array('fieldsetID' => $this->get('id'), 'raid_type' => 1, 'size' => 0, 'meta_update_time' => time(), 'meta_update_user' => 0, 'total' => 0);
             $raid = new Model_Raid($props);
             $raid->save();
         }
     }
     if ($this->get('type') == 'ram') {
         if (!$this->get('ram')) {
             $props = array('fieldsetID' => $this->get('id'), 'ram_type' => 1, 'size' => 0, 'total' => 0, 'meta_update_time' => time(), 'meta_update_user' => 0);
             $ram = new Model_Ram($props);
             $ram->save();
         }
     }
     if ($this->get('type') == 'network') {
         if (!$this->get('network')) {
             $dev = $this->get('device');
             $prop = array('fieldsetID' => $this->get('id'), 'deviceID' => $dev->id, 'nics' => 0, 'vports' => 0, 'ports' => 0, 'uplinks' => 0, 'config_data' => '', 'type' => $this->setTypeOfDevice($dev));
             $network = new Model_Device_Network($prop);
             $network->save();
         }
     }
     if ($this->get('type') == 'power_out') {
         if (!$this->get('power')) {
             $dev = $this->get('device');
             $prop = array('fieldsetID' => $this->get('id'), 'deviceID' => $dev->id, 'current' => 10, 'input' => 1, 'output' => 1, 'ru' => 1, 'pos' => 0, 'type' => 0);
             $power = new Model_Device_Power($prop);
             $power->save();
             //input socket
             $prop = array('powerID' => $power->id, 'conn_type' => 1, 'type' => 1);
             $socket = new Model_Device_Power_Socket($prop);
             $socket->save();
             //output socket
             $prop = array('powerID' => $power->id, 'conn_type' => 1, 'type' => 2);
             $socket = new Model_Device_Power_Socket($prop);
             $socket->save();
         }
     }
     if ($this->get('type') == 'power_in') {
         if (!$this->get('power')) {
             $dev = $this->get('device');
             $prop = array('fieldsetID' => $this->get('id'), 'deviceID' => $dev->id, 'current' => 0, 'input' => 1, 'output' => 0, 'ru' => 0, 'pos' => 0, 'type' => 0);
             $power = new Model_Device_Power($prop);
             $power->save();
             //input power
             $prop = array('powerID' => $power->id, 'conn_type' => 1, 'type' => 1);
             $socket = new Model_Device_Power_Socket($prop);
             $socket->save();
         }
     }
     if ($this->get('type') == 'kvm_in') {
         if (!$this->get('kvm')) {
             $dev = $this->get('device');
             $prop = array('fieldsetID' => $this->get('id'), 'deviceID' => $dev->id, 'input' => 1, 'output' => 0, 'type' => 0);
             $kvm = new Model_Device_Kvm($prop);
             $kvm->save();
             //input power
             $prop = array('kvmID' => $kvm->id, 'conn_type' => 1, 'type' => 1);
             $socket = new Model_Device_Kvm_Socket($prop);
             $socket->save();
         }
     }
     if ($this->get('type') == 'kvm_out') {
         if (!$this->get('kvm')) {
             $dev = $this->get('device');
             $prop = array('fieldsetID' => $this->get('id'), 'deviceID' => $dev->id, 'input' => 1, 'output' => 1, 'type' => 0);
             $kvm = new Model_Device_Kvm($prop);
             $kvm->save();
             //input kvm
             $prop = array('kvmID' => $kvm->id, 'conn_type' => 1, 'type' => 2);
             $socket = new Model_Device_Kvm_Socket($prop);
             $socket->save();
             //output kvm
             $prop = array('kvmID' => $kvm->id, 'conn_type' => 1, 'type' => 1);
             $socket = new Model_Device_Kvm_Socket($prop);
             $socket->save();
         }
     }
 }
コード例 #5
0
ファイル: testdemo.php プロジェクト: quickpacket/noclayer
 private function add_server($pos, $rack, $user, $sw, $macs, $pdu)
 {
     $pduid = $pdu['id'];
     $sockets = $pdu['sockets'];
     $props = array('hostname' => 's' . $pos . '.rck1.fl1.noclayer.com', 'type' => 0, 'cat' => 1, 'rack' => $rack->id, 'rack_pos' => $pos, 'rack_units' => 1, 'parent_device' => 0, 'meta_default_data' => 0, 'meta_update_time' => time(), 'meta_update_user' => $user);
     //print_r($props);
     $server = new Model_Device($props);
     $server->save();
     $this->net_type = 1;
     $this->add_device_default_fields($server);
     $network = Model_Device_Network::find()->where('deviceID', $server->id)->get_one();
     $network->nics = 2;
     $network->save();
     for ($i = 0; $i <= 1; $i++) {
         $prop = array('networkID' => $network->id, 'nic_name' => '', 'ipv4' => '192.168.8.' . $i, 'ipv6' => '', 'conn_type' => 1, 'conn_speed' => 3, 'type' => 1);
         $ip = new Model_Network_Ip($prop);
         $ip->save();
     }
     //add cabel
     $props = array('dev1' => $sw, 'port1' => $macs[$pos - 9], 'dev2' => $server->id, 'port2' => $ip->id, 'name1' => $pos - 9, 'name2' => 2, 'type' => 1, 'meta_update_time' => time(), 'meta_update_user' => $user);
     $cable = new Model_Cable($props);
     $cable->save();
     $power = Model_Device_Power::find()->where('deviceID', $server->id)->get_one();
     $powsockets = $power->socket;
     foreach ($powsockets as $sock) {
         $n = $pos - 9;
         $props = array('dev1' => $pduid, 'port1' => $sockets[38 - $n], 'dev2' => $server->id, 'port2' => $sock->id, 'name1' => $pos - 9, 'name2' => 1, 'type' => 2, 'meta_update_time' => time(), 'meta_update_user' => $user);
         $cable = new Model_Cable($props);
         $cable->save();
     }
     /*
     
     
      $props=Array(
      'dev1'=>$sw,
      'port1'=>$macs[$pos-9],
      'dev2'=>$server->id,
      'port2'=>$ip->id,
      'name1'=>$pos-9,
      'name2'=>1,
      'type'=>2,
      'meta_update_time'=>time(),
      'meta_update_user'=>$user
      );
      $cable=new Model_Cable($props);
      $cable->save();
     */
     return $server;
 }
コード例 #6
0
ファイル: templates.php プロジェクト: quickpacket/noclayer
 public function action_device($id = null)
 {
     if ($_POST) {
         $val = \Validation::forge('templates');
         if ($id == 'edit') {
             $val->add_field('did', 'device id', 'required|min_length[1]|max_length[20]');
             $val->add_field('type', 'device new type', 'required|min_length[1]|max_length[10]');
             if ($val->run()) {
                 //get device current template type
                 $dev = Model_Device::find($val->validated('did'));
                 //set template
                 $template = Model_Device_Template::find($val->validated('type'));
                 //category
                 $cat = $template->category;
                 //store position of vertical pdu
                 $power_temp = false;
                 if ($cat->id == 4) {
                     if ($dev->meta_default_data > 0) {
                         $power_temp = $dev->power;
                     }
                 }
                 $pdu_size_wrong = $this->check_for_PDU($template, $dev);
                 if ($pdu_size_wrong) {
                     echo json_encode(array('error' => 'You cant use this template, no enough space in rack'));
                 } else {
                     $dev_fields = Model_Device_Fieldset::find()->where('deviceID', $dev->id)->get();
                     //delete all data from device
                     foreach ($dev_fields as $dev_field) {
                         $dev_field->delete();
                     }
                     $fields = $template->field;
                     $dev->type = $template->id;
                     $dev->save();
                     foreach ($fields as $field) {
                         $data = array('name' => $field['name'], 'static' => $field['static'], 'value' => htmlspecialchars_decode($field['value']), 'type' => $field['type'], 'deviceID' => $dev->id, 'tab' => $field['tab'], 'extra' => $field['extra']);
                         $new_field = new Model_Device_Fieldset($data);
                         $new_field->save();
                         $this->insert_template_to_device_data($field, $new_field);
                     }
                     $out = false;
                     if ($cat->id == 4) {
                         $dev = Model_Device::find($val->validated('did'));
                         //check if vertical PDU , and echo number of output pins
                         if ($dev->meta_default_data > 0) {
                             $po = Model_Device_Power::find()->where('deviceID', $val->validated('did'))->get_one();
                             $po->pos = $power_temp->pos;
                             $po->ru = $power_temp->ru;
                             $po->save();
                             $out = $po->output;
                             echo json_encode(array('type' => $template->id, 'id' => $dev->id, 'cat' => $cat->id, 'out' => $out));
                         }
                     }
                     if (!$out) {
                         echo json_encode(array('type' => $template->id, 'id' => $dev->id, 'cat' => $cat->id));
                     }
                 }
             }
         }
     }
 }