Skip to content
Snippets Groups Projects
Commit 69ef9951 authored by Florent Gluck's avatar Florent Gluck
Browse files

Restructured and factorized documentation

Added src/client/cmdTemplate/templateListSingle.go which I had forgotten to add previously
parent eb6191f0
Branches
No related tags found
No related merge requests found
......@@ -8,13 +8,13 @@
Nexus VDI is divided into three components:
**[nexus-server](docs/README_server.md)**
- Documentation about inner working of nexus-server and how to install it is described here: [README_server.md](docs/README_server.md)
**[nexus-server](docs/server.md)**
- Documentation about inner working of nexus-server and how to install it [is described here](docs/server.md)
- The server program (backend) that runs on a server
- Exposes a REST API to manage users, VMs and templates
**[nexus-client](docs/README_client.md)**
- Documentation about how to use nexus clients is described here: [README_client.md](docs/README_client.md)
**[nexus-client](docs/client.md)**
- Documentation about how to use nexus clients [is described here](docs/client.md)
- The client or end-user program to manage users, VMs and templates
- The client uses REST messages to communicate with `nexus-server`
- The client can be run from anywhere (locally or remotely) as long as it can communicate with `nexus-server`
......@@ -33,4 +33,4 @@ Nexus VDI is divided into three components:
## Installation
Instructions on how to build and install nexus-server for development and production use, as well as building clients, [are described here](docs/INSTALL.md).
Instructions on how to build and install nexus-server for development and production use, as well as building clients, [are described here](docs/install.md).
## Access control
Access control is implemented through capabilities.
Capabilities define what users can or cannot do. They are divided into two categories:
- **User capabilities**: define user access control; these are stored in the user config
- **VM access capabilities**: define access to VMs; these are stored in the VM config
### User capabilities
The various operations a user can or cannot do are defined by her/his capabilities.
The table below lists all potential capabilities associated to a user:
| Capability | Description |
|--- |--- |
| USER_CREATE | Can create a user |
| USER_DESTROY | Can destroy a user |
| USER_SET_CAPS | Can change a user's capabilities |
| USER_LIST | Can list all users |
| VM_CREATE | Can create a VM |
| VM_DESTROY_ANY | Can destoy **ANY** VM |
| VM_EDIT_ANY | Can edit **ANY** VM |
| VM_START_ANY | Can start **ANY** VM |
| VM_STOP_ANY | Can kill/shutdown **ANY** VM |
| VM_REBOOT_ANY | Can Reboot **ANY** VM |
| VM_LIST_ANY | Can list **ANY** VM |
| VM_ATTACH_ANY | Can attach to **ANY** VM |
| VM_READFS_ANY | Can export files from **ANY** VM |
| VM_WRITEFS_ANY | Can import files into **ANY** VM |
| VM_SET_ACCESS | Can change (edit or delete) a VM's access |
| VM_SET_ACCESS_ANY | Can change (edit or delete) any VM's access |
| TPL_CREATE | Can create a template |
| TPL_EDIT | Can edit a template |
| TPL_EDIT_ANY | Can edit **ANY** template |
| TPL_DESTROY | Can destroy a template |
| TPL_DESTROY_ANY | Can destroy **ANY** template |
| TPL_LIST | Can list public or owned templates |
| TPL_LIST_ANY | Can list **ANY** template |
| TPL_READFS | Can export files from a public or owned templates |
| TPL_READFS_ANY | Can export files from **ANY** template |
### VM access capabilities
What a user can or cannot do **with a VM** is defined by the capabilities stored in the VM for this very user.
The table below lists all potential capabilities granted to a user for a given VM.
These capabilities are called "VM access capabilities":
| Capability | Description |
|--- |--- |
| VM_SET_ACCESS | User can add/change access to the (running or stopped) VM |
| | VM_SET_ACCESS **must also be present** in the user's capabilities! |
| VM_DESTROY | User can destroy the (stopped) VM |
| VM_EDIT | User can edit the (running or stopped) VM |
| VM_START | User can start the (stopped) VM |
| VM_STOP | User can kill/shutdown the (running) VM |
| VM_REBOOT | User can reboot the (running) VM |
| VM_LIST | User can list the VM's meta-data |
| VM_ATTACH | User can attach to the (running) VM |
| VM_READFS | User can export files from the (stopped) VM |
| VM_WRITEFS | User can import files into the (stopped) VM |
### IMPORTANT
- When a user creates a VM, she/he is this VM's owner
- the owner is granted all VM access capabilities
- No other users is granted any access to the created VM. However, the VM owner can add any access type to any users they like
......@@ -672,71 +672,11 @@ source .env.nexus
## Access control
Access control is implemented through capabilities.
Capabilities define what users can or cannot do. They are divided into two categories:
- **User capabilities**: define user access control; these are stored in the user config
- **VM access capabilities**: define access to VMs; these are stored in the VM config
### User capabilities
The various operations a user can or cannot do are defined by her/his capabilities.
The table below lists all potential capabilities associated to a user:
| Capability | Description |
|--- |--- |
| USER_CREATE | Can create a user |
| USER_DESTROY | Can destroy a user |
| USER_SET_CAPS | Can change a user's capabilities |
| USER_LIST | Can list all users |
| VM_CREATE | Can create a VM |
| VM_DESTROY_ANY | Can destoy **ANY** VM |
| VM_EDIT_ANY | Can edit **ANY** VM |
| VM_START_ANY | Can start **ANY** VM |
| VM_STOP_ANY | Can kill/shutdown **ANY** VM |
| VM_REBOOT_ANY | Can Reboot **ANY** VM |
| VM_LIST_ANY | Can list **ANY** VM |
| VM_ATTACH_ANY | Can attach to **ANY** VM |
| VM_READFS_ANY | Can export files from **ANY** VM |
| VM_WRITEFS_ANY | Can import files into **ANY** VM |
| VM_SET_ACCESS | Can change (edit or delete) a VM's access |
| VM_SET_ACCESS_ANY | Can change (edit or delete) any VM's access |
| TPL_CREATE | Can create a template |
| TPL_EDIT | Can edit a template |
| TPL_EDIT_ANY | Can edit **ANY** template |
| TPL_DESTROY | Can destroy a template |
| TPL_DESTROY_ANY | Can destroy **ANY** template |
| TPL_LIST | Can list public or owned templates |
| TPL_LIST_ANY | Can list **ANY** template |
| TPL_READFS | Can export files from a public or owned templates |
| TPL_READFS_ANY | Can export files from **ANY** template |
### VM access capabilities
What a user can or cannot do **with a VM** is defined by the capabilities stored in the VM for this very user.
The table below lists all potential capabilities granted to a user for a given VM.
These capabilities are called "VM access capabilities":
| Capability | Description |
|--- |--- |
| VM_SET_ACCESS | User can add/change access to the (running or stopped) VM |
| | VM_SET_ACCESS **must also be present** in the user's capabilities! |
| VM_DESTROY | User can destroy the (stopped) VM |
| VM_EDIT | User can edit the (running or stopped) VM |
| VM_START | User can start the (stopped) VM |
| VM_STOP | User can kill/shutdown the (running) VM |
| VM_REBOOT | User can reboot the (running) VM |
| VM_LIST | User can list the VM's meta-data |
| VM_ATTACH | User can attach to the (running) VM |
| VM_READFS | User can export files from the (stopped) VM |
| VM_WRITEFS | User can import files into the (stopped) VM |
### IMPORTANT
- When a user creates a VM, she/he is **automatically granted all VM access capabilities**.
- No other users is granted any access to the created VM. However, the VM owner can add any access type to any users they like.
Access control [is described here](access_control.md).
## REST API
The REST API [is described here](rest_api.md).
## Domain firewall
......
File moved
## REST API
### Login and version management
| Route | Description | Method | Parameters |
|--- |--- |--- |--- |
| `/login` | login (return access token) | POST | email,pwd |
| `/token/refresh` | obtain a new access token | GET | |
| `/version` | obtain version number | GET | |
### User management
| Route | Description | Method | Parameters | Req. user cap. |
|--- |--- |--- |--- |--- |
| `/users` | create a user | POST | email,firstname,lastname,pwd,caps | `USER_CREATE` |
| `/users/{email}` | delete a user | DELETE | | `USER_DESTROY` |
| `/users/{email}/caps` | set caps for a user | PUT | caps | `USER_SET_CAPS` |
| `/users/pwd` | set current user's pwd | PUT | pwd | |
| `/users` | list users | GET | | `USER_LIST` |
| `/users/{email}` | list a user | GET | | `USER_LIST` |
| `/users/whoami` | list current user | GET | | |
- Open question: shall we forbid the deletion of a user if they still own templates or VMs?
### VM management
| Route | Description | Method | Parameters | Req. user cap. | Op. | Req. VM access cap. |
|--- |--- |--- |--- |--- |--- |--- |
| `/vms` | returns VMs that can be listed | GET | | `VM_LIST_ANY` | OR | `VM_LIST` |
| `/vms/{id}` | returns a VM | GET | | `VM_LIST_ANY` | OR | `VM_LIST` |
| `/vms/start` | returns VMs that can be started | GET | | `VM_START_ANY` | OR | `VM_START` |
| `/vms/attach` | returns VMs that can be attached to | GET | | `VM_ATTACH_ANY` | OR | `VM_ATTACH` |
| `/vms/stop` | returns VMs that can be killed/shutdown | GET | | `VM_STOP_ANY` | OR | `VM_STOP` |
| `/vms/reboot` | returns VMs that can be rebooted | GET | | `VM_REBOOT_ANY` | OR | `VM_REBOOT` |
| `/vms/edit` | returns VMs that can be edited | GET | | `VM_EDIT_ANY` | OR | `VM_EDIT` |
| `/vms/editaccess` | returns VMs that can have their access changed | GET | | `VM_SET_ACCESS` | AND | `VM_SET_ACCESS` |
| `/vms/del` | returns VMs that can be deleted | GET | | `VM_DESTROY_ANY` | OR | `VM_DESTROY` |
| `/vms/exportdir` | returns VMs that can have a dir downloaded | GET | | `VM_READFS_ANY` | OR | `VM_READFS` |
| `/vms/importfiles` | returns VMs allowing files upload | GET | | `VM_WRITEFS_ANY` | OR | `VM_WRITEFS` |
| Route | Description | Method | Parameters | Req. user cap. | Op. | Req. VM access cap. |
|--- |--- |--- |--- |--- |--- |--- |
| `/vms` | create a VM | POST | name,cpus,ram,nic,usb,template | `VM_CREATE` | | |
| `/vms/{id}` | delete a VM | DELETE | | `VM_DESTROY_ANY` | OR | `VM_DESTROY` |
| `/vms/{id}` | edit a VM | PUT | name,cpus,ram,nic,usb | `VM_EDIT_ANY` | OR | `VM_EDIT` |
| `/vms/{id}/start` | start a VM | PUT | | `VM_START_ANY` | OR | `VM_START` |
| `/vms/{id}/startwithcreds` | start a VM with credentials | PUT | port,pwd | `VM_START_ANY` | OR | `VM_START` |
| `/vms/{id}/stop` | kill a VM | PUT | | `VM_STOP_ANY` | OR | `VM_STOP` |
| `/vms/{id}/reboot` | reboot a VM | PUT | | `VM_REBOOT_ANY` | OR | `VM_REBOOT` |
| `/vms/{id}/shutdown` | gracefully shutdown a VM | PUT | | `VM_STOP_ANY` | OR | `VM_STOP` |
| `/vms/{id}/access/{email}` | set VM access for a user | PUT | caps | `VM_SET_ACCESS` | AND | `VM_SET_ACCESS` |
| `/vms/{id}/access/{email}` | del VM access for a user | DELETE | | `VM_SET_ACCESS` | AND | `VM_SET_ACCESS` |
| `/vms/{id}/exportdir` | download a VM's dir | GET | dir | `VM_READFS_ANY` | OR | `VM_READFS` |
| `/vms/{id}/importfiles` | upload files into a VM's dir | POST | files (.tar archive),dir | `VM_WRITEFS_ANY` | OR | `VM_WRITEFS` |
### Template management
| Route | Description | Method | Parameters | Req. user cap. |
|--- |--- |--- |--- |--- |
| `/templates` | returns templates that can be listed | GET | | `TPL_LIST_ANY` OR `TPL_LIST` |
| `/templates/{id}` | returns a template | GET | | `TPL_LIST_ANY` OR `TPL_LIST` |
| `/templates/vm` | create a template | POST | vmID,name,access | `TPL_CREATE` |
| `/templates/qcow` | create a template | POST | qcow,name,access | `TPL_CREATE` |
| `/templates/{id}` | edit a template | PUT | name,access | `TPL_EDIT_ANY` OR `TPL_EDIT` |
| `/templates/{id}` | delete a template | DELETE | | `TPL_DESTROY_ANY` OR `TPL_DESTROY` |
| `/templates/{id}/disk` | download a template's disk | GET | | `TPL_READFS_ANY` OR `TPL_READFS` |
Remarks:
- A template can only be deleted if no VM references it!
<!--
### Group management
| `/vms/group/{gid}` | list all VMs in a group | GET | | `VM_LIST|VM_LIST_ANY` |
| `/vms/group/{gid}` | delete all VMs in a group | DELETE | | `VM_DESTROY|VM_DESTROY_ANY` |
| `/vms/group/{gid}/start` | start all VMs in a group | PUT | | `VM_START|VM_START_ANY` |
| `/vms/group/{gid}/stop` | stop all VMs in a group | PUT | | `VM_STOP|VM_STOP_ANY` |
| `/vms/group/{gid}/mask` | mask (to non-owner) all VMs in a group | PUT | | `VM_MASK|VM_MASK_ANY` |
| `/vms/group/{gid}/unmask`| unmask (to non-owner) all VMs in a group | PUT | | `VM_MASK|VM_MASK_ANY` |
| `/vms/{id}/move/{gid}` | move a VM into a group | PUT | | `VM_MOVE|VM_MOVE_ANY` |
| Route | Description | Method | Parameters | Required capabilities |
|--- |--- |--- |--- |--- |
| `/groups` | create a group | POST | name | `GRP_CREATE` |
| `/groups/{id}` | delete a group | DELETE | | `GRP_DESTROY|GRP_DESTROY_ANY` |
| `/groups/{id}/rename` | rename a group | PUT | new name | `GRP_RENAME|GRP_RENAME_ANY` |
| `/groups` | list groups | GET | | `GRP_LIST|GRP_LIST_ANY` |
-->
......@@ -246,162 +246,11 @@ Consequently, it is highly recommended to install it in all templates as it give
## Access control
Access control is implemented through capabilities.
Capabilities define what users can or cannot do. They are divided into two categories:
- **User capabilities**: define user access control; these are stored in the user config
- **VM access capabilities**: define access to VMs; these are stored in the VM config
### User capabilities
The various operations a user can or cannot do are defined by her/his capabilities.
The table below lists all potential capabilities associated to a user:
| Capability | Description |
|--- |--- |
| USER_CREATE | Can create a user |
| USER_DESTROY | Can destroy a user |
| USER_SET_CAPS | Can change a user's capabilities |
| USER_LIST | Can list all users |
| VM_CREATE | Can create a VM |
| VM_DESTROY_ANY | Can destoy **ANY** VM |
| VM_EDIT_ANY | Can edit **ANY** VM |
| VM_START_ANY | Can start **ANY** VM |
| VM_STOP_ANY | Can kill/shutdown **ANY** VM |
| VM_REBOOT_ANY | Can Reboot **ANY** VM |
| VM_LIST_ANY | Can list **ANY** VM |
| VM_ATTACH_ANY | Can attach to **ANY** VM |
| VM_READFS_ANY | Can export files from **ANY** VM |
| VM_WRITEFS_ANY | Can import files into **ANY** VM |
| VM_SET_ACCESS | Can change (edit or delete) a VM's access |
| VM_SET_ACCESS_ANY | Can change (edit or delete) any VM's access |
| TPL_CREATE | Can create a template |
| TPL_EDIT | Can edit a template |
| TPL_EDIT_ANY | Can edit **ANY** template |
| TPL_DESTROY | Can destroy a template |
| TPL_DESTROY_ANY | Can destroy **ANY** template |
| TPL_LIST | Can list public or owned templates |
| TPL_LIST_ANY | Can list **ANY** template |
| TPL_READFS | Can export files from a public or owned templates |
| TPL_READFS_ANY | Can export files from **ANY** template |
### VM access capabilities
What a user can or cannot do **with a VM** is defined by the capabilities stored in the VM for this very user.
The table below lists all potential capabilities granted to a user for a given VM.
These capabilities are called "VM access capabilities":
| Capability | Description |
|--- |--- |
| VM_SET_ACCESS | User can add/change access to the (running or stopped) VM |
| | VM_SET_ACCESS **must also be present** in the user's capabilities! |
| VM_DESTROY | User can destroy the (stopped) VM |
| VM_EDIT | User can edit the (running or stopped) VM |
| VM_START | User can start the (stopped) VM |
| VM_STOP | User can kill/shutdown the (running) VM |
| VM_REBOOT | User can reboot the (running) VM |
| VM_LIST | User can list the VM's meta-data |
| VM_ATTACH | User can attach to the (running) VM |
| VM_READFS | User can export files from the (stopped) VM |
| VM_WRITEFS | User can import files into the (stopped) VM |
### IMPORTANT
- When a user creates a VM, she/he is this VM's owner
- the owner is granted all VM access capabilities
- No other users is granted any access to the created VM. However, the VM owner can add any access type to any users they like
Access control [is described here](access_control.md).
## REST API
### Login and version management
| Route | Description | Method | Parameters |
|--- |--- |--- |--- |
| `/login` | login (return access token) | POST | email,pwd |
| `/token/refresh` | obtain a new access token | GET | |
| `/version` | obtain version number | GET | |
### User management
| Route | Description | Method | Parameters | Req. user cap. |
|--- |--- |--- |--- |--- |
| `/users` | create a user | POST | email,firstname,lastname,pwd,caps | `USER_CREATE` |
| `/users/{email}` | delete a user | DELETE | | `USER_DESTROY` |
| `/users/{email}/caps` | set caps for a user | PUT | caps | `USER_SET_CAPS` |
| `/users/pwd` | set current user's pwd | PUT | pwd | |
| `/users` | list users | GET | | `USER_LIST` |
| `/users/{email}` | list a user | GET | | `USER_LIST` |
| `/users/whoami` | list current user | GET | | |
- Open question: shall we forbid the deletion of a user if they still own templates or VMs?
### VM management
| Route | Description | Method | Parameters | Req. user cap. | Op. | Req. VM access cap. |
|--- |--- |--- |--- |--- |--- |--- |
| `/vms` | returns VMs that can be listed | GET | | `VM_LIST_ANY` | OR | `VM_LIST` |
| `/vms/{id}` | returns a VM | GET | | `VM_LIST_ANY` | OR | `VM_LIST` |
| `/vms/start` | returns VMs that can be started | GET | | `VM_START_ANY` | OR | `VM_START` |
| `/vms/attach` | returns VMs that can be attached to | GET | | `VM_ATTACH_ANY` | OR | `VM_ATTACH` |
| `/vms/stop` | returns VMs that can be killed/shutdown | GET | | `VM_STOP_ANY` | OR | `VM_STOP` |
| `/vms/reboot` | returns VMs that can be rebooted | GET | | `VM_REBOOT_ANY` | OR | `VM_REBOOT` |
| `/vms/edit` | returns VMs that can be edited | GET | | `VM_EDIT_ANY` | OR | `VM_EDIT` |
| `/vms/editaccess` | returns VMs that can have their access changed | GET | | `VM_SET_ACCESS` | AND | `VM_SET_ACCESS` |
| `/vms/del` | returns VMs that can be deleted | GET | | `VM_DESTROY_ANY` | OR | `VM_DESTROY` |
| `/vms/exportdir` | returns VMs that can have a dir downloaded | GET | | `VM_READFS_ANY` | OR | `VM_READFS` |
| `/vms/importfiles` | returns VMs allowing files upload | GET | | `VM_WRITEFS_ANY` | OR | `VM_WRITEFS` |
| Route | Description | Method | Parameters | Req. user cap. | Op. | Req. VM access cap. |
|--- |--- |--- |--- |--- |--- |--- |
| `/vms` | create a VM | POST | name,cpus,ram,nic,usb,template | `VM_CREATE` | | |
| `/vms/{id}` | delete a VM | DELETE | | `VM_DESTROY_ANY` | OR | `VM_DESTROY` |
| `/vms/{id}` | edit a VM | PUT | name,cpus,ram,nic,usb | `VM_EDIT_ANY` | OR | `VM_EDIT` |
| `/vms/{id}/start` | start a VM | PUT | | `VM_START_ANY` | OR | `VM_START` |
| `/vms/{id}/startwithcreds` | start a VM with credentials | PUT | port,pwd | `VM_START_ANY` | OR | `VM_START` |
| `/vms/{id}/stop` | kill a VM | PUT | | `VM_STOP_ANY` | OR | `VM_STOP` |
| `/vms/{id}/reboot` | reboot a VM | PUT | | `VM_REBOOT_ANY` | OR | `VM_REBOOT` |
| `/vms/{id}/shutdown` | gracefully shutdown a VM | PUT | | `VM_STOP_ANY` | OR | `VM_STOP` |
| `/vms/{id}/access/{email}` | set VM access for a user | PUT | caps | `VM_SET_ACCESS` | AND | `VM_SET_ACCESS` |
| `/vms/{id}/access/{email}` | del VM access for a user | DELETE | | `VM_SET_ACCESS` | AND | `VM_SET_ACCESS` |
| `/vms/{id}/exportdir` | download a VM's dir | GET | dir | `VM_READFS_ANY` | OR | `VM_READFS` |
| `/vms/{id}/importfiles` | upload files into a VM's dir | POST | files (.tar archive),dir | `VM_WRITEFS_ANY` | OR | `VM_WRITEFS` |
### Template management
| Route | Description | Method | Parameters | Req. user cap. |
|--- |--- |--- |--- |--- |
| `/templates` | returns templates that can be listed | GET | | `TPL_LIST_ANY` OR `TPL_LIST` |
| `/templates/{id}` | returns a template | GET | | `TPL_LIST_ANY` OR `TPL_LIST` |
| `/templates/vm` | create a template | POST | vmID,name,access | `TPL_CREATE` |
| `/templates/qcow` | create a template | POST | qcow,name,access | `TPL_CREATE` |
| `/templates/{id}` | edit a template | PUT | name,access | `TPL_EDIT_ANY` OR `TPL_EDIT` |
| `/templates/{id}` | delete a template | DELETE | | `TPL_DESTROY_ANY` OR `TPL_DESTROY` |
| `/templates/{id}/disk` | download a template's disk | GET | | `TPL_READFS_ANY` OR `TPL_READFS` |
Remarks:
- A template can only be deleted if no VM references it!
<!--
### Group management
| `/vms/group/{gid}` | list all VMs in a group | GET | | `VM_LIST|VM_LIST_ANY` |
| `/vms/group/{gid}` | delete all VMs in a group | DELETE | | `VM_DESTROY|VM_DESTROY_ANY` |
| `/vms/group/{gid}/start` | start all VMs in a group | PUT | | `VM_START|VM_START_ANY` |
| `/vms/group/{gid}/stop` | stop all VMs in a group | PUT | | `VM_STOP|VM_STOP_ANY` |
| `/vms/group/{gid}/mask` | mask (to non-owner) all VMs in a group | PUT | | `VM_MASK|VM_MASK_ANY` |
| `/vms/group/{gid}/unmask`| unmask (to non-owner) all VMs in a group | PUT | | `VM_MASK|VM_MASK_ANY` |
| `/vms/{id}/move/{gid}` | move a VM into a group | PUT | | `VM_MOVE|VM_MOVE_ANY` |
| Route | Description | Method | Parameters | Required capabilities |
|--- |--- |--- |--- |--- |
| `/groups` | create a group | POST | name | `GRP_CREATE` |
| `/groups/{id}` | delete a group | DELETE | | `GRP_DESTROY|GRP_DESTROY_ANY` |
| `/groups/{id}/rename` | rename a group | PUT | new name | `GRP_RENAME|GRP_RENAME_ANY` |
| `/groups` | list groups | GET | | `GRP_LIST|GRP_LIST_ANY` |
-->
The REST API [is described here](rest_api.md).
## Building and installing nexus-server
......
File moved
package cmdTemplate
import (
u "nexus-client/utils"
g "nexus-client/globals"
)
type ListSingle struct {
Name string
}
func (cmd *ListSingle)GetName() string {
return cmd.Name
}
func (cmd *ListSingle)GetDesc() []string {
return []string{
"Lists a single template.",
"Requires TPL_LIST or TPL_LIST_ANY user capability."}
}
func (cmd *ListSingle)PrintUsage() {
for _, desc := range cmd.GetDesc() {
u.PrintlnErr(desc)
}
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
u.PrintlnErr("USAGE: ",cmd.GetName(), " ID")
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
}
func (cmd *ListSingle)Run(args []string) int {
client := g.GetInstance().Client
host := g.GetInstance().Host
argc := len(args)
if argc < 1 {
cmd.PrintUsage()
return 1
}
uuid := args[0]
resp, err := client.R().Get(host+"/templates/"+uuid)
if err != nil {
u.PrintlnErr("Failed retrieving template \""+uuid+"\": "+err.Error())
return 1
} else {
if resp.IsSuccess() {
tpl, err := deserializeTemplate(resp)
if err != nil {
u.PrintlnErr("Failed retrieving server's response: "+err.Error())
return 1
}
str, err := tpl.String()
if err != nil {
u.PrintlnErr("Failed decoding template "+tpl.ID.String()+" to string. Skipped.")
} else {
u.Println(str)
}
} else {
u.PrintlnErr("Failed retrieving template \""+uuid+"\": "+resp.Status()+": "+resp.String())
return 1
}
}
return 0
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment