private void button_RemoveVirtual_Click(object sender, EventArgs e) { System.Windows.Forms.ListBox.SelectedIndexCollection selItems = listBox_VirtualServersUsing.SelectedIndices; if (selItems.Count > 0) { iControl.LocalLBVirtualServerVirtualServerRule[][] rules = new iControl.LocalLBVirtualServerVirtualServerRule[selItems.Count][]; String[] vs_list = new String[selItems.Count]; iRuleInfo iri = (iRuleInfo)m_tn.Tag; for (int i = 0; i < selItems.Count; i++) { vs_list[i] = listBox_VirtualServersUsing.Items[selItems[i]].ToString(); rules[i] = new iControl.LocalLBVirtualServerVirtualServerRule[1]; rules[i][0] = new iControl.LocalLBVirtualServerVirtualServerRule(); rules[i][0].rule_name = iri.rule_name; rules[i][0].priority = 500; } try { Clients.VirtualServer.remove_rule(vs_list, rules); for (int i = 0; i < selItems.Count; i++) { listBox_VirtualServersUsing.Items.RemoveAt(selItems[i]); listBox_VirtualServersNotUsing.Items.Add(vs_list[i]); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Occurred"); } } }
protected override void ProcessRecord() { if (ValidateInput()) { if (isInitialized()) { try { String[] vs_list = GetiControl().LocalLBVirtualServer.get_list(); iControl.CommonEnabledState[] enabled_states = GetiControl().LocalLBVirtualServer.get_enabled_state(vs_list); // Build a list of indexes ArrayList index_list = new ArrayList(); for (int i = 0; i < vs_list.Length; i++) { if (true == matchString(vs_list[i], _name)) { index_list.Add(i); } } if (index_list.Count > 0) { String[] target_vs_list = new String[index_list.Count]; iControl.LocalLBVirtualServerVirtualServerRule[][] rule_lists = new iControl.LocalLBVirtualServerVirtualServerRule[index_list.Count][]; iControl.CommonEnabledState[] target_enabled_states = new iControl.CommonEnabledState[index_list.Count]; for (int j = 0; j < index_list.Count; j++) { int index = Convert.ToInt32(index_list[j]); target_vs_list[j] = vs_list[index]; rule_lists[j] = new iControl.LocalLBVirtualServerVirtualServerRule[1]; rule_lists[j][0] = new iControl.LocalLBVirtualServerVirtualServerRule(); rule_lists[j][0].rule_name = Rule; rule_lists[j][0].priority = 500; } GetiControl().LocalLBVirtualServer.remove_rule(target_vs_list, rule_lists); } } catch (Exception ex) { handleException(ex); } } else { handleNotInitialized(); } } }
private void button_RemoveVirtual_Click(object sender, EventArgs e) { System.Windows.Forms.ListBox.SelectedIndexCollection selItems = listBox_VirtualServersUsing.SelectedIndices; if (selItems.Count > 0) { iControl.LocalLBVirtualServerVirtualServerRule[][] rules = new iControl.LocalLBVirtualServerVirtualServerRule[selItems.Count][]; String[] vs_list = new String[selItems.Count]; iRuleInfo iri = (iRuleInfo)m_tn.Tag; for (int i = 0; i < selItems.Count; i++) { vs_list[i] = listBox_VirtualServersUsing.Items[selItems[i]].ToString(); rules[i] = new iControl.LocalLBVirtualServerVirtualServerRule[1]; rules[i][0] = new iControl.LocalLBVirtualServerVirtualServerRule(); rules[i][0].rule_name = iri.rule_name; rules[i][0].priority = 500; } try { Clients.VirtualServer.remove_rule(vs_list, rules); for (int i = 0; i < selItems.Count; i++) { listBox_VirtualServersUsing.Items.RemoveAt(selItems[i]); listBox_VirtualServersNotUsing.Items.Add(vs_list[i]); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Occurred"); } } }
private void button_AddVirtual_Click(object sender, EventArgs e) { System.Windows.Forms.ListBox.SelectedIndexCollection selItems = listBox_VirtualServersNotUsing.SelectedIndices; if (selItems.Count > 0) { iControl.LocalLBVirtualServerVirtualServerRule[][] rules = new iControl.LocalLBVirtualServerVirtualServerRule[selItems.Count][]; String[] vs_list = new String[selItems.Count]; iRuleInfo iri = (iRuleInfo)m_tn.Tag; for (int i = 0; i < selItems.Count; i++) { vs_list[i] = listBox_VirtualServersNotUsing.Items[selItems[i]].ToString(); rules[i] = new iControl.LocalLBVirtualServerVirtualServerRule[1]; rules[i][0] = new iControl.LocalLBVirtualServerVirtualServerRule(); rules[i][0].rule_name = iri.rule_name; rules[i][0].priority = 500; // Look for a specified priority in the iRule itself System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("priority\\s+(?<pri>[0-9]+)\\s+"); System.Text.RegularExpressions.Match match = regex.Match(iri.rule_details); if ( null != match ) { int pri = 500; try { String sPri = match.Groups["pri"].Value; pri = Convert.ToInt32(sPri); } catch(Exception) { } rules[i][0].priority = pri; } } // Query old iRules for selected VIPs (to look for matching priorities) iControl.LocalLBVirtualServerVirtualServerRule[][] existing_rules = Clients.VirtualServer.get_rule(vs_list); for (int i = 0; i < vs_list.Length; i++) { for (int j = 0; j < existing_rules[i].Length; j++) { if (rules[i][0].priority == existing_rules[i][j].priority) { // Increment it and try again... rules[i][0].priority++; j = -1; continue; } } } // Apply the iRules to the selected Virtuals try { Clients.VirtualServer.add_rule(vs_list, rules); for (int i = 0; i < selItems.Count; i++) { listBox_VirtualServersNotUsing.Items.RemoveAt(selItems[i]); listBox_VirtualServersUsing.Items.Add(vs_list[i]); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Occurred"); } } }
private void button_AddVirtual_Click(object sender, EventArgs e) { System.Windows.Forms.ListBox.SelectedIndexCollection selItems = listBox_VirtualServersNotUsing.SelectedIndices; if (selItems.Count > 0) { iControl.LocalLBVirtualServerVirtualServerRule[][] rules = new iControl.LocalLBVirtualServerVirtualServerRule[selItems.Count][]; String[] vs_list = new String[selItems.Count]; iRuleInfo iri = (iRuleInfo)m_tn.Tag; for (int i = 0; i < selItems.Count; i++) { vs_list[i] = listBox_VirtualServersNotUsing.Items[selItems[i]].ToString(); rules[i] = new iControl.LocalLBVirtualServerVirtualServerRule[1]; rules[i][0] = new iControl.LocalLBVirtualServerVirtualServerRule(); rules[i][0].rule_name = iri.rule_name; rules[i][0].priority = 500; // Look for a specified priority in the iRule itself System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("priority\\s+(?<pri>[0-9]+)\\s+"); System.Text.RegularExpressions.Match match = regex.Match(iri.rule_details); if (null != match) { int pri = 500; try { String sPri = match.Groups["pri"].Value; pri = Convert.ToInt32(sPri); } catch (Exception) { } rules[i][0].priority = pri; } } // Query old iRules for selected VIPs (to look for matching priorities) iControl.LocalLBVirtualServerVirtualServerRule[][] existing_rules = Clients.VirtualServer.get_rule(vs_list); for (int i = 0; i < vs_list.Length; i++) { for (int j = 0; j < existing_rules[i].Length; j++) { if (rules[i][0].priority == existing_rules[i][j].priority) { // Increment it and try again... rules[i][0].priority++; j = -1; continue; } } } // Apply the iRules to the selected Virtuals try { Clients.VirtualServer.add_rule(vs_list, rules); for (int i = 0; i < selItems.Count; i++) { listBox_VirtualServersNotUsing.Items.RemoveAt(selItems[i]); listBox_VirtualServersUsing.Items.Add(vs_list[i]); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Occurred"); } } }