Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy params #14

Merged
merged 9 commits into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GO_LDFLAGS +="

TAG ?= $(COMMIT)

GOLANGCI_LINTER_VERSION = v1.9.3
GOLANGCI_LINTER_VERSION = v1.10

all: lint test docker

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ See available environment variables examples in [.env.example](https://github.co
```bash
export VMWARE_URL=username:[email protected]
export VMWARE_INSECURE=1
export VMWARE_DC=DC1
export VMWARE_DATACENTER=DC1
export VMWARE_FOLDER=DevVMs
```

## Development
Expand All @@ -30,5 +31,5 @@ or using Docker and Docker Compose
make dc
```

## API
## API docs
See [swagger file](https://github.com/vterdunov/janna-api/blob/master/api/swagger.yaml)
171 changes: 169 additions & 2 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ paths:
tags:
- Virtual Machines
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: datacenter
in: query
description: Datacenter name
Expand All @@ -90,12 +95,48 @@ paths:
schema:
$ref: "#/components/schemas/vm_list_response"

post:
summary: Deploy OVA file
description: Deploy OVA file
tags:
- Virtual Machines
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/deploy_ova_body'

responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
task_id:
type: string
example:
"task_id": "548f65e9-2f79-2af9-8641-be75088f43c5"

/vm/{vm_uuid}:
get:
summary: "Get information about VM"
tags:
- Virtual Machines
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: vm_uuid
in: path
required: true
Expand Down Expand Up @@ -123,6 +164,11 @@ paths:
- Virtual Machines
- Snapshots
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: vm_uuid
in: path
required: true
Expand All @@ -148,6 +194,11 @@ paths:
- Virtual Machines
- Snapshots
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: vm_uuid
in: path
required: true
Expand Down Expand Up @@ -181,6 +232,11 @@ paths:
- Virtual Machines
- Snapshots
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: vm_uuid
in: path
required: true
Expand All @@ -207,6 +263,11 @@ paths:
- Virtual Machines
- Snapshots
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: vm_uuid
in: path
required: true
Expand All @@ -233,6 +294,11 @@ paths:
- Virtual Machines
- Snapshots
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: vm_uuid
in: path
required: true
Expand All @@ -259,6 +325,11 @@ paths:
- Virtual Machines
- Permissions
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: vm_uuid
in: path
required: true
Expand Down Expand Up @@ -289,8 +360,8 @@ paths:
tags:
- Permissions
parameters:
- in: header
name: X-Request-ID
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
Expand All @@ -308,6 +379,11 @@ paths:
tags:
- Find
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: path
in: query
required: true
Expand Down Expand Up @@ -335,6 +411,33 @@ paths:
schema:
$ref: "#/components/schemas/find_vm_error_response"

/status/{task_id}:
get:
summary: "Get information about backgroud task"
tags:
- Tasks
parameters:
- name: X-Request-ID
in: header
schema:
type: string
format: uuid
- name: task_id
in: path
required: true
description: Task ID
schema:
type: string
format: uuid
example: 6ef18379-6220-6f7e-30ca-1d1c20a3cc97
responses:
'200':
description: OK
content:
application/json::
schema:
$ref: "#/components/schemas/task_id_response"

components:
schemas:
build_info_response:
Expand Down Expand Up @@ -469,3 +572,67 @@ components:
"description":
"label": "Virtual machine user (sample)"
"summary": "Provides virtual machine interaction permissions"

task_id_response:
type: object
properties:
task_id:
type: string
example:
"status": "Starting deploy"

deploy_ova_body:
type: object
properties:
name:
type: string
example: Janna VM
ova_url:
type: string
format: uri
example: https://stable.release.core-os.net/amd64-usr/current/coreos_production_vmware_ova.ova
datacenter:
type: string
example: DC1
folder:
type: string
example: Dev VMs
annotation:
type: string
example: This is an annotation of the deployed VM
datastores:
type: object
properties:
type:
type: string
description: "Storage type. Possible values: 'cluster', 'datastore'. If 'cluster' type was chosen then Janna try to get DRS recommendation to choose proper 'datastore'."
example: cluster
names:
type: array
items:
type: string
description: List of storages. One of them will be chosen randomly.
example: DatastoreCluster1
required:
- type
networks:
type: object
description: Network defines a mapping from each network inside the OVF to a ESXi network. The networks must be presented on the ESXi host.
example:
"VM Network": "esxi-net1"
computer_resources:
type: object
properties:
type:
type: string
description: "Computer resource type. Possible values: 'host', 'cluster', 'rp'."
example: cluster
path:
type: string
description: Name or path to a computer resource. The parameter Can be omitted, then Janna will try to get default computer resource.
example: my-esxi-cluster
required:
- type
required:
- name
- ova_url
22 changes: 12 additions & 10 deletions config/.env.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Example configuration file

# Janna common settings
### Janna common settings
PORT=8080
DEBUG=false

# VMWare settings
# Task info Time-To-Live
TASKS_TTL=27

### VMware setting
# Connection settings
[email protected]:[email protected]
VMWARE_INSECURE=1

# VMWare default parameters. May be overriden in API request.
VMWARE_DC=DC1
VMWARE_DS=Cluster/host1
VMWARE_FOLDER=vm-folder
VMWARE_RP=janna
### VMWare resources default parameters. May be overriden in API request.
# Datacenter
VMWARE_DATACENTER=DC1

# VMWARE_HOST is optional. So if you use empty value, then vCenter will choose a host to deploy.
# If you need a specify a cluster then specify a Resource Pool (VMWARE_RP env) param.
# VMWARE_HOST=vi-devops-esx7.lab.vi.local
# Folder VMs deploy to
VMWARE_FOLDER=vm-folder
33 changes: 3 additions & 30 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ type resources struct {
URL string
Insecure bool
DC string
DS string
RP string
Folder string
Host string
}

type protocols struct {
Expand Down Expand Up @@ -72,42 +69,18 @@ func Load() (*Config, error) {
config.VMWare.URL = vmwareURL

// VMWare Datacenter
vmwareDC, ok := os.LookupEnv("VMWARE_DC")
vmwareDC, ok := os.LookupEnv("VMWARE_DATACENTER")
if !ok {
return nil, errors.New("provide 'VMWARE_DC' environment variable")
return nil, errors.New("provide 'VMWARE_DATACENTER' environment variable")
}
config.VMWare.DC = vmwareDC

// VMWare Datastore
vmwareDS, exist := os.LookupEnv("VMWARE_DS")
if !exist {
return nil, errors.New("provide 'VMWARE_DS' environment variable")
}
config.VMWare.DS = vmwareDS

// VMWare Resource Pool
vmwareRP, exist := os.LookupEnv("VMWARE_RP")
if !exist {
return nil, errors.New("provide 'VMWARE_RP' environment variable")
}
config.VMWare.RP = vmwareRP

// VMWare VM Folder
vmwareFolder, exist := os.LookupEnv("VMWARE_FOLDER")
if !exist {
config.VMWare.Folder = ""
} else {
if exist {
config.VMWare.Folder = vmwareFolder
}

// VMWare ESXi Host
vmwareHost, exist := os.LookupEnv("VMWARE_HOST")
if !exist {
config.VMWare.Host = ""
} else {
config.VMWare.Host = vmwareHost
}

// Background jobs time to live
defaultTTL := time.Minute * 30
taskTTL, exist := os.LookupEnv("TASKS_TTL")
Expand Down
Loading