zoukankan      html  css  js  c++  java
  • openstack端口禁用安全规则

    #!/bin/bash
    source ~/admin-openrc
    
    UserHelp() {
    cat <<EOF
    # Disable the security rules and ports of the cloud host
    
    Usage:
      ./disablePort.sh <network> server..
    
    Options:
      <network>   Enter the network name. For example: selfnetwork provider
    
    Example:
      ./disablePort.sh selfnetwork test01 test02
    EOF
    }
    
    if [[ $1 == 'selfnetwork' || $1 == 'provider' ]]; then
      network=$1
      shift
    
      for i in $*; do
        # 根据主机名,查IP地址
        # "/${i}/"'{print $5}' 两者之间不能有空格,如果过滤项是变量请使用双引号
        # '{sub("^ *","");sub(" *$","");print $2}' 显示第二项并删除前后空格
        IP_Field=`openstack server list | awk -F"|" "/$i/"'{print $5}'`
        # 判断主机是否存在,不存在则跳过本次循环。继续下一次循环
        if [[ -z $IP_Field ]];then
          echo "$i Host does not exist"
          continue
        fi
    
        for j in $IP_Field;do
          if [[ $j =~ "$network" ]];then
            IP=`echo $j | awk -F"[,;=]" '{sub("^ *","");sub(" *$","");print $2}'`
            # echo $IP
          fi
        done
      
        # 根据IP地址,查port id
        if [[ ! -z $IP ]];then
          Port_id=`openstack port list | awk "/'${IP}'/"'{print $2}'`
          # echo $Port_id
        fi
      
        # 禁用安全规则和端口规格
        openstack port set --no-security-group --disable-port-security ${Port_id}
      done
    
    elif [[ $1 == '--help' || $1 == '-h' || $# == 0 ]];then
      UserHelp
    
    else
      echo -e "Wrong option
    
    "
      UserHelp
    
    fi
    
  • 相关阅读:
    Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. ......
    UVA 1597 Searching the Web
    UVA 1596 Bug Hunt
    UVA 230 Borrowers
    UVA 221 Urban Elevations
    UVA 814 The Letter Carrier's Rounds
    UVA 207 PGA Tour Prize Money
    UVA 1592 Database
    UVA 540 Team Queue
    UVA 12096 The SetStack Computer
  • 原文地址:https://www.cnblogs.com/mycloudedu/p/14962054.html
Copyright © 2011-2022 走看看