• 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
    
  • 相关阅读:
    什么是软件质量?
    软件生存周期及其模型是什么?
    给你一个网站,你如何测试?
    jquery中$.get()提交和$.post()提交有区别吗?
    JQuery有几种选择器?
    ajax和layui总结
    md5加密
    Collection接口相关介绍
    JS 中document.URL 和 windows.location.href 的区别
    window.location.href的用法(动态输出跳转)
  • 原文地址:https://www.cnblogs.com/mycloudedu/p/14962054.html
Copyright © 2020-2023  润新知