#compdef isi networks

# Copyright C 2002-2007 by Isilon Systems, Inc. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
# 
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# Inc.
# 
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems. 
#  
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  Legion is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.

(( $+functions[__isi_networks] )) ||
_isi_networks() {
  if (( CURRENT == 2 )); then
    _tags values && {compadd $@ create new modify delete rm list ls support dnscache}
    _arguments \
      '--dns-servers=[Set the domain name server IP address list]' \
      '--add-dns-servers=[Add one or more domain name server IP addresses]' \
      '--remove-dns-servers=[Remove one or more domain name server IP addresses]' \
      '--dns-search=[Set the DNS search suffix list]' \
      '--add-dns-search=[Add one or more DNS search suffixes]' \
      '--remove-dns-search=[Remove one or more DNS search suffixes]' \
      '--tcp-ports=[Set client TCP port list]' \
      '--add-tcp-port=[Add one or more recognized client TCP ports]' \
      '--remove-tcp-port=[Remove one or more recognized client TCP ports]' \
      '--help[Print usage help and exit]' \
      '--sc-rebalance-all[Rebalance IP addresses in all pools]' \
      '--sc-rebalance-delay[Delay (in seconds) for IP rebalance]'
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == create ]] || [[ $cmd == new ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-create:"
      _isi_networks_create
    elif [[ $cmd == modify ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-modify:"
      _isi_networks_modify
    elif [[ $cmd == delete ]] || [[ $cmd == rm ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-delete:"
      _isi_networks_delete
    elif [[ $cmd == list ]] || [[ $cmd == ls ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-list:"
      _isi_networks_list
    elif [[ $cmd == support ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-support:"
      _isi_networks_support
    elif [[ $cmd == dnscache ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-dnscache:"
      _isi_networks_dnscache
    fi
  fi
}

(( $+functions[_isi_list_net_objs] )) ||
_isi_list_net_objs() {
    _tags values && { compadd $1 $2 `/usr/local/share/zsh/site-functions/list-net-objs $3` }
}

(( $+functions[_isi_sc_policy] )) ||
_isi_sc_policy() {
    _tags values && { compadd $@ round-robin throughput cpu-usage conn-count }
}

(( $+functions[_isi_node_type] )) ||
_isi_node_type() {
    _tags values && { compadd $@ all accelerator accelerator-x storage storage-x }
}

(( $+functions[_isi_networks_create] )) ||
_isi_networks_create() {
  if (( CURRENT == 2 ))
  then
    _tags values && {compadd $@ pool subnet rule}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == pool ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-create-pool:"
      _isi_networks_create_pool
    elif [[ $cmd == subnet ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-create-subnet:"
      _isi_networks_create_subnet
    elif [[ $cmd == rule ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-create-rule:"
      _isi_networks_create_rule
    fi
  fi
}

(( $+functions[_isi_networks_create_pool] )) ||
_isi_networks_create_pool() {
  _arguments \
    '--name=[Name of the pool in the form Subnet:Pool; must be unique throughout the subnet]:pool_name:_isi_list_net_objs -sc' \
    '--ranges=[Set the IP address range(s) in this pool]' \
    '--ifaces=[Set the interface members in this pool]' \
    '--desc=[Optional description of the pool]' \
    '--dynamic[Dynamically allocate addresses among pool members]' \
    '--static[Statically assign addresses to pool members]' \
    '--zone=[SmartConnect zone name for the pool]' \
    '--connect-policy=[SmartConnect client connection balancing policy]:sc-policy:_isi_sc_policy' \
    '--failover-policy=[SmartConnect failover policy]:sc-policy:_isi_sc_policy' \
    '--manual-failback[Rebalancing is only performed manually]' \
    '--auto-failback[Automatically rebalance after failback]' \
    '--sc-subnet=[Name of SmartConnect Service subnet responsible for this zone]' \
    '--aggregation-mode=[Set the aggregation mode type for the pool]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_create_subnet] )) ||
_isi_networks_create_subnet() {
  _arguments \
    '--name=[Name of the subnet; must be unique throughout the cluster]' \
    '--netmask=[Netmask of the subnet]' \
    '--dsr-addrs=[Set the Direct Server Return address(es) for this subnet]' \
    '--desc=[Description of the subnet]' \
    '--gateway=[Gateway IP address]' \
    '--gateway-prio=[Gateway priority]' \
    '--mtu=[MTU of the subnet]' \
    '--sc-service-addr=[The address that SmartConnect listens on for DNS requests on this subnet]' \
    '--vlan-id=[VLAN ID/Tag for all interfaces in the subnet]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_create_rule] )) ||
_isi_networks_create_rule() {
  _arguments \
    '--name=[Name of the provisioning rule in the form Subnet:Pool:Rule; must be unique throughout the pool]:rule_name:_isi_list_net_objs -pfc' \
    '--iface=[Interface name the provisioning rule applies to]' \
    '--desc=[Optional description for the provisioning rule]' \
    '--any [Provisioning rule applies to Any nodes]' \
    '--storage-i[Provisioning rule applies to Storage-I nodes]' \
    '--accelerator-i[Provisioning rule applies to Accelerator-I nodes]' \
    '--storage[Provisioning rule applies to Storage nodes]' \
    '--accelerator[Provisioning rule applies to Accelerator nodes]' \
    '--backup-accelerator[Provisioning rule applies to Backup-Accelerator nodes]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_modify] )) ||
_isi_networks_modify() {
  if (( CURRENT == 2 ))
  then
    _tags values && {compadd $@ pool subnet rule}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == pool ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-modify-pool:"
      _isi_networks_modify_pool
    elif [[ $cmd == subnet ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-modify-subnet:"
      _isi_networks_modify_subnet
    elif [[ $cmd == rule ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-modify-rule:"
      _isi_networks_modify_rule
    fi
  fi
}

(( $+functions[_isi_networks_modify_pool] )) ||
_isi_networks_modify_pool() {
  _arguments \
    '--name=[Name of the pool in the form Subnet:Pool]:pool_name:_isi_list_net_objs -pf' \
    '--new-name=[New name for the pool; must be unique throughout the subnet]' \
    '--ranges=[Set the IP address range(s) in this pool]' \
    '--add-ranges=[Add one or more IP ranges to this pool]' \
    '--remove-ranges=[Remove one or more IP ranges from this pool]' \
    '--ifaces=[Set the interface member(s) in this pool]' \
    '--add-ifaces=[Add one or more member interfaces to this pool]' \
    '--remove-ifaces=[Remove one or more member interfaces from this pool]' \
    '--sc-subnet=[Name of SmartConnect service subnet responsible for this zone]' \
    '--desc=[Optional description of the pool]' \
    '--dynamic[Dynamically allocate addresses among pool members]' \
    '--static[Statically assign addresses to pool members]' \
    '--zone=[SmartConnect zone name for the pool]' \
    '--connect-policy=[SmartConnect client connection balancing policy]:sc-policy:_isi_sc_policy' \
    '--failover-policy=[SmartConnect failover policy]:sc-policy:_isi_sc_policy' \
    '--manual-failback[Rebalancing is performed manually after failback]' \
    '--auto-failback[Automatically rebalance after failback]' \
    '--sc-suspend-node[Suspend SmartConnect DNS query responses for node]:node:_isi_node' \
    '--sc-resume-node[Resume SmartConnect DNS query responses for node]:node:_isi_node' \
    '--sc-rebalance[Rebalance IP addresses for the specified pool]' \
    '--add-zone-aliases[Add one or more SmartConnect zone alias names]' \
    '--remove-zone-aliases[Remove one or more SmartConnect zone alias names]' \
    '--aggregation-mode[Set the aggregation mode type for the pool]' \
    '--add-static-routes[Add one or more static routes to pool.]' \
    '--remove-static-routes[Remove one or more static routes from pool.]' \
    '--ttl[Time to live value for SmartConnect DNS query responses (seconds)]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_modify_subnet] )) ||
_isi_networks_modify_subnet() {
  _arguments \
    '--name=[Name of the subnet]:subnet_name:_isi_list_net_objs -s' \
    '--new-name=[New name for the subnet; must be unique throughout the cluster]' \
    '--netmask=[Netmask of the subnet]' \
    '--disable-vlan[Disable any Virtual LAN tagging on the subnet]' \
    '--enable-vlan[Enable all Virtual LAN tagging on the subnet]' \
    '--dsr-addrs=[Set the Direct Server Return address(es) for this subnet]' \
    '--add-dsr-addrs=[Add one or more Direct Server Return addresses to this subnet]' \
    '--remove-dsr-addrs=[Remove one or more Direct Server Return addresses from this subnet]' \
    '--desc=[Description of the subnet]' \
    '--gateway=[Gateway IP address and priority]' \
    '--gateway-prio=[Gateway priority]' \
    '--mtu=[MTU of the subnet]' \
    '--sc-service-addr=[The address that SmartConnect listens on for DNS requests on this subnet]' \
    '--vlan-id=[VLAN ID/Tag for all interfaces in the subnet]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_modify_rule] )) ||
_isi_networks_modify_rule() {
  _arguments \
    '--name=[Name of the provisioning rule in the form Subnet:Pool:Rule]:rule_name:_isi_list_net_objs -rf' \
    '--new-name=[New name for the provisioning rule; must be unique throughout the pool]' \
    '--pool=[Name of the pool the provisioning rule belongs to in the form Subnet:Pool]:pool_name:_isi_list_net_objs -pf' \
    '--iface=[Interface name the provisioning rule applies to]' \
    '--desc=[Optional description for the provisioning rule]' \
    '--all[Provisioning rule applies to All nodes]' \
    '--storage[Provisioning rule applies to Storage nodes]' \
    '--accelerator[Provisioning rule applies to Accelerator nodes]' \
    '--storage-x[Provisioning rule applies to Storage-X nodes]' \
    '--accelerator-x[Provisioning rule applies to Accelerator-X nodes]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_delete] )) ||
_isi_networks_delete() {
  if (( CURRENT == 2 ))
  then
    _tags values && {compadd $@ pool subnet rule}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == pool ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-delete-pool:"
      _isi_networks_delete_pool
    elif [[ $cmd == subnet ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-delete-subnet:"
      _isi_networks_delete_subnet
    elif [[ $cmd == rule ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-delete-rule:"
      _isi_networks_delete_rule
    fi
  fi
}

(( $+functions[_isi_networks_delete_pool] )) ||
_isi_networks_delete_pool() {
  _arguments \
    '--name=[Name of the pool in the form Subnet:Pool]:pool_name:_isi_list_net_objs -pf' \
    '--force[Force command execution without warnings]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_delete_subnet] )) ||
_isi_networks_delete_subnet() {
  _arguments \
    '--name=[Name of the subnet]:subnet_name:_isi_list_net_objs -s' \
    '--force[Force command execution without warnings]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_delete_rule] )) ||
_isi_networks_delete_rule() {
  _arguments \
    '--name=[Name of the provisioning rule in the form Subnet:Pool:Rule]:rule_name:_isi_list_net_objs -rf' \
    '--force[Force command execution without warnings]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_list] )) ||
_isi_networks_list() {
  if (( CURRENT == 2 ))
  then
    _tags values && {compadd $@ pools subnets rules interfaces ifaces}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == pools ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-list-pools:"
      _isi_networks_list_pools
    elif [[ $cmd == subnets ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-list-subnets:"
      _isi_networks_list_subnets
    elif [[ $cmd == rules ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-list-rules:"
      _isi_networks_list_rules
    elif [[ $cmd == interfaces ]] || [[ $cmd == ifaces ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-list-interfaces:"
      _isi_networks_list_interfaces
    fi
  fi
}

(( $+functions[_isi_networks_list_pools] )) ||
_isi_networks_list_pools() {
  _arguments \
    '--name=[(Part of) the pool name, or a full name of the form Subnet:Pool]:pool_name:_isi_list_net_objs -pF' \
    '--subnet=[(Part of) the name of the subnet the pool belongs to]:subnet_name:_isi_list_net_objs -s' \
    '--iface=[Name of a member in the pool]' \
    '--rule=[Name of a rule in the pool]:rule_name:_isi_list_net_objs -r' \
    '--has-addr=[An IP address in the pool]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_list_subnets] )) ||
_isi_networks_list_subnets() {
  _arguments \
    '--name=[(Part of) the subnet name]:subnet_name:_isi_list_net_objs -s' \
    '--has-addr=[An IP address in the subnet range]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_list_rules] )) ||
_isi_networks_list_rules() {
  _arguments \
    '--name=[(Part of) the provisioning rule name, or a full name of the form Subnet:Pool:Rule]:rule_name:_isi_list_net_objs -rF' \
    '--subnet=[(Part of) the name of the subnet containing the pool the provisioning rule belongs to]:subnet_name:_isi_list_net_objs -s' \
    '--pool=[(Part of) the name of the pool the provisioning rule belongs to, or a full name of the form Subnet:Pool]:pool_name:_isi_list_net_objs -pF' \
    '--iface=[Interface name the provisioning rule applies to]' \
    '--all[Provisioning rule applies to All nodes]' \
    '--storage[Provisioning rule applies to Storage nodes]' \
    '--accelerator[Provisioning rule applies to Accelerator nodes]' \
    '--storage-x [Provisioning rule applies to Storage-X nodes]' \
    '--accelerator-x[Provisioning rule applies to Accelerator-X nodes]' \
    '--verbose[Print verbose output]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_list_interfaces] )) ||
_isi_networks_list_interfaces() {
  _arguments \
    '--verbose[Print verbose output]' \
    '--show-inactive[Show inactive interfaces (suppressed by default)]'
}

(( $+functions[_isi_networks_support] )) ||
_isi_networks_support() {
  if (( CURRENT == 2 ))
  then
    _tags values && {compadd $@ sc_put_ip}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == sc_put_ip ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-support-sc_put_ip:"
      _isi_networks_support_sc_put_ip
    fi
  fi
}

(( $+functions[_isi_networks_support_sc_put_ip] )) ||
_isi_networks_support_sc_put_ip() {
  _arguments \
    '--sc-ip=[IP address to move/put (must be in a dynamic IP Pool)]' \
    '--sc-iface=[Destination node:interface for IP (must be a member of the same dynamic IP Pool as the IP being moved)]' \
    '--help[Print usage help and exit]'
}

(( $+functions[_isi_networks_dnscache] )) ||
_isi_networks_dnscache() {
  if (( CURRENT == 2 ))
  then
    _tags values && {compadd $@ enable disable modify flush statistics}
  else
    local cmd=${words[2]}
    (( CURRENT-- ))
    shift words
    if [[ $cmd == modify ]]; then
      curcontext="${curcontext%:*:*}:isi-networks-dnscache-modify:"
      _isi_networks_dnscache_modify
    fi
  fi
}

(( $+functions[_isi_networks_dnscache_modify] )) ||
_isi_networks_dnscache_modify() {
  _arguments \
    '--ttl-max-noerror=[Upper bound on ttl for cache hits]' \
    '--ttl-min-noerror=[Lower bound on ttl for cache hits]' \
    '--ttl-max-nxdomain=[Upper bould for ttl for nxdomain]' \
    '--ttl-min-nxdomain=[Lower bould for ttl for nxdomain]' \
    '--ttl-max-other=[Upper bound for ttl for non-nxdomain failures]' \
    '--ttl-min-other=[Lower bound for ttl for non-nxdomain failures]' \
    '--eager-refresh=[Lead time to refresh cache entries nearing expiration]' \
    '--cache-entry-limit=[DNS Cache entry limit]' \
    '--testping-delta=[Delta for checking cbind cluster health]' \
    '--help[Print usage help and exit]'
}

