Code Stream Aria Automation Uncategorized

Announcing Code Stream CLI

I’ve been working on a little project for a few weeks now, and it’s finally time to share it with the world! Say hello to the Code Stream CLI!

The CLI is built in Golang (my very first project written in Go!) and uses the Cobra and Viper libraries to create a kubectl-like command line interface, and the Go-Resty REST client library to interact with the Code Stream API.

The Code Stream CLI is being released as a Fling, and as an open source project. It’s available as a pre-compiled binary for several platforms, via homebrew, as well as a Docker image. Or you can build it yourself from source!

Why do we need a Code Stream CLI?

Firstly, it opens up Code Stream to more people – it’s another way of consuming Code Stream that might fit a little better into your workflow – and that can’t be a bad thing!

Moving content between instances of Code Stream, or between Projects within Code Stream, is (at present) a manual task, and while all the Content is exportable/importable as YAML, it can be tricky to move a lot of content. Code Stream CLI allows you to export content by Project, ID or Name

This is also useful to bring your content under version control, by exporting the code to a Git repository (or other VCS).

Show me the CLI already!

Each Code Stream instance is added as a “target” configuration for cs-cli – here I’m creating a target for my test vRA 8.2 instance, and my vRA Cloud instance. For vRA Cloud you need to generate an API token first.

# Create the vRealize Automation 8.3 target
cs-cli config set-target --name vra8-test-ga --password secretpassword --username smcgeown --domain cmbu.local --server vra8-test-ga.cmbu.local
# Create the vRealize Automation Cloud target
cs-cli config set-target --name vrac-smcg-org --apitoken myapitoken --server api.mgmt.cloud.vmware.com
# Target vra8-test-ga
cs-cli config use-target --name vra8-test-ga
# View the current active target
cs-cli config current-target

To view all the Pipelines in my “Field Demo” project, I use the following:

$ cs-cli get pipeline --project "Field Demo"
+--------------------------------------+--------------------------------+------------+
| ID | NAME | PROJECT |
+--------------------------------------+--------------------------------+------------+
| dfb3b8f5-561e-4b36-b56b-235346686d2c | Packer-Template-Builds | Field Demo |
| 5ff034a0-2f8c-4cb6-8efe-00544ac92db7 | SSH Exports | Field Demo |
| f504e999-2bf1-4c72-aacf-45d446103a64 | MOAD - Deploy OpenCart | Field Demo |
| | Kubernetes | |
| 7a3b41af-0e49-4e3d-999b-6c4c5ec55956 | vra-authenticateUser | Field Demo |
| 0908617c-c651-4d1d-899a-5bb45879bcac | Add Kubernetes Endpoint to | Field Demo |
| | Cloud Assembly - Token | |
| 12a5e036-993c-43e2-8a17-b37daca589d1 | Add Kubernetes Endpoint to | Field Demo |
| | Code Stream | |
| 4ccec150-f27b-4745-aed6-1aa0e35e17ed | Deploy-OpenCart-Salt-Demo | Field Demo |
| 3214b496-bb49-43c5-95ca-3a813ded8c08 | vrops-POST | Field Demo |
| c9e51b1c-0987-4cf4-8667-e8af1aaa9c4d | tkg-downloadImages | Field Demo |
| 4edf5be8-8e51-43a3-a823-6f27991f2fc1 | Add Kubernetes Endpoint to | Field Demo |
| | Code Stream - Token | |
| 090611b2-5d26-4f9d-a297-a3d0e182d5ac | TKG Management Cluster | Field Demo |
| d0185f04-2e87-4f3c-b6d7-ee58abba3e92 | vra-GET | Field Demo |
| 8b5b4d8c-7774-4ead-9f4d-9b794fe19379 | MOAD - Deploy TKG Workload | Field Demo |
| | Cluster | |
+--------------------------------------+--------------------------------+------------+

Migrating content

To migrate content between a Project, or Code Stream instances, you can use the export function of the CLI. Let’s assume I have three pipelines I want to export from my “Field Demo” project, and import into my “Production” project.

# Export the pipelines to ./pipelines/
cs-cli get pipeline --name vra-authenticateUser --exportPath pipelines
cs-cli get pipeline --name vra-POST --exportPath pipelines
cs-cli get pipeline --name vra-GET --exportPath pipelines
# Modify the pipeline to use the "Production" project
sed -i 's/project: Field Demo/project: Production/g' pipelines/*
# Import the pipelines
cs-cli create pipeline --importPath pipelines
# Pipelines are now in "Production" project
cs-cli get pipeline --project Production

You can see this in action here

To import the pipelines to my vRealize Automation Cloud Code Stream I can simply switch to use the correct config betweem the export and import stages

cs-cli config use-target --name vrac-smcg-org

Getting Started

You can view the instructions and download the binary on the Code Stream CLI fling site, or view the README on GitHub for other options. There are also more examples in the README file, so I’d suggest starting there!

If you have a problem, you can log it as an issue in the repository, and if you’re comfortable issue a PR with a fix!

Lastly, if you find this useful and want to let me know, or you want to reach out about the tool you can get hold of me on Twitter @sammcgeown