This CLI allows you to interact with Bare Metal Cloud APIs to deploy new and manage existing servers directly from the terminal.
Bare Metal Cloud • API • Developers Portal • Knowledge Base • Support
- Bare Metal Cloud account
- Go
- Go to the Bare Metal Cloud signup page.
- Follow the prompts to set up your account.
- Use your credentials to log in to Bare Metal Cloud portal.
The CLI can be either used manually or as part of automation scripts.
You can use pnapctl on Linux, OS X, and Windows-based AMD64 systems. The binary is available for download through the following links:
- Linux: pnapctl-linux-amd64.tar.gz
- OS X: pnapctl-darwin-amd64.tar.gz
- Windows: pnapctl-windows-amd64.zip
📖 Detailed steps on how to install CLI are available on our developers portal: https://developers.phoenixnap.com/cli
- Get
go
and install. - Install
make
using the following command:sudo apt-get install build-essential
- Clone this repository.
- Go into the
pnapctl
folder. - Move the
sample-config.yaml
file to$HOME/.pnap/config.yaml
and add your client credentials (ID and secret) - Run
make build-simple
to build.
The executable will be generated in the bin
folder. This is an example of command execution:
./bin/pnapctl get servers
You can view all the available commands with different options for each command on our GitHub page.
These commands enable you to create, delete, modify or shut down a resource, as well as to perform actions such as submit a modification request, print version, reset, tag or update a resource. For a better understanding of what each action does, please consult the API documentation.
We are using gox
for the multi OS build. Note that unless otherwise specified, gox
will build the pnapctl against an unnecessarily long list of OSs so it is suggested to define the desired OS architectures.
make build
-> build a version for all supported OS architectures.make build BUILD_PLATFORMS="linux/amd64 windows/amd64"
-> build a version for linux and windows, 64 bit.
Usage:
make test
to run testsmake test-verbose
to run tests in verbose modemake test-race
for race testsmake test-coverage
for test coverage (will output report.xml in out/unit-tests/).make test-coverage-show
for showing a GUI with coverage information (will outputcover.out
)make test-tparse
to run tests in a pretty format (requirestparse
to be installed)make test PKG=./commands/create
to restrict test to a package
TParse is a command line tool used to summarize a Go test output. It is also useful when analysing test coverage.
- Verify that the bin directory for GO is included in
$PATH
- Install
tparse
by runninggo install github.com/mfridman/tparse@latest
- Use
go test -json -cover ./... | tparse -all
to run all tests orgo test -json -cover ./commands/get | tparse -all
to run specific tests.
❕ NOTE: You can also run make test-tparse
as a shortcut, which also works with PKG
.
TParse can show you the total coverage%, but there's a way to find the exact lines being covered.
- Run
go test ./... -coverprofile cover.out
. This runs all tests and outputs coverage information intocover.out
. - Run
go tool cover -html=cover.out
. This will use thecover.out
you just generated to display coverage information in your browser.
❕ NOTE: You can also run make test-coverage-show
, which will run both of the mentioned commands. It works with PKG
as well.
Component tests are executed using bats
. To install bats using npm
run:
$ npm install -g bats
Usage:
make component-tests
to fetch and verify versions of required libraries and run the component tests (will output junit report in out/component-tests/).
Our preferred IDE for developemnt in Go is VSCode. To debug Go we make use of Delve, which is a debugger for the Go programming language.
Setup:
- Clone and install Delve
$ git clone https://github.com/go-delve/delve
$ cd delve
$ go install github.com/go-delve/delve/cmd/dlv
- In VSCode, create a new debug configuration
- Select the
Run and Debug
button from the Run view or hit theF5
button to start the debugging mode. - From the drop down menu next to
Run and Debug
selectAdd Configuration...
. A new configuration.vscode/launch.json
will be created. - Paste the following configuration in
launch.json
:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "<reaplace_with_path_to_your_workspace>/pnapctl/src",
"env": {},
"args": ["get", "servers"] // replace args accordingly
}
]
}
We are using mockgen
, the mock generation tool by gomock
.
Note that only interfaces can be mocked. An example can be seen in Client
, and Printer
.
Mocks must be placed in the tests/mocks
directory. They also need to have a package name of mocks
. The following is an example command to generate the Printer
's mocks:
make generate-mock MOCK_SOURCE=common/printer/printer.go MOCK_DESTINATION=tests/mocks/mock_printer.go
Details can be passed using a config file. This file can be passed as an argument, as environment variable PNAPCTL_HOME
, or can be read if placed in ~/.pnap/config.yaml
. An example of this file is in sample-config.yaml
. In order to currently test the application, this yaml
file can be used by using the following command: pnapctl --config=sample-config.yaml ...
or simply copying/symlinking the file to your home directory.
Every command is its own folder, having a .go
file that represents it. So, to check pnapctl get servers
, the directory structure would be ./pnapctl/commands/get/servers
.
Become part of the Bare Metal Cloud community to get updates on new features, help us improve the platform, and engage with developers and other users.
- Follow @phoenixNAP on Twitter
- Join the official Slack channel
- Sign up for our Developers Monthly newsletter
Get in touch with us if you have questions or need help with Bare Metal Cloud.