Applies to ReadyAPI 3.2.7, last modified on May 28, 2020

You can deploy and modify virtual services (virtual APIs) on VirtServer from the command line. For this purpose, you use the command-line interface utility provided with VirtServer and ReadyAPI installation.

About the VirtServer command-line interface utility

The VirtServer command-line utility is typically used to work with virtual services on VirtServer from client machines that do not have access to ServiceV. You can deploy and update services from it without stopping VirtServer, or integrate a command into your development environment. You can also start virtual services during your builds by using Maven integration or the Jenkins plugin.

Tip: If you do not automate your virtual service startup, you can also use the VirtServer Web UI to work with virtual services from your browser.

Requirements and limitations

  • To interact with VirtServer, you need a user on it. Use the VirtServer web interface or the VirtServer application command line to add a user.

  • The VirtServer command-line interface does not support working with JMS virtual services that use HermesJMS. Use the direct connection from ReadyAPI to deploy the services from the command line.

Get the command line interface utility

The command-line interface is included in VirtServer and ReadyAPI installations. It includes:

  • Executable file: virtserver-cli.bat/.sh file (.bat on Windows, .sh on Linux and MacOS). You can find it in the ReadyAPI/bin or VirtServer/bin folder.

  • Library: virtserver-cli-<library-version>.jar. You can find it in the ReadyAPI/tools or VirtServer/tools folder.

Syntax

The general command line syntax is as follows:

<path>/virtserver-cli -s IP:port [more-options]

Argument Description
-s IP:port, or
‑‑server IP:port

Required at least once. The IP address and port of the VirtServer instance to which you are sending the command. For example, ‑s 192.168.1.12:9090.

Once you specify the VirtServer address, you can omit the argument. In this case, the command-line utility will use the address specified in the previous command. When you need to change the address, specify the -s (‑‑server) argument again.

Log in to VirtServer

To perform any tasks using the command line interface, you must first log in. To do that, use the following command:

<path>/virtserver-cli -login -s IP:port -u name -pw password

For example:

"c:\Program Files\SmartBear\VirtServer\bin\virtserver-cli.bat" -login -s 10.0.81.128:9090 -u John -pw pswd1

The command uses the following arguments:

Argument Description
-login, or
--login

Commands VirtServer to send a token that will be stored on the computer and used for authenticating other commands. The expiration time of the token is controlled by the timeout settings of VirtServer.

-s IP:port, or
‑‑server IP:port

Optional. The IP address and port of the VirtServer instance to which you are logging in. For example, ‑s 192.168.1.12:9090.

If you omit this argument, the utility uses the address specified in the previous command.

-u user-name, or
‑‑user user-name

Required. The user account for interacting with VirtServer. This can be the user account you created when running VirtServer for the first time or an account you added later.

-pw password, or
‑‑password password

Optional. The password of the user you specified in the -u argument.

Tip: If you don't want to enter your password as a part of the command because it will be visible, omit the -pw argument. In this case, VirtServer will prompt you to enter the password in the command line. The password won't be visible when you are entering it.
Important: In VirtServer 3.2.0, the use of the -u and -pw arguments with commands other than -login has been deprecated.

Log out of VirtServer

When you have finished working with VirtServer, log out by using the following command:

<path>/virtserver-cli -logout -s IP:port

For example:

"c:\Program Files\SmartBear\VirtServer\bin\virtserver-cli.bat" -logout -s 10.0.81.128:9090

The command uses the following arguments:

Argument Description
-logout, or
--logout

Commands VirtServer to delete the stored session token that is used for authenticating commands.

-s IP:port, or
‑‑server IP:port

Optional. The IP address and port of the VirtServer instance to which you are logging in. For example, ‑s 192.168.1.12:9090.

If you omit this argument, the utility uses the address specified in the previous command.

Tasks

Deploy a virtual service to VirtServer

The following command deploys a virtual service (virtual API) to VirtServer:

<path>/virtserver-cli -d project -n virt-name [-p virt-port] [-a true/false] [-r] [-ppw project-password] -s IP:port

Example

Before running any commands on VirtServer, you must log in using the -login command.

Result value: The command returns the deployment id for your virtual service. This id is used by other operations that work with virtual services on VirtServer.

The command uses the following arguments:

Argument Description
-d project-file-name, or
--deploy project-file-name

Required. The fully-qualified name of the ReadyAPI project file that contains your virtual service. If the name contains spaces, enclose it in quotes.

-n virt-name, or
--name virt-name

Required. The name of the virtual service to deploy. If the name contains spaces, enclose it in quotes.

-p port-number, or
--port port-number

Optional. Specifies the port the virtual service will use on VirtServer. This port must be free in order for the virtual service to be able to run. If you skip this parameter, VirtServer will try to use the port specified by the service settings.

You can reassign the port number from the VirtServer UI or ServiceV UI, or from the command line.

-a true, or
--autostart true

Optional. true or false, default – false. If this parameter is true, VirtServer starts the virtual service automatically after the deployment, and every time VirtServer starts. If the parameter is false, you will have to start the service yourself.

-r, or
--replace

If this parameter is used, the virtual service will replace an existing service with the same name that was deployed to your VirtServer earlier.

-ppw password, or
--projectpassword password

Must be used for encrypted projects. Specifies the project password to decrypt the project.

-s IP:port, or
‑‑server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Start and stop virtual services on VirtServer

To start a virtual service that you deployed to VirtServer, use the following command:

<path>/virtserver-cli -start deployment-id -s IP:port

To stop a working virtual service, use the following command:

<path>/virtserver-cli -stop deployment-id -s IP:port

Example

Before running any commands on VirtServer, you must log in using the -login command.
Argument Description
-start deployment-id, or
--start deployment-id,
-stop deployment-id, or
--stop deployment-id

Commands VirtServer to start or stop a virtual service. The deployment-id value is the identifier that VirtServer assigned to your virtual service when you deployed it to VirtServer. If you forget it, you can get it later by using the -ls parameter.

-s IP:port, or
‑‑server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Notes:

  • Before starting a virtual service on VirtServer, you need to deploy this virtual service to VirtServer.

  • The commands above start and stop individual virtual services. You can start and stop multiple services by their tag values. See below.

  • You can command VirtServer to start a virtual service automatically by using the -a true parameter when deploying the service to VirtServer. See above.

Get a list of virtual services

To obtain information on virtual services deployed to your VirtServer, use the following command:

<path>/virtserver-cli -ls -s IP:port

The command returns a list of virtual services and their deployment identifiers – unique values used to work with services on VirtServer.

Before running any commands on VirtServer, you must log in using the -login command.
Argument Description
-ls, or --list

Commands VirtServer to output information on the virtual services that were deployed to this VirtServer.

-s IP:port, or
‑‑server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Change the virtual service properties

To change a virtual service port on VirtServer, or to change the Autostart property of a service, use a command line like this:

<path>/virtserver-cli -update deployment-id [-p new-port] [-a true/false] -s IP:port

For example:

"c:\Program Files\SmartBear\VirtServer\virtserver-cli.bat" -update 39 -p 8080 -u John -pw pswd1 -s 10.0.81.128:9090
Before running any commands on VirtServer, you must log in using the -login command.
Argument Description
-update deployment-id, or
--update deployment-id

Commands VirtServer to change the parameters of a virtual service that the deployment id specifies. deployment-id is the identifier that VirtServer assigned to your virtual service when you deployed it to VirtServer. You can get it by using the -ls parameter.

-p port-number, or
--port port-number

Optional. Specifies the new port number that the virtual service will use on VirtServer. The port must be free in order for the virtual service to be able to run.

You can also reassign the port number in the VirtServer UI or ServiceV UI.

-a true, or
--autostart true

Optional. Specifies the Autostart property of the virtual service, can be true or false. If true, VirtServer will start the service automatically when VirtServer starts.

-s IP:port, or
‑‑server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Assign and unassign tags

The virtserver-cli utility supports a number of arguments to help you assign tags to virtual services and remove tags from them:

Argument Description
-at deployment-id tag, or
--assignTag deployment-id tag

Assigns a tag to the virtual service specified by its deployment id. If the tag does not exist on the VirtServer side, it is created.

-ct tag, or
--createTag tag

Creates a tag on VirtServer, but does not assign it to any virtual service.

-dt tag, or
--deleteTag tag

Deletes the specified tag from VirtServer. If a tag is assigned to some virtual service, it is removed from this service.

-uat deployment-id tag, or
--unAssignTag deployment-id tag

Removes a tag from the specified virtual service.

-ut old-tag new-tag, or
--updateTag old-tag new-tag

Replaces an existing tag with a new one on VirtServer. If the existing tag is assigned to some virtual services, this command will replace it with a new tag on all these services.

-s IP:port, or
‑‑server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Notes:

  • Before running any commands on VirtServer, you must log in using the -login command.

  • If a tag name includes spaces, enclose it in quotes.

  • Deployment id is the identifier that VirtServer assigns to your virtual service when you deploy it to VirtServer. If you forget it, you can check it at any time later.

Examples:

  • Assigns the new tag “My tag” to a virtual service with the ID 39:

    "c:\Program Files\SmartBear\VirtServer\bin\virtserver-cli.bat" -at 39 "My tag" -s 192.168.1.56:9090

  • Removes a tag from all the virtual services, to which it is assigned, and from VirtServer:

    "c:\Program Files\SmartBear\VirtServer\bin\virtserver-cli.bat" -dt "My tag" -s 192.168.1.56:9090

  • Updates the tag value:

    "c:\Program Files\SmartBear\VirtServer\bin\virtserver-cli.bat" -ut "My tag" "New tag" -s 192.168.1.56:9090

Start and stop virtual services by tags

To start and stop multiple services by their tags, use the following commands:

<path>/virtserver-cli -startwt tag -s IP:port

<path>/virtserver-cli -stopwt tag -s IP:port

For example:

"c:\Program Files\SmartBear\VirtServer\bin\virtserver.bat -startwt "My tag" -s 192.168.1.10:9090

Argument Description
-startwt tag, or --startWithTag tag,
-stopwt tag, or--stopWithTag tag

Commands VirtServer to start or stop all virtual services to which the specified tag is assigned.

Note: If the tag name includes spaces, enclose it in quotes.

-s IP:port, or
‑‑server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Notes:

  • Before running any commands on VirtServer, you must log in using the -login command.

  • Before starting a virtual service on VirtServer, you need to deploy this virtual service to your instance of VirtServer.

  • The commands work with one tag only. If you want to start or stop virtual services that have different tags assigned, call the commands several times – once per each tag.

  • To start and stop individual services, you can also use the -start and -stop commands. See above.

Undeploy a virtual service from VirtServer

To remove a virtual service from VirtServer, use the following command line:

<path>/virtserver-cli -delete deployment-id -s IP:port

Example

Before running any commands on VirtServer, you must log in using the -login command.
Argument Description
-delete deployment-id, or
--delete deployment-id

Commands VirtServer to remove a virtual service from your VirtServer instance. The deployment-id value is the identifier that VirtServer assigned to your service when you deployed it to VirtServer. If you forget it, you can get it at any time later.

-s IP:port, or
--server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Add user

To add a user to VirtServer, use the following command line:

<path>/virtserver-cli --adduser -nu username -npw password -s IP:port

Example

To manage VirtServer users, you must log in as an administrator by using the -login command.
Argument Description
--adduser

Adds a new user to VirtServer.

The new user will not have administrator permissions. To give them, edit the user in the web interface.

-nu username

Required. Specifies the username of the new user.

-npw password

Required. Specifies the password of the new user.

-s IP:port, or
--server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Remove user

To remove a user from VirtServer, use the following command line:

<path>/virtserver-cli --deleteuser -du username -s IP:port

Example

To manage VirtServer users, you must log in as an administrator by using the -login command.
Argument Description
--deleteuser

Removes the specified user from VirtServer.

-du username

Required. Specifies the username to delete.

-s IP:port, or
--server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Edit user

To modify a user’s password or role, use the following command line:

<path>/virtserver-cli --edituser -eu username -epw new-password -er user-role -s IP:port

Example

To manage VirtServer users, you must log in as an administrator by using the -login command.
Argument Description
--edituser

Updates the password or role of a VirtServer user.

-eu username

Required. Specifies the user whose password or role you want to change.

-epw new-password

Optional. Specifies the new password for the user.

-er user-role

Optional. Specifies the new role for the user. Possible values: user, admin.

-s IP:port, or
--server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

Get list of VirtServer users

To get a list of users added to VirtServer, use the following command line:

<path>/virtserver-cli --enumerateusers -s IP:port

Example

To manage VirtServer users, you must log in as an administrator by using the -login command.
Argument Description
--enumerateusers

Shows a list of all users added to VirtServer.

-s IP:port, or
--server IP:port

Optional. Specifies the IP address and port of the VirtServer instance.

If you omit this argument, the utility uses the address specified in the previous command.

More commands

The virtserver-cli utility also has the following arguments:

Argument Description
-audit, or --audit

Outputs the contents of the VirtServer Audit Log page to the console. Supported for VirtServer 1.2 and later.

-legacy, or --legacy

Indicates that you are sending commands to VirtServer version 1.1 or earlier.

-h, or --help

Displays quick help on the command-line arguments.

See Also

Connect With ServiceV
VirtServer Tutorial
VirtServer Command-Line Arguments

Highlight search results