Ejemplo n.º 1
0
 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();
         }
     }
 }
Ejemplo n.º 2
0
 public function action_index()
 {
     if (isset($this->field)) {
         $val = \Validation::forge();
         $out = true;
         $val->add_field('act', 'action id', 'required|min_length[1]|max_length[20]');
         $val->add_field('val', 'value', 'required|min_length[1]');
         if ($val->run()) {
             $data['err'] = '';
             $size = $val->validated('val');
             $kvm = $this->field->kvm;
             if ($this->tmpl) {
                 $data['cables'] = array();
             } else {
                 $data['cables'] = Model_Cable::find()->where('type', 2)->where('dev1', $this->field->deviceID)->or_where('dev2', $this->field->deviceID)->get();
             }
             switch ($val->validated('act')) {
                 case 'act1':
                     //current
                     //$pdu->current=$size;
                     break;
                 case 'act2':
                     //input sockets
                     if ($this->tmpl) {
                         $ip_q = Model_Device_Template_Kvm_Socket::find()->where('kvmID', $kvm->id)->where('type', 1);
                     } else {
                         $ip_q = Model_Device_Kvm_Socket::find()->where('kvmID', $kvm->id)->where('type', 1);
                     }
                     $this->fix_fields($size, $ip_q->count(), 1);
                     $kvm->input = $size;
                     break;
                 case 'act3':
                     //output sockets
                     if ($this->tmpl) {
                         $ip_q = Model_Device_Template_Kvm_Socket::find()->where('kvmID', $kvm->id)->where('type', 2);
                     } else {
                         $ip_q = Model_Device_Kvm_Socket::find()->where('kvmID', $kvm->id)->where('type', 2);
                     }
                     //if($this->check_boundary($pdu, $size)){
                     $this->fix_fields($size, $ip_q->count(), 2);
                     $kvm->output = $size;
                     break;
             }
             $kvm->save();
             $out = true;
             if ($out) {
                 $data['kvm'] = $this->field->kvm;
                 if ($this->isKVM()) {
                     return \Response::forge(\View::forge('kvm/supply', $data));
                 } else {
                     return \Response::forge(\View::forge('kvm/consumer', $data));
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 private function insert_template_to_device_data($field, $new_field)
 {
     #hdd element data
     #####################################################################################
     if ($field->type == 'hdd') {
         //get raid data
         $old_raid = Model_Raid::find()->where('tempfieldID', $field->id)->get_one();
         $hdd = Model_Raid::find()->where('fieldsetID', $new_field->id)->get_one();
         //create new hardware_raid
         $hdd->raid_type = $old_raid->raid_type;
         $hdd->size = $old_raid->size;
         $hdd->total = $old_raid->total;
         $hdd->meta_update_time = time();
         $hdd->meta_update_user = $this->user;
         //$hdd=new Model_Raid($prop);
         $hdd->save();
         //get all discs from array
         foreach ($old_raid->rows as $disc) {
             $m = array('model' => $disc->model, 'size' => $disc->size, 'vport' => $disc->vport, 'serial_number' => $disc->serial_number, 'hardware_raid' => $hdd->id, 'meta_update_time' => time(), 'meta_update_user' => $this->user);
             $discs = new Model_Raid_Data($m);
             $discs->save();
         }
     }
     //ram
     #####################################################################################
     if ($field->type == 'ram') {
         //get ram data
         $old_ram = Model_Ram::find()->where('tempfieldID', $field->id)->get_one();
         $ram = Model_Ram::find()->where('fieldsetID', $new_field->id)->get_one();
         //create new hardware_ram
         $ram->ram_type = $old_ram->ram_type;
         $ram->size = $old_ram->size;
         $ram->total = $old_ram->total;
         $ram->meta_update_time = time();
         $ram->meta_update_user = $this->user;
         $ram->save();
         //get all modules from array
         foreach ($old_ram->rows as $modul) {
             $m = array('hardware_ram' => $ram->id, 'meta_update_time' => time(), 'meta_update_user' => $this->user, 'model' => $modul->model, 'size' => $modul->size, 'port' => $modul->port, 'serial_number' => $modul->serial_number);
             $rams = new Model_Ram_Data($m);
             $rams->save();
         }
     }
     //images
     #####################################################################################
     if ($field->type == 'img') {
         //get field images
         $temp_imags = Model_Device_Template_Image::find()->where('elementID', $field->id)->get();
         foreach ($temp_imags as $img) {
             $props = array('name' => $img->name, 'elementID' => $new_field->id, 'type' => $img->type, 'width' => $img->width, 'height' => $img->height);
             $imgs = new Model_Image($props);
             $imgs->save();
             copy(DOCROOT . 'images/temp' . $img->id . '.png', DOCROOT . 'images/' . $imgs->id . '.png');
             copy(DOCROOT . 'images/tumb/temp' . $img->id . '.png', DOCROOT . 'images/tumb/' . $imgs->id . '.png');
         }
     }
     //power out (PDU,ATS,UPS)
     #####################################################################################
     if ($field->type == 'power_out') {
         //power is set automatic as field saved
         $power = Model_Device_Power::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->power;
         if ($new_field->device->meta_default_data > 0) {
             $max = 42;
         } else {
             $max = 24;
         }
         if ($extra->output > $max) {
             $extra->output = $max;
         }
         //update default data with template power data
         $power->input = $extra->input;
         $power->output = $extra->output;
         $power->type = $extra->type;
         $power->current = $extra->current;
         if ($power->ru == 0) {
             $power->ru = $extra->ru;
             $power->pos = $extra->pos;
         }
         $power->save();
         //delete any default socket
         $defsockets = Model_Device_Power_Socket::find()->where('powerID', $power->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         $n = 1;
         foreach ($field->power->socket as $socket) {
             if ($n > $max) {
                 break;
             }
             $prop = array('powerID' => $power->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Power_Socket($prop);
             $newsocket->save();
             if ($socket->type == 2) {
                 $n++;
             }
         }
     }
     //power in (Server,Switch,Router,...)
     #####################################################################################
     if ($field->type == 'power_in') {
         //power is set automatic as field saved
         $power = Model_Device_Power::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->power;
         //update default data with template power data
         $power->input = $extra->input;
         $power->output = $extra->output;
         $power->type = $extra->type;
         $power->current = $extra->current;
         $power->ru = $extra->ru;
         $power->pos = $extra->pos;
         $power->save();
         //delete any default socket
         $defsockets = Model_Device_Power_Socket::find()->where('powerID', $power->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         foreach ($field->power->socket as $socket) {
             $prop = array('powerID' => $power->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Power_Socket($prop);
             $newsocket->save();
         }
     }
     //kvm out (KVM switch)
     #####################################################################################
     if ($field->type == 'kvm_out') {
         //power is set automatic as field saved
         $kvm = Model_Device_Kvm::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->kvm;
         //update default data with template power data
         $kvm->input = $extra->input;
         $kvm->output = $extra->output;
         $kvm->type = $extra->type;
         $kvm->save();
         //delete any default socket
         $defsockets = Model_Device_Kvm_Socket::find()->where('kvmID', $kvm->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         foreach ($field->kvm->socket as $socket) {
             $prop = array('kvmID' => $kvm->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Kvm_Socket($prop);
             $newsocket->save();
         }
     }
     //KVM in (Server,Switch,Router,...)
     #####################################################################################
     if ($field->type == 'kvm_in') {
         //kvm is set automatic as field saved
         $kvm = Model_Device_Kvm::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->kvm;
         //update default data with template kvm data
         $kvm->input = $extra->input;
         $kvm->output = $extra->output;
         $kvm->type = $extra->type;
         $kvm->save();
         //delete any default socket
         $defsockets = Model_Device_Kvm_Socket::find()->where('kvmID', $kvm->id)->get();
         foreach ($defsockets as $ds) {
             $ds->delete();
         }
         foreach ($field->kvm->socket as $socket) {
             $prop = array('kvmID' => $kvm->id, 'conn_type' => $socket->conn_type, 'type' => $socket->type);
             $newsocket = new Model_Device_Kvm_Socket($prop);
             $newsocket->save();
         }
     }
     //network
     #####################################################################################
     if ($field->type == 'network') {
         //newtwork is set automatic as field saved
         $network = Model_Device_Network::find()->where('fieldsetID', $new_field->id)->get_one();
         $extra = $field->network;
         //update default data with  template network data
         $network->type = $extra->type;
         $network->nics = $extra->nics;
         $network->vports = $extra->vports;
         $network->ports = $extra->ports;
         $network->uplinks = $extra->uplinks;
         $network->save();
         switch ($network->type) {
             case 1:
                 //IP addresses
                 foreach ($field->network->ip as $ip) {
                     $prop = array('networkID' => $network->id, 'nic_name' => $ip->nic_name, 'ipv4' => $ip->ipv4, 'ipv6' => $ip->ipv6, 'conn_type' => $ip->conn_type, 'conn_speed' => $ip->conn_speed, 'type' => $ip->type);
                     $ips = new Model_Network_Ip($prop);
                     $ips->save();
                 }
                 break;
                 //MAC and VLAN
             //MAC and VLAN
             case 2:
                 $vlan2port = array();
                 //if no vlan is set to mac
                 $vlan2port[0] = 0;
                 foreach ($field->network->vlan as $vlan) {
                     $prop = array('networkID' => $network->id, 'name' => $vlan->name);
                     $vlans = new Model_Network_Vlan($prop);
                     $vlans->save();
                     $vlan2port[$vlan->id] = $vlans->id;
                 }
                 foreach ($field->network->mac as $mac) {
                     $prop = array('networkID' => $network->id, 'mac_address' => $mac->mac_address, 'conn_device' => $mac->conn_device, 'vlan' => $vlan2port[$mac->vlan], 'type' => $mac->type);
                     $macs = new Model_Network_Mac($prop);
                     $macs->save();
                 }
                 break;
             case 3:
                 foreach ($field->network->mac as $mac) {
                     $prop = array('networkID' => $network->id, 'mac_address' => $mac->mac_address, 'conn_device' => $mac->conn_device, 'vlan' => $mac->vlan, 'type' => $mac->type);
                     $macs = new Model_Network_Mac($prop);
                     $macs->save();
                 }
                 break;
         }
     }
 }