Package: qcloudcli
Tencent Cloud (aka QCloud) Command Line Interface qcloudcli is an open source tool built on top of the Tencent Cloud API that provides commands for interacting with Tencent Cloud services.It works on Python versions:2.7.x and greater3.6.x and greaterInstallThe recommended way to install qcloudcli is to usepip:$pipinstall--userqcloudcli--useroption will install qcloudcli to current user path instead of system path, for Linux system, it might be~/.local, which means it doesn’t requiresudopriviledge.Attention!If you are in avirtualenvenvironment, the--useroption should be removed.Get the version of qcloudcli:$qcloudcli--versionto upgrade:$pipinstall--user--upgradeqcloudclito remove:$pipuninstall--yesqcloudcliCommand CompletionOn Unix-like systems, the qcloudcli includes a command-completion feature that enables you to use the TAB key to complete a partially typed command. This feature is not automatically installed, so you need to configure it manually.$complete-Cqcloud_completerqcloudcliAdd it to your~/.bashrcto enable it by default.Usage GuideConfigurationqcloudcli needs account information to interact with Tencent Cloud Services. Log in Tencent CloudConsole, shift toAPI Credential Managementpage to view your credentials, if the list is empty, you will need to create a new one.SecretIdis used like your account name,SecretKeyis used like your password, so keep in mind that never leak yourSecretKeyto others.Attention!You might not be able to have such page in international site or translations in English version for now.Runqcloudcli congifureto enter interactive mode and provide information like this:$qcloudcliconfigureQcloudAPISecretId[None]:fooQcloudAPISecretKey[None]:barRegionId(gz,hk,ca,sh,shjr,bj,sg)[None]:gzOutputFormat(json,table,text)[None]:jsonThese information will be stored in files under your home root path, for example, in Linux system, it will be~/.qcloudcli/configureand~/.qcloudcli/credentials.The content of~/.qcloudcli/configurein last example is:[default]
output = json
region = gzThe content of~/.qcloudcli/credentialsin last example is:[default]
qcloud_secretkey = bar
qcloud_secretid = forAttention!These information will be stored as plain text, it relies on your correct access control of your private home directory.In Linux system, the default priviledge is:$ ls -l ~/.qcloudcli/
total 8
4 -rw-rw-r-- 1 john john 36 Nov 29 23:35 configure
4 -rw------- 1 john john 55 Nov 29 23:35 credentialsAttention!Currently, these two configure files will not be removed when you uninstall qcloudcli, you will need to manually remove them.Use HelpTo get available module list, includingconfigurecommand, run:$ qcloudcli helpTo get action list of specific module, for example, cvm (Cloud Virtual Machine), run:$ qcloudcli cvm helpTo get parameter list of specific action, for example, DescribeInstances, run:$ qcloudcli cvm DescribeInstances helpSpecify Complex Object ParamtersTo specify base type parameters, like string and int, you can directly use it. For example, to get instance (virtual machine) list, use default API version, limit the return item to 10, run:$ qcloudcli cvm DescribeInstances --limit 10For complex object parameters, like array and dictionary, you have to use json format string.For example, to get instance list, use default API version, only query instances which id areqcvmf4b542ad7b4cd49f2db57a733368d5b1andqcvmaf636dd06a816765b4f2c51595f2d84d, run:$ qcloudcli cvm DescribeInstances --instanceIds '["qcvmf4b542ad7b4cd49f2db57a733368d5b1", "qcvmaf636dd06a816765b4f2c51595f2d84d"]'For example, to get instance list, use API version 2017-03-12, withFiltersparameter, only return instances in ap-guangzhou-2 zone, run:$ qcloudcli cvm DescribeInstances --Filters '[{"Name":"zone","Values":["ap-guangzhou-2"]}]'For example, to create new instances, use API version 2017-03-12, a complex example might be:$ qcloudcli cvm RunInstances --Placement '{"Zone":"ap-beijing-3"}' --InstanceChargeType PREPAID --InstanceChargePrepaid '{"Period":1,"RenewFlag":"NOTIFY_AND_AUTO_RENEW"}' --ImageId img-dkwyg6sr --InstanceType S2.SMALL1 --SystemDisk '{"DiskType":"CLOUD_BASIC","DiskSize":50}' --InternetAccessible '{"InternetChargeType":"TRAFFIC_POSTPAID_BY_HOUR","InternetMaxBandwidthOut":2,"PublicIpAssigned":"TRUE"}' --InstanceName prod-jumpserver-01 --EnhancedService '{"SecurityService":{"Enabled":"TRUE"},"MonitorService":{"Enabled":"TRUE"}}' --InstanceCount 1 --VirtualPrivateCloud '{"VpcId":"vpc-njkwg482","SubnetId":"subnet-6rs8ienn"}'NOTE: HerePlacementhas specify availability zone to beap-beijing-3, so the region value in~/.qcloudcli/configuremust bebj, or you can specify global parameter--RegionIdap-beijingto override configured value.Filter Dataqcloudcli provides--filteroption which bases onjmespathto filter returned data, it is pretty useful when you want to get specific data from a bunch of items. However, you need to know the exact structure of returned json format.For example, to get security groups and only return security gourp id, run:$ qcloudcli dfw DescribeSecurityGroups --filter data[*].sgId
[
    "sg-icy671l9",
    "sg-o9rfv42p",
    "sg-pknfyaar",
    "sg-2rjokpt7",
    "sg-4ehjaoh3"
]*means get all elements.For example, using CVM API version 2017-03-12, to get security groups id of a specific instance ins-od1laqxs, run:$ qcloudcli cvm DescribeInstances --InstanceIds '["ins-od1laqxs"]' --filter Response.InstanceSet[0].SecurityGroupIds
[
    "sg-4ehjaoh3"
]The index0means get the first instance.Specify API VersionNOTE: New in version 1.9.0Some services of Tencent Cloud have multiple API versions, for example, CVM has a API version 2017-03-12, to use it, open~/.qcloudcli/configureand add the following content in profile section:api_versions =
    cvm = 2017-03-12If the specified version doesn’t exist, you will get an error when you run related commands.
If the service only has one version, then you don’t need to add such configuration, please remove it.
If the service has multiple versions, and there is no such configuration, then the default one will be used.Use HTTPS ProxyNOTE: New in version 1.8.9If you are in an environment behinds a proxy, and*.api.qcloud.comis not in the proxy white list, then you will need to configure HTTPS proxy to get qcloudcli work.Currently, only verified in Linux and Windows system, with proxy doesn’t require user name and password.In Linux system, to set your temporary global proxy, run:$ export https_proxy=YourProxyRealHost:YourProxyRealPortPlease note that replaceYourProxyRealHostandYourProxyRealPortwith your real proxy information.
You can add it to your~/.bashrcto active it by default.In Windows system, to set your temporary global proxy, run:> set https_proxy=YourProxyRealHost:YourProxyRealPortYou can add it to your system environment variables to active it by default.