日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python如何调用阿里云接口_Python调用aliyun API设置阿里云负载均衡虚拟服务器组权重...

發布時間:2024/7/5 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python如何调用阿里云接口_Python调用aliyun API设置阿里云负载均衡虚拟服务器组权重... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

環境準備

系統環境

CentOS Linux release 7.2.1511 (Core)

[root@localhost ~]# cat /proc/version

Linux version 3.10.0-327.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015

[root@localhost ~]#

[root@localhost ~]# uname -a

Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ~]#

[root@localhost ~]# python -V

Python 2.7.5

軟件環境

[root@localhost ~]# yum groupinstall "Development Tools"

[root@localhost ~]# yum install python-setuptools ntsysv python-devel setuptool

[root@localhost ~]# pip install setuptools

[root@localhost ~]# pip install aliyun-python-sdk-core

[root@localhost ~]# pip install aliyun-python-sdk-slb

腳本編寫

#!/usr/bin/env python

#coding=utf-8

import sys

import json

from aliyunsdkcore import client

from aliyunsdkslb.request.v20140515 import SetVServerGroupAttributeRequest

from aliyunsdkslb.request.v20140515 import DescribeVServerGroupAttributeRequest

clt = client.AcsClient('','','cn-hangzhou')

# 查詢

## 設置參數

request = DescribeVServerGroupAttributeRequest.DescribeVServerGroupAttributeRequest()

request.set_accept_format('json')

request.add_query_param('RegionId', 'cn-beijing')

request.add_query_param('VServerGroupId', 'rsp-2zef……5p80')

## 發起請求

response = clt.do_action_with_exception(request)

## 輸出結果

print "查詢結果:", response, '\n'

# 處理

weight = json.loads(response)["BackendServers"]["BackendServer"]

for i in range(len(weight)):

weight[i]["Weight"] = sys.argv[i+1]

print "參數設置Client"+str(i+1)+':', weight[i]["Weight"], '\n'

weight = json.dumps(weight)

# 設置

## 設置參數

request = SetVServerGroupAttributeRequest.SetVServerGroupAttributeRequest()

request.set_accept_format('json')

request.add_query_param('RegionId', 'cn-beijing')

request.add_query_param('BackendServers', weight)

request.add_query_param('VServerGroupId', 'rsp-2z……p80')

## 發起請求

response = clt.do_action_with_exception(request)

## 輸出結果

print "設置結果:", response, '\n'

使用方法

執行腳本傳入參數即可。

[root@localhost ~]# python ali-slb.py ……

結果展示

操作前

執行腳本

結果展示

歡迎大佬,批評指正!

總結

以上是生活随笔為你收集整理的python如何调用阿里云接口_Python调用aliyun API设置阿里云负载均衡虚拟服务器组权重...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。