Ncloud CLI
    • PDF

    Ncloud CLI

    • PDF

    Article summary

    The latest service changes have not yet been reflected in this content. We will update the content as soon as possible. Please refer to the Korean version for information on the latest updates.

    Available in Classic and VPC

    This guide describes initial settings and brief instructions for the Ncloud CLI.

    Note

    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.

    Install

    Download the latest CLI file for your operating system (Windows, Linux).

    Note

    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 or JDK already installed in 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 the CLI.

    Note

    For more information about API authentication keys, refer to Security settings in the Portal and console guide and Create authentication key in the API guide.

    You can get the entries for Access Key and Secret Key when you enter the ncloud configure command.

    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 an example of a call.

    Naver@Al01221192:/mnt/c/Users/Naver/Desktop/cli_linux$ ./ncloud server getZoneList --regionNo 1 --profile example_profile
    

    Command help

    To check help for smooth use of Ncloud CLI, run commans by adding help at the end. The following command lists the options and help, as well as usable top-level commands related to the 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

    The 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. You can also use parameters in the Map or List format. List is used in commands as 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 examples below, single quotation marks (') and double quotation marks (") can be used in Linux, macOS, Unix, and Windows PowerShell, and double quotation marks (") is used in Windows Command Prompt.

    • 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

    The Ncloud CLI supports two types of output formats. If the --output option is not used, then the output is formatted as the default JSON string.

    • JSON (json): default
    • XML(xml)

    If you want the output as an 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 environment

    The scenario in the VPC environment is as follows.

    1. Create VPC
    2. Search Network ACL
    3. Create subnet.
    4. Create init script (Install and run Apache, and then create an index.html file using the touch command)
    5. Search server image
    6. Search ACG
    7. Create server (Set init script)
    8. Create and assign public IP address
    9. Allow Port 80 in ACG
    10. Check results
    • Create VPC (VPC number: ***224)
    $ ./ncloud vpc createVpc --ipv4CidrBlock 192.168.0.0/16
    
    • Search 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": ""
    }
    
    • Search 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 the 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
      image.png

    Classic environment

    The scenario in the Classic environment is as follows.

    1. Search server image
    2. Create server (Set init script to install and run Apache, and then create an index.html file using the touch command)
    3. Create and assign public IP address
    4. 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 the 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 the 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)
      image.png

    • Check results in browser
      image.png


    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.