function __free_cloud_ips($cr_id, $noop) { $error = ''; $cc_conf = new cloudconfig(); $show_ip_mgmt = $cc_conf->get_value(26); // ip-mgmt enabled ? if ($cr_id == 0) { // check and clean all ips if (!strcmp($show_ip_mgmt, "true")) { if (file_exists($this->webdir . "/plugins/ip-mgmt/.running")) { require_once $this->webdir . "/plugins/ip-mgmt/class/ip-mgmt.class.php"; $ip_mgmt = new ip_mgmt(); $ip_mgmt_id_array = $ip_mgmt->get_ids(); foreach ($ip_mgmt_id_array as $ip_id) { $ip = $ip_mgmt->get_instance('id', $ip_id['ip_mgmt_id']); $state = $ip['ip_mgmt_state']; $token = $ip['ip_mgmt_token']; $found_token = false; // check if the appliance still exists if (strlen($ip['ip_mgmt_appliance_id'])) { $ip_appliance = new appliance(); if ($ip_appliance->is_id_free($ip['ip_mgmt_appliance_id'])) { // error $error .= "found left over ip " . $ip['ip_mgmt_address'] . "<br>"; } } // check if we have a token set, if yes check all appliances for that token if (strlen($token) && $token != '0') { $ip_appliance = new appliance(); $ip_appliance_id_array = $ip_appliance->get_all_ids(); foreach ($ip_appliance_id_array as $ip_app_id_arr) { $ip_app_id = $ip_app_id_arr['appliance_id']; $ip_appliance->get_instance_by_id($ip_app_id); if (strlen($ip_appliance->capabilities)) { $pos = strpos($ip_appliance->capabilities, $token); if ($pos !== false) { $found_token = true; } } } if (!$found_token) { // error $error .= "found left over ip with token set / appliance missing " . $ip[ip_mgmt_address] . "<br>"; } } else { if ($state == 1) { // error $error .= "found left over ip with no token set " . $ip[ip_mgmt_address] . "<br>"; } } } } } } else { // clean ips for a specific cr $cr_ip = new cloudrequest(); $cr_ip->get_instance_by_id($cr_id); if (!strcmp($show_ip_mgmt, "true")) { if (file_exists($this->webdir . "/plugins/ip-mgmt/.running")) { require_once $this->webdir . "/plugins/ip-mgmt/class/ip-mgmt.class.php"; $ip_mgmt_array = explode(",", $cr_ip->ip_mgmt); foreach ($ip_mgmt_array as $ip_mgmt_config_str) { $collon_pos = strpos($ip_mgmt_config_str, ":"); $nic_id = substr($ip_mgmt_config_str, 0, $collon_pos); $ip_mgmt_id = substr($ip_mgmt_config_str, $collon_pos + 1); $ip_mgmt_fields = array(); $ip_mgmt_fields["ip_mgmt_appliance_id"] = NULL; $ip_mgmt_fields["ip_mgmt_nic_id"] = NULL; $ip_mgmt_assign = new ip_mgmt(); if ($noop) { $ip_mgmt_assign->update_ip($ip_mgmt_id, $ip_mgmt_fields); } else { // error $error .= "freeing up ip " . $ip_mgmt_id . "<br>"; } } } } } return $error; }