- Print
- PDF
Ncloud CLI
- Print
- PDF
Available in Classic and VPC
This guide describes initial settings and brief instructions for Ncloud CLI.
If you'll like to see detailed commands and examples related to the CLI, execute the CLI help
command.
Initial settings
It describes the installation process and API authentication key configuration method required for the use of Ncloud CLI.
Installation
Download the latest CLI file for your operating system (Windows, Linux).
Refer to Download CLI for information related to downloading the latest CLI files and their configurations.
Run the ncloud
command from the downloaded folder path (cli_window/cli_linux). The following message is displayed upon successful execution.
- Windows
C:\Users\Naver\cli_window>ncloud ncloud <command> [subcommand] help ncloud: error: The command does not exist. For help, input 'help' command.
- Linux
Naver@AL01221192:/mnt/c/Users/NAVER/Desktop/cli_linux$ ./ncloud ncloud <command> [subcommand] help ncloud: error: The command does not exist. For help, input 'help' command.
If JRE or JDK of version 1.8 or later is installed in the local environment, then you can also use the following file.
C:\Users\Naver>javac -version
javac 1.8.0_80
Connect existing JRE or JDK
If you're using existing JRE or JDK installed locally, instead of the included JRE file, then change ./jre8/bin/java
to java
from the ncloud script file. This only applies when trying to use the JRE, JDK already installed the local environment.
- Before Modification
#!/bin/bash HOME='./lib' /jre8/bin/java -jar ${HOME}/ncloud-api-cli-1.0.2-SNAPSHOT-jar-with-dependencies.jar $@
- After Modification
#!/bin/bash HOME='./lib' java -jar ${HOME}/ncloud-api-cli-1.0.2-SNAPSHOT-jar-with-dependencies.jar $@
Set API authentication key
An API authentication key must be set up first to use CLI.
For more information on API authentication key, see the API guide.
Entering the ncloud configure
command will allow the input of Access Key and Secret Key.
Naver@AL01221192:/mnt/c/Users/Naver/Desktop/cli_linux$ ./ncloud configure
set [DEFAULT]'s configuration.
Ncloud Access Key Id [] :***js9sk$K)DA!#***
Ncloud Secret Access Key [] :***kdofFIik9D$Kdk2***
Ncloud API URL (Default:https://ncloud.apigw.ntruss.com) []:
Each API authentication key is saved as a configure file under the user environment home directory's .ncloud
folder. If the API authentication key has been entered properly, then the command will be executed successfully. If the entered API authentication key is not valid, then the following message will be displayed.
Naver@Al01221192:/mnt/c/Users/Naver/Desktop/cli_linux$ ./ncloud server getRegionList
Invalid consumer
If the authentication key value is valid, then the following result is displayed when running getZoneList.
Naver@Al01221192:/mnt/c/Users/Naver/Desktop/cli_linux$ ./ncloud server getZoneList --regionNo 1
{
"getZoneListResponse" : {
"requestId" : "5604cb78-67c9-4d91-ae74-085152f23df3",
"returnCode" : 0,
"returnMessage" : "success",
"zoneList" : [
{
"zone" : {
"zoneNo" : 2,
"zoneName" : "KR-1",
"zoneDescription" : "Gasan NANG zone"
}
}
]
}
}
You can run the command with the authentication information of the profile configured through the profile option.
Naver@AL01221192:/mnt/c/Users/Naver/Desktop/cli_linux$ ./ncloud configure --profile example_profile
set [example_profile]'s configuration.
Ncloud Access Key Id [] :***js9sk$K)DA!#***
Ncloud Secret Access Key [] :***kdofFIik9D$Kdk2***
Ncloud API URL (Default:https://ncloud.apigw.ntruss.com) []:
The following is a call example.
Naver@Al01221192:/mnt/c/Users/Naver/Desktop/cli_linux$ ./ncloud server getZoneList --regionNo 1 --profile example_profile
Command help
To check help for seamless use of Ncloud CLI, run commands by adding help
at the end. The following command lists the options and help, as well as usable top-level commands related to Ncloud CLI.
$ ./ncloud help
The following command lists subcommands that can be used from top-level commands of Ncloud.
$ ./ncloud server help
$ ./ncloud loadbalancer help
Command Structure
Ncloud CLI uses a multipart structure in the command line. This structure starts as a default call for Ncloud, and each command has subcommands for jobs to be performed. When adding options from CLI, it doesn't matter in which order you specify certain parameters.
$ ./ncloud <command> <subcommand> [options and parameters]
Specify CLI parameters and options
Most parameter values are simple strings or numbers. Other than that, Maps and Lists may be used as parameters. The List is used like the commands shown below. The List parameter can be used with spaces ( ), commas (,), declaration of additional parameters, etc.
$ ./ncloud server getPublicIpInstanceList --publicIpInstanceNoList 573361 571968
$ ./ncloud server getPublicIpInstanceList --publicIpInstanceNoList 573361,571968
$ ./ncloud server getPublicIpInstanceList --publicIpInstanceNoList 573361 --publicIpInstanceNoList 571968
Strings that do not contain spaces may or may not be contained within quotation marks. However, strings in Map format must be contained within quotation marks. As shown in the following example, Linux, Mac OS, Unix, and Windows PowerShell can use single quotation marks (') and double quotation marks ("), and Windows Command Prompt uses double quotation marks (").
Windows PowerShell, Linux, MacOS, Unix
$ ./ncloud loadbalancer createLoadBalancerInstance --loadBalancerName penguin --loadBalancerRuleList 'protocolTypeCode="HTTP",loadBalancerPort="80",serverPort="80",l7HealthCheckPath="/l7check.html",proxyProtocolUseYn="N"'
Windows Command Prompt
> ncloud loadbalancer createLoadBalancerInstance --loadBalancerName penguin --loadBalancerRuleList "protocolTypeCode='HTTP',loadBalancerPort='80',serverPort='80',l7HealthCheckPath='/l7check.html',proxyProtocolUseYn='N'"
Control command output
Ncloud CLI supports two types of output formats. If the --output
option is not used, then the default JSON format will be output.
- JSON (json): Default
- XML(xml)
If you want to output to XML, run the following.
$ ncloud server getZoneList --output xml
Set timeout
You can set the times for read timeout and connection timeout. You can set them in seconds, and the default value is 300 seconds.
$ ncloud server getZoneList --read-timeout 10
$ ncloud server getZoneList --connect-timeout 5
CLI execution scenario
The following are simple test scenarios created using the CLI.
VPC
The scenario in the VPC environment is as follows.
- Create VPC
- Get network ACL
- Create subnet
- Create "init" script (Install and run Apache; create an index.html file using the "touch" command)
- Get server image
- Search ACG
- Create server (Set "init" script)
- Create and assign public IP address
- Allow port 80 in ACG
- Check results
Create VPC (VPC number: ***224)
$ ./ncloud vpc createVpc --ipv4CidrBlock 192.168.0.0/16
Get default network ACL of the created VPC (Network ACL number: ***960)
$ ./ncloud vpc getNetworkAclList --vpcNo ***224
Create subnet (Subnet number ***928)
$ ./ncloud vpc createSubnet --zoneCode KR-1 --vpcNo ***224 --subnet 192.168.1.0/24 --networkAclNo ***960 --subnetTypeCode PUBLIC
Create "init" script to run when creating server ("init" script number ***751)
$ ./ncloud vserver createInitScript --initScriptContent '#!/bin/sh'$'\n''yum install -y httpd'$'\n''service httpd start'$'\n''echo '\''Hello World'\'' > /var/www/html/index.html'$'\n''chkconfig --level 2345 httpd on'
Server image: CentOS 6.6 (64-bit) (Product code (productCode): SW.VSVR.OS.LNX64.CNTOS.0606.B050)
$ ./ncloud vserver getServerImageProductList | grep `CentOS 6.6(64bit)' -C 8
{ "productCode": "SW.VSVR.OS.LNX64.CNTOS.0606.B050", "productName": "centos-6.6-64", "productType": { "code": "LINUX", "codeName": "Linux" }, "productDescription": "CentOS 6.6(64bit)", "infraResourceType": { "code": "SW", "codeName": "Software" }, "cpuCount": 0, "memorySize": 0, "baseBlockStorageSize": 53687091200, "platformType": { "code": "LNX64", "codeName": "Linux 64 Bit" }, "osInformation": "CentOS 6.6 (64-bit)", "dbKindCode": "", "addBlockStorageSize": 0, "generationCode": "" }
Get default ACG of the created VPC (ACG number: ***009)
$ ./ncloud vserver getAccessControlGroupList --vpcNo ***224
Create a server instance with the minimum specifications using the CentOS 6.6 (64-bit) server image (Server instance number: ***182)
$ ./ncloud vserver createServerInstances --vpcNo ***224 --subnetNo ***928 --serverImageProductCode 'SW.VSVR.OS.LNX64.CNTOS.0606.B050' --networkInterfaceList 'networkInterfaceOrder="0", accessControlGroupNoList=["***009"]' --initScriptNo ***751
Create and assign Public IP Address to a server (***.***.145.185)
$ ./ncloud vserver createPublicIpInstance --serverInstanceNo ***182
Set permission rule for Port 80 in the ACG applied to the server's network interface
$ ./ncloud vserver addAccessControlGroupInboundRule --vpcNo ***224 --accessControlGroupNo ***009 --accessControlGroupRuleList 'protocolTypeCode="TCP", ipBlock="0.0.0.0/0", portRange="80"'
Check results in browser
Classic
The scenario in the Classic environment is as follows.
- Get server image
- Create server (Set the "init" script to install and run Apache; create an index.html file using the "touch" command)
- Create and assign public IP address
- Check server creation
Server image: CentOS 6.6 (64-bit) (Product code (productCode): SPSW0LINUX000044)
$ ./ncloud server getServerImageProductList | grep `CentOS 6.6(64bit)' -C 8
{ "productCode": "SPSW0LINUX000044", "productName": "centos-6.6-64", "productType": { "code": "LINUX", "codeName": "Linux" }, "productDescription": "CentOS 6.6(64bit)", "infraResourceType": { "code": "SW", "codeName": "Software" }, "cpuCount": 0, "memorySize": 0, "baseBlockStorageSize": 53687091200, "platformType": { "code": "LNX64", "codeName": "Linux 64 Bit" }, "osInformation": "CentOS 6.6 (64-bit)", "dbKindCode": "", "addBlockStorageSize": 0 }
Create a server instance with the minimum specifications using the CentOS 6.6 (64-bit) server image (Server instance number: ***385)
$ ./ncloud server createServerInstances --serverImageProductCode 'SPSW0LINUX000044' --userData 'file:///mnt/c/Users/NAVER/Desktop/cli_linux/userData.sh'
User file (userData.sh) to run when creating server
#!/bin/sh yum install -y httpd service httpd start echo 'Hello World' > /var/www/html/index.html chkconfig --level 2345 httpd on
{ "createServerInstancesResponse" : { "requestId" : "df5aebe7-6875-49fb-91fb-2df11f67ffa5", "returnCode" : 0, "returnMessage" : "success", "totalRows" : 1, "serverInstanceList" : [ { "serverInstanceNo" : ***385, ... } ] } }
Create and assign Public IP Address to a server (..145.185)
$ ./ncloud server createPublicIpInstance --serverInstanceNo '***385'
{ "createPublicIpInstanceResponse" : { "requestId" : "ec5feb0b-9d9c-4539-bef1-81e94fc81dc6", "returnCode" : 0, "returnMessage" : "success", "totalRows" : 1, "publicIpInstanceList" : [ { "publicIpInstanceNo" : ***389, "publicIp" : "***.***.145.185" } ] } }
In the NAVER Cloud Platform console, set to allow Port 80 in ACG for the ***.***.145.185 public IP address (Server > ACG)
Check results in browser