mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Compare commits
No commits in common. "main" and "2.5.0" have entirely different histories.
78 changed files with 6981 additions and 5967 deletions
12
.dockerignore
Normal file
12
.dockerignore
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
**/*.yml
|
||||
**/*.yaml
|
||||
**/*.md
|
||||
**/*example
|
||||
**/Dockerfile*
|
||||
Rakefile
|
||||
Vagrantfile
|
||||
coverage
|
||||
docs
|
||||
examples
|
||||
scripts
|
||||
vendor
|
||||
5
.github/dependabot.yml
vendored
5
.github/dependabot.yml
vendored
|
|
@ -5,9 +5,8 @@ updates:
|
|||
schedule:
|
||||
interval: weekly
|
||||
open-pull-requests-limit: 10
|
||||
|
||||
- package-ecosystem: github-actions
|
||||
directory: "/"
|
||||
- package-ecosystem: bundler
|
||||
directory: "/docker/"
|
||||
schedule:
|
||||
interval: weekly
|
||||
open-pull-requests-limit: 10
|
||||
|
|
|
|||
12
.github/workflows/auto_release_prep.yml
vendored
12
.github/workflows/auto_release_prep.yml
vendored
|
|
@ -1,12 +0,0 @@
|
|||
name: Automated release prep
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
auto_release_prep:
|
||||
uses: puppetlabs/release-engineering-repo-standards/.github/workflows/auto_release_prep.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
project-type: ruby
|
||||
version-file-path: lib/vmpooler/version.rb
|
||||
8
.github/workflows/dependabot_merge.yml
vendored
8
.github/workflows/dependabot_merge.yml
vendored
|
|
@ -1,8 +0,0 @@
|
|||
name: Dependabot auto-merge
|
||||
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
dependabot_merge:
|
||||
uses: puppetlabs/release-engineering-repo-standards/.github/workflows/dependabot_merge.yml@v1
|
||||
secrets: inherit
|
||||
8
.github/workflows/ensure_label.yml
vendored
8
.github/workflows/ensure_label.yml
vendored
|
|
@ -1,8 +0,0 @@
|
|||
name: Ensure label
|
||||
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
ensure_label:
|
||||
uses: puppetlabs/release-engineering-repo-standards/.github/workflows/ensure_label.yml@v1
|
||||
secrets: inherit
|
||||
39
.github/workflows/release.yml
vendored
39
.github/workflows/release.yml
vendored
|
|
@ -7,10 +7,10 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'puppetlabs/vmpooler'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Get Current Version
|
||||
uses: actions/github-script@v7
|
||||
uses: actions/github-script@v6
|
||||
id: cv
|
||||
with:
|
||||
script: |
|
||||
|
|
@ -29,6 +29,37 @@ jobs:
|
|||
echo "version=$version" >> $GITHUB_OUTPUT
|
||||
echo "Found version $version from lib/vmpooler/version.rb"
|
||||
|
||||
- name: Generate Changelog
|
||||
uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2
|
||||
with:
|
||||
args: >-
|
||||
--future-release ${{ steps.nv.outputs.version }}
|
||||
env:
|
||||
CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Validate Changelog
|
||||
run : |
|
||||
set -e
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "Here is the current git status:"
|
||||
git status
|
||||
echo
|
||||
echo "The following changes were detected:"
|
||||
git --no-pager diff
|
||||
echo "Uncommitted PRs found in the changelog. Please submit a release prep PR of changes after running `./update-changelog`"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Generate Release Notes
|
||||
uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2
|
||||
with:
|
||||
args: >-
|
||||
--since-tag ${{ steps.cv.outputs.result }}
|
||||
--future-release ${{ steps.nv.outputs.version }}
|
||||
--output release-notes.md
|
||||
env:
|
||||
CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Tag Release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
|
|
@ -39,10 +70,10 @@ jobs:
|
|||
prerelease: false
|
||||
|
||||
# This step should closely match what is used in `docker/Dockerfile` in vmpooler-deployment
|
||||
- name: Install Ruby jruby-9.4.12.1
|
||||
- name: Install Ruby jruby-9.4.1.0
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 'jruby-9.4.12.1'
|
||||
ruby-version: 'jruby-9.4.1.0'
|
||||
|
||||
- name: Build gem
|
||||
run: gem build *.gemspec
|
||||
|
|
|
|||
4
.github/workflows/security.yml
vendored
4
.github/workflows/security.yml
vendored
|
|
@ -11,7 +11,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout repo content
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: setup ruby
|
||||
|
|
@ -22,7 +22,7 @@ jobs:
|
|||
- name: check lock
|
||||
run: '[ -f "Gemfile.lock" ] && echo "package lock file exists, skipping" || bundle lock'
|
||||
# install java
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin' # See 'Supported distributions' for available options
|
||||
java-version: '17'
|
||||
|
|
|
|||
8
.github/workflows/testing.yml
vendored
8
.github/workflows/testing.yml
vendored
|
|
@ -18,9 +18,9 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
ruby-version:
|
||||
- 'jruby-9.4.12.1'
|
||||
- 'jruby-9.4.1.0'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
|
|
@ -34,9 +34,9 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
ruby-version:
|
||||
- 'jruby-9.4.12.1'
|
||||
- 'jruby-9.4.1.0'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
project=vmpooler
|
||||
user=puppetlabs
|
||||
exclude_labels=maintenance
|
||||
github-api=https://api.github.com
|
||||
release-branch=main
|
||||
|
|
@ -12,7 +12,8 @@
|
|||
# SupportedStyles: with_first_parameter, with_fixed_indentation
|
||||
Layout/ParameterAlignment:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -21,13 +22,15 @@ Layout/ParameterAlignment:
|
|||
Layout/CaseIndentation:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/helpers.rb'
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
Layout/ClosingParenthesisIndentation:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -58,14 +61,16 @@ Layout/EmptyLinesAroundModuleBody:
|
|||
Layout/FirstHashElementIndentation:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/helpers.rb'
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Width, IgnoredPatterns.
|
||||
Layout/IndentationWidth:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -73,7 +78,8 @@ Layout/IndentationWidth:
|
|||
# SupportedStyles: symmetrical, new_line, same_line
|
||||
Layout/MultilineMethodCallBraceLayout:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -87,14 +93,16 @@ Layout/SpaceAroundEqualsInParameterDefault:
|
|||
# Cop supports --auto-correct.
|
||||
Layout/SpaceAroundKeyword:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowForAlignment.
|
||||
Layout/SpaceAroundOperators:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 8
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -109,14 +117,16 @@ Layout/SpaceInsideHashLiteralBraces:
|
|||
# Cop supports --auto-correct.
|
||||
Layout/SpaceInsideParens:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Configuration parameters: AllowSafeAssignment.
|
||||
Lint/AssignmentInCondition:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/helpers.rb'
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 2
|
||||
Lint/SuppressedException:
|
||||
|
|
@ -148,7 +158,8 @@ Lint/UselessAssignment:
|
|||
Style/AndOr:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/helpers.rb'
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
Style/CaseEquality:
|
||||
|
|
@ -169,7 +180,8 @@ Style/For:
|
|||
Style/HashSyntax:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/helpers.rb'
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -177,7 +189,8 @@ Style/HashSyntax:
|
|||
Style/IfUnlessModifier:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/helpers.rb'
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -185,13 +198,15 @@ Style/IfUnlessModifier:
|
|||
# SupportedStyles: both, prefix, postfix
|
||||
Style/NegatedIf:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
Style/Not:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -200,26 +215,30 @@ Style/Not:
|
|||
Style/NumericPredicate:
|
||||
Exclude:
|
||||
- 'spec/**/*'
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/ParallelAssignment:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: AllowSafeAssignment.
|
||||
Style/ParenthesesAroundCondition:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
Style/PerlBackrefs:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
||||
|
|
@ -235,7 +254,8 @@ Naming/PredicateName:
|
|||
# Cop supports --auto-correct.
|
||||
Style/RedundantParentheses:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -256,7 +276,8 @@ Style/RedundantSelf:
|
|||
# SupportedStyles: single_quotes, double_quotes
|
||||
Style/StringLiterals:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
|
|
@ -271,7 +292,8 @@ Style/TernaryParentheses:
|
|||
# SupportedStyles: snake_case, camelCase
|
||||
Naming/VariableName:
|
||||
Exclude:
|
||||
- 'lib/vmpooler/api/v3.rb'
|
||||
- 'lib/vmpooler/api/v1.rb'
|
||||
- 'lib/vmpooler/api/v2.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
|
|
|
|||
285
CHANGELOG.md
285
CHANGELOG.md
|
|
@ -1,187 +1,5 @@
|
|||
# Changelog
|
||||
|
||||
## [3.8.1](https://github.com/puppetlabs/vmpooler/tree/3.8.1) (2026-01-14)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.7.0...3.8.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- \(P4DEVOPS-9434\) Add rate limiting and input validation security enhancements [\#690](https://github.com/puppetlabs/vmpooler/pull/690) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- \(P4DEVOPS-8570\) Add Phase 2 optimizations: status API caching and improved Redis pipelining [\#689](https://github.com/puppetlabs/vmpooler/pull/689) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- \(P4DEVOPS-8567\) Add DLQ, auto-purge, and health checks for Redis queues [\#688](https://github.com/puppetlabs/vmpooler/pull/688) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- Add retry logic for immediate clone failures [\#687](https://github.com/puppetlabs/vmpooler/pull/687) ([mahima-singh](https://github.com/mahima-singh))
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- \(P4DEVOPS-8567\) Prevent VM allocation for already-deleted request-ids [\#688](https://github.com/puppetlabs/vmpooler/pull/688) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- Prevent re-queueing requests already marked as failed [\#687](https://github.com/puppetlabs/vmpooler/pull/687) ([mahima-singh](https://github.com/mahima-singh))
|
||||
|
||||
## [3.7.0](https://github.com/puppetlabs/vmpooler/tree/3.7.0) (2025-06-04)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.6.0...3.7.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- \(P4DEVOPS-6096\) Include VMs that have been requested but not moved to pending when getting queue metrics [\#681](https://github.com/puppetlabs/vmpooler/pull/681) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
- Bump redis from 5.1.0 to 5.2.0 [\#675](https://github.com/puppetlabs/vmpooler/pull/675) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rake from 13.1.0 to 13.2.1 [\#673](https://github.com/puppetlabs/vmpooler/pull/673) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump redis from 5.0.8 to 5.1.0 [\#665](https://github.com/puppetlabs/vmpooler/pull/665) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rspec from 3.12.0 to 3.13.0 [\#664](https://github.com/puppetlabs/vmpooler/pull/664) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump opentelemetry-sdk from 1.3.1 to 1.4.0 [\#663](https://github.com/puppetlabs/vmpooler/pull/663) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump mock\_redis from 0.43.0 to 0.44.0 [\#662](https://github.com/puppetlabs/vmpooler/pull/662) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump mock\_redis from 0.41.0 to 0.43.0 [\#658](https://github.com/puppetlabs/vmpooler/pull/658) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump net-ldap from 0.18.0 to 0.19.0 [\#653](https://github.com/puppetlabs/vmpooler/pull/653) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump sinatra from 3.1.0 to 3.2.0 [\#652](https://github.com/puppetlabs/vmpooler/pull/652) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump mock\_redis from 0.40.0 to 0.41.0 [\#650](https://github.com/puppetlabs/vmpooler/pull/650) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump mock\_redis from 0.37.0 to 0.40.0 [\#643](https://github.com/puppetlabs/vmpooler/pull/643) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rake from 13.0.6 to 13.1.0 [\#638](https://github.com/puppetlabs/vmpooler/pull/638) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump thor from 1.2.2 to 1.3.0 [\#635](https://github.com/puppetlabs/vmpooler/pull/635) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Bump opentelemetry-sdk from 1.4.0 to 1.4.1 [\#672](https://github.com/puppetlabs/vmpooler/pull/672) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rack from 2.2.8.1 to 2.2.9 [\#671](https://github.com/puppetlabs/vmpooler/pull/671) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump thor from 1.3.0 to 1.3.1 [\#668](https://github.com/puppetlabs/vmpooler/pull/668) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rack from 2.2.8 to 2.2.8.1 [\#666](https://github.com/puppetlabs/vmpooler/pull/666) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump concurrent-ruby from 1.2.2 to 1.2.3 [\#660](https://github.com/puppetlabs/vmpooler/pull/660) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump puma from 6.4.1 to 6.4.2 [\#655](https://github.com/puppetlabs/vmpooler/pull/655) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump puma from 6.4.0 to 6.4.1 [\#654](https://github.com/puppetlabs/vmpooler/pull/654) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update opentelemetry-instrumentation-http\_client requirement from = 0.22.2 to = 0.22.3 [\#646](https://github.com/puppetlabs/vmpooler/pull/646) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update opentelemetry-instrumentation-concurrent\_ruby requirement from = 0.21.1 to = 0.21.2 [\#645](https://github.com/puppetlabs/vmpooler/pull/645) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump opentelemetry-sdk from 1.3.0 to 1.3.1 [\#642](https://github.com/puppetlabs/vmpooler/pull/642) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump prometheus-client from 4.2.1 to 4.2.2 [\#641](https://github.com/puppetlabs/vmpooler/pull/641) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump redis from 5.0.7 to 5.0.8 [\#637](https://github.com/puppetlabs/vmpooler/pull/637) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- \(RE-15817\) Reword fail warning and get error from redis before generating message [\#633](https://github.com/puppetlabs/vmpooler/pull/633) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- \(P4DEVOPS-6096\) Fix gems to prevent warnings in logs [\#685](https://github.com/puppetlabs/vmpooler/pull/685) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
- \(maint\) Revert gems to last release [\#683](https://github.com/puppetlabs/vmpooler/pull/683) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
- Bump actions/setup-java from 3 to 4 [\#648](https://github.com/puppetlabs/vmpooler/pull/648) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump actions/github-script from 6 to 7 [\#644](https://github.com/puppetlabs/vmpooler/pull/644) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
## [3.6.0](https://github.com/puppetlabs/vmpooler/tree/3.6.0) (2023-10-05)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.5.1...3.6.0)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- \(maint\) Fix message for timeout notification. [\#624](https://github.com/puppetlabs/vmpooler/pull/624) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Bump rubocop from 1.56.3 to 1.56.4 [\#631](https://github.com/puppetlabs/vmpooler/pull/631) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump puma from 6.3.1 to 6.4.0 [\#630](https://github.com/puppetlabs/vmpooler/pull/630) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rubocop from 1.56.2 to 1.56.3 [\#628](https://github.com/puppetlabs/vmpooler/pull/628) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump actions/checkout from 3 to 4 [\#627](https://github.com/puppetlabs/vmpooler/pull/627) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update opentelemetry-resource\_detectors requirement from = 0.24.1 to = 0.24.2 [\#626](https://github.com/puppetlabs/vmpooler/pull/626) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rubocop from 1.56.1 to 1.56.2 [\#625](https://github.com/puppetlabs/vmpooler/pull/625) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rubocop from 1.56.0 to 1.56.1 [\#623](https://github.com/puppetlabs/vmpooler/pull/623) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
## [3.5.1](https://github.com/puppetlabs/vmpooler/tree/3.5.1) (2023-08-24)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.5.0...3.5.1)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- \(maint\) Fix bugs from redis and timeout notification updates. [\#621](https://github.com/puppetlabs/vmpooler/pull/621) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
|
||||
## [3.5.0](https://github.com/puppetlabs/vmpooler/tree/3.5.0) (2023-08-23)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.4.0...3.5.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Improve LDAP auth [\#616](https://github.com/puppetlabs/vmpooler/issues/616)
|
||||
- \(maint\) Raise error when ip address is not given to vm after clone. [\#619](https://github.com/puppetlabs/vmpooler/pull/619) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
- \(POD-8\) Add timeout\_notification config to log warning before vm is destroyed. [\#618](https://github.com/puppetlabs/vmpooler/pull/618) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
- \(RE-15565\) Add ability to use bind\_as with a service account [\#617](https://github.com/puppetlabs/vmpooler/pull/617) ([yachub](https://github.com/yachub))
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Bump puma from 6.3.0 to 6.3.1 [\#615](https://github.com/puppetlabs/vmpooler/pull/615) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
## [3.4.0](https://github.com/puppetlabs/vmpooler/tree/3.4.0) (2023-08-18)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.3.0...3.4.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- \(POD-10\) Log reason for failed VM checks. [\#611](https://github.com/puppetlabs/vmpooler/pull/611) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Log reason connection on port 22 of a failed VM [\#609](https://github.com/puppetlabs/vmpooler/issues/609)
|
||||
|
||||
## [3.3.0](https://github.com/puppetlabs/vmpooler/tree/3.3.0) (2023-08-16)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.2.0...3.3.0)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Redis 5.x Deprecations [\#603](https://github.com/puppetlabs/vmpooler/issues/603)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Update rubocop requirement from ~\> 1.55.1 to ~\> 1.56.0 [\#608](https://github.com/puppetlabs/vmpooler/pull/608) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
## [3.2.0](https://github.com/puppetlabs/vmpooler/tree/3.2.0) (2023-08-10)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.1.0...3.2.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- \(maint\) Update opentelemetry gems. [\#606](https://github.com/puppetlabs/vmpooler/pull/606) ([isaac-hammes](https://github.com/isaac-hammes))
|
||||
- Bump jruby to 9.4.3.0 and bundle update [\#604](https://github.com/puppetlabs/vmpooler/pull/604) ([yachub](https://github.com/yachub))
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- \(RE-15692\) Do not attempt loading DNS classes if none are defined [\#602](https://github.com/puppetlabs/vmpooler/pull/602) ([yachub](https://github.com/yachub))
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Fix startup error when not using any dns plugins [\#601](https://github.com/puppetlabs/vmpooler/issues/601)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Bump prometheus-client from 4.1.0 to 4.2.1 [\#599](https://github.com/puppetlabs/vmpooler/pull/599) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update rubocop requirement from ~\> 1.54.2 to ~\> 1.55.1 [\#597](https://github.com/puppetlabs/vmpooler/pull/597) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rack from 2.2.7 to 2.2.8 [\#594](https://github.com/puppetlabs/vmpooler/pull/594) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update rubocop requirement from ~\> 1.51.0 to ~\> 1.54.2 [\#593](https://github.com/puppetlabs/vmpooler/pull/593) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump puma from 6.2.2 to 6.3.0 [\#586](https://github.com/puppetlabs/vmpooler/pull/586) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump connection\_pool from 2.4.0 to 2.4.1 [\#583](https://github.com/puppetlabs/vmpooler/pull/583) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update rubocop requirement from ~\> 1.50.1 to ~\> 1.51.0 [\#582](https://github.com/puppetlabs/vmpooler/pull/582) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump thor from 1.2.1 to 1.2.2 [\#581](https://github.com/puppetlabs/vmpooler/pull/581) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rack from 2.2.6.4 to 2.2.7 [\#579](https://github.com/puppetlabs/vmpooler/pull/579) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
## [3.1.0](https://github.com/puppetlabs/vmpooler/tree/3.1.0) (2023-05-01)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.0.0...3.1.0)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Bump rubocop from 1.50.1 to 1.50.2 [\#578](https://github.com/puppetlabs/vmpooler/pull/578) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update puma requirement from ~\> 5.0, \>= 5.0.4 to \>= 5.0.4, \< 7 [\#577](https://github.com/puppetlabs/vmpooler/pull/577) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update opentelemetry-resource\_detectors requirement from = 0.19.1 to = 0.23.0 [\#576](https://github.com/puppetlabs/vmpooler/pull/576) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Migrate issue management to Jira [\#575](https://github.com/puppetlabs/vmpooler/pull/575) ([yachub](https://github.com/yachub))
|
||||
- Bump jruby to 9.4.2.0 [\#574](https://github.com/puppetlabs/vmpooler/pull/574) ([yachub](https://github.com/yachub))
|
||||
- Update rubocop requirement from ~\> 1.28.2 to ~\> 1.50.1 [\#573](https://github.com/puppetlabs/vmpooler/pull/573) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update sinatra requirement from ~\> 2.0 to \>= 2, \< 4 [\#572](https://github.com/puppetlabs/vmpooler/pull/572) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump net-ldap from 0.17.1 to 0.18.0 [\#571](https://github.com/puppetlabs/vmpooler/pull/571) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update prometheus-client requirement from ~\> 2.0 to \>= 2, \< 5 [\#566](https://github.com/puppetlabs/vmpooler/pull/566) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Bump rack-test from 2.0.2 to 2.1.0 [\#564](https://github.com/puppetlabs/vmpooler/pull/564) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update rack requirement from ~\> 2.2 to \>= 2.2, \< 4.0 [\#562](https://github.com/puppetlabs/vmpooler/pull/562) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- Update opentelemetry-exporter-jaeger requirement from = 0.20.1 to = 0.22.0 [\#524](https://github.com/puppetlabs/vmpooler/pull/524) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
## [3.0.0](https://github.com/puppetlabs/vmpooler/tree/3.0.0) (2023-03-28)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/2.5.0...3.0.0)
|
||||
|
||||
**Breaking changes:**
|
||||
|
||||
- Direct Users to vmpooler-deployment [\#568](https://github.com/puppetlabs/vmpooler/pull/568) ([yachub](https://github.com/yachub))
|
||||
- \(RE-15124\) Implement DNS Plugins and Remove api v1 and v2 [\#551](https://github.com/puppetlabs/vmpooler/pull/551) ([yachub](https://github.com/yachub))
|
||||
|
||||
## [2.5.0](https://github.com/puppetlabs/vmpooler/tree/2.5.0) (2023-03-06)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/2.4.0...2.5.0)
|
||||
|
|
@ -246,7 +64,6 @@
|
|||
- \(maint\) Adding a provider method tag\_vm\_user [\#469](https://github.com/puppetlabs/vmpooler/pull/469) ([sbeaulie](https://github.com/sbeaulie))
|
||||
- Update testing.yml [\#468](https://github.com/puppetlabs/vmpooler/pull/468) ([sbeaulie](https://github.com/sbeaulie))
|
||||
- Move vsphere specific methods out of vmpooler [\#467](https://github.com/puppetlabs/vmpooler/pull/467) ([sbeaulie](https://github.com/sbeaulie))
|
||||
- Release prep for v2.0.0 [\#465](https://github.com/puppetlabs/vmpooler/pull/465) ([genebean](https://github.com/genebean))
|
||||
|
||||
## [2.0.0](https://github.com/puppetlabs/vmpooler/tree/2.0.0) (2021-12-08)
|
||||
|
||||
|
|
@ -255,6 +72,7 @@
|
|||
**Merged pull requests:**
|
||||
|
||||
- Use credentials file for Rubygems auth [\#466](https://github.com/puppetlabs/vmpooler/pull/466) ([genebean](https://github.com/genebean))
|
||||
- Release prep for v2.0.0 [\#465](https://github.com/puppetlabs/vmpooler/pull/465) ([genebean](https://github.com/genebean))
|
||||
- Add Gem release workflow [\#464](https://github.com/puppetlabs/vmpooler/pull/464) ([genebean](https://github.com/genebean))
|
||||
- Update icon in the readme to reference this repo [\#463](https://github.com/puppetlabs/vmpooler/pull/463) ([genebean](https://github.com/genebean))
|
||||
- \(DIO-2769\) Move vsphere provider to its own gem [\#462](https://github.com/puppetlabs/vmpooler/pull/462) ([genebean](https://github.com/genebean))
|
||||
|
|
@ -299,17 +117,13 @@
|
|||
**Merged pull requests:**
|
||||
|
||||
- \(POOLER-176\) Add Operation Label to User Metric [\#455](https://github.com/puppetlabs/vmpooler/pull/455) ([yachub](https://github.com/yachub))
|
||||
- Update OTel gems to 0.15.0 [\#450](https://github.com/puppetlabs/vmpooler/pull/450) ([genebean](https://github.com/genebean))
|
||||
- Migrate testing to GH Actions from Travis [\#446](https://github.com/puppetlabs/vmpooler/pull/446) ([genebean](https://github.com/genebean))
|
||||
|
||||
## [1.1.0-rc.1](https://github.com/puppetlabs/vmpooler/tree/1.1.0-rc.1) (2021-08-11)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/1.0.0...1.1.0-rc.1)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- \(POOLER-176\) Add Operation Label to User Metric [\#454](https://github.com/puppetlabs/vmpooler/pull/454) ([yachub](https://github.com/yachub))
|
||||
- Update OTel gems to 0.15.0 [\#450](https://github.com/puppetlabs/vmpooler/pull/450) ([genebean](https://github.com/genebean))
|
||||
- Migrate testing to GH Actions from Travis [\#446](https://github.com/puppetlabs/vmpooler/pull/446) ([genebean](https://github.com/genebean))
|
||||
|
||||
## [1.0.0](https://github.com/puppetlabs/vmpooler/tree/1.0.0) (2021-02-02)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/0.18.2...1.0.0)
|
||||
|
|
@ -818,13 +632,13 @@
|
|||
- Do not have a hardcoded list of VM providers [\#230](https://github.com/puppetlabs/vmpooler/issues/230)
|
||||
- Use a dynamic check\_pool period [\#226](https://github.com/puppetlabs/vmpooler/issues/226)
|
||||
- vmpooler doesn't seem to recognize ready VMs [\#218](https://github.com/puppetlabs/vmpooler/issues/218)
|
||||
- `find\_vmdks` in `vsphere\_helper` should not use `vmdk\_datastore.\_connection` [\#213](https://github.com/puppetlabs/vmpooler/issues/213)
|
||||
- `get\_base\_vm\_container\_from` in `vsphere\_helper` ensures the wrong connection [\#212](https://github.com/puppetlabs/vmpooler/issues/212)
|
||||
- `find_vmdks` in `vsphere_helper` should not use `vmdk_datastore._connection` [\#213](https://github.com/puppetlabs/vmpooler/issues/213)
|
||||
- `get_base_vm_container_from` in `vsphere_helper` ensures the wrong connection [\#212](https://github.com/puppetlabs/vmpooler/issues/212)
|
||||
- `close` in vsphere\_helper throws an error if a connection was never made [\#211](https://github.com/puppetlabs/vmpooler/issues/211)
|
||||
- `find\_pool` in vsphere\_helper.rb has subtle errors [\#210](https://github.com/puppetlabs/vmpooler/issues/210)
|
||||
- `find\_pool` in vsphere\_helper tends to throw instead of returning nil for missing pools [\#209](https://github.com/puppetlabs/vmpooler/issues/209)
|
||||
- `find_pool` in vsphere\_helper.rb has subtle errors [\#210](https://github.com/puppetlabs/vmpooler/issues/210)
|
||||
- `find_pool` in vsphere\_helper tends to throw instead of returning nil for missing pools [\#209](https://github.com/puppetlabs/vmpooler/issues/209)
|
||||
- Vsphere connections are always insecure \(Ignore cert errors\) [\#207](https://github.com/puppetlabs/vmpooler/issues/207)
|
||||
- `find\_folder` in vsphere\_helper.rb has subtle errors [\#204](https://github.com/puppetlabs/vmpooler/issues/204)
|
||||
- `find_folder` in vsphere\_helper.rb has subtle errors [\#204](https://github.com/puppetlabs/vmpooler/issues/204)
|
||||
- Should not use `abort` in vsphere\_helper [\#203](https://github.com/puppetlabs/vmpooler/issues/203)
|
||||
- No reason why get\_snapshot\_list is defined in vsphere\_helper [\#202](https://github.com/puppetlabs/vmpooler/issues/202)
|
||||
- Setting max\_tries in configuration results in vSphereHelper going into infinite loop [\#199](https://github.com/puppetlabs/vmpooler/issues/199)
|
||||
|
|
@ -886,7 +700,7 @@
|
|||
- \(POOLER-93\) Extend API endpoint to provide just what is needed [\#245](https://github.com/puppetlabs/vmpooler/pull/245) ([sbeaulie](https://github.com/sbeaulie))
|
||||
- \(POOLER-92\) Add the alias information in the API status page for each… [\#244](https://github.com/puppetlabs/vmpooler/pull/244) ([sbeaulie](https://github.com/sbeaulie))
|
||||
- \(QENG-5305\) Improve vmpooler host selection [\#242](https://github.com/puppetlabs/vmpooler/pull/242) ([mattkirby](https://github.com/mattkirby))
|
||||
- Allow user to specify a configuration file in VMPOOLER\_CONFIG\_FILE variable [\#241](https://github.com/puppetlabs/vmpooler/pull/241) ([amcdson](https://github.com/amcdson))
|
||||
- Allow user to specify a configuration file in VMPOOLER\_CONFIG\_FILE variable [\#241](https://github.com/puppetlabs/vmpooler/pull/241) ([adamdav](https://github.com/adamdav))
|
||||
- Fix no implicit conversion to rational from nil [\#239](https://github.com/puppetlabs/vmpooler/pull/239) ([sbeaulie](https://github.com/sbeaulie))
|
||||
- Updated Vagrant box and associated docs [\#237](https://github.com/puppetlabs/vmpooler/pull/237) ([genebean](https://github.com/genebean))
|
||||
- \(GH-226\) Respond quickly to VMs being consumed [\#236](https://github.com/puppetlabs/vmpooler/pull/236) ([glennsarti](https://github.com/glennsarti))
|
||||
|
|
@ -920,7 +734,88 @@
|
|||
- \(maint\) Add rubocop and allow failures in Travis CI [\#183](https://github.com/puppetlabs/vmpooler/pull/183) ([glennsarti](https://github.com/glennsarti))
|
||||
- \(POOLER-73\) Update unit tests prior to refactoring [\#182](https://github.com/puppetlabs/vmpooler/pull/182) ([glennsarti](https://github.com/glennsarti))
|
||||
- \(POOLER-71\) Add dummy authentication provider [\#180](https://github.com/puppetlabs/vmpooler/pull/180) ([glennsarti](https://github.com/glennsarti))
|
||||
- \(maint\) Remove Ruby 1.9.3 testing from Travis [\#178](https://github.com/puppetlabs/vmpooler/pull/178) ([glennsarti](https://github.com/glennsarti))
|
||||
- \(maint\) Enhance VM Pooler developer experience [\#177](https://github.com/puppetlabs/vmpooler/pull/177) ([glennsarti](https://github.com/glennsarti))
|
||||
- \(POOLER-47\) Send clone errors up [\#175](https://github.com/puppetlabs/vmpooler/pull/175) ([mattkirby](https://github.com/mattkirby))
|
||||
- \(POOLER-48\) Clear migrations at application start time [\#174](https://github.com/puppetlabs/vmpooler/pull/174) ([mattkirby](https://github.com/mattkirby))
|
||||
- Add retry logic with a delay for vsphere connections [\#173](https://github.com/puppetlabs/vmpooler/pull/173) ([mattkirby](https://github.com/mattkirby))
|
||||
- \(POOLER-44\) Fix vmpooler.migrate reference [\#172](https://github.com/puppetlabs/vmpooler/pull/172) ([mattkirby](https://github.com/mattkirby))
|
||||
- Add `puma` as required gem [\#171](https://github.com/puppetlabs/vmpooler/pull/171) ([sschneid](https://github.com/sschneid))
|
||||
- Fix JavaScript error on nil `weekly_data` [\#170](https://github.com/puppetlabs/vmpooler/pull/170) ([sschneid](https://github.com/sschneid))
|
||||
- Containerize vmpooler [\#169](https://github.com/puppetlabs/vmpooler/pull/169) ([sschneid](https://github.com/sschneid))
|
||||
- Add vagrant-vmpooler plugin to readme [\#168](https://github.com/puppetlabs/vmpooler/pull/168) ([briancain](https://github.com/briancain))
|
||||
- Improve vmpooler scheduling logic [\#167](https://github.com/puppetlabs/vmpooler/pull/167) ([mattkirby](https://github.com/mattkirby))
|
||||
- \[QENG-4181\] Add per-pool stats to `/status` API [\#162](https://github.com/puppetlabs/vmpooler/pull/162) ([rick](https://github.com/rick))
|
||||
- Merge CI.next into Master [\#161](https://github.com/puppetlabs/vmpooler/pull/161) ([shermdog](https://github.com/shermdog))
|
||||
- \(maint\) update README.md and LICENSE to reflect rebranding [\#157](https://github.com/puppetlabs/vmpooler/pull/157) ([erosa](https://github.com/erosa))
|
||||
- Add info about vmfloaty [\#156](https://github.com/puppetlabs/vmpooler/pull/156) ([briancain](https://github.com/briancain))
|
||||
- Added IP lookup functionality for /vm/hostname [\#154](https://github.com/puppetlabs/vmpooler/pull/154) ([frozenfoxx](https://github.com/frozenfoxx))
|
||||
- Improved tests for vmpooler [\#152](https://github.com/puppetlabs/vmpooler/pull/152) ([rick](https://github.com/rick))
|
||||
- Added prefix parameter to the vmpooler configuration [\#149](https://github.com/puppetlabs/vmpooler/pull/149) ([frozenfoxx](https://github.com/frozenfoxx))
|
||||
- Update license copyright [\#148](https://github.com/puppetlabs/vmpooler/pull/148) ([sschneid](https://github.com/sschneid))
|
||||
- Allow new disks to be added to running VMs via vmpooler API [\#147](https://github.com/puppetlabs/vmpooler/pull/147) ([sschneid](https://github.com/sschneid))
|
||||
- Updated YAML config variables in create\_template\_deltas.rb [\#145](https://github.com/puppetlabs/vmpooler/pull/145) ([frozenfoxx](https://github.com/frozenfoxx))
|
||||
- \(QA-2036\) Update README for Client Utility [\#143](https://github.com/puppetlabs/vmpooler/pull/143) ([cowofevil](https://github.com/cowofevil))
|
||||
- add guestinfo.hostname to VirtualMachineConfigSpecs [\#139](https://github.com/puppetlabs/vmpooler/pull/139) ([heathseals](https://github.com/heathseals))
|
||||
- \(QENG-2807\) Allow pool 'alias' names [\#138](https://github.com/puppetlabs/vmpooler/pull/138) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2995\) Display associated VMs in GET /token/:token endpoint [\#137](https://github.com/puppetlabs/vmpooler/pull/137) ([sschneid](https://github.com/sschneid))
|
||||
- Update API docs to include "domain" key for get vm requests [\#136](https://github.com/puppetlabs/vmpooler/pull/136) ([briancain](https://github.com/briancain))
|
||||
- \(MAINT\) Remove Ping Check on Running VMs [\#133](https://github.com/puppetlabs/vmpooler/pull/133) ([colinPL](https://github.com/colinPL))
|
||||
- \(maint\) Move VM Only When SSH Check Succeeds [\#131](https://github.com/puppetlabs/vmpooler/pull/131) ([colinPL](https://github.com/colinPL))
|
||||
- \(QENG-2952\) Check that SSH is available [\#130](https://github.com/puppetlabs/vmpooler/pull/130) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Update license copyright [\#128](https://github.com/puppetlabs/vmpooler/pull/128) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Remove duplicate \(nested\) "ok" responses [\#127](https://github.com/puppetlabs/vmpooler/pull/127) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Documentation updates [\#126](https://github.com/puppetlabs/vmpooler/pull/126) ([sschneid](https://github.com/sschneid))
|
||||
- Track token use times [\#125](https://github.com/puppetlabs/vmpooler/pull/125) ([sschneid](https://github.com/sschneid))
|
||||
- Docs update [\#124](https://github.com/puppetlabs/vmpooler/pull/124) ([sschneid](https://github.com/sschneid))
|
||||
- User token list [\#123](https://github.com/puppetlabs/vmpooler/pull/123) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Additional utility and reporting scripts [\#122](https://github.com/puppetlabs/vmpooler/pull/122) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Syntax fixup [\#121](https://github.com/puppetlabs/vmpooler/pull/121) ([sschneid](https://github.com/sschneid))
|
||||
- \(MAINT\) Reduce redis Calls in API [\#120](https://github.com/puppetlabs/vmpooler/pull/120) ([colinPL](https://github.com/colinPL))
|
||||
- \(maint\) Use expect\_json helper method for determining JSON response status [\#119](https://github.com/puppetlabs/vmpooler/pull/119) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-1304\) vmpooler should require an auth key for VM destruction [\#118](https://github.com/puppetlabs/vmpooler/pull/118) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2636\) Host snapshots [\#117](https://github.com/puppetlabs/vmpooler/pull/117) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Use dep caching and containers [\#116](https://github.com/puppetlabs/vmpooler/pull/116) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Include travis-ci build status in README [\#115](https://github.com/puppetlabs/vmpooler/pull/115) ([sschneid](https://github.com/sschneid))
|
||||
- Show test contexts and names [\#114](https://github.com/puppetlabs/vmpooler/pull/114) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2246\) Add Default Rake Task [\#113](https://github.com/puppetlabs/vmpooler/pull/113) ([colinPL](https://github.com/colinPL))
|
||||
- Log empty pools [\#112](https://github.com/puppetlabs/vmpooler/pull/112) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2246\) Add Travis CI [\#111](https://github.com/puppetlabs/vmpooler/pull/111) ([colinPL](https://github.com/colinPL))
|
||||
- \(QENG-2388\) Tagging restrictions [\#110](https://github.com/puppetlabs/vmpooler/pull/110) ([sschneid](https://github.com/sschneid))
|
||||
- An updated dashboard [\#109](https://github.com/puppetlabs/vmpooler/pull/109) ([sschneid](https://github.com/sschneid))
|
||||
- API summary rework [\#108](https://github.com/puppetlabs/vmpooler/pull/108) ([sschneid](https://github.com/sschneid))
|
||||
- Only filter regex matches [\#106](https://github.com/puppetlabs/vmpooler/pull/106) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2518\) Tag-filtering [\#105](https://github.com/puppetlabs/vmpooler/pull/105) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2360\) check\_running\_vm Spec Tests [\#104](https://github.com/puppetlabs/vmpooler/pull/104) ([colinPL](https://github.com/colinPL))
|
||||
- \(QENG-2056\) Create daily tag indexes, report in /summary [\#102](https://github.com/puppetlabs/vmpooler/pull/102) ([sschneid](https://github.com/sschneid))
|
||||
- Store token metadata in vmpooler\_\_vm\_\_ Redis hash [\#101](https://github.com/puppetlabs/vmpooler/pull/101) ([sschneid](https://github.com/sschneid))
|
||||
- Display VM state in GET /vm/:hostname route [\#100](https://github.com/puppetlabs/vmpooler/pull/100) ([sschneid](https://github.com/sschneid))
|
||||
- Add basic auth token functionality [\#98](https://github.com/puppetlabs/vmpooler/pull/98) ([sschneid](https://github.com/sschneid))
|
||||
- Add basic HTTP authentication and /token routes [\#97](https://github.com/puppetlabs/vmpooler/pull/97) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2208\) Add more helper tests [\#95](https://github.com/puppetlabs/vmpooler/pull/95) ([colinPL](https://github.com/colinPL))
|
||||
- \(QENG-2208\) Move Sinatra Helpers to own file [\#94](https://github.com/puppetlabs/vmpooler/pull/94) ([colinPL](https://github.com/colinPL))
|
||||
- Fix rspec tests broken in f9de28236b726e37977123cea9b4f3a562bfdcdb [\#93](https://github.com/puppetlabs/vmpooler/pull/93) ([sschneid](https://github.com/sschneid))
|
||||
- Redirect / to /dashboard [\#92](https://github.com/puppetlabs/vmpooler/pull/92) ([sschneid](https://github.com/sschneid))
|
||||
- Ensure 'lifetime' val returned by GET /vm/:hostname is an int [\#91](https://github.com/puppetlabs/vmpooler/pull/91) ([sschneid](https://github.com/sschneid))
|
||||
- running-to-lifetime comparison should be 'greater than or equal to' [\#90](https://github.com/puppetlabs/vmpooler/pull/90) ([sschneid](https://github.com/sschneid))
|
||||
- Auto-expire Redis metadata key via Redis EXPIRE [\#89](https://github.com/puppetlabs/vmpooler/pull/89) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-1906\) Add specs for Dashboard and root API class [\#88](https://github.com/puppetlabs/vmpooler/pull/88) ([colinPL](https://github.com/colinPL))
|
||||
- \(maint\) Fix bad redis reference [\#87](https://github.com/puppetlabs/vmpooler/pull/87) ([colinPL](https://github.com/colinPL))
|
||||
- \(QENG-1906\) Break apart check\_pending\_vm and add spec tests [\#86](https://github.com/puppetlabs/vmpooler/pull/86) ([colinPL](https://github.com/colinPL))
|
||||
- Remove defined? when checking configuration for graphite server. [\#85](https://github.com/puppetlabs/vmpooler/pull/85) ([colinPL](https://github.com/colinPL))
|
||||
- \(QENG-1906\) Add spec tests for Janitor [\#78](https://github.com/puppetlabs/vmpooler/pull/78) ([colinPL](https://github.com/colinPL))
|
||||
- \(QENG-1906\) Refactor initialize to allow config passing [\#77](https://github.com/puppetlabs/vmpooler/pull/77) ([colinPL](https://github.com/colinPL))
|
||||
- Use 'checkout' time to calculate 'running' time [\#75](https://github.com/puppetlabs/vmpooler/pull/75) ([sschneid](https://github.com/sschneid))
|
||||
- Catch improperly-formatted data payloads [\#73](https://github.com/puppetlabs/vmpooler/pull/73) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-1905\) Adding VM-tagging support via PUT /vm/:hostname endpoint [\#72](https://github.com/puppetlabs/vmpooler/pull/72) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-2057\) Historic Redis VM metadata [\#71](https://github.com/puppetlabs/vmpooler/pull/71) ([sschneid](https://github.com/sschneid))
|
||||
- \(QENG-1899\) Add documentation for /summary [\#67](https://github.com/puppetlabs/vmpooler/pull/67) ([colinPL](https://github.com/colinPL))
|
||||
- Use $redis.hgetall rather than hget in a loop [\#66](https://github.com/puppetlabs/vmpooler/pull/66) ([sschneid](https://github.com/sschneid))
|
||||
- /summary per-pool metrics [\#65](https://github.com/puppetlabs/vmpooler/pull/65) ([sschneid](https://github.com/sschneid))
|
||||
- Show boot metrics in /status and /summary endpoints [\#64](https://github.com/puppetlabs/vmpooler/pull/64) ([sschneid](https://github.com/sschneid))
|
||||
- \(maint\) Fixing spacing [\#63](https://github.com/puppetlabs/vmpooler/pull/63) ([sschneid](https://github.com/sschneid))
|
||||
- Metric calc via helpers [\#62](https://github.com/puppetlabs/vmpooler/pull/62) ([sschneid](https://github.com/sschneid))
|
||||
- More granular metrics [\#61](https://github.com/puppetlabs/vmpooler/pull/61) ([sschneid](https://github.com/sschneid))
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
4
Gemfile
4
Gemfile
|
|
@ -3,11 +3,11 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
|
|||
gemspec
|
||||
|
||||
# Evaluate Gemfile.local if it exists
|
||||
if File.exist? "#{__FILE__}.local"
|
||||
if File.exists? "#{__FILE__}.local"
|
||||
instance_eval(File.read("#{__FILE__}.local"))
|
||||
end
|
||||
|
||||
# Evaluate ~/.gemfile if it exists
|
||||
if File.exist?(File.join(Dir.home, '.gemfile'))
|
||||
if File.exists?(File.join(Dir.home, '.gemfile'))
|
||||
instance_eval(File.read(File.join(Dir.home, '.gemfile')))
|
||||
end
|
||||
|
|
|
|||
258
Gemfile.lock
258
Gemfile.lock
|
|
@ -1,219 +1,185 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
vmpooler (3.8.1)
|
||||
vmpooler (2.5.0)
|
||||
concurrent-ruby (~> 1.1)
|
||||
connection_pool (~> 2.4)
|
||||
connection_pool (~> 2.2)
|
||||
deep_merge (~> 1.2)
|
||||
net-ldap (~> 0.16)
|
||||
opentelemetry-exporter-jaeger (= 0.23.0)
|
||||
opentelemetry-instrumentation-concurrent_ruby (= 0.21.1)
|
||||
opentelemetry-instrumentation-http_client (= 0.22.2)
|
||||
opentelemetry-instrumentation-rack (= 0.23.4)
|
||||
opentelemetry-instrumentation-redis (= 0.25.3)
|
||||
opentelemetry-instrumentation-sinatra (= 0.23.2)
|
||||
opentelemetry-resource_detectors (= 0.24.2)
|
||||
opentelemetry-sdk (~> 1.8)
|
||||
opentelemetry-exporter-jaeger (= 0.20.1)
|
||||
opentelemetry-instrumentation-concurrent_ruby (= 0.19.2)
|
||||
opentelemetry-instrumentation-http_client (= 0.19.4)
|
||||
opentelemetry-instrumentation-redis (= 0.21.3)
|
||||
opentelemetry-instrumentation-sinatra (= 0.19.3)
|
||||
opentelemetry-resource_detectors (= 0.19.1)
|
||||
opentelemetry-sdk (~> 1.0, >= 1.0.2)
|
||||
pickup (~> 0.0.11)
|
||||
prometheus-client (>= 2, < 5)
|
||||
puma (>= 5.0.4, < 7)
|
||||
rack (>= 2.2, < 4.0)
|
||||
prometheus-client (~> 2.0)
|
||||
puma (~> 5.0, >= 5.0.4)
|
||||
rack (~> 2.2)
|
||||
rake (~> 13.0)
|
||||
redis (~> 5.0)
|
||||
sinatra (>= 2, < 4)
|
||||
redis (~> 4.1)
|
||||
sinatra (~> 2.0)
|
||||
spicy-proton (~> 2.1)
|
||||
statsd-ruby (~> 1.4)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.3)
|
||||
base64 (0.1.2)
|
||||
bindata (2.5.1)
|
||||
builder (3.3.0)
|
||||
ast (2.4.2)
|
||||
bindata (2.4.15)
|
||||
builder (3.2.4)
|
||||
climate_control (1.2.0)
|
||||
coderay (1.1.3)
|
||||
concurrent-ruby (1.3.5)
|
||||
connection_pool (2.5.3)
|
||||
concurrent-ruby (1.2.2)
|
||||
connection_pool (2.3.0)
|
||||
deep_merge (1.2.2)
|
||||
diff-lcs (1.6.2)
|
||||
docile (1.4.1)
|
||||
faraday (2.13.1)
|
||||
faraday-net_http (>= 2.0, < 3.5)
|
||||
json
|
||||
logger
|
||||
faraday-net_http (3.4.0)
|
||||
net-http (>= 0.5.0)
|
||||
ffi (1.17.2-java)
|
||||
google-cloud-env (2.2.1)
|
||||
faraday (>= 1.0, < 3.a)
|
||||
json (2.12.2)
|
||||
json (2.12.2-java)
|
||||
language_server-protocol (3.17.0.5)
|
||||
logger (1.7.0)
|
||||
method_source (1.1.0)
|
||||
mock_redis (0.37.0)
|
||||
mustermann (3.0.3)
|
||||
diff-lcs (1.5.0)
|
||||
docile (1.4.0)
|
||||
faraday (2.7.4)
|
||||
faraday-net_http (>= 2.0, < 3.1)
|
||||
ruby2_keywords (>= 0.0.4)
|
||||
faraday-net_http (3.0.2)
|
||||
ffi (1.15.5-java)
|
||||
google-cloud-env (1.6.0)
|
||||
faraday (>= 0.17.3, < 3.0)
|
||||
method_source (1.0.0)
|
||||
mock_redis (0.36.0)
|
||||
ruby2_keywords
|
||||
mustermann (2.0.2)
|
||||
ruby2_keywords (~> 0.0.1)
|
||||
net-http (0.6.0)
|
||||
uri
|
||||
net-ldap (0.19.0)
|
||||
nio4r (2.7.4)
|
||||
nio4r (2.7.4-java)
|
||||
opentelemetry-api (1.5.0)
|
||||
opentelemetry-common (0.20.1)
|
||||
net-ldap (0.17.1)
|
||||
nio4r (2.5.8)
|
||||
nio4r (2.5.8-java)
|
||||
opentelemetry-api (1.1.0)
|
||||
opentelemetry-common (0.19.6)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-exporter-jaeger (0.23.0)
|
||||
opentelemetry-api (~> 1.1)
|
||||
opentelemetry-common (~> 0.20)
|
||||
opentelemetry-sdk (~> 1.2)
|
||||
opentelemetry-semantic_conventions
|
||||
thrift
|
||||
opentelemetry-instrumentation-base (0.22.3)
|
||||
opentelemetry-exporter-jaeger (0.20.1)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-registry (~> 0.1)
|
||||
opentelemetry-instrumentation-concurrent_ruby (0.21.1)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-instrumentation-base (~> 0.22.1)
|
||||
opentelemetry-instrumentation-http_client (0.22.2)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.20.0)
|
||||
opentelemetry-instrumentation-base (~> 0.22.1)
|
||||
opentelemetry-instrumentation-rack (0.23.4)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.20.0)
|
||||
opentelemetry-instrumentation-base (~> 0.22.1)
|
||||
opentelemetry-instrumentation-redis (0.25.3)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.20.0)
|
||||
opentelemetry-instrumentation-base (~> 0.22.1)
|
||||
opentelemetry-instrumentation-sinatra (0.23.2)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.20.0)
|
||||
opentelemetry-instrumentation-base (~> 0.22.1)
|
||||
opentelemetry-instrumentation-rack (~> 0.21)
|
||||
opentelemetry-registry (0.4.0)
|
||||
opentelemetry-api (~> 1.1)
|
||||
opentelemetry-resource_detectors (0.24.2)
|
||||
google-cloud-env
|
||||
opentelemetry-common (~> 0.19.2)
|
||||
opentelemetry-sdk (~> 1.0)
|
||||
opentelemetry-sdk (1.8.0)
|
||||
thrift
|
||||
opentelemetry-instrumentation-base (0.19.0)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-instrumentation-concurrent_ruby (0.19.2)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-instrumentation-http_client (0.19.4)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-instrumentation-redis (0.21.3)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-instrumentation-sinatra (0.19.3)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-registry (0.2.0)
|
||||
opentelemetry-api (~> 1.1)
|
||||
opentelemetry-common (~> 0.20)
|
||||
opentelemetry-resource_detectors (0.19.1)
|
||||
google-cloud-env
|
||||
opentelemetry-sdk
|
||||
opentelemetry-sdk (1.2.0)
|
||||
opentelemetry-api (~> 1.1)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-registry (~> 0.2)
|
||||
opentelemetry-semantic_conventions
|
||||
opentelemetry-semantic_conventions (1.11.0)
|
||||
opentelemetry-semantic_conventions (1.8.0)
|
||||
opentelemetry-api (~> 1.0)
|
||||
parallel (1.27.0)
|
||||
parser (3.3.8.0)
|
||||
parallel (1.22.1)
|
||||
parser (3.2.1.0)
|
||||
ast (~> 2.4.1)
|
||||
racc
|
||||
pickup (0.0.11)
|
||||
prism (1.4.0)
|
||||
prometheus-client (4.2.4)
|
||||
base64
|
||||
pry (0.15.2)
|
||||
prometheus-client (2.1.0)
|
||||
pry (0.14.2)
|
||||
coderay (~> 1.1)
|
||||
method_source (~> 1.0)
|
||||
pry (0.15.2-java)
|
||||
pry (0.14.2-java)
|
||||
coderay (~> 1.1)
|
||||
method_source (~> 1.0)
|
||||
spoon (~> 0.0)
|
||||
puma (6.6.0)
|
||||
puma (5.6.5)
|
||||
nio4r (~> 2.0)
|
||||
puma (6.6.0-java)
|
||||
puma (5.6.5-java)
|
||||
nio4r (~> 2.0)
|
||||
racc (1.8.1)
|
||||
racc (1.8.1-java)
|
||||
rack (2.2.17)
|
||||
rack-protection (3.2.0)
|
||||
base64 (>= 0.1.0)
|
||||
rack (~> 2.2, >= 2.2.4)
|
||||
rack-test (2.2.0)
|
||||
rack (2.2.6.2)
|
||||
rack-protection (2.2.4)
|
||||
rack
|
||||
rack-test (2.0.2)
|
||||
rack (>= 1.3)
|
||||
rainbow (3.1.1)
|
||||
rake (13.3.0)
|
||||
redis (5.4.0)
|
||||
redis-client (>= 0.22.0)
|
||||
redis-client (0.24.0)
|
||||
connection_pool
|
||||
regexp_parser (2.10.0)
|
||||
rexml (3.4.1)
|
||||
rspec (3.13.1)
|
||||
rspec-core (~> 3.13.0)
|
||||
rspec-expectations (~> 3.13.0)
|
||||
rspec-mocks (~> 3.13.0)
|
||||
rspec-core (3.13.4)
|
||||
rspec-support (~> 3.13.0)
|
||||
rspec-expectations (3.13.5)
|
||||
rake (13.0.6)
|
||||
redis (4.8.1)
|
||||
regexp_parser (2.7.0)
|
||||
rexml (3.2.5)
|
||||
rspec (3.12.0)
|
||||
rspec-core (~> 3.12.0)
|
||||
rspec-expectations (~> 3.12.0)
|
||||
rspec-mocks (~> 3.12.0)
|
||||
rspec-core (3.12.1)
|
||||
rspec-support (~> 3.12.0)
|
||||
rspec-expectations (3.12.2)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.13.0)
|
||||
rspec-mocks (3.13.5)
|
||||
rspec-support (~> 3.12.0)
|
||||
rspec-mocks (3.12.3)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.13.0)
|
||||
rspec-support (3.13.4)
|
||||
rubocop (1.56.4)
|
||||
base64 (~> 0.1.1)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (>= 3.17.0)
|
||||
rspec-support (~> 3.12.0)
|
||||
rspec-support (3.12.0)
|
||||
rubocop (1.28.2)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.2.2.3)
|
||||
parser (>= 3.1.0.0)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 1.8, < 3.0)
|
||||
rexml (>= 3.2.5, < 4.0)
|
||||
rubocop-ast (>= 1.28.1, < 2.0)
|
||||
rexml
|
||||
rubocop-ast (>= 1.17.0, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 2.4.0, < 3.0)
|
||||
rubocop-ast (1.44.1)
|
||||
parser (>= 3.3.7.2)
|
||||
prism (~> 1.4)
|
||||
ruby-progressbar (1.13.0)
|
||||
unicode-display_width (>= 1.4.0, < 3.0)
|
||||
rubocop-ast (1.27.0)
|
||||
parser (>= 3.2.1.0)
|
||||
ruby-progressbar (1.12.0)
|
||||
ruby2_keywords (0.0.5)
|
||||
simplecov (0.22.0)
|
||||
docile (~> 1.1)
|
||||
simplecov-html (~> 0.11)
|
||||
simplecov_json_formatter (~> 0.1)
|
||||
simplecov-html (0.13.1)
|
||||
simplecov-html (0.12.3)
|
||||
simplecov_json_formatter (0.1.4)
|
||||
sinatra (3.2.0)
|
||||
mustermann (~> 3.0)
|
||||
rack (~> 2.2, >= 2.2.4)
|
||||
rack-protection (= 3.2.0)
|
||||
sinatra (2.2.4)
|
||||
mustermann (~> 2.0)
|
||||
rack (~> 2.2)
|
||||
rack-protection (= 2.2.4)
|
||||
tilt (~> 2.0)
|
||||
spicy-proton (2.1.15)
|
||||
bindata (~> 2.3)
|
||||
spoon (0.0.6)
|
||||
ffi
|
||||
statsd-ruby (1.5.0)
|
||||
thor (1.3.2)
|
||||
thrift (0.22.0)
|
||||
tilt (2.6.0)
|
||||
unicode-display_width (2.6.0)
|
||||
uri (1.0.3)
|
||||
thor (1.2.1)
|
||||
thrift (0.18.1)
|
||||
tilt (2.1.0)
|
||||
unicode-display_width (2.4.2)
|
||||
yarjuf (2.0.0)
|
||||
builder
|
||||
rspec (~> 3)
|
||||
|
||||
PLATFORMS
|
||||
arm64-darwin-22
|
||||
arm64-darwin-23
|
||||
arm64-darwin-25
|
||||
universal-java-1.8
|
||||
universal-java-11
|
||||
universal-java-17
|
||||
x86_64-darwin-22
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
climate_control (>= 0.2.0)
|
||||
mock_redis (= 0.37.0)
|
||||
mock_redis (>= 0.17.0)
|
||||
pry
|
||||
rack-test (>= 0.6)
|
||||
rspec (>= 3.2)
|
||||
rubocop (~> 1.56.0)
|
||||
rubocop (~> 1.28.2)
|
||||
simplecov (>= 0.11.2)
|
||||
thor (~> 1.0, >= 1.0.1)
|
||||
vmpooler!
|
||||
yarjuf (>= 2.0)
|
||||
|
||||
BUNDLED WITH
|
||||
2.4.18
|
||||
2.3.18
|
||||
|
|
|
|||
35
README.md
35
README.md
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
- [VMPooler](#vmpooler)
|
||||
- [Usage](#usage)
|
||||
- [Migrating to v3](#migrating-to-v3)
|
||||
- [v2.0.0 note](#v200-note)
|
||||
- [Installation](#installation)
|
||||
- [Dependencies](#dependencies)
|
||||
|
|
@ -31,40 +30,6 @@ VMPooler provides configurable 'pools' of instantly-available (pre-provisioned)
|
|||
|
||||
At [Puppet, Inc.](http://puppet.com) we run acceptance tests on thousands of disposable VMs every day. VMPooler manages the life cycle of these VMs from request through deletion, with options available to pool ready instances, and provision on demand.
|
||||
|
||||
The recommended method for deploying VMPooler is via [https://github.com/puppetlabs/vmpooler-deployment](vmpooler-deployment).
|
||||
|
||||
### Migrating to v3
|
||||
|
||||
Starting with the v3.x release, management of DNS records is implemented as DNS plugins, similar to compute providers. This means each pool configuration should be pointing to a configuration object in `:dns_config` to determine it's method of record management.
|
||||
|
||||
For those using the global `DOMAIN` environment variable or global `:config.domain` key, this means records were not previously being managed by VMPooler (presumably managed via dynamic dns), so it's value should be moved to `:dns_configs:<INSERT_YOUR_OWN_SYMBOL>:domain` with the value for `dns_class` for the config set to `dynamic-dns`.
|
||||
|
||||
For example, the following < v3.x configuration:
|
||||
|
||||
```yaml
|
||||
:config:
|
||||
domain: 'example.com'
|
||||
```
|
||||
|
||||
becomes:
|
||||
|
||||
```yaml
|
||||
:dns_configs:
|
||||
:example:
|
||||
dns_class: dynamic-dns
|
||||
domain: 'example.com'
|
||||
```
|
||||
|
||||
Then any pools that should have records created via the dns config above should now reference the named dns config in the `dns_plugin` key:
|
||||
|
||||
```yaml
|
||||
:pools:
|
||||
- name: 'debian-8-x86_64'
|
||||
dns_plugin: 'example'
|
||||
```
|
||||
|
||||
For those using the GCE provider, [vmpooler-provider-gce](https://github.com/puppetlabs/vmpooler-provider-gce), as of version 1.x the DNS management has been decoupled. See <https://github.com/puppetlabs/vmpooler-provider-gce#migrating-to-v1>
|
||||
|
||||
### v2.0.0 note
|
||||
|
||||
As of version 2.0.0, all providers other than the dummy one are now separate gems. Historically the vSphere provider was included within VMPooler itself. That code has been moved to the [puppetlabs/vmpooler-provider-vsphere](https://github.com/puppetlabs/vmpooler-provider-vsphere) repository and the `vmpooler-provider-vsphere` gem. To migrate from VMPooler 1.x to 2.0 you will need to ensure that `vmpooler-provider-vsphere` is installed along side the `vmpooler` gem. See the [Provider API](docs/PROVIDER_API.md) docs for more information.
|
||||
|
|
|
|||
26
docker/Dockerfile
Normal file
26
docker/Dockerfile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# This Dockerfile is intended to be used with the
|
||||
# docker-compose file in the same directory.
|
||||
|
||||
FROM jruby:9.3-jdk
|
||||
|
||||
ENV RACK_ENV=production
|
||||
|
||||
RUN apt-get update -qq && \
|
||||
apt-get install -y --no-install-recommends make git && \
|
||||
apt-get clean autoclean && \
|
||||
apt-get autoremove -y && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY docker/docker-entrypoint.sh /usr/local/bin/
|
||||
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
COPY docker/Gemfile* ./
|
||||
|
||||
COPY ./ ./vmpooler-source
|
||||
|
||||
RUN gem install bundler && \
|
||||
bundle config set --local jobs 3 && \
|
||||
bundle install
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
5
docker/Gemfile
Normal file
5
docker/Gemfile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
|
||||
|
||||
gem 'vmpooler', path: './vmpooler-source'
|
||||
gem 'vmpooler-provider-gce', git: 'https://github.com/puppetlabs/vmpooler-provider-gce.git'
|
||||
gem 'vmpooler-provider-vsphere', git: 'https://github.com/puppetlabs/vmpooler-provider-vsphere.git'
|
||||
191
docker/Gemfile.lock
Normal file
191
docker/Gemfile.lock
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
GIT
|
||||
remote: https://github.com/puppetlabs/vmpooler-provider-gce.git
|
||||
revision: 46b9c5aef06184f8a2bd0be6086ae2256b19020a
|
||||
specs:
|
||||
vmpooler-provider-gce (0.3.0)
|
||||
google-apis-compute_v1 (~> 0.14)
|
||||
google-cloud-dns (~> 0.35.1)
|
||||
googleauth (>= 0.16.2, < 1.2.0)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/puppetlabs/vmpooler-provider-vsphere.git
|
||||
revision: a9662622d5574a7f9f6e97ff4c8bc82786982266
|
||||
specs:
|
||||
vmpooler-provider-vsphere (1.5.0)
|
||||
rbvmomi (>= 2.1, < 4.0)
|
||||
|
||||
PATH
|
||||
remote: vmpooler-source
|
||||
specs:
|
||||
vmpooler (2.4.0)
|
||||
concurrent-ruby (~> 1.1)
|
||||
connection_pool (~> 2.2)
|
||||
deep_merge (~> 1.2)
|
||||
net-ldap (~> 0.16)
|
||||
opentelemetry-exporter-jaeger (= 0.20.1)
|
||||
opentelemetry-instrumentation-concurrent_ruby (= 0.19.2)
|
||||
opentelemetry-instrumentation-http_client (= 0.19.4)
|
||||
opentelemetry-instrumentation-redis (= 0.21.3)
|
||||
opentelemetry-instrumentation-sinatra (= 0.19.3)
|
||||
opentelemetry-resource_detectors (= 0.19.1)
|
||||
opentelemetry-sdk (~> 1.0, >= 1.0.2)
|
||||
pickup (~> 0.0.11)
|
||||
prometheus-client (~> 2.0)
|
||||
puma (~> 5.0, >= 5.0.4)
|
||||
rack (~> 2.2)
|
||||
rake (~> 13.0)
|
||||
redis (~> 4.1)
|
||||
sinatra (~> 2.0)
|
||||
spicy-proton (~> 2.1)
|
||||
statsd-ruby (~> 1.4)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.8.0)
|
||||
public_suffix (>= 2.0.2, < 5.0)
|
||||
bindata (2.4.10)
|
||||
builder (3.2.4)
|
||||
concurrent-ruby (1.1.10)
|
||||
connection_pool (2.2.5)
|
||||
declarative (0.0.20)
|
||||
deep_merge (1.2.2)
|
||||
faraday (2.3.0)
|
||||
faraday-net_http (~> 2.0)
|
||||
ruby2_keywords (>= 0.0.4)
|
||||
faraday-net_http (2.0.3)
|
||||
google-apis-compute_v1 (0.44.0)
|
||||
google-apis-core (>= 0.7, < 2.a)
|
||||
google-apis-core (0.7.0)
|
||||
addressable (~> 2.5, >= 2.5.1)
|
||||
googleauth (>= 0.16.2, < 2.a)
|
||||
httpclient (>= 2.8.1, < 3.a)
|
||||
mini_mime (~> 1.0)
|
||||
representable (~> 3.0)
|
||||
retriable (>= 2.0, < 4.a)
|
||||
rexml
|
||||
webrick
|
||||
google-apis-dns_v1 (0.23.0)
|
||||
google-apis-core (>= 0.7, < 2.a)
|
||||
google-cloud-core (1.6.0)
|
||||
google-cloud-env (~> 1.0)
|
||||
google-cloud-errors (~> 1.0)
|
||||
google-cloud-dns (0.35.1)
|
||||
google-apis-dns_v1 (~> 0.1)
|
||||
google-cloud-core (~> 1.6)
|
||||
googleauth (>= 0.16.2, < 2.a)
|
||||
zonefile (~> 1.04)
|
||||
google-cloud-env (1.6.0)
|
||||
faraday (>= 0.17.3, < 3.0)
|
||||
google-cloud-errors (1.2.0)
|
||||
googleauth (1.1.3)
|
||||
faraday (>= 0.17.3, < 3.a)
|
||||
jwt (>= 1.4, < 3.0)
|
||||
memoist (~> 0.16)
|
||||
multi_json (~> 1.11)
|
||||
os (>= 0.9, < 2.0)
|
||||
signet (>= 0.16, < 2.a)
|
||||
httpclient (2.8.3)
|
||||
json (2.6.2-java)
|
||||
jwt (2.4.1)
|
||||
memoist (0.16.2)
|
||||
mini_mime (1.1.2)
|
||||
multi_json (1.15.0)
|
||||
mustermann (2.0.2)
|
||||
ruby2_keywords (~> 0.0.1)
|
||||
net-ldap (0.17.1)
|
||||
nio4r (2.5.8-java)
|
||||
nokogiri (1.13.8-java)
|
||||
racc (~> 1.4)
|
||||
opentelemetry-api (1.0.2)
|
||||
opentelemetry-common (0.19.6)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-exporter-jaeger (0.20.1)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.2)
|
||||
opentelemetry-sdk (~> 1.0)
|
||||
thrift
|
||||
opentelemetry-instrumentation-base (0.19.0)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-instrumentation-concurrent_ruby (0.19.2)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-instrumentation-http_client (0.19.4)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-instrumentation-redis (0.21.3)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-instrumentation-sinatra (0.19.3)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-instrumentation-base (~> 0.19.0)
|
||||
opentelemetry-registry (0.1.0)
|
||||
opentelemetry-api (~> 1.0.1)
|
||||
opentelemetry-resource_detectors (0.19.1)
|
||||
google-cloud-env
|
||||
opentelemetry-sdk
|
||||
opentelemetry-sdk (1.1.0)
|
||||
opentelemetry-api (~> 1.0)
|
||||
opentelemetry-common (~> 0.19.3)
|
||||
opentelemetry-registry (~> 0.1)
|
||||
opentelemetry-semantic_conventions
|
||||
opentelemetry-semantic_conventions (1.8.0)
|
||||
opentelemetry-api (~> 1.0)
|
||||
optimist (3.0.1)
|
||||
os (1.1.4)
|
||||
pickup (0.0.11)
|
||||
prometheus-client (2.1.0)
|
||||
public_suffix (4.0.7)
|
||||
puma (5.6.4-java)
|
||||
nio4r (~> 2.0)
|
||||
racc (1.6.0-java)
|
||||
rack (2.2.4)
|
||||
rack-protection (2.2.2)
|
||||
rack
|
||||
rake (13.0.6)
|
||||
rbvmomi (3.0.0)
|
||||
builder (~> 3.2)
|
||||
json (~> 2.3)
|
||||
nokogiri (~> 1.10)
|
||||
optimist (~> 3.0)
|
||||
redis (4.7.1)
|
||||
representable (3.2.0)
|
||||
declarative (< 0.1.0)
|
||||
trailblazer-option (>= 0.1.1, < 0.2.0)
|
||||
uber (< 0.2.0)
|
||||
retriable (3.1.2)
|
||||
rexml (3.2.5)
|
||||
ruby2_keywords (0.0.5)
|
||||
signet (0.17.0)
|
||||
addressable (~> 2.8)
|
||||
faraday (>= 0.17.5, < 3.a)
|
||||
jwt (>= 1.5, < 3.0)
|
||||
multi_json (~> 1.10)
|
||||
sinatra (2.2.2)
|
||||
mustermann (~> 2.0)
|
||||
rack (~> 2.2)
|
||||
rack-protection (= 2.2.2)
|
||||
tilt (~> 2.0)
|
||||
spicy-proton (2.1.14)
|
||||
bindata (~> 2.3)
|
||||
statsd-ruby (1.5.0)
|
||||
thrift (0.16.0)
|
||||
tilt (2.0.11)
|
||||
trailblazer-option (0.1.2)
|
||||
uber (0.1.0)
|
||||
webrick (1.7.0)
|
||||
zonefile (1.06)
|
||||
|
||||
PLATFORMS
|
||||
universal-java-1.8
|
||||
|
||||
DEPENDENCIES
|
||||
vmpooler!
|
||||
vmpooler-provider-gce!
|
||||
vmpooler-provider-vsphere!
|
||||
|
||||
BUNDLED WITH
|
||||
2.3.18
|
||||
85
docker/docker-compose.yml
Normal file
85
docker/docker-compose.yml
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
# For local development run with a dummy provider
|
||||
version: '3.8'
|
||||
services:
|
||||
vmpooler-api:
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: docker/Dockerfile
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ${PWD}/vmpooler.yaml
|
||||
target: /etc/vmpooler/vmpooler.yaml
|
||||
ports:
|
||||
- "8080:4567"
|
||||
networks:
|
||||
- redis-net
|
||||
environment:
|
||||
- VMPOOLER_DEBUG=true # for use of dummy auth
|
||||
- VMPOOLER_CONFIG_FILE=/etc/vmpooler/vmpooler.yaml
|
||||
- REDIS_SERVER=redislocal
|
||||
- LOGFILE=/dev/null
|
||||
- VMPOOLER_TRACING_ENABLED=true
|
||||
- VMPOOLER_TRACING_JAEGER_HOST=http://jaeger-aio:14268/api/traces
|
||||
image: vmpooler-local
|
||||
command: api
|
||||
depends_on:
|
||||
- redislocal
|
||||
vmpooler-manager:
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: docker/Dockerfile
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ${PWD}/vmpooler.yaml
|
||||
target: /etc/vmpooler/vmpooler.yaml
|
||||
ports:
|
||||
- "8081:4567"
|
||||
networks:
|
||||
- redis-net
|
||||
environment:
|
||||
- VMPOOLER_DEBUG=true # for use of dummy auth
|
||||
- VMPOOLER_CONFIG_FILE=/etc/vmpooler/vmpooler.yaml
|
||||
- REDIS_SERVER=redislocal
|
||||
- LOGFILE=/dev/null
|
||||
- JRUBY_OPTS=-Xinvokedynamic.yield=false
|
||||
- VMPOOLER_TRACING_ENABLED=true
|
||||
- VMPOOLER_TRACING_JAEGER_HOST=http://jaeger-aio:14268/api/traces
|
||||
image: vmpooler-local
|
||||
command: manager
|
||||
depends_on:
|
||||
- redislocal
|
||||
redislocal:
|
||||
image: redis
|
||||
# Uncomment this if you don't want the redis data to persist
|
||||
#command: "redis-server --save '' --appendonly no"
|
||||
ports:
|
||||
- "6379:6379"
|
||||
networks:
|
||||
- redis-net
|
||||
redis-commander:
|
||||
container_name: redis-commander
|
||||
hostname: redis-commander
|
||||
image: rediscommander/redis-commander:latest
|
||||
restart: always
|
||||
environment:
|
||||
- REDIS_HOSTS=local:redislocal:6379
|
||||
ports:
|
||||
- "8079:8081"
|
||||
networks:
|
||||
- redis-net
|
||||
depends_on:
|
||||
- redislocal
|
||||
jaeger-aio:
|
||||
image: jaegertracing/all-in-one:1.18
|
||||
ports:
|
||||
- "14250:14250"
|
||||
- "8082:16686"
|
||||
networks:
|
||||
- redis-net
|
||||
user: '1001'
|
||||
read_only: true
|
||||
cap_drop:
|
||||
- ALL
|
||||
|
||||
networks:
|
||||
redis-net:
|
||||
6
docker/docker-entrypoint.sh
Normal file
6
docker/docker-entrypoint.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
set -- bundle exec vmpooler "$@"
|
||||
|
||||
exec "$@"
|
||||
8
docker/update-gemfile-lock.sh
Executable file
8
docker/update-gemfile-lock.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
docker run -it --rm \
|
||||
-v $(pwd)/docker:/app \
|
||||
-v $(pwd):/app/vmpooler-source \
|
||||
$(grep ^FROM docker/Dockerfile |cut -d ' ' -f2) \
|
||||
/bin/bash -c 'apt-get update -qq && apt-get install -y --no-install-recommends make git && cd /app && gem install bundler && bundle install --jobs 3 && bundle update; echo "LOCK_FILE_UPDATE_EXIT_CODE=$?"'
|
||||
rmdir docker/vmpooler-source
|
||||
936
docs/API-v1.md
Normal file
936
docs/API-v1.md
Normal file
|
|
@ -0,0 +1,936 @@
|
|||
# Table of contents
|
||||
1. [API](#API)
|
||||
2. [Token operations](#token)
|
||||
3. [VM operations](#vmops)
|
||||
4. [Add disks](#adddisks)
|
||||
5. [VM snapshots](#vmsnapshots)
|
||||
6. [Status and metrics](#statusmetrics)
|
||||
7. [Pool configuration](#poolconfig)
|
||||
8. [Ondemand VM provisioning](#ondemandvm)
|
||||
|
||||
### API <a name="API"></a>
|
||||
|
||||
vmpooler provides a REST API for VM management. The following examples use `curl` for communication.
|
||||
|
||||
#### Token operations <a name="token"></a>
|
||||
|
||||
Token-based authentication can be used when requesting or modifying VMs. The `/token` route can be used to create, query, or delete tokens. See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), for information on configuring an authentication store to use when performing token operations.
|
||||
|
||||
##### GET /token
|
||||
|
||||
Get a list of issued tokens.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 401 when not authorized
|
||||
* 404 when config:auth not found or other error
|
||||
|
||||
```
|
||||
$ curl -u jdoe --url vmpooler.example.com/api/v1/token
|
||||
Enter host password for user 'jdoe':
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"utpg2i2xswor6h8ttjhu3d47z53yy47y": {
|
||||
"created": "2015-04-28 19:17:47 -0700"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
##### POST /token
|
||||
|
||||
Generate a new authentication token.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 401 when not authorized
|
||||
* 404 when config:auth not found
|
||||
|
||||
```
|
||||
$ curl -X POST -u jdoe --url vmpooler.example.com/api/v1/token
|
||||
Enter host password for user 'jdoe':
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"token": "utpg2i2xswor6h8ttjhu3d47z53yy47y"
|
||||
}
|
||||
```
|
||||
|
||||
##### GET /token/<token>
|
||||
|
||||
Get information about an existing token (including associated VMs).
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 404 when config:auth or token not found
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v1/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"utpg2i2xswor6h8ttjhu3d47z53yy47y": {
|
||||
"user": "jdoe",
|
||||
"created": "2015-04-28 19:17:47 -0700",
|
||||
"last": "2015-11-04 12:28:37 -0700",
|
||||
"vms": {
|
||||
"running": [
|
||||
"dqs4914g2wjyy5w",
|
||||
"hul7ib0ssr0f4o0"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
##### DELETE /token/<token>
|
||||
|
||||
Delete an authentication token.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 401 when not authorized
|
||||
* 404 when config:auth not found
|
||||
|
||||
```
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v1/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||
Enter host password for user 'jdoe':
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
||||
#### VM operations <a name="vmops"></a>
|
||||
|
||||
##### GET /vm
|
||||
|
||||
Retrieve a list of available VM pools.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v1/vm
|
||||
```
|
||||
```json
|
||||
[
|
||||
"debian-7-i386",
|
||||
"debian-7-x86_64"
|
||||
]
|
||||
```
|
||||
|
||||
##### POST /vm
|
||||
|
||||
Useful for batch operations; post JSON (see format below), get back allocated VMs.
|
||||
|
||||
If an authentication store is configured, an authentication token supplied via the `X-AUTH-TOKEN` HTTP header will modify a VM's default lifetime. See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), and the 'token operations' section above for more information.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 404 when sending invalid JSON in the request body or requesting an invalid VM pool name
|
||||
* 503 when the vm failed to allocate a vm, or the pool is empty
|
||||
|
||||
```
|
||||
$ curl -d '{"debian-7-i386":"2","debian-7-x86_64":"1"}' --url vmpooler.example.com/api/v1/vm
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"debian-7-i386": {
|
||||
"hostname": [
|
||||
"o41xtodlvnvu5cw",
|
||||
"khirruvwfjlmx3y"
|
||||
]
|
||||
},
|
||||
"debian-7-x86_64": {
|
||||
"hostname": "y91qbrpbfj6d13q"
|
||||
},
|
||||
"domain": "example.com"
|
||||
}
|
||||
```
|
||||
|
||||
**NOTE: Returns either all requested VMs or no VMs.**
|
||||
|
||||
##### POST /vm/<pool>
|
||||
|
||||
Check-out a VM or VMs.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 404 when sending invalid JSON in the request body or requesting an invalid VM pool name
|
||||
* 503 when the vm failed to allocate a vm, or the pool is empty
|
||||
|
||||
```
|
||||
$ curl -d --url vmpooler.example.com/api/v1/vm/debian-7-i386
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"debian-7-i386": {
|
||||
"hostname": "fq6qlpjlsskycq6"
|
||||
},
|
||||
"domain": "example.com"
|
||||
}
|
||||
```
|
||||
|
||||
Multiple VMs can be requested by using multiple query parameters in the URL:
|
||||
|
||||
```
|
||||
$ curl -d --url vmpooler.example.com/api/v1/vm/debian-7-i386+debian-7-i386+debian-7-x86_64
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"debian-7-i386": {
|
||||
"hostname": [
|
||||
"sc0o4xqtodlul5w",
|
||||
"4m4dkhqiufnjmxy"
|
||||
]
|
||||
},
|
||||
"debian-7-x86_64": {
|
||||
"hostname": "zb91y9qbrbf6d3q"
|
||||
},
|
||||
"domain": "example.com"
|
||||
}
|
||||
```
|
||||
|
||||
**NOTE: Returns either all requested VMs or no VMs.**
|
||||
|
||||
##### GET /vm/<hostname>
|
||||
|
||||
Query metadata information for a checked-out VM.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 404 when requesting an invalid VM hostname
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v1/vm/pxpmtoonx7fiqg6
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"pxpmtoonx7fiqg6": {
|
||||
"template": "centos-6-x86_64",
|
||||
"lifetime": 12,
|
||||
"running": 3,
|
||||
"remaining": 9,
|
||||
"state": "running",
|
||||
"tags": {
|
||||
"department": "engineering",
|
||||
"user": "jdoe"
|
||||
},
|
||||
"ip": "192.168.0.1",
|
||||
"domain": "example.com",
|
||||
"host": "host1.example.com",
|
||||
"migrated": "true"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
##### PUT /vm/<hostname>
|
||||
|
||||
Modify a checked-out VM.
|
||||
|
||||
The following are valid PUT parameters and their required data structures:
|
||||
|
||||
parameter | description | required structure
|
||||
--------- | ----------- | ------------------
|
||||
*lifetime* | VM TTL (in hours) | integer
|
||||
*tags* | free-form VM tagging | hash
|
||||
|
||||
Any modifications can be verified using the [GET /vm/<hostname>](#get-vmhostname) endpoint.
|
||||
|
||||
If an authentication store is configured, an authentication token is required (via the `X-AUTH-TOKEN` HTTP header) to access this route. See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), and the 'token operations' section above for more information.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 401 when you need an auth token
|
||||
* 404 when requesting an invalid VM hostname
|
||||
* 400 when supplied PUT parameters fail validation
|
||||
|
||||
```
|
||||
$ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
$ curl -X PUT -d '{"tags":{"department":"engineering","user":"jdoe"}}' --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
||||
##### DELETE /vm/<hostname>
|
||||
|
||||
Schedule a checked-out VM for deletion.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 401 when you need an auth token
|
||||
* 404 when requesting an invalid VM hostname
|
||||
|
||||
```
|
||||
$ curl -X DELETE --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
||||
#### Adding additional disk(s) <a name="adddisks"></a>
|
||||
|
||||
##### POST /vm/<hostname>/disk/<size>
|
||||
|
||||
Add an additional disk to a running VM.
|
||||
|
||||
Return codes:
|
||||
* 202 OK
|
||||
* 401 when you need an auth token
|
||||
* 404 when requesting an invalid VM hostname or size is not an integer
|
||||
|
||||
````
|
||||
$ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6/disk/8
|
||||
````
|
||||
````json
|
||||
{
|
||||
"ok": true,
|
||||
"fq6qlpjlsskycq6": {
|
||||
"disk": "+8gb"
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Provisioning and attaching disks can take a moment, but once the task completes it will be reflected in a `GET /vm/<hostname>` query:
|
||||
|
||||
````
|
||||
$ curl --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6
|
||||
````
|
||||
````json
|
||||
{
|
||||
"ok": true,
|
||||
"fq6qlpjlsskycq6": {
|
||||
"template": "debian-7-x86_64",
|
||||
"lifetime": 2,
|
||||
"running": 0.08,
|
||||
"state": "running",
|
||||
"disk": [
|
||||
"+8gb"
|
||||
],
|
||||
"domain": "delivery.puppetlabs.net"
|
||||
}
|
||||
}
|
||||
|
||||
````
|
||||
|
||||
#### VM snapshots <a name="vmsnapshots"></a>
|
||||
|
||||
##### POST /vm/<hostname>/snapshot
|
||||
|
||||
Create a snapshot of a running VM.
|
||||
|
||||
Return codes:
|
||||
* 202 OK
|
||||
* 401 when you need an auth token
|
||||
* 404 when requesting an invalid VM hostname
|
||||
|
||||
````
|
||||
$ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6/snapshot
|
||||
````
|
||||
````json
|
||||
{
|
||||
"ok": true,
|
||||
"fq6qlpjlsskycq6": {
|
||||
"snapshot": "n4eb4kdtp7rwv4x158366vd9jhac8btq"
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Snapshotting a live VM can take a moment, but once the snapshot task completes it will be reflected in a `GET /vm/<hostname>` query:
|
||||
|
||||
````
|
||||
$ curl --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6
|
||||
````
|
||||
````json
|
||||
{
|
||||
"ok": true,
|
||||
"fq6qlpjlsskycq6": {
|
||||
"template": "debian-7-x86_64",
|
||||
"lifetime": 2,
|
||||
"running": 0.08,
|
||||
"state": "running",
|
||||
"snapshots": [
|
||||
"n4eb4kdtp7rwv4x158366vd9jhac8btq"
|
||||
],
|
||||
"domain": "delivery.puppetlabs.net"
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
##### POST /vm/<hostname>/snapshot/<snapshot>
|
||||
|
||||
Revert a VM back to a snapshot.
|
||||
|
||||
Return codes:
|
||||
* 202 OK
|
||||
* 401 when you need an auth token
|
||||
* 404 when requesting an invalid VM hostname or snapshot is not valid
|
||||
|
||||
````
|
||||
$ curl X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v1/vm/fq6qlpjlsskycq6/snapshot/n4eb4kdtp7rwv4x158366vd9jhac8btq
|
||||
````
|
||||
````json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
````
|
||||
|
||||
#### Status and metrics <a name="statusmetrics"></a>
|
||||
|
||||
##### GET /status
|
||||
|
||||
A "live" status endpoint, representing the current state of the service.
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v1/status
|
||||
```
|
||||
```json
|
||||
{
|
||||
"capacity": {
|
||||
"current": 716,
|
||||
"total": 717,
|
||||
"percent": 99.9
|
||||
},
|
||||
"clone": {
|
||||
"duration": {
|
||||
"average": 8.8,
|
||||
"min": 2.79,
|
||||
"max": 69.76
|
||||
},
|
||||
"count": {
|
||||
"total": 1779
|
||||
}
|
||||
},
|
||||
"queue": {
|
||||
"pending": 1,
|
||||
"cloning": 0,
|
||||
"booting": 1,
|
||||
"ready": 716,
|
||||
"running": 142,
|
||||
"completed": 0,
|
||||
"total": 859
|
||||
},
|
||||
"status": {
|
||||
"ok": true,
|
||||
"message": "Battle station fully armed and operational."
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If there are empty pools, the "status" section will convey this:
|
||||
|
||||
```json
|
||||
"status": {
|
||||
"ok": false,
|
||||
"message": "Found 2 empty pools.",
|
||||
"empty": [
|
||||
"centos-6-x86_64",
|
||||
"debian-7-x86_64"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
The top level sections are: "capacity", "queue", "clone", "boot", "pools" and "status".
|
||||
If the query parameter 'view' is provided, it will be used to select which top level
|
||||
element to compute and return. Select them by specifying which one you want in a comma
|
||||
separated list.
|
||||
For example `vmpooler.example.com/api/v1/status?view=capacity,boot`
|
||||
|
||||
##### GET /summary[?from=YYYY-MM-DD[&to=YYYY-MM-DD]]
|
||||
|
||||
Returns a summary, or report, for the timespan between `from` and `to` (inclusive)
|
||||
parameters. The response includes both an overall and daily view of tracked
|
||||
metrics, such as boot and cloning durations.
|
||||
|
||||
Any omitted query parameter will default to now/today. A request without any
|
||||
parameters will result in the current day's summary.
|
||||
|
||||
Return codes:
|
||||
* 200 OK
|
||||
* 400 Invalid date format or range
|
||||
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v1/summary
|
||||
```
|
||||
```json
|
||||
{
|
||||
"boot": {
|
||||
"duration": {
|
||||
"average": 106.6,
|
||||
"min": 83.09,
|
||||
"max": 121.06,
|
||||
"total": 639.36,
|
||||
},
|
||||
"count": {
|
||||
"average": 6,
|
||||
"min": 6,
|
||||
"max": 6,
|
||||
"total": 6,
|
||||
}
|
||||
},
|
||||
"clone": {
|
||||
"duration": {
|
||||
"average": 4.6,
|
||||
"min": 2.78,
|
||||
"max": 8.1,
|
||||
"total": 63.94,
|
||||
},
|
||||
"count": {
|
||||
"average": 14,
|
||||
"min": 14,
|
||||
"max": 14,
|
||||
"total": 14,
|
||||
}
|
||||
},
|
||||
"tag": {
|
||||
"department": {
|
||||
"engineering": 14,
|
||||
"help desk": 10,
|
||||
"IT": 44,
|
||||
"total": 68
|
||||
},
|
||||
"user": {
|
||||
"arodgers": 54,
|
||||
"cmatthews": 10,
|
||||
"jnelson": 4,
|
||||
"total": 68
|
||||
}
|
||||
},
|
||||
"daily": [
|
||||
{
|
||||
"date": "2015-03-11",
|
||||
"boot": {
|
||||
"duration": {
|
||||
"average": 106.6,
|
||||
"min": 83.09,
|
||||
"max": 121.06,
|
||||
"total": 639.36
|
||||
},
|
||||
"count": {
|
||||
"total": 6
|
||||
}
|
||||
},
|
||||
"clone": {
|
||||
"duration": {
|
||||
"average": 4.6,
|
||||
"min": 2.78,
|
||||
"max": 8.1,
|
||||
"total": 63.94
|
||||
},
|
||||
"count": {
|
||||
"total": 14
|
||||
}
|
||||
},
|
||||
"tag": {
|
||||
"department": {
|
||||
"engineering": 14,
|
||||
"help desk": 10,
|
||||
"IT": 44,
|
||||
"total": 68
|
||||
},
|
||||
"user": {
|
||||
"arodgers": 54,
|
||||
"cmatthews": 10,
|
||||
"jnelson": 4,
|
||||
"total": 68
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
$ curl -G -d 'from=2015-03-10' -d 'to=2015-03-11' --url vmpooler.example.com/api/v1/summary
|
||||
```
|
||||
```json
|
||||
{
|
||||
"boot": {...},
|
||||
"clone": {...},
|
||||
"daily": [
|
||||
{
|
||||
"date": "2015-03-10",
|
||||
"boot": {
|
||||
"duration": {
|
||||
"average": 0,
|
||||
"min": 0,
|
||||
"max": 0,
|
||||
"total": 0
|
||||
},
|
||||
"count": {
|
||||
"total": 0
|
||||
}
|
||||
},
|
||||
"clone": {
|
||||
"duration": {
|
||||
"average": 0,
|
||||
"min": 0,
|
||||
"max": 0,
|
||||
"total": 0
|
||||
},
|
||||
"count": {
|
||||
"total": 0
|
||||
}
|
||||
},
|
||||
"tag": { }
|
||||
},
|
||||
{
|
||||
"date": "2015-03-11",
|
||||
"boot": {
|
||||
"duration": {
|
||||
"average": 106.6,
|
||||
"min": 83.09,
|
||||
"max": 121.06,
|
||||
"total": 639.36
|
||||
},
|
||||
"count": {
|
||||
"total": 6
|
||||
}
|
||||
},
|
||||
"clone": {
|
||||
"duration": {
|
||||
"average": 4.6,
|
||||
"min": 2.78,
|
||||
"max": 8.1,
|
||||
"total": 63.94
|
||||
},
|
||||
"count": {
|
||||
"total": 14
|
||||
}
|
||||
},
|
||||
"tag": { }
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You can also query only the specific top level section you want by including it after `summary/`.
|
||||
The valid sections are "boot", "clone" or "tag" eg. `vmpooler.example.com/api/v1/summary/boot/`.
|
||||
You can further drill-down the data by specifying the second level parameter to query eg
|
||||
`vmpooler.example.com/api/v1/summary/tag/created_by`
|
||||
|
||||
##### GET /poolstat?pool=FOO
|
||||
|
||||
For parameter `pool`, containing a comma separated list of pool names to query, this endpoint returns
|
||||
each of the pool's ready, max and alias information. It can be used to get a fast response for
|
||||
the required pools instead of using the /status API endpoint
|
||||
|
||||
Return codes
|
||||
* 200 OK
|
||||
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v1/poolstat?pool=centos-6-x86_64
|
||||
```
|
||||
```json
|
||||
{
|
||||
"pools": {
|
||||
"centos-6-x86_64": {
|
||||
"ready": 25,
|
||||
"max": 25,
|
||||
"alias": [
|
||||
"centos-6-64",
|
||||
"centos-6-amd64"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
##### GET /totalrunning
|
||||
|
||||
Fast endpoint to return the total number of VMs in a 'running' state
|
||||
|
||||
Return codes
|
||||
* 200 OK
|
||||
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v1/totalrunning
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
|
||||
"running": 362
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
#### Managing pool configuration via API <a name="poolconfig"></a>
|
||||
|
||||
##### GET /config
|
||||
|
||||
Returns the running pool configuration
|
||||
|
||||
Return codes
|
||||
* 200 OK
|
||||
* 400 No configuration found
|
||||
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v1/config
|
||||
```
|
||||
```json
|
||||
{
|
||||
"pool_configuration": [
|
||||
{
|
||||
"name": "redhat-7-x86_64",
|
||||
"template": "templates/redhat-7.2-x86_64-0.0.3",
|
||||
"folder": "vmpooler/redhat-7-x86_64",
|
||||
"datastore": "stor1",
|
||||
"size": 1,
|
||||
"datacenter": "dc1",
|
||||
"provider": "vsphere",
|
||||
"capacity": 1,
|
||||
"major": "redhat",
|
||||
"template_ready": true
|
||||
}
|
||||
],
|
||||
"status": {
|
||||
"ok": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note: to enable poolsize and pooltemplate config endpoints it is necessary to set 'experimental_features: true' in your vmpooler configuration. A 405 is returned when you attempt to interact with these endpoints when this configuration option is not set.
|
||||
|
||||
##### POST /config/poolsize
|
||||
|
||||
Change pool size without having to restart the service.
|
||||
|
||||
All pool template changes requested must be for pools that exist in the vmpooler configuration running, or a 404 code will be returned
|
||||
|
||||
When a pool size is changed due to the configuration posted a 201 status will be returned. When the pool configuration is valid, but will not result in any changes, 200 is returned.
|
||||
|
||||
Pool size configuration changes persist through application restarts, and take precedence over a pool size value configured in the pool configuration provided when the application starts. This persistence is dependent on redis. So, if the redis data is lost then the configuration updates revert to those provided at startup at the next application start.
|
||||
|
||||
An authentication token is required in order to change pool configuration when authentication is configured.
|
||||
Responses:
|
||||
* 200 - No changes required
|
||||
* 201 - Changes made on at least one pool with changes requested
|
||||
* 400 - An invalid configuration was provided causing requested changes to fail
|
||||
* 404 - An unknown error occurred
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"2","debian-7-x86_64":"1"}' --url https://vmpooler.example.com/api/v1/config/poolsize
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
||||
##### DELETE /config/poolsize/<pool>
|
||||
|
||||
Delete an overridden pool size. This results in the values from VMPooler's config being used.
|
||||
|
||||
Return codes:
|
||||
* 200 - when nothing was changed but no error occurred
|
||||
* 201 - size reset successful
|
||||
* 401 - when not authorized
|
||||
* 404 - pool does not exist
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
|
||||
```
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v1/poolsize/almalinux-8-x86_64
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"pool_size_before_overrides": 2,
|
||||
"pool_size_before_reset": 4
|
||||
}
|
||||
```
|
||||
|
||||
##### POST /config/pooltemplate
|
||||
|
||||
Change the template configured for a pool, and replenish the pool with instances built from the new template.
|
||||
|
||||
All pool template changes requested must be for pools that exist in the vmpooler configuration running, or a 404 code will be returned
|
||||
|
||||
When a pool template is changed due to the configuration posted a 201 status will be returned. When the pool configuration is valid, but will not result in any changes, 200 is returned.
|
||||
|
||||
A pool template being updated will cause the following actions, which are logged in vmpooler.log:
|
||||
* Destroy all instances for the pool template being updated that are in the ready and pending state
|
||||
* Halt repopulating the pool while creating template deltas for the newly configured template
|
||||
* Unblock pool population and let the pool replenish with instances based on the newly configured template
|
||||
|
||||
Pool template changes persist through application restarts, and take precedence over a pool template configured in the pool configuration provided when the application starts. This persistence is dependent on redis. As a result, if the redis data is lost then the configuration values revert to those provided at startup at the next application start.
|
||||
|
||||
An authentication token is required in order to change pool configuration when authentication is configured.
|
||||
|
||||
Responses:
|
||||
* 200 - No changes required
|
||||
* 201 - Changes made on at least one pool with changes requested
|
||||
* 400 - An invalid configuration was provided causing requested changes to fail
|
||||
* 404 - An unknown error occurred
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"templates/debian-7-i386"}' --url https://vmpooler.example.com/api/v1/config/pooltemplate
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
||||
##### DELETE /config/pooltemplate/<pool>
|
||||
|
||||
Delete an overridden pool template. This results in the values from VMPooler's config being used.
|
||||
|
||||
Return codes:
|
||||
* 200 - when nothing was changed but no error occurred
|
||||
* 201 - template reset successful
|
||||
* 401 - when not authorized
|
||||
* 404 - pool does not exist
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
|
||||
```
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v1/pooltemplate/almalinux-8-x86_64
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"template_before_overrides": "templates/almalinux-8-x86_64-0.0.2",
|
||||
"template_before_reset": "templates/almalinux-8-x86_64-0.0.3-beta"
|
||||
}
|
||||
```
|
||||
|
||||
##### POST /poolreset
|
||||
|
||||
Clear all pending and ready instances in a pool, and deploy replacements
|
||||
|
||||
All pool reset requests must be for pools that exist in the vmpooler configuration running, or a 404 code will be returned.
|
||||
|
||||
When a pool reset is requested a 201 status will be returned.
|
||||
|
||||
A pool reset will cause vmpooler manager to log that it has cleared ready and pending instances.
|
||||
|
||||
For poolreset to be available it is necessary to enable experimental features. Additionally, the request must be performed with an authentication token when authentication is configured.
|
||||
|
||||
Responses:
|
||||
* 201 - Pool reset requested received
|
||||
* 400 - An invalid configuration was provided causing requested changes to fail
|
||||
* 404 - An unknown error occurred
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"1"}' --url https://vmpooler.example.com/api/v1/poolreset
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
||||
#### Ondemand VM operations <a name="ondemandvm"></a>
|
||||
|
||||
Ondemand VM operations offer a user an option to directly request instances to be allocated for use. This can be very useful when supporting a wide range of images because idle instances can be eliminated.
|
||||
|
||||
##### POST /ondemandvm
|
||||
|
||||
All instance types requested must match a pool name or alias in the running application configuration, or a 404 code will be returned
|
||||
|
||||
When a provisioning request is accepted the API will return an indication that the request is successful. You may then poll /ondemandvm to monitor request status.
|
||||
|
||||
An authentication token is required in order to request instances on demand when authentication is configured.
|
||||
|
||||
Responses:
|
||||
* 201 - Provisioning request accepted
|
||||
* 400 - Payload contains invalid JSON and cannot be parsed
|
||||
* 401 - No auth token provided, or provided auth token is not valid, and auth is enabled
|
||||
* 403 - Request exceeds the configured per pool maximum
|
||||
* 404 - A pool was requested, which is not available in the running configuration, or an unknown error occurred.
|
||||
* 409 - A request of the matching ID has already been created
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"4"}' --url https://vmpooler.example.com/api/v1/ondemandvm
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"request_id": "e3ff6271-d201-4f31-a315-d17f4e15863a"
|
||||
}
|
||||
```
|
||||
|
||||
##### GET /ondemandvm
|
||||
|
||||
Get the status of an ondemandvm request that has already been posted.
|
||||
|
||||
When the request is ready the ready status will change to 'true'.
|
||||
|
||||
The number of instances pending vs ready will be reflected in the API response.
|
||||
|
||||
Responses:
|
||||
* 200 - The API request was successful and the status is ok
|
||||
* 202 - The request is not ready yet
|
||||
* 404 - The request can not be found, or an unknown error occurred
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v1/ondemandvm/e3ff6271-d201-4f31-a315-d17f4e15863a
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"request_id": "e3ff6271-d201-4f31-a315-d17f4e15863a",
|
||||
"ready": false,
|
||||
"debian-7-i386": {
|
||||
"ready": "3",
|
||||
"pending": "1"
|
||||
}
|
||||
}
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"request_id": "e3ff6271-d201-4f31-a315-d17f4e15863a",
|
||||
"ready": true,
|
||||
"debian-7-i386": {
|
||||
"hostname": [
|
||||
"vm1",
|
||||
"vm2",
|
||||
"vm3",
|
||||
"vm4"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
##### DELETE /ondemandvm
|
||||
|
||||
Delete a ondemand request
|
||||
|
||||
Deleting a ondemand request will delete any instances created for the request and mark the backend data for expiration in two weeks. Any subsequent attempts to retrieve request data will indicate it has been deleted.
|
||||
|
||||
Responses:
|
||||
* 200 - The API request was sucessful. A message will indicate if the request has already been deleted.
|
||||
* 401 - No auth token provided, or provided auth token is not valid, and auth is enabled
|
||||
* 404 - The request can not be found, or an unknown error occurred.
|
||||
```
|
||||
$ curl -X DELETE https://vmpooler.example.com/api/v1/ondemandvm/e3ff6271-d201-4f31-a315-d17f4e15863a
|
||||
```
|
||||
```json
|
||||
{
|
||||
"ok": true
|
||||
}
|
||||
```
|
||||
|
|
@ -12,15 +12,6 @@
|
|||
|
||||
vmpooler provides a REST API for VM management. The following examples use `curl` for communication.
|
||||
|
||||
## Major change in V3 versus V2
|
||||
|
||||
The api/v1 and api/v2 endpoints have been removed. Additionally, the generic api endpoint that reroutes to a versioned endpoint has been removed.
|
||||
|
||||
The api/v3 endpoint removes the deprecated "domain" key returned in some of the operations like getting a VM, etc. If there is a "domain" configured in the top level configuration or for a specific provider,
|
||||
the hostname now returns an FQDN including that domain. That is to say, we can now have multiple, different domains for each pool instead of only a single domain for all pools, or a domain restricted to a particular provider.
|
||||
|
||||
Clients using some of the direct API paths (without specifying api/v1 or api/v2) will now now need to specify the versioned endpoint (api/v3).
|
||||
|
||||
## Major change in V2 versus V1
|
||||
|
||||
The api/v2 endpoint removes a separate "domain" key returned in some of the operations like getting a VM, etc. If there is a "domain" configured in the top level configuration or for a specific provider,
|
||||
|
|
@ -50,7 +41,7 @@ Return codes:
|
|||
* 404 when config:auth not found or other error
|
||||
|
||||
```
|
||||
$ curl -u jdoe --url vmpooler.example.com/api/v3/token
|
||||
$ curl -u jdoe --url vmpooler.example.com/api/v2/token
|
||||
Enter host password for user 'jdoe':
|
||||
```
|
||||
```json
|
||||
|
|
@ -72,7 +63,7 @@ Return codes:
|
|||
* 404 when config:auth not found
|
||||
|
||||
```
|
||||
$ curl -X POST -u jdoe --url vmpooler.example.com/api/v3/token
|
||||
$ curl -X POST -u jdoe --url vmpooler.example.com/api/v2/token
|
||||
Enter host password for user 'jdoe':
|
||||
```
|
||||
```json
|
||||
|
|
@ -91,7 +82,7 @@ Return codes:
|
|||
* 404 when config:auth or token not found
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v3/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||
$ curl --url vmpooler.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -120,7 +111,7 @@ Return codes:
|
|||
* 404 when config:auth not found
|
||||
|
||||
```
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v3/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||
Enter host password for user 'jdoe':
|
||||
```
|
||||
```json
|
||||
|
|
@ -139,7 +130,7 @@ Return codes:
|
|||
* 200 OK
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v3/vm
|
||||
$ curl --url vmpooler.example.com/api/v2/vm
|
||||
```
|
||||
```json
|
||||
[
|
||||
|
|
@ -160,7 +151,7 @@ Return codes:
|
|||
* 503 when the vm failed to allocate a vm, or the pool is empty
|
||||
|
||||
```
|
||||
$ curl -d '{"debian-7-i386":"2","debian-7-x86_64":"1"}' --url vmpooler.example.com/api/v3/vm
|
||||
$ curl -d '{"debian-7-i386":"2","debian-7-x86_64":"1"}' --url vmpooler.example.com/api/v2/vm
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -189,7 +180,7 @@ Return codes:
|
|||
* 503 when the vm failed to allocate a vm, or the pool is empty
|
||||
|
||||
```
|
||||
$ curl -d --url vmpooler.example.com/api/v3/vm/debian-7-i386
|
||||
$ curl -d --url vmpooler.example.com/api/v2/vm/debian-7-i386
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -203,7 +194,7 @@ $ curl -d --url vmpooler.example.com/api/v3/vm/debian-7-i386
|
|||
Multiple VMs can be requested by using multiple query parameters in the URL:
|
||||
|
||||
```
|
||||
$ curl -d --url vmpooler.example.com/api/v3/vm/debian-7-i386+debian-7-i386+debian-7-x86_64
|
||||
$ curl -d --url vmpooler.example.com/api/v2/vm/debian-7-i386+debian-7-i386+debian-7-x86_64
|
||||
```
|
||||
|
||||
```json
|
||||
|
|
@ -232,7 +223,7 @@ Return codes:
|
|||
* 404 when requesting an invalid VM hostname
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v3/vm/pxpmtoonx7fiqg6
|
||||
$ curl --url vmpooler.example.com/api/v2/vm/pxpmtoonx7fiqg6
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -276,7 +267,7 @@ Return codes:
|
|||
* 400 when supplied PUT parameters fail validation
|
||||
|
||||
```
|
||||
$ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6
|
||||
$ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -285,7 +276,7 @@ $ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.example.com/api/v3/vm/fq6qlpj
|
|||
```
|
||||
|
||||
```
|
||||
$ curl -X PUT -d '{"tags":{"department":"engineering","user":"jdoe"}}' --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6
|
||||
$ curl -X PUT -d '{"tags":{"department":"engineering","user":"jdoe"}}' --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -303,7 +294,7 @@ Return codes:
|
|||
* 404 when requesting an invalid VM hostname
|
||||
|
||||
```
|
||||
$ curl -X DELETE --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6
|
||||
$ curl -X DELETE --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -323,7 +314,7 @@ Return codes:
|
|||
* 404 when requesting an invalid VM hostname or size is not an integer
|
||||
|
||||
````
|
||||
$ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6/disk/8
|
||||
$ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6/disk/8
|
||||
````
|
||||
````json
|
||||
{
|
||||
|
|
@ -337,7 +328,7 @@ $ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.e
|
|||
Provisioning and attaching disks can take a moment, but once the task completes it will be reflected in a `GET /vm/<hostname>` query:
|
||||
|
||||
````
|
||||
$ curl --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6
|
||||
$ curl --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6
|
||||
````
|
||||
````json
|
||||
{
|
||||
|
|
@ -367,7 +358,7 @@ Return codes:
|
|||
* 404 when requesting an invalid VM hostname
|
||||
|
||||
````
|
||||
$ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6/snapshot
|
||||
$ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6/snapshot
|
||||
````
|
||||
````json
|
||||
{
|
||||
|
|
@ -381,7 +372,7 @@ $ curl -X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.e
|
|||
Snapshotting a live VM can take a moment, but once the snapshot task completes it will be reflected in a `GET /vm/<hostname>` query:
|
||||
|
||||
````
|
||||
$ curl --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6
|
||||
$ curl --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6
|
||||
````
|
||||
````json
|
||||
{
|
||||
|
|
@ -408,7 +399,7 @@ Return codes:
|
|||
* 404 when requesting an invalid VM hostname or snapshot is not valid
|
||||
|
||||
````
|
||||
$ curl X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v3/vm/fq6qlpjlsskycq6/snapshot/n4eb4kdtp7rwv4x158366vd9jhac8btq
|
||||
$ curl X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.example.com/api/v2/vm/fq6qlpjlsskycq6/snapshot/n4eb4kdtp7rwv4x158366vd9jhac8btq
|
||||
````
|
||||
````json
|
||||
{
|
||||
|
|
@ -423,7 +414,7 @@ $ curl X POST -H X-AUTH-TOKEN:a9znth9dn01t416hrguu56ze37t790bl --url vmpooler.ex
|
|||
A "live" status endpoint, representing the current state of the service.
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v3/status
|
||||
$ curl --url vmpooler.example.com/api/v2/status
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -475,7 +466,7 @@ The top level sections are: "capacity", "queue", "clone", "boot", "pools" and "s
|
|||
If the query parameter 'view' is provided, it will be used to select which top level
|
||||
element to compute and return. Select them by specifying which one you want in a comma
|
||||
separated list.
|
||||
For example `vmpooler.example.com/api/v3/status?view=capacity,boot`
|
||||
For example `vmpooler.example.com/api/v2/status?view=capacity,boot`
|
||||
|
||||
##### GET /summary[?from=YYYY-MM-DD[&to=YYYY-MM-DD]]
|
||||
|
||||
|
|
@ -492,7 +483,7 @@ Return codes:
|
|||
|
||||
|
||||
```
|
||||
$ curl --url vmpooler.example.com/api/v3/summary
|
||||
$ curl --url vmpooler.example.com/api/v2/summary
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -584,7 +575,7 @@ $ curl --url vmpooler.example.com/api/v3/summary
|
|||
|
||||
|
||||
```
|
||||
$ curl -G -d 'from=2015-03-10' -d 'to=2015-03-11' --url vmpooler.example.com/api/v3/summary
|
||||
$ curl -G -d 'from=2015-03-10' -d 'to=2015-03-11' --url vmpooler.example.com/api/v2/summary
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -648,9 +639,9 @@ $ curl -G -d 'from=2015-03-10' -d 'to=2015-03-11' --url vmpooler.example.com/api
|
|||
```
|
||||
|
||||
You can also query only the specific top level section you want by including it after `summary/`.
|
||||
The valid sections are "boot", "clone" or "tag" eg. `vmpooler.example.com/api/v3/summary/boot/`.
|
||||
The valid sections are "boot", "clone" or "tag" eg. `vmpooler.example.com/api/v2/summary/boot/`.
|
||||
You can further drill-down the data by specifying the second level parameter to query eg
|
||||
`vmpooler.example.com/api/v3/summary/tag/created_by`
|
||||
`vmpooler.example.com/api/v2/summary/tag/created_by`
|
||||
|
||||
##### GET /poolstat?pool=FOO
|
||||
|
||||
|
|
@ -662,7 +653,7 @@ Return codes
|
|||
* 200 OK
|
||||
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v3/poolstat?pool=centos-6-x86_64
|
||||
$ curl https://vmpooler.example.com/api/v2/poolstat?pool=centos-6-x86_64
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -687,7 +678,7 @@ Return codes
|
|||
* 200 OK
|
||||
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v3/totalrunning
|
||||
$ curl https://vmpooler.example.com/api/v2/totalrunning
|
||||
```
|
||||
|
||||
```json
|
||||
|
|
@ -709,7 +700,7 @@ Return codes
|
|||
* 400 No configuration found
|
||||
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v3/config
|
||||
$ curl https://vmpooler.example.com/api/v2/config
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -753,7 +744,7 @@ Responses:
|
|||
* 404 - An unknown error occurred
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"2","debian-7-x86_64":"1"}' --url https://vmpooler.example.com/api/v3/config/poolsize
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"2","debian-7-x86_64":"1"}' --url https://vmpooler.example.com/api/v2/config/poolsize
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -773,7 +764,7 @@ Return codes:
|
|||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
|
||||
```
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v3/poolsize/almalinux-8-x86_64
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v2/poolsize/almalinux-8-x86_64
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -807,7 +798,7 @@ Responses:
|
|||
* 404 - An unknown error occurred
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"templates/debian-7-i386"}' --url https://vmpooler.example.com/api/v3/config/pooltemplate
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"templates/debian-7-i386"}' --url https://vmpooler.example.com/api/v2/config/pooltemplate
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -827,7 +818,7 @@ Return codes:
|
|||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
|
||||
```
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v3/pooltemplate/almalinux-8-x86_64
|
||||
$ curl -X DELETE -u jdoe --url vmpooler.example.com/api/v2/pooltemplate/almalinux-8-x86_64
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -855,7 +846,7 @@ Responses:
|
|||
* 404 - An unknown error occurred
|
||||
* 405 - The endpoint is disabled because experimental features are disabled
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"1"}' --url https://vmpooler.example.com/api/v3/poolreset
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"1"}' --url https://vmpooler.example.com/api/v2/poolreset
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -883,7 +874,7 @@ Responses:
|
|||
* 404 - A pool was requested, which is not available in the running configuration, or an unknown error occurred.
|
||||
* 409 - A request of the matching ID has already been created
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"4"}' --url https://vmpooler.example.com/api/v3/ondemandvm
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"debian-7-i386":"4"}' --url https://vmpooler.example.com/api/v2/ondemandvm
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -905,7 +896,7 @@ Responses:
|
|||
* 202 - The request is not ready yet
|
||||
* 404 - The request can not be found, or an unknown error occurred
|
||||
```
|
||||
$ curl https://vmpooler.example.com/api/v3/ondemandvm/e3ff6271-d201-4f31-a315-d17f4e15863a
|
||||
$ curl https://vmpooler.example.com/api/v2/ondemandvm/e3ff6271-d201-4f31-a315-d17f4e15863a
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -945,7 +936,7 @@ Responses:
|
|||
* 401 - No auth token provided, or provided auth token is not valid, and auth is enabled
|
||||
* 404 - The request can not be found, or an unknown error occurred.
|
||||
```
|
||||
$ curl -X DELETE https://vmpooler.example.com/api/v3/ondemandvm/e3ff6271-d201-4f31-a315-d17f4e15863a
|
||||
$ curl -X DELETE https://vmpooler.example.com/api/v2/ondemandvm/e3ff6271-d201-4f31-a315-d17f4e15863a
|
||||
```
|
||||
```json
|
||||
{
|
||||
|
|
@ -19,6 +19,11 @@ Provide the entire configuration as a blob of yaml. Individual parameters passed
|
|||
|
||||
Path to a the file to use when loading the vmpooler configuration. This is only evaluated if `VMPOOLER_CONFIG` has not been specified.
|
||||
|
||||
### DOMAIN
|
||||
|
||||
This environment variable is to set the configuration config.domain
|
||||
(optional)
|
||||
|
||||
### REDIS\_SERVER
|
||||
|
||||
The redis server to use for vmpooler.
|
||||
|
|
@ -246,18 +251,6 @@ This can be a string providing a single DN. For multiple DNs please specify the
|
|||
The LDAP object-type used to designate a user object.
|
||||
(optional)
|
||||
|
||||
### LDAP\_SERVICE_ACCOUNT\_HASH
|
||||
|
||||
A hash containing the following parameters for a service account to perform the
|
||||
initial bind. After the initial bind, then a search query is performed using the
|
||||
'base' and 'user_object', then re-binds as the returned user.
|
||||
|
||||
- :user_dn: The full distinguished name (DN) of the service account used to bind.
|
||||
|
||||
- :password: The password for the service account used to bind.
|
||||
|
||||
(optional)
|
||||
|
||||
### SITE\_NAME
|
||||
|
||||
The name of your deployment.
|
||||
|
|
|
|||
|
|
@ -17,20 +17,15 @@
|
|||
logfile: '/Users/samuel/workspace/vmpooler/vmpooler.log'
|
||||
task_limit: 10
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
vm_checktime: 1
|
||||
vm_lifetime: 12
|
||||
vm_lifetime_auth: 24
|
||||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
prefix: 'poolvm-'
|
||||
|
||||
:dns_configs:
|
||||
:example:
|
||||
dns_class: dynamic-dns
|
||||
domain: 'example.com'
|
||||
|
||||
:pools:
|
||||
- name: 'debian-7-i386'
|
||||
alias: [ 'debian-7-32' ]
|
||||
|
|
@ -39,10 +34,8 @@
|
|||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
- name: 'debian-7-i386-stringalias'
|
||||
alias: 'debian-7-32-stringalias'
|
||||
template: 'Templates/debian-7-i386'
|
||||
|
|
@ -50,10 +43,8 @@
|
|||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
- name: 'debian-7-x86_64'
|
||||
alias: [ 'debian-7-64', 'debian-7-amd64' ]
|
||||
template: 'Templates/debian-7-x86_64'
|
||||
|
|
@ -61,20 +52,16 @@
|
|||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
- name: 'debian-7-i386-noalias'
|
||||
template: 'Templates/debian-7-i386'
|
||||
folder: 'Pooled VMs/debian-7-i386'
|
||||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
- name: 'debian-7-x86_64-alias-otherpool-extended'
|
||||
alias: [ 'debian-7-x86_64' ]
|
||||
template: 'Templates/debian-7-x86_64'
|
||||
|
|
@ -82,7 +69,6 @@
|
|||
datastore: 'other-vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
|
||||
|
|
|
|||
|
|
@ -76,13 +76,9 @@ module Vmpooler
|
|||
parsed_config[:config]['prefix'] = ENV['PREFIX'] || parsed_config[:config]['prefix'] || ''
|
||||
parsed_config[:config]['logfile'] = ENV['LOGFILE'] if ENV['LOGFILE']
|
||||
parsed_config[:config]['site_name'] = ENV['SITE_NAME'] if ENV['SITE_NAME']
|
||||
if !parsed_config[:config]['domain'].nil? || !ENV['DOMAIN'].nil?
|
||||
puts '[!] [error] The "domain" config setting has been removed in v3. Please see the docs for migrating the domain config to use a dns plugin at https://github.com/puppetlabs/vmpooler/blob/main/README.md#migrating-to-v3'
|
||||
exit 1
|
||||
end
|
||||
parsed_config[:config]['domain'] = ENV['DOMAIN'] if ENV['DOMAIN']
|
||||
parsed_config[:config]['clone_target'] = ENV['CLONE_TARGET'] if ENV['CLONE_TARGET']
|
||||
parsed_config[:config]['timeout'] = string_to_int(ENV['TIMEOUT']) if ENV['TIMEOUT']
|
||||
parsed_config[:config]['timeout_notification'] = string_to_int(ENV['TIMEOUT_NOTIFICATION']) if ENV['TIMEOUT_NOTIFICATION']
|
||||
parsed_config[:config]['vm_lifetime_auth'] = string_to_int(ENV['VM_LIFETIME_AUTH']) if ENV['VM_LIFETIME_AUTH']
|
||||
parsed_config[:config]['max_tries'] = string_to_int(ENV['MAX_TRIES']) if ENV['MAX_TRIES']
|
||||
parsed_config[:config]['retry_factor'] = string_to_int(ENV['RETRY_FACTOR']) if ENV['RETRY_FACTOR']
|
||||
|
|
@ -104,7 +100,7 @@ module Vmpooler
|
|||
parsed_config[:redis]['data_ttl'] = string_to_int(ENV['REDIS_DATA_TTL']) || parsed_config[:redis]['data_ttl'] || 168
|
||||
parsed_config[:redis]['connection_pool_size'] = string_to_int(ENV['REDIS_CONNECTION_POOL_SIZE']) || parsed_config[:redis]['connection_pool_size'] || 10
|
||||
parsed_config[:redis]['connection_pool_timeout'] = string_to_int(ENV['REDIS_CONNECTION_POOL_TIMEOUT']) || parsed_config[:redis]['connection_pool_timeout'] || 5
|
||||
parsed_config[:redis]['reconnect_attempts'] = string_array_to_array(ENV['REDIS_RECONNECT_ATTEMPTS']) || parsed_config[:redis]['reconnect_attempts'] || 10
|
||||
parsed_config[:redis]['reconnect_attempts'] = string_to_int(ENV['REDIS_RECONNECT_ATTEMPTS']) || parsed_config[:redis]['reconnect_attempts'] || 10
|
||||
|
||||
parsed_config[:statsd] = parsed_config[:statsd] || {} if ENV['STATSD_SERVER']
|
||||
parsed_config[:statsd]['server'] = ENV['STATSD_SERVER'] if ENV['STATSD_SERVER']
|
||||
|
|
@ -210,13 +206,8 @@ module Vmpooler
|
|||
end
|
||||
|
||||
def self.new_redis(host = 'localhost', port = nil, password = nil, redis_reconnect_attempts = 10)
|
||||
Redis.new(
|
||||
host: host,
|
||||
port: port,
|
||||
password: password,
|
||||
reconnect_attempts: redis_reconnect_attempts,
|
||||
connect_timeout: 300
|
||||
)
|
||||
Redis.new(host: host, port: port, password: password, reconnect_attempts: redis_reconnect_attempts, reconnect_delay: 1.5,
|
||||
reconnect_delay_max: 10.0)
|
||||
end
|
||||
|
||||
def self.pools(conf)
|
||||
|
|
@ -241,13 +232,6 @@ module Vmpooler
|
|||
Integer(s)
|
||||
end
|
||||
|
||||
def self.string_array_to_array(s)
|
||||
# Returns an array from an array like string
|
||||
return if s.nil?
|
||||
|
||||
JSON.parse(s)
|
||||
end
|
||||
|
||||
def self.true?(obj)
|
||||
obj.to_s.downcase == 'true'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
module Vmpooler
|
||||
class API < Sinatra::Base
|
||||
# Load API components
|
||||
%w[helpers dashboard v3 request_logger healthcheck].each do |lib|
|
||||
%w[helpers dashboard reroute v1 v2 request_logger healthcheck].each do |lib|
|
||||
require "vmpooler/api/#{lib}"
|
||||
end
|
||||
# Load dashboard components
|
||||
|
|
@ -52,7 +52,9 @@ module Vmpooler
|
|||
|
||||
use Vmpooler::Dashboard
|
||||
use Vmpooler::API::Dashboard
|
||||
use Vmpooler::API::V3
|
||||
use Vmpooler::API::Reroute
|
||||
use Vmpooler::API::V1
|
||||
use Vmpooler::API::V2
|
||||
end
|
||||
|
||||
# Get thee started O WebServer
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'vmpooler/api/input_validator'
|
||||
|
||||
module Vmpooler
|
||||
|
||||
class API
|
||||
|
||||
module Helpers
|
||||
include InputValidator
|
||||
|
||||
def tracer
|
||||
@tracer ||= OpenTelemetry.tracer_provider.tracer('api', Vmpooler::VERSION)
|
||||
|
|
@ -28,7 +25,7 @@ module Vmpooler
|
|||
def validate_token(backend)
|
||||
tracer.in_span("Vmpooler::API::Helpers.#{__method__}") do
|
||||
if valid_token?(backend)
|
||||
backend.hset("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'last', Time.now.to_s)
|
||||
backend.hset("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'last', Time.now)
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
@ -71,7 +68,7 @@ module Vmpooler
|
|||
end
|
||||
end
|
||||
|
||||
def authenticate_ldap(port, host, encryption_hash, user_object, base, username_str, password_str, service_account_hash = nil)
|
||||
def authenticate_ldap(port, host, encryption_hash, user_object, base, username_str, password_str)
|
||||
tracer.in_span(
|
||||
"Vmpooler::API::Helpers.#{__method__}",
|
||||
attributes: {
|
||||
|
|
@ -82,14 +79,6 @@ module Vmpooler
|
|||
},
|
||||
kind: :client
|
||||
) do
|
||||
if service_account_hash
|
||||
username = service_account_hash[:user_dn]
|
||||
password = service_account_hash[:password]
|
||||
else
|
||||
username = "#{user_object}=#{username_str},#{base}"
|
||||
password = password_str
|
||||
end
|
||||
|
||||
ldap = Net::LDAP.new(
|
||||
:host => host,
|
||||
:port => port,
|
||||
|
|
@ -97,22 +86,12 @@ module Vmpooler
|
|||
:base => base,
|
||||
:auth => {
|
||||
:method => :simple,
|
||||
:username => username,
|
||||
:password => password
|
||||
:username => "#{user_object}=#{username_str},#{base}",
|
||||
:password => password_str
|
||||
}
|
||||
)
|
||||
|
||||
if service_account_hash
|
||||
return true if ldap.bind_as(
|
||||
:base => base,
|
||||
:filter => "(#{user_object}=#{username_str})",
|
||||
:password => password_str
|
||||
)
|
||||
elsif ldap.bind
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
return true if ldap.bind
|
||||
|
||||
return false
|
||||
end
|
||||
|
|
@ -137,7 +116,6 @@ module Vmpooler
|
|||
:method => :start_tls,
|
||||
:tls_options => { :ssl_version => 'TLSv1' }
|
||||
}
|
||||
service_account_hash = auth[:ldap]['service_account_hash']
|
||||
|
||||
unless ldap_base.is_a? Array
|
||||
ldap_base = ldap_base.split
|
||||
|
|
@ -156,8 +134,7 @@ module Vmpooler
|
|||
search_user_obj,
|
||||
search_base,
|
||||
username_str,
|
||||
password_str,
|
||||
service_account_hash
|
||||
password_str
|
||||
)
|
||||
return true if result
|
||||
end
|
||||
|
|
@ -204,7 +181,8 @@ module Vmpooler
|
|||
/^\d{4}-\d{2}-\d{2}$/ === date_str
|
||||
end
|
||||
|
||||
def hostname_shorten(hostname)
|
||||
# NOTE: domain is not needed here, so we should update the callers of this method
|
||||
def hostname_shorten(hostname, domain=nil)
|
||||
hostname[/[^.]+/]
|
||||
end
|
||||
|
||||
|
|
@ -292,7 +270,6 @@ module Vmpooler
|
|||
def get_queue_metrics(pools, backend)
|
||||
tracer.in_span("Vmpooler::API::Helpers.#{__method__}") do
|
||||
queue = {
|
||||
requested: 0,
|
||||
pending: 0,
|
||||
cloning: 0,
|
||||
booting: 0,
|
||||
|
|
@ -302,35 +279,15 @@ module Vmpooler
|
|||
total: 0
|
||||
}
|
||||
|
||||
# Use a single pipeline to fetch all queue counts at once for better performance
|
||||
results = backend.pipelined do |pipeline|
|
||||
# Order matters - we'll use indices to extract values
|
||||
pools.each do |pool|
|
||||
pipeline.scard("vmpooler__provisioning__request#{pool['name']}") # 0..n-1
|
||||
pipeline.scard("vmpooler__provisioning__processing#{pool['name']}") # n..2n-1
|
||||
pipeline.scard("vmpooler__odcreate__task#{pool['name']}") # 2n..3n-1
|
||||
pipeline.scard("vmpooler__pending__#{pool['name']}") # 3n..4n-1
|
||||
pipeline.scard("vmpooler__ready__#{pool['name']}") # 4n..5n-1
|
||||
pipeline.scard("vmpooler__running__#{pool['name']}") # 5n..6n-1
|
||||
pipeline.scard("vmpooler__completed__#{pool['name']}") # 6n..7n-1
|
||||
end
|
||||
pipeline.get('vmpooler__tasks__clone') # 7n
|
||||
pipeline.get('vmpooler__tasks__ondemandclone') # 7n+1
|
||||
end
|
||||
queue[:pending] = get_total_across_pools_redis_scard(pools, 'vmpooler__pending__', backend)
|
||||
queue[:ready] = get_total_across_pools_redis_scard(pools, 'vmpooler__ready__', backend)
|
||||
queue[:running] = get_total_across_pools_redis_scard(pools, 'vmpooler__running__', backend)
|
||||
queue[:completed] = get_total_across_pools_redis_scard(pools, 'vmpooler__completed__', backend)
|
||||
|
||||
n = pools.length
|
||||
# Safely extract results with default to empty array if slice returns nil
|
||||
queue[:requested] = (results[0...n] || []).sum(&:to_i) +
|
||||
(results[n...(2 * n)] || []).sum(&:to_i) +
|
||||
(results[(2 * n)...(3 * n)] || []).sum(&:to_i)
|
||||
queue[:pending] = (results[(3 * n)...(4 * n)] || []).sum(&:to_i)
|
||||
queue[:ready] = (results[(4 * n)...(5 * n)] || []).sum(&:to_i)
|
||||
queue[:running] = (results[(5 * n)...(6 * n)] || []).sum(&:to_i)
|
||||
queue[:completed] = (results[(6 * n)...(7 * n)] || []).sum(&:to_i)
|
||||
queue[:cloning] = (results[7 * n] || 0).to_i + (results[7 * n + 1] || 0).to_i
|
||||
queue[:booting] = queue[:pending].to_i - queue[:cloning].to_i
|
||||
queue[:booting] = 0 if queue[:booting] < 0
|
||||
queue[:total] = queue[:requested] + queue[:pending].to_i + queue[:ready].to_i + queue[:running].to_i + queue[:completed].to_i
|
||||
queue[:cloning] = backend.get('vmpooler__tasks__clone').to_i + backend.get('vmpooler__tasks__ondemandclone').to_i
|
||||
queue[:booting] = queue[:pending].to_i - queue[:cloning].to_i
|
||||
queue[:booting] = 0 if queue[:booting] < 0
|
||||
queue[:total] = queue[:pending].to_i + queue[:ready].to_i + queue[:running].to_i + queue[:completed].to_i
|
||||
|
||||
queue
|
||||
end
|
||||
|
|
@ -595,6 +552,18 @@ module Vmpooler
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def vm_ready?(vm_name, domain = nil)
|
||||
tracer.in_span("Vmpooler::API::Helpers.#{__method__}") do
|
||||
begin
|
||||
open_socket(vm_name, domain)
|
||||
rescue StandardError => _e
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,159 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Vmpooler
|
||||
class API
|
||||
# Input validation helpers to enhance security
|
||||
module InputValidator
|
||||
# Maximum lengths to prevent abuse
|
||||
MAX_HOSTNAME_LENGTH = 253
|
||||
MAX_TAG_KEY_LENGTH = 50
|
||||
MAX_TAG_VALUE_LENGTH = 255
|
||||
MAX_REASON_LENGTH = 500
|
||||
MAX_POOL_NAME_LENGTH = 100
|
||||
MAX_TOKEN_LENGTH = 64
|
||||
|
||||
# Valid patterns
|
||||
HOSTNAME_PATTERN = /\A[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)* \z/ix.freeze
|
||||
POOL_NAME_PATTERN = /\A[a-zA-Z0-9_-]+\z/.freeze
|
||||
TAG_KEY_PATTERN = /\A[a-zA-Z0-9_\-.]+\z/.freeze
|
||||
TOKEN_PATTERN = /\A[a-zA-Z0-9\-_]+\z/.freeze
|
||||
INTEGER_PATTERN = /\A\d+\z/.freeze
|
||||
|
||||
class ValidationError < StandardError; end
|
||||
|
||||
# Validate hostname format and length
|
||||
def validate_hostname(hostname)
|
||||
return error_response('Hostname is required') if hostname.nil? || hostname.empty?
|
||||
return error_response('Hostname too long') if hostname.length > MAX_HOSTNAME_LENGTH
|
||||
return error_response('Invalid hostname format') unless hostname.match?(HOSTNAME_PATTERN)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# Validate pool/template name
|
||||
def validate_pool_name(pool_name)
|
||||
return error_response('Pool name is required') if pool_name.nil? || pool_name.empty?
|
||||
return error_response('Pool name too long') if pool_name.length > MAX_POOL_NAME_LENGTH
|
||||
return error_response('Invalid pool name format') unless pool_name.match?(POOL_NAME_PATTERN)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# Validate tag key and value
|
||||
def validate_tag(key, value)
|
||||
return error_response('Tag key is required') if key.nil? || key.empty?
|
||||
return error_response('Tag key too long') if key.length > MAX_TAG_KEY_LENGTH
|
||||
return error_response('Invalid tag key format') unless key.match?(TAG_KEY_PATTERN)
|
||||
|
||||
if value
|
||||
return error_response('Tag value too long') if value.length > MAX_TAG_VALUE_LENGTH
|
||||
|
||||
# Sanitize value to prevent injection attacks
|
||||
sanitized_value = value.gsub(/[^\w\s\-.@:\/]/, '')
|
||||
return error_response('Tag value contains invalid characters') if sanitized_value != value
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# Validate token format
|
||||
def validate_token_format(token)
|
||||
return error_response('Token is required') if token.nil? || token.empty?
|
||||
return error_response('Token too long') if token.length > MAX_TOKEN_LENGTH
|
||||
return error_response('Invalid token format') unless token.match?(TOKEN_PATTERN)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# Validate integer parameter
|
||||
def validate_integer(value, name = 'value', min: nil, max: nil)
|
||||
return error_response("#{name} is required") if value.nil?
|
||||
|
||||
value_str = value.to_s
|
||||
return error_response("#{name} must be a valid integer") unless value_str.match?(INTEGER_PATTERN)
|
||||
|
||||
int_value = value.to_i
|
||||
return error_response("#{name} must be at least #{min}") if min && int_value < min
|
||||
return error_response("#{name} must be at most #{max}") if max && int_value > max
|
||||
|
||||
int_value
|
||||
end
|
||||
|
||||
# Validate VM request count
|
||||
def validate_vm_count(count)
|
||||
validated = validate_integer(count, 'VM count', min: 1, max: 100)
|
||||
return validated if validated.is_a?(Hash) # error response
|
||||
|
||||
validated
|
||||
end
|
||||
|
||||
# Validate disk size
|
||||
def validate_disk_size(size)
|
||||
validated = validate_integer(size, 'Disk size', min: 1, max: 2048)
|
||||
return validated if validated.is_a?(Hash) # error response
|
||||
|
||||
validated
|
||||
end
|
||||
|
||||
# Validate lifetime (TTL) in hours
|
||||
def validate_lifetime(lifetime)
|
||||
validated = validate_integer(lifetime, 'Lifetime', min: 1, max: 168) # max 1 week
|
||||
return validated if validated.is_a?(Hash) # error response
|
||||
|
||||
validated
|
||||
end
|
||||
|
||||
# Validate reason text
|
||||
def validate_reason(reason)
|
||||
return true if reason.nil? || reason.empty?
|
||||
return error_response('Reason too long') if reason.length > MAX_REASON_LENGTH
|
||||
|
||||
# Sanitize to prevent XSS/injection
|
||||
sanitized = reason.gsub(/[<>"']/, '')
|
||||
return error_response('Reason contains invalid characters') if sanitized != reason
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# Sanitize JSON body to prevent injection
|
||||
def sanitize_json_body(body)
|
||||
return {} if body.nil? || body.empty?
|
||||
|
||||
begin
|
||||
parsed = JSON.parse(body)
|
||||
return error_response('Request body must be a JSON object') unless parsed.is_a?(Hash)
|
||||
|
||||
# Limit depth and size to prevent DoS
|
||||
return error_response('Request body too complex') if json_depth(parsed) > 5
|
||||
return error_response('Request body too large') if body.length > 10_240 # 10KB max
|
||||
|
||||
parsed
|
||||
rescue JSON::ParserError => e
|
||||
error_response("Invalid JSON: #{e.message}")
|
||||
end
|
||||
end
|
||||
|
||||
# Check if validation result is an error
|
||||
def validation_error?(result)
|
||||
result.is_a?(Hash) && result['ok'] == false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def error_response(message)
|
||||
{ 'ok' => false, 'error' => message }
|
||||
end
|
||||
|
||||
def json_depth(obj, depth = 0)
|
||||
return depth unless obj.is_a?(Hash) || obj.is_a?(Array)
|
||||
return depth + 1 if obj.empty?
|
||||
|
||||
if obj.is_a?(Hash)
|
||||
depth + 1 + obj.values.map { |v| json_depth(v, 0) }.max
|
||||
else
|
||||
depth + 1 + obj.map { |v| json_depth(v, 0) }.max
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Vmpooler
|
||||
class API
|
||||
# Rate limiter middleware to protect against abuse
|
||||
# Uses Redis to track request counts per IP and token
|
||||
class RateLimiter
|
||||
DEFAULT_LIMITS = {
|
||||
global_per_ip: { limit: 100, period: 60 }, # 100 requests per minute per IP
|
||||
authenticated: { limit: 500, period: 60 }, # 500 requests per minute with token
|
||||
vm_creation: { limit: 20, period: 60 }, # 20 VM creations per minute
|
||||
vm_deletion: { limit: 50, period: 60 } # 50 VM deletions per minute
|
||||
}.freeze
|
||||
|
||||
def initialize(app, redis, config = {})
|
||||
@app = app
|
||||
@redis = redis
|
||||
@config = DEFAULT_LIMITS.merge(config[:rate_limits] || {})
|
||||
@enabled = config.fetch(:rate_limiting_enabled, true)
|
||||
end
|
||||
|
||||
def call(env)
|
||||
return @app.call(env) unless @enabled
|
||||
|
||||
request = Rack::Request.new(env)
|
||||
client_id = identify_client(request)
|
||||
endpoint_type = classify_endpoint(request)
|
||||
|
||||
# Check rate limits
|
||||
return rate_limit_response(client_id, endpoint_type) if rate_limit_exceeded?(client_id, endpoint_type, request)
|
||||
|
||||
# Track the request
|
||||
increment_request_count(client_id, endpoint_type)
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def identify_client(request)
|
||||
# Prioritize token-based identification for authenticated requests
|
||||
token = request.env['HTTP_X_AUTH_TOKEN']
|
||||
return "token:#{token}" if token && !token.empty?
|
||||
|
||||
# Fall back to IP address
|
||||
ip = request.ip || request.env['REMOTE_ADDR'] || 'unknown'
|
||||
"ip:#{ip}"
|
||||
end
|
||||
|
||||
def classify_endpoint(request)
|
||||
path = request.path
|
||||
method = request.request_method
|
||||
|
||||
return :vm_creation if method == 'POST' && path.include?('/vm')
|
||||
return :vm_deletion if method == 'DELETE' && path.include?('/vm')
|
||||
return :authenticated if request.env['HTTP_X_AUTH_TOKEN']
|
||||
|
||||
:global_per_ip
|
||||
end
|
||||
|
||||
def rate_limit_exceeded?(client_id, endpoint_type, _request)
|
||||
limit_config = @config[endpoint_type] || @config[:global_per_ip]
|
||||
key = "vmpooler__ratelimit__#{endpoint_type}__#{client_id}"
|
||||
|
||||
current_count = @redis.get(key).to_i
|
||||
current_count >= limit_config[:limit]
|
||||
rescue StandardError => e
|
||||
# If Redis fails, allow the request through (fail open)
|
||||
warn "Rate limiter Redis error: #{e.message}"
|
||||
false
|
||||
end
|
||||
|
||||
def increment_request_count(client_id, endpoint_type)
|
||||
limit_config = @config[endpoint_type] || @config[:global_per_ip]
|
||||
key = "vmpooler__ratelimit__#{endpoint_type}__#{client_id}"
|
||||
|
||||
@redis.pipelined do |pipeline|
|
||||
pipeline.incr(key)
|
||||
pipeline.expire(key, limit_config[:period])
|
||||
end
|
||||
rescue StandardError => e
|
||||
# Log error but don't fail the request
|
||||
warn "Rate limiter increment error: #{e.message}"
|
||||
end
|
||||
|
||||
def rate_limit_response(client_id, endpoint_type)
|
||||
limit_config = @config[endpoint_type] || @config[:global_per_ip]
|
||||
key = "vmpooler__ratelimit__#{endpoint_type}__#{client_id}"
|
||||
|
||||
begin
|
||||
ttl = @redis.ttl(key)
|
||||
rescue StandardError
|
||||
ttl = limit_config[:period]
|
||||
end
|
||||
|
||||
headers = {
|
||||
'Content-Type' => 'application/json',
|
||||
'X-RateLimit-Limit' => limit_config[:limit].to_s,
|
||||
'X-RateLimit-Remaining' => '0',
|
||||
'X-RateLimit-Reset' => (Time.now.to_i + ttl).to_s,
|
||||
'Retry-After' => ttl.to_s
|
||||
}
|
||||
|
||||
body = JSON.pretty_generate({
|
||||
'ok' => false,
|
||||
'error' => 'Rate limit exceeded',
|
||||
'limit' => limit_config[:limit],
|
||||
'period' => limit_config[:period],
|
||||
'retry_after' => ttl
|
||||
})
|
||||
|
||||
[429, headers, [body]]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
89
lib/vmpooler/api/reroute.rb
Normal file
89
lib/vmpooler/api/reroute.rb
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Vmpooler
|
||||
class API
|
||||
class Reroute < Sinatra::Base
|
||||
api_version = '1'
|
||||
|
||||
get '/status/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called /status/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/status")
|
||||
end
|
||||
|
||||
get '/summary/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called /summary/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/summary")
|
||||
end
|
||||
|
||||
get '/summary/:route/?:key?/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called /summary/:route/?:key?/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/summary/#{params[:route]}/#{params[:key]}")
|
||||
end
|
||||
|
||||
get '/token/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called /token/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token")
|
||||
end
|
||||
|
||||
post '/token/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called post /token/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token")
|
||||
end
|
||||
|
||||
get '/token/:token/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called /token/:token/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token/#{params[:token]}")
|
||||
end
|
||||
|
||||
delete '/token/:token/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called delete /token/:token/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token/#{params[:token]}")
|
||||
end
|
||||
|
||||
get '/vm/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called /vm? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm")
|
||||
end
|
||||
|
||||
post '/vm/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called post /vm? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm")
|
||||
end
|
||||
|
||||
post '/vm/:template/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called post /vm/:template/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:template]}")
|
||||
end
|
||||
|
||||
get '/vm/:hostname/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called /vm/:hostname/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
|
||||
delete '/vm/:hostname/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called delete /vm/:hostname/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
|
||||
put '/vm/:hostname/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called put /vm/:hostname/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
|
||||
post '/vm/:hostname/snapshot/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called post /vm/:hostname/snapshot/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot")
|
||||
end
|
||||
|
||||
post '/vm/:hostname/snapshot/:snapshot/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called post /vm/:hostname/snapshot/:snapshot/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot/#{params[:snapshot]}")
|
||||
end
|
||||
|
||||
put '/vm/:hostname/disk/:size/?' do
|
||||
puts "DEPRECATION WARNING a client (#{request.user_agent}) called put /vm/:hostname/disk/:size/? and got redirected to api_version=1, this behavior will change in the next major version, please modify the client to use v2 in advance"
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/disk/#{params[:size]}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
1757
lib/vmpooler/api/v1.rb
Normal file
1757
lib/vmpooler/api/v1.rb
Normal file
File diff suppressed because it is too large
Load diff
505
lib/vmpooler/api/v2.rb
Normal file
505
lib/vmpooler/api/v2.rb
Normal file
|
|
@ -0,0 +1,505 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'vmpooler/api/v1'
|
||||
|
||||
module Vmpooler
|
||||
class API
|
||||
class V2 < Vmpooler::API::V1
|
||||
api_version = '2'
|
||||
api_prefix = "/api/v#{api_version}"
|
||||
|
||||
def full_config
|
||||
Vmpooler::API.settings.config
|
||||
end
|
||||
|
||||
def get_template_aliases(template)
|
||||
tracer.in_span("Vmpooler::API::V2.#{__method__}") do
|
||||
result = []
|
||||
aliases = Vmpooler::API.settings.config[:alias]
|
||||
if aliases
|
||||
result += aliases[template] if aliases[template].is_a?(Array)
|
||||
template_backends << aliases[template] if aliases[template].is_a?(String)
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
# Fetch a single vm from a pool
|
||||
#
|
||||
# @param [String] template
|
||||
# The template that the vm should be created from
|
||||
#
|
||||
# @return [Tuple] vmname, vmpool, vmtemplate
|
||||
# Returns a tuple containing the vm's name, the pool it came from, and
|
||||
# what template was used, if successful. Otherwise the tuple contains.
|
||||
# nil values.
|
||||
def fetch_single_vm(template)
|
||||
tracer.in_span("Vmpooler::API::V2.#{__method__}") do
|
||||
template_backends = [template]
|
||||
aliases = Vmpooler::API.settings.config[:alias]
|
||||
if aliases
|
||||
template_backends += aliases[template] if aliases[template].is_a?(Array)
|
||||
template_backends << aliases[template] if aliases[template].is_a?(String)
|
||||
pool_index = pool_index(pools)
|
||||
weighted_pools = {}
|
||||
template_backends.each do |t|
|
||||
next unless pool_index.key? t
|
||||
|
||||
index = pool_index[t]
|
||||
clone_target = pools[index]['clone_target'] || config['clone_target']
|
||||
next unless config.key?('backend_weight')
|
||||
|
||||
weight = config['backend_weight'][clone_target]
|
||||
if weight
|
||||
weighted_pools[t] = weight
|
||||
end
|
||||
end
|
||||
|
||||
if weighted_pools.count == template_backends.count
|
||||
pickup = Pickup.new(weighted_pools)
|
||||
selection = pickup.pick
|
||||
template_backends.delete(selection)
|
||||
template_backends.unshift(selection)
|
||||
else
|
||||
first = template_backends.sample
|
||||
template_backends.delete(first)
|
||||
template_backends.unshift(first)
|
||||
end
|
||||
end
|
||||
|
||||
checkoutlock.synchronize do
|
||||
template_backends.each do |template_backend|
|
||||
vms = backend.smembers("vmpooler__ready__#{template_backend}")
|
||||
next if vms.empty?
|
||||
|
||||
vm = vms.pop
|
||||
smoved = backend.smove("vmpooler__ready__#{template_backend}", "vmpooler__running__#{template_backend}", vm)
|
||||
if smoved
|
||||
return [vm, template_backend, template]
|
||||
end
|
||||
end
|
||||
[nil, nil, nil]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The domain in the result body will be set to the one associated with the
|
||||
# last vm added. The part of the response is only being retained for
|
||||
# backwards compatibility as the hostnames are now fqdn's instead of bare
|
||||
# hostnames. This change is a result of now being able to specify a domain
|
||||
# per pool. If no vm's in the result had a domain sepcified then the
|
||||
# domain key will be omitted similar to how it was previously omitted if
|
||||
# the global option domain wasn't specified.
|
||||
def atomically_allocate_vms(payload)
|
||||
tracer.in_span("Vmpooler::API::V2.#{__method__}") do |span|
|
||||
result = { 'ok' => false }
|
||||
failed = false
|
||||
vms = [] # vmpool, vmname, vmtemplate
|
||||
|
||||
validate_token(backend) if Vmpooler::API.settings.config[:auth] and has_token?
|
||||
|
||||
payload.each do |requested, count|
|
||||
count.to_i.times do |_i|
|
||||
vmname, vmpool, vmtemplate = fetch_single_vm(requested)
|
||||
if vmname
|
||||
account_for_starting_vm(vmpool, vmname)
|
||||
vms << [vmpool, vmname, vmtemplate]
|
||||
metrics.increment("checkout.success.#{vmpool}")
|
||||
update_user_metrics('allocate', vmname) if Vmpooler::API.settings.config[:config]['usage_stats']
|
||||
else
|
||||
failed = true
|
||||
metrics.increment("checkout.empty.#{requested}")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if failed
|
||||
vms.each do |(vmpool, vmname, _vmtemplate)|
|
||||
return_vm_to_ready_state(vmpool, vmname)
|
||||
end
|
||||
span.add_event('error', attributes: {
|
||||
'error.type' => 'Vmpooler::API::V2.atomically_allocate_vms',
|
||||
'error.message' => '503 due to failing to allocate one or more vms'
|
||||
})
|
||||
status 503
|
||||
else
|
||||
vm_names = []
|
||||
vms.each do |(vmpool, vmname, vmtemplate)|
|
||||
vmdomain = Parsing.get_domain_for_pool(full_config, vmpool)
|
||||
if vmdomain
|
||||
vmfqdn = "#{vmname}.#{vmdomain}"
|
||||
update_result_hosts(result, vmtemplate, vmfqdn)
|
||||
vm_names.append(vmfqdn)
|
||||
else
|
||||
update_result_hosts(result, vmtemplate, vmname)
|
||||
vm_names.append(vmname)
|
||||
end
|
||||
end
|
||||
|
||||
span.set_attribute('vmpooler.vm_names', vm_names.join(',')) unless vm_names.empty?
|
||||
|
||||
result['ok'] = true
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def generate_ondemand_request(payload)
|
||||
tracer.in_span("Vmpooler::API::V2.#{__method__}") do |span|
|
||||
result = { 'ok': false }
|
||||
|
||||
requested_instances = payload.reject { |k, _v| k == 'request_id' }
|
||||
if too_many_requested?(requested_instances)
|
||||
e_message = "requested amount of instances exceeds the maximum #{config['max_ondemand_instances_per_request']}"
|
||||
result['message'] = e_message
|
||||
status 403
|
||||
span.add_event('error', attributes: {
|
||||
'error.type' => 'Vmpooler::API::V2.generate_ondemand_request',
|
||||
'error.message' => "403 due to #{e_message}"
|
||||
})
|
||||
return result
|
||||
end
|
||||
|
||||
score = Time.now.to_i
|
||||
request_id = payload['request_id']
|
||||
request_id ||= generate_request_id
|
||||
result['request_id'] = request_id
|
||||
span.set_attribute('vmpooler.request_id', request_id)
|
||||
|
||||
if backend.exists?("vmpooler__odrequest__#{request_id}")
|
||||
e_message = "request_id '#{request_id}' has already been created"
|
||||
result['message'] = e_message
|
||||
status 409
|
||||
span.add_event('error', attributes: {
|
||||
'error.type' => 'Vmpooler::API::V2.generate_ondemand_request',
|
||||
'error.message' => "409 due to #{e_message}"
|
||||
})
|
||||
metrics.increment('ondemandrequest_generate.duplicaterequests')
|
||||
return result
|
||||
end
|
||||
|
||||
status 201
|
||||
|
||||
platforms_with_aliases = []
|
||||
requested_instances.each do |poolname, count|
|
||||
selection = evaluate_template_aliases(poolname, count)
|
||||
selection.map { |selected_pool, selected_pool_count| platforms_with_aliases << "#{poolname}:#{selected_pool}:#{selected_pool_count}" }
|
||||
end
|
||||
platforms_string = platforms_with_aliases.join(',')
|
||||
|
||||
return result unless backend.zadd('vmpooler__provisioning__request', score, request_id)
|
||||
|
||||
backend.hset("vmpooler__odrequest__#{request_id}", 'requested', platforms_string)
|
||||
if Vmpooler::API.settings.config[:auth] and has_token?
|
||||
token_token = request.env['HTTP_X_AUTH_TOKEN']
|
||||
token_user = backend.hget("vmpooler__token__#{token_token}", 'user')
|
||||
backend.hset("vmpooler__odrequest__#{request_id}", 'token:token', token_token)
|
||||
backend.hset("vmpooler__odrequest__#{request_id}", 'token:user', token_user)
|
||||
span.set_attribute('enduser.id', token_user)
|
||||
end
|
||||
|
||||
result[:ok] = true
|
||||
metrics.increment('ondemandrequest_generate.success')
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
# Endpoints that use overridden methods
|
||||
|
||||
post "#{api_prefix}/vm/?" do
|
||||
content_type :json
|
||||
result = { 'ok' => false }
|
||||
metrics.increment('http_requests_vm_total.post.vm.checkout')
|
||||
|
||||
payload = JSON.parse(request.body.read)
|
||||
|
||||
if payload
|
||||
invalid = invalid_templates(payload)
|
||||
if invalid.empty?
|
||||
result = atomically_allocate_vms(payload)
|
||||
else
|
||||
invalid.each do |bad_template|
|
||||
metrics.increment("checkout.invalid.#{bad_template}")
|
||||
end
|
||||
status 404
|
||||
end
|
||||
else
|
||||
metrics.increment('checkout.invalid.unknown')
|
||||
status 404
|
||||
end
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
post "#{api_prefix}/vm/:template/?" do
|
||||
content_type :json
|
||||
result = { 'ok' => false }
|
||||
metrics.increment('http_requests_vm_total.get.vm.template')
|
||||
|
||||
payload = extract_templates_from_query_params(params[:template])
|
||||
|
||||
if payload
|
||||
invalid = invalid_templates(payload)
|
||||
if invalid.empty?
|
||||
result = atomically_allocate_vms(payload)
|
||||
else
|
||||
invalid.each do |bad_template|
|
||||
metrics.increment("checkout.invalid.#{bad_template}")
|
||||
end
|
||||
status 404
|
||||
end
|
||||
else
|
||||
metrics.increment('checkout.invalid.unknown')
|
||||
status 404
|
||||
end
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get "#{api_prefix}/vm/:hostname/?" do
|
||||
content_type :json
|
||||
metrics.increment('http_requests_vm_total.get.vm.hostname')
|
||||
|
||||
result = {}
|
||||
|
||||
status 404
|
||||
result['ok'] = false
|
||||
|
||||
params[:hostname] = hostname_shorten(params[:hostname], nil)
|
||||
|
||||
rdata = backend.hgetall("vmpooler__vm__#{params[:hostname]}")
|
||||
unless rdata.empty?
|
||||
status 200
|
||||
result['ok'] = true
|
||||
|
||||
result[params[:hostname]] = {}
|
||||
|
||||
result[params[:hostname]]['template'] = rdata['template']
|
||||
result[params[:hostname]]['lifetime'] = (rdata['lifetime'] || config['vm_lifetime']).to_i
|
||||
|
||||
if rdata['destroy']
|
||||
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2) if rdata['checkout']
|
||||
result[params[:hostname]]['state'] = 'destroyed'
|
||||
elsif rdata['checkout']
|
||||
result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
||||
result[params[:hostname]]['remaining'] = ((Time.parse(rdata['checkout']) + rdata['lifetime'].to_i*60*60 - Time.now) / 60 / 60).round(2)
|
||||
result[params[:hostname]]['start_time'] = Time.parse(rdata['checkout']).to_datetime.rfc3339
|
||||
result[params[:hostname]]['end_time'] = (Time.parse(rdata['checkout']) + rdata['lifetime'].to_i*60*60).to_datetime.rfc3339
|
||||
result[params[:hostname]]['state'] = 'running'
|
||||
elsif rdata['check']
|
||||
result[params[:hostname]]['state'] = 'ready'
|
||||
else
|
||||
result[params[:hostname]]['state'] = 'pending'
|
||||
end
|
||||
|
||||
rdata.keys.each do |key|
|
||||
if key.match('^tag\:(.+?)$')
|
||||
result[params[:hostname]]['tags'] ||= {}
|
||||
result[params[:hostname]]['tags'][$1] = rdata[key]
|
||||
end
|
||||
|
||||
if key.match('^snapshot\:(.+?)$')
|
||||
result[params[:hostname]]['snapshots'] ||= []
|
||||
result[params[:hostname]]['snapshots'].push($1)
|
||||
end
|
||||
end
|
||||
|
||||
if rdata['disk']
|
||||
result[params[:hostname]]['disk'] = rdata['disk'].split(':')
|
||||
end
|
||||
|
||||
# Look up IP address of the hostname
|
||||
begin
|
||||
ipAddress = TCPSocket.gethostbyname(params[:hostname])[3]
|
||||
rescue StandardError
|
||||
ipAddress = ""
|
||||
end
|
||||
|
||||
result[params[:hostname]]['ip'] = ipAddress
|
||||
|
||||
if rdata['pool']
|
||||
vmdomain = Parsing.get_domain_for_pool(full_config, rdata['pool'])
|
||||
if vmdomain
|
||||
result[params[:hostname]]['fqdn'] = "#{params[:hostname]}.#{vmdomain}"
|
||||
end
|
||||
end
|
||||
|
||||
result[params[:hostname]]['host'] = rdata['host'] if rdata['host']
|
||||
result[params[:hostname]]['migrated'] = rdata['migrated'] if rdata['migrated']
|
||||
|
||||
end
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
post "#{api_prefix}/ondemandvm/?" do
|
||||
content_type :json
|
||||
metrics.increment('http_requests_vm_total.post.ondemand.requestid')
|
||||
|
||||
need_token! if Vmpooler::API.settings.config[:auth]
|
||||
|
||||
result = { 'ok' => false }
|
||||
|
||||
begin
|
||||
payload = JSON.parse(request.body.read)
|
||||
|
||||
if payload
|
||||
invalid = invalid_templates(payload.reject { |k, _v| k == 'request_id' })
|
||||
if invalid.empty?
|
||||
result = generate_ondemand_request(payload)
|
||||
else
|
||||
result[:bad_templates] = invalid
|
||||
invalid.each do |bad_template|
|
||||
metrics.increment("ondemandrequest_fail.invalid.#{bad_template}")
|
||||
end
|
||||
status 404
|
||||
end
|
||||
else
|
||||
metrics.increment('ondemandrequest_fail.invalid.unknown')
|
||||
status 404
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
span = OpenTelemetry::Trace.current_span
|
||||
span.status = OpenTelemetry::Trace::Status.error('JSON payload could not be parsed')
|
||||
status 400
|
||||
result = {
|
||||
'ok' => false,
|
||||
'message' => 'JSON payload could not be parsed'
|
||||
}
|
||||
end
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
post "#{api_prefix}/ondemandvm/:template/?" do
|
||||
content_type :json
|
||||
result = { 'ok' => false }
|
||||
metrics.increment('http_requests_vm_total.delete.ondemand.template')
|
||||
|
||||
need_token! if Vmpooler::API.settings.config[:auth]
|
||||
|
||||
payload = extract_templates_from_query_params(params[:template])
|
||||
|
||||
if payload
|
||||
invalid = invalid_templates(payload.reject { |k, _v| k == 'request_id' })
|
||||
if invalid.empty?
|
||||
result = generate_ondemand_request(payload)
|
||||
else
|
||||
result[:bad_templates] = invalid
|
||||
invalid.each do |bad_template|
|
||||
metrics.increment("ondemandrequest_fail.invalid.#{bad_template}")
|
||||
end
|
||||
status 404
|
||||
end
|
||||
else
|
||||
metrics.increment('ondemandrequest_fail.invalid.unknown')
|
||||
status 404
|
||||
end
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get "#{api_prefix}/ondemandvm/:requestid/?" do
|
||||
content_type :json
|
||||
metrics.increment('http_requests_vm_total.get.ondemand.request')
|
||||
|
||||
status 404
|
||||
result = check_ondemand_request(params[:requestid])
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
def check_ondemand_request(request_id)
|
||||
tracer.in_span("Vmpooler::API::V2.#{__method__}") do |span|
|
||||
span.set_attribute('vmpooler.request_id', request_id)
|
||||
result = { 'ok' => false }
|
||||
request_hash = backend.hgetall("vmpooler__odrequest__#{request_id}")
|
||||
if request_hash.empty?
|
||||
e_message = "no request found for request_id '#{request_id}'"
|
||||
result['message'] = e_message
|
||||
span.add_event('error', attributes: {
|
||||
'error.type' => 'Vmpooler::API::V2.check_ondemand_request',
|
||||
'error.message' => e_message
|
||||
})
|
||||
return result
|
||||
end
|
||||
|
||||
result['request_id'] = request_id
|
||||
result['ready'] = false
|
||||
result['ok'] = true
|
||||
status 202
|
||||
|
||||
case request_hash['status']
|
||||
when 'ready'
|
||||
result['ready'] = true
|
||||
Parsing.get_platform_pool_count(request_hash['requested']) do |platform_alias, pool, _count|
|
||||
instances = backend.smembers("vmpooler__#{request_id}__#{platform_alias}__#{pool}")
|
||||
domain = Parsing.get_domain_for_pool(full_config, pool)
|
||||
instances.map! { |instance| instance.concat(".#{domain}") } if domain
|
||||
|
||||
if result.key?(platform_alias)
|
||||
result[platform_alias][:hostname] = result[platform_alias][:hostname] + instances
|
||||
else
|
||||
result[platform_alias] = { 'hostname': instances }
|
||||
end
|
||||
end
|
||||
status 200
|
||||
when 'failed'
|
||||
result['message'] = "The request failed to provision instances within the configured ondemand_request_ttl '#{config['ondemand_request_ttl']}'"
|
||||
status 200
|
||||
when 'deleted'
|
||||
result['message'] = 'The request has been deleted'
|
||||
status 200
|
||||
else
|
||||
Parsing.get_platform_pool_count(request_hash['requested']) do |platform_alias, pool, count|
|
||||
instance_count = backend.scard("vmpooler__#{request_id}__#{platform_alias}__#{pool}")
|
||||
instances_pending = count.to_i - instance_count.to_i
|
||||
|
||||
if result.key?(platform_alias) && result[platform_alias].key?(:ready)
|
||||
result[platform_alias][:ready] = (result[platform_alias][:ready].to_i + instance_count).to_s
|
||||
result[platform_alias][:pending] = (result[platform_alias][:pending].to_i + instances_pending).to_s
|
||||
else
|
||||
result[platform_alias] = {
|
||||
'ready': instance_count.to_s,
|
||||
'pending': instances_pending.to_s
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
# Endpoints that only use bits from the V1 api are called here
|
||||
# Note that traces will be named based on the route used in the V1 api
|
||||
# but the http.url trace attribute will still have the actual requested url in it
|
||||
|
||||
delete "#{api_prefix}/*" do
|
||||
versionless_path_info = request.path_info.delete_prefix("#{api_prefix}/")
|
||||
request.path_info = "/api/v1/#{versionless_path_info}"
|
||||
call env
|
||||
end
|
||||
|
||||
get "#{api_prefix}/*" do
|
||||
versionless_path_info = request.path_info.delete_prefix("#{api_prefix}/")
|
||||
request.path_info = "/api/v1/#{versionless_path_info}"
|
||||
call env
|
||||
end
|
||||
|
||||
post "#{api_prefix}/*" do
|
||||
versionless_path_info = request.path_info.delete_prefix("#{api_prefix}/")
|
||||
request.path_info = "/api/v1/#{versionless_path_info}"
|
||||
call env
|
||||
end
|
||||
|
||||
put "#{api_prefix}/*" do
|
||||
versionless_path_info = request.path_info.delete_prefix("#{api_prefix}/")
|
||||
request.path_info = "/api/v1/#{versionless_path_info}"
|
||||
call env
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,91 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'pathname'
|
||||
|
||||
module Vmpooler
|
||||
class Dns
|
||||
# Load one or more VMPooler DNS plugin gems by name
|
||||
#
|
||||
# @param names [Array<String>] The list of gem names to load
|
||||
def self.load_by_name(names)
|
||||
names = Array(names)
|
||||
instance = new
|
||||
names.map { |name| instance.load_from_gems(name) }.flatten
|
||||
end
|
||||
|
||||
# Returns the plugin class for the specified dns config by name
|
||||
#
|
||||
# @param config [Object] The entire VMPooler config object
|
||||
# @param name [Symbol] The name of the dns config key to get the dns class
|
||||
# @return [String] The plugin class for the specifid dns config
|
||||
def self.get_dns_plugin_class_by_name(config, name)
|
||||
dns_configs = config[:dns_configs].keys
|
||||
plugin_class = ''
|
||||
|
||||
dns_configs.map do |dns_config_name|
|
||||
plugin_class = config[:dns_configs][dns_config_name]['dns_class'] if dns_config_name.to_s == name
|
||||
end
|
||||
|
||||
plugin_class
|
||||
end
|
||||
|
||||
# Returns the domain for the specified pool
|
||||
#
|
||||
# @param config [String] - the full config structure
|
||||
# @param pool_name [String] - the name of the pool
|
||||
# @return [String] - domain name for pool, which is set via reference to the dns_configs block
|
||||
def self.get_domain_for_pool(config, pool_name)
|
||||
pool = config[:pools].find { |p| p['name'] == pool_name }
|
||||
pool_dns_config = pool['dns_plugin']
|
||||
dns_configs = config[:dns_configs].keys
|
||||
dns_configs.map do |dns_config_name|
|
||||
return config[:dns_configs][dns_config_name]['domain'] if dns_config_name.to_s == pool_dns_config
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the plugin domain for the specified dns config by name
|
||||
#
|
||||
# @param config [Object] The entire VMPooler config object
|
||||
# @param name [Symbol] The name of the dns config key to get the dns domain
|
||||
# @return [String] The domain for the specifid dns config
|
||||
def self.get_dns_plugin_domain_by_name(config, name)
|
||||
dns_configs = config[:dns_configs].keys
|
||||
dns_configs.map do |dns_config_name|
|
||||
return config[:dns_configs][dns_config_name]['domain'] if dns_config_name.to_s == name
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a list of DNS plugin classes specified in the vmpooler configuration
|
||||
#
|
||||
# @param config [Object] The entire VMPooler config object
|
||||
# @return nil || [Array<String>] A list of DNS plugin classes
|
||||
def self.get_dns_plugin_config_classes(config)
|
||||
return nil unless config[:dns_configs]
|
||||
|
||||
dns_configs = config[:dns_configs].keys
|
||||
dns_plugins = dns_configs.map do |dns_config_name|
|
||||
if config[:dns_configs][dns_config_name] && config[:dns_configs][dns_config_name]['dns_class']
|
||||
config[:dns_configs][dns_config_name]['dns_class'].to_s
|
||||
else
|
||||
dns_config_name.to_s
|
||||
end
|
||||
end.compact.uniq
|
||||
|
||||
# dynamic-dns is not actually a class, it's just used as a value to denote
|
||||
# that dynamic dns is used so no loading or record management is needed
|
||||
dns_plugins.delete('dynamic-dns')
|
||||
|
||||
dns_plugins
|
||||
end
|
||||
|
||||
# Load a single DNS plugin gem by name
|
||||
#
|
||||
# @param name [String] The name of the DNS plugin gem to load
|
||||
# @return [String] The full require path to the specified gem
|
||||
def load_from_gems(name = nil)
|
||||
require_path = "vmpooler/dns/#{name.gsub('-', '/')}"
|
||||
require require_path
|
||||
require_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Vmpooler
|
||||
class PoolManager
|
||||
class Dns
|
||||
class Base
|
||||
# These defs must be overidden in child classes
|
||||
|
||||
# Helper Methods
|
||||
# Global Logger object
|
||||
attr_reader :logger
|
||||
# Global Metrics object
|
||||
attr_reader :metrics
|
||||
# Provider options passed in during initialization
|
||||
attr_reader :dns_options
|
||||
|
||||
def initialize(config, logger, metrics, redis_connection_pool, name, options)
|
||||
@config = config
|
||||
@logger = logger
|
||||
@metrics = metrics
|
||||
@redis = redis_connection_pool
|
||||
@dns_plugin_name = name
|
||||
|
||||
@dns_options = options
|
||||
|
||||
logger.log('s', "[!] Creating dns plugin '#{name}'")
|
||||
end
|
||||
|
||||
def pool_config(pool_name)
|
||||
# Get the configuration of a specific pool
|
||||
@config[:pools].each do |pool|
|
||||
return pool if pool['name'] == pool_name
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
# Returns this dns plugin's configuration
|
||||
#
|
||||
# @returns [Hashtable] This dns plugins's configuration from the config file. Returns nil if the dns plugin config does not exist
|
||||
def dns_config
|
||||
@config[:dns_configs].each do |dns|
|
||||
# Convert the symbol from the config into a string for comparison
|
||||
return (dns[1].nil? ? {} : dns[1]) if dns[0].to_s == @dns_plugin_name
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
def global_config
|
||||
# This entire VM Pooler config
|
||||
@config
|
||||
end
|
||||
|
||||
def name
|
||||
@dns_plugin_name
|
||||
end
|
||||
|
||||
def get_ip(vm_name)
|
||||
@redis.with_metrics do |redis|
|
||||
redis.hget("vmpooler__vm__#{vm_name}", 'ip')
|
||||
end
|
||||
end
|
||||
|
||||
# returns
|
||||
# Array[String] : Array of pool names this provider services
|
||||
def provided_pools
|
||||
@config[:pools].select { |pool| pool['dns_config'] == name }.map { |pool| pool['name'] }
|
||||
end
|
||||
|
||||
def create_or_replace_record(hostname)
|
||||
raise("#{self.class.name} does not implement create_or_replace_record #{hostname}")
|
||||
end
|
||||
|
||||
def delete_record(hostname)
|
||||
raise("#{self.class.name} does not implement delete_record for #{hostname}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -329,30 +329,6 @@ module Vmpooler
|
|||
buckets: REDIS_CONNECT_BUCKETS,
|
||||
docstring: 'vmpooler redis connection wait time',
|
||||
param_labels: %i[type provider]
|
||||
},
|
||||
vmpooler_health: {
|
||||
mtype: M_GAUGE,
|
||||
torun: %i[manager],
|
||||
docstring: 'vmpooler health check metrics',
|
||||
param_labels: %i[metric_path]
|
||||
},
|
||||
vmpooler_purge: {
|
||||
mtype: M_GAUGE,
|
||||
torun: %i[manager],
|
||||
docstring: 'vmpooler purge metrics',
|
||||
param_labels: %i[metric_path]
|
||||
},
|
||||
vmpooler_destroy: {
|
||||
mtype: M_GAUGE,
|
||||
torun: %i[manager],
|
||||
docstring: 'vmpooler destroy metrics',
|
||||
param_labels: %i[poolname]
|
||||
},
|
||||
vmpooler_clone: {
|
||||
mtype: M_GAUGE,
|
||||
torun: %i[manager],
|
||||
docstring: 'vmpooler clone metrics',
|
||||
param_labels: %i[poolname]
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -58,10 +58,6 @@ module Vmpooler
|
|||
nil
|
||||
end
|
||||
|
||||
def dns_config(dns_config_name)
|
||||
Vmpooler::Dns.get_dns_plugin_domain_by_name(@config, dns_config_name)
|
||||
end
|
||||
|
||||
# returns
|
||||
# [Hashtable] : The entire VMPooler configuration
|
||||
def global_config
|
||||
|
|
@ -261,10 +257,6 @@ module Vmpooler
|
|||
raise("#{self.class.name} does not implement purge_unconfigured_resources")
|
||||
end
|
||||
|
||||
def get_vm_ip_address(vm_name, pool_name)
|
||||
raise("#{self.class.name} does not implement get_vm_ip_address for vm #{vm_name} in pool #{pool_name}")
|
||||
end
|
||||
|
||||
# DEPRECATED if a provider does not implement the new method, it will hit this base class method
|
||||
# and return a deprecation message
|
||||
def purge_unconfigured_folders(_deprecated, _deprecated2, allowlist)
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ Date.prototype.yyyymmdd = function() {
|
|||
|
||||
var data_url = {
|
||||
'capacity': '/dashboard/stats/vmpooler/pool',
|
||||
'pools' : '/api/v3/vm',
|
||||
'pools' : '/api/v1/vm',
|
||||
'running' : '/dashboard/stats/vmpooler/running',
|
||||
'status' : '/api/v3/status',
|
||||
'summary' : '/api/v3/summary'
|
||||
'status' : '/api/v1/status',
|
||||
'summary' : '/api/v1/summary'
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,5 +12,25 @@ module Vmpooler
|
|||
yield platform_alias, pool, count
|
||||
end
|
||||
end
|
||||
|
||||
# @param config [String] - the full config structure
|
||||
# @param pool_name [String] - the name of the pool
|
||||
# @return [String] - domain name for pool, if set in the provider for the pool or in the config block
|
||||
def self.get_domain_for_pool(config, pool_name)
|
||||
pool = config[:pools].find { |p| p['name'] == pool_name }
|
||||
return nil unless pool
|
||||
|
||||
provider_name = pool.fetch('provider', 'vsphere') # see vmpooler.yaml.example where it states defaulting to vsphere
|
||||
|
||||
if config[:providers] && config[:providers][provider_name.to_sym] && config[:providers][provider_name.to_sym]['domain']
|
||||
domain = config[:providers][provider_name.to_sym]['domain']
|
||||
elsif config[:config] && config[:config]['domain']
|
||||
domain = config[:config]['domain']
|
||||
else
|
||||
domain = nil
|
||||
end
|
||||
|
||||
domain
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Vmpooler
|
||||
VERSION = '3.8.1'
|
||||
VERSION = '2.5.0'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
## [3.8.1](https://github.com/puppetlabs/vmpooler/tree/3.8.1) (2026-01-14)
|
||||
|
||||
[Full Changelog](https://github.com/puppetlabs/vmpooler/compare/3.7.0...3.8.1)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- \(P4DEVOPS-9434\) Add rate limiting and input validation security enhancements [\#690](https://github.com/puppetlabs/vmpooler/pull/690) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- \(P4DEVOPS-8570\) Add Phase 2 optimizations: status API caching and improved Redis pipelining [\#689](https://github.com/puppetlabs/vmpooler/pull/689) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- \(P4DEVOPS-8567\) Add DLQ, auto-purge, and health checks for Redis queues [\#688](https://github.com/puppetlabs/vmpooler/pull/688) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- Add retry logic for immediate clone failures [\#687](https://github.com/puppetlabs/vmpooler/pull/687) ([mahima-singh](https://github.com/mahima-singh))
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- \(P4DEVOPS-8567\) Prevent VM allocation for already-deleted request-ids [\#688](https://github.com/puppetlabs/vmpooler/pull/688) ([mahima-singh](https://github.com/mahima-singh))
|
||||
- Prevent re-queueing requests already marked as failed [\#687](https://github.com/puppetlabs/vmpooler/pull/687) ([mahima-singh](https://github.com/mahima-singh))
|
||||
11
release-prep
11
release-prep
|
|
@ -3,14 +3,13 @@
|
|||
# The container tag should closely match what is used in `docker/Dockerfile` in vmpooler-deployment
|
||||
#
|
||||
# Update Gemfile.lock
|
||||
docker run -t --rm \
|
||||
docker run -it --rm \
|
||||
-v $(pwd):/app \
|
||||
jruby:9.4.12.1-jdk11 \
|
||||
jruby:9.4.1.0-jdk11 \
|
||||
/bin/bash -c 'apt-get update -qq && apt-get install -y --no-install-recommends git make netbase && cd /app && gem install bundler && bundle install --jobs 3; echo "LOCK_FILE_UPDATE_EXIT_CODE=$?"'
|
||||
|
||||
# Update Changelog
|
||||
docker run -t --rm -e CHANGELOG_GITHUB_TOKEN -v $(pwd):/usr/local/src/your-app \
|
||||
githubchangeloggenerator/github-changelog-generator:1.16.4 \
|
||||
github_changelog_generator --future-release $(grep VERSION lib/vmpooler/version.rb |rev |cut -d "'" -f2 |rev) \
|
||||
--token $CHANGELOG_GITHUB_TOKEN --release-branch main
|
||||
docker run -it --rm -e CHANGELOG_GITHUB_TOKEN -v $(pwd):/usr/local/src/your-app \
|
||||
githubchangeloggenerator/github-changelog-generator:1.16.2 \
|
||||
github_changelog_generator --future-release $(grep VERSION lib/vmpooler/version.rb |rev |cut -d "'" -f2 |rev)
|
||||
|
||||
|
|
|
|||
1
spec/fixtures/extra_config2.yaml
vendored
1
spec/fixtures/extra_config2.yaml
vendored
|
|
@ -8,5 +8,4 @@
|
|||
- name: 'pool05'
|
||||
size: 5
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
ready_ttl: 5
|
||||
8
spec/fixtures/vmpooler.yaml
vendored
8
spec/fixtures/vmpooler.yaml
vendored
|
|
@ -23,13 +23,9 @@
|
|||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
prefix: 'poolvm-'
|
||||
|
||||
:dns_configs:
|
||||
:example:
|
||||
dns_class: dynamic-dns
|
||||
domain: 'example.com'
|
||||
|
||||
# Uncomment the lines below to suppress metrics to STDOUT
|
||||
# :statsd:
|
||||
# server: 'localhost'
|
||||
|
|
@ -40,10 +36,8 @@
|
|||
- name: 'pool01'
|
||||
size: 5
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
ready_ttl: 5
|
||||
- name: 'pool02'
|
||||
size: 5
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
ready_ttl: 5
|
||||
|
|
|
|||
8
spec/fixtures/vmpooler2.yaml
vendored
8
spec/fixtures/vmpooler2.yaml
vendored
|
|
@ -23,13 +23,9 @@
|
|||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
prefix: 'poolvm-'
|
||||
|
||||
:dns_configs:
|
||||
:example:
|
||||
dns_class: dynamic-dns
|
||||
domain: 'example.com'
|
||||
|
||||
# Uncomment the lines below to suppress metrics to STDOUT
|
||||
# :statsd:
|
||||
# server: 'localhost'
|
||||
|
|
@ -40,10 +36,8 @@
|
|||
- name: 'pool03'
|
||||
size: 5
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
ready_ttl: 5
|
||||
- name: 'pool04'
|
||||
size: 5
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
ready_ttl: 5
|
||||
|
|
|
|||
45
spec/fixtures/vmpooler_domain.yaml
vendored
45
spec/fixtures/vmpooler_domain.yaml
vendored
|
|
@ -1,45 +0,0 @@
|
|||
---
|
||||
:providers:
|
||||
:dummy:
|
||||
|
||||
:redis:
|
||||
server: 'localhost'
|
||||
|
||||
:auth:
|
||||
provider: dummy
|
||||
|
||||
:tagfilter:
|
||||
url: '(.*)\/'
|
||||
|
||||
:config:
|
||||
site_name: 'vmpooler'
|
||||
# Need to change this on Windows
|
||||
logfile: '/var/log/vmpooler.log'
|
||||
task_limit: 10
|
||||
timeout: 15
|
||||
vm_checktime: 1
|
||||
vm_lifetime: 12
|
||||
vm_lifetime_auth: 24
|
||||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
prefix: 'poolvm-'
|
||||
|
||||
# Uncomment the lines below to suppress metrics to STDOUT
|
||||
# :statsd:
|
||||
# server: 'localhost'
|
||||
# prefix: 'vmpooler'
|
||||
# port: 8125
|
||||
|
||||
:pools:
|
||||
- name: 'pool01'
|
||||
size: 5
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
ready_ttl: 5
|
||||
- name: 'pool02'
|
||||
size: 5
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
ready_ttl: 5
|
||||
|
|
@ -14,16 +14,6 @@ class MockLogger
|
|||
end
|
||||
end
|
||||
|
||||
class MockPoolManagerDnsBase
|
||||
def delete_record(hostname)
|
||||
|
||||
end
|
||||
|
||||
def create_or_replace_record(hostname)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def expect_json(ok = true, http = 200)
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -37,7 +37,7 @@ describe Vmpooler::API::V3 do
|
|||
}
|
||||
|
||||
describe '/config/pooltemplate' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
|
@ -388,7 +388,7 @@ describe Vmpooler::API::V3 do
|
|||
end
|
||||
|
||||
describe 'GET /config' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
|
||||
it 'returns pool configuration when set' do
|
||||
get "#{prefix}/config"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -15,7 +15,7 @@ describe Vmpooler::API::V3 do
|
|||
end
|
||||
|
||||
describe '/ondemandvm' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
|
|
@ -28,25 +28,16 @@ describe Vmpooler::API::V3 do
|
|||
'compute2' => 0
|
||||
}
|
||||
},
|
||||
dns_configs: {
|
||||
:mock => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'example.com'
|
||||
}
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 0, 'clone_target' => 'compute1', 'dns_plugin' => 'mock'},
|
||||
{'name' => 'pool2', 'size' => 0, 'clone_target' => 'compute2', 'dns_plugin' => 'mock'},
|
||||
{'name' => 'pool3', 'size' => 0, 'clone_target' => 'compute1', 'dns_plugin' => 'mock'}
|
||||
{'name' => 'pool1', 'size' => 0, 'clone_target' => 'compute1'},
|
||||
{'name' => 'pool2', 'size' => 0, 'clone_target' => 'compute2'},
|
||||
{'name' => 'pool3', 'size' => 0, 'clone_target' => 'compute1'}
|
||||
],
|
||||
alias: {
|
||||
'poolone' => ['pool1'],
|
||||
'pool2' => ['pool1']
|
||||
},
|
||||
pool_names: [ 'pool1', 'pool2', 'pool3', 'poolone' ],
|
||||
providers: {
|
||||
:dummy => {},
|
||||
}
|
||||
pool_names: [ 'pool1', 'pool2', 'pool3', 'poolone' ]
|
||||
}
|
||||
}
|
||||
let(:current_time) { Time.now }
|
||||
|
|
@ -120,6 +111,24 @@ describe Vmpooler::API::V3 do
|
|||
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'pool2:pool1:1')
|
||||
post "#{prefix}/ondemandvm", '{"pool2":"1"}'
|
||||
end
|
||||
|
||||
context 'with domain set in the config' do
|
||||
let(:domain) { 'example.com' }
|
||||
before(:each) do
|
||||
config[:config]['domain'] = domain
|
||||
end
|
||||
|
||||
it 'should include domain in the return reply' do
|
||||
post "#{prefix}/ondemandvm", '{"poolone":"1"}'
|
||||
expect_json(true, 201)
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"domain": domain
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a resource request that exceeds the specified limit' do
|
||||
|
|
@ -253,12 +262,35 @@ describe Vmpooler::API::V3 do
|
|||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
"#{vmname}.example.com"
|
||||
vmname
|
||||
]
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with domain set' do
|
||||
let(:domain) { 'example.com' }
|
||||
before(:each) do
|
||||
config[:config]['domain'] = domain
|
||||
end
|
||||
|
||||
it 'should include the domain in the result' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
vmname
|
||||
]
|
||||
},
|
||||
"domain": domain
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a deleted request' do
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -30,7 +30,7 @@ describe Vmpooler::API::V3 do
|
|||
}
|
||||
|
||||
describe '/poolreset' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
|
@ -5,7 +5,7 @@ def has_set_tag?(vm, tag, value)
|
|||
value == redis.hget("vmpooler__vm__#{vm}", "tag:#{tag}")
|
||||
end
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -17,12 +17,10 @@ describe Vmpooler::API::V3 do
|
|||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
# Clear status cache to prevent test interference
|
||||
Vmpooler::API::V3.clear_status_cache
|
||||
end
|
||||
|
||||
describe 'status and metrics endpoints' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -16,7 +16,7 @@ describe Vmpooler::API::V3 do
|
|||
end
|
||||
|
||||
describe '/token' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:current_time) { Time.now }
|
||||
let(:config) { {
|
||||
config: {}
|
||||
|
|
@ -111,7 +111,7 @@ describe Vmpooler::API::V3 do
|
|||
end
|
||||
|
||||
describe '/token/:token' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
|
|
@ -5,7 +5,7 @@ def has_set_tag?(vm, tag, value)
|
|||
value == redis.hget("vmpooler__vm__#{vm}", "tag:#{tag}")
|
||||
end
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -20,7 +20,7 @@ describe Vmpooler::API::V3 do
|
|||
end
|
||||
|
||||
describe '/vm/:hostname' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:config) {
|
||||
435
spec/integration/api/v1/vm_spec.rb
Normal file
435
spec/integration/api/v1/vm_spec.rb
Normal file
|
|
@ -0,0 +1,435 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
# Added to ensure no leakage in rack state from previous tests.
|
||||
# Removes all routes, filters, middleware and extension hooks from the current class
|
||||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
end
|
||||
|
||||
describe '/vm' do
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10},
|
||||
{'name' => 'pool3', 'size' => 10}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => ['pool1'] },
|
||||
pool_names: [ 'pool1', 'pool2', 'pool3', 'poolone', 'genericpool' ]
|
||||
}
|
||||
}
|
||||
let(:current_time) { Time.now }
|
||||
let(:vmname) { 'abcdefghijkl' }
|
||||
let(:checkoutlock) { Mutex.new }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, metrics, nil)
|
||||
app.settings.set :config, auth: false
|
||||
app.settings.set :checkoutlock, checkoutlock
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'GET /vm/:hostname' do
|
||||
it 'returns correct information on a running vm' do
|
||||
create_running_vm 'pool1', vmname, redis
|
||||
expect(TCPSocket).to receive(:gethostbyname).and_raise(RuntimeError)
|
||||
get "#{prefix}/vm/#{vmname}"
|
||||
expect_json(ok = true, http = 200)
|
||||
response_body = (JSON.parse(last_response.body)[vmname])
|
||||
|
||||
expect(response_body["template"]).to eq("pool1")
|
||||
expect(response_body["lifetime"]).to eq(0)
|
||||
expect(response_body["running"]).to be >= 0
|
||||
expect(response_body["remaining"]).to be <= 0
|
||||
expect(response_body["start_time"]).to eq(current_time.to_datetime.rfc3339)
|
||||
expect(response_body["end_time"]).to eq(current_time.to_datetime.rfc3339)
|
||||
expect(response_body["state"]).to eq("running")
|
||||
expect(response_body["ip"]).to eq("")
|
||||
expect(response_body["host"]).to eq("host1")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /vm' do
|
||||
|
||||
let(:socket) { double('socket') }
|
||||
it 'returns a single VM' do
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: vmname
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"poolone":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
poolone: {
|
||||
hostname: vmname
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails on nonexistant pools' do
|
||||
post "#{prefix}/vm", '{"poolpoolpool":"1"}'
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'returns 503 for empty pool when aliases are not defined' do
|
||||
app.settings.config.delete(:alias)
|
||||
app.settings.config[:pool_names] = ['pool1', 'pool2']
|
||||
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
post "#{prefix}/vm/pool1"
|
||||
post "#{prefix}/vm/pool1"
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns 503 for empty pool referenced by alias' do
|
||||
create_ready_vm 'pool2', vmname, redis
|
||||
post "#{prefix}/vm/poolone"
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1","pool2":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: vmname
|
||||
},
|
||||
pool2: {
|
||||
hostname: 'qrstuvwxyz012345'
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'returns multiple VMs even when multiple instances from the same pool are requested' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"1"}'
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: [ '1abcdefghijklmnop', '2abcdefghijklmnop' ]
|
||||
},
|
||||
pool2: {
|
||||
hostname: 'qrstuvwxyz012345'
|
||||
}
|
||||
}
|
||||
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result['ok']).to eq(true)
|
||||
expect(result['pool1']['hostname']).to include('1abcdefghijklmnop', '2abcdefghijklmnop')
|
||||
expect(result['pool2']['hostname']).to eq('qrstuvwxyz012345')
|
||||
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'returns multiple VMs even when multiple instances from multiple pools are requested' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '1qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '2qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '3qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"3"}'
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: [ '1abcdefghijklmnop', '2abcdefghijklmnop' ]
|
||||
},
|
||||
pool2: {
|
||||
hostname: [ '1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345' ]
|
||||
}
|
||||
}
|
||||
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result['ok']).to eq(true)
|
||||
expect(result['pool1']['hostname']).to include('1abcdefghijklmnop', '2abcdefghijklmnop')
|
||||
expect(result['pool2']['hostname']).to include('1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345')
|
||||
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'returns VMs from multiple backend pools requested by an alias' do
|
||||
Vmpooler::API.settings.config[:alias]['genericpool'] = ['pool1', 'pool2', 'pool3']
|
||||
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool3', '1qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"genericpool":"3"}'
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
genericpool: {
|
||||
hostname: [ '1abcdefghijklmnop', '2abcdefghijklmnop', '1qrstuvwxyz012345' ]
|
||||
}
|
||||
}
|
||||
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result['ok']).to eq(true)
|
||||
expect(result['genericpool']['hostname']).to include('1abcdefghijklmnop', '2abcdefghijklmnop', '1qrstuvwxyz012345')
|
||||
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'returns the first VM that was moved to the ready state when checking out a VM' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '3abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
"pool1": {
|
||||
"hostname": "1abcdefghijklmnop"
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1","pool2":"1"}'
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1","pool2":"1"}'
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"1"}'
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"1"}'
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"3"}'
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"2","pool2":"3"}'
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', '1abcdefghijklmnop', redis)).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '2abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns the second VM when the first fails to respond' do
|
||||
create_ready_vm 'pool1', vmname, redis
|
||||
create_ready_vm 'pool1', "2#{vmname}", redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).with(vmname, nil).and_raise('mockerror')
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).with("2#{vmname}", nil).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: "2#{vmname}"
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', vmname, redis)).to be false
|
||||
end
|
||||
|
||||
context '(auth not configured)' do
|
||||
it 'does not extend VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: false
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}', {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
vm = fetch_vm('abcdefghijklmnop')
|
||||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
it 'extends VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: true
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}', {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
vm = fetch_vm('abcdefghijklmnop')
|
||||
expect(vm['lifetime'].to_i).to eq(2)
|
||||
end
|
||||
|
||||
it 'does not extend VM lifetime if auth token is not provided' do
|
||||
app.settings.set :config, auth: true
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
vm = fetch_vm('abcdefghijklmnop')
|
||||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
327
spec/integration/api/v1/vm_template_spec.rb
Normal file
327
spec/integration/api/v1/vm_template_spec.rb
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V1 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
# Added to ensure no leakage in rack state from previous tests.
|
||||
# Removes all routes, filters, middleware and extension hooks from the current class
|
||||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
end
|
||||
|
||||
describe '/vm/:template' do
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
},
|
||||
providers: { vsphere: {} },
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10},
|
||||
{'name' => 'poolone', 'size' => 0}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
pool_names: [ 'pool1', 'pool2', 'poolone' ]
|
||||
}
|
||||
}
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
let(:socket) { double('socket') }
|
||||
let(:checkoutlock) { Mutex.new }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, metrics, nil)
|
||||
app.settings.set :config, auth: false
|
||||
app.settings.set :checkoutlock, checkoutlock
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'POST /vm/:template' do
|
||||
it 'returns a single VM' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1", ''
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/poolone", ''
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
poolone: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails on nonexistant pools' do
|
||||
post "#{prefix}/vm/poolpoolpool", ''
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'returns 503 for empty pool when aliases are not defined' do
|
||||
app.settings.config.delete(:alias)
|
||||
app.settings.config[:pool_names] = ['pool1', 'pool2']
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
post "#{prefix}/vm/pool1"
|
||||
post "#{prefix}/vm/pool1"
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns 503 for empty pool referenced by alias' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
post "#{prefix}/vm/poolone"
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', 'qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1+pool2", ''
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
},
|
||||
pool2: {
|
||||
hostname: 'qrstuvwxyz012345'
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'returns multiple VMs even when multiple instances from multiple pools are requested' do
|
||||
create_ready_vm 'pool1', '1abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '2abcdefghijklmnop', redis
|
||||
|
||||
create_ready_vm 'pool2', '1qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '2qrstuvwxyz012345', redis
|
||||
create_ready_vm 'pool2', '3qrstuvwxyz012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1+pool1+pool2+pool2+pool2", ''
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: [ '1abcdefghijklmnop', '2abcdefghijklmnop' ]
|
||||
},
|
||||
pool2: {
|
||||
hostname: [ '1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345' ]
|
||||
}
|
||||
}
|
||||
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result['ok']).to eq(true)
|
||||
expect(result['pool1']['hostname']).to include('1abcdefghijklmnop', '2abcdefghijklmnop')
|
||||
expect(result['pool2']['hostname']).to include('1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345')
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
post "#{prefix}/vm/pool1+pool2", ''
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1+pool2", ''
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '0123456789012345', redis
|
||||
|
||||
post "#{prefix}/vm/pool1+pool1+pool2", ''
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from a pool' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool1', '0123456789012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1+pool1+pool2", ''
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop', redis)).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool1', '0123456789012345', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '0123456789012345', redis
|
||||
|
||||
post "#{prefix}/vm/pool1+pool1+pool2+pool2+pool2", ''
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
end
|
||||
|
||||
it 'returns any checked out vms to their pools when not all requested vms can be allocated, when requesting multiple instances from multiple pools' do
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
create_ready_vm 'pool2', '0123456789012345', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1+pool1+pool2+pool2+pool2", ''
|
||||
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
expect_json(ok = false, http = 503)
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', 'abcdefghijklmnop', redis)).to eq(true)
|
||||
expect(pool_has_ready_vm?('pool2', '0123456789012345', redis)).to eq(true)
|
||||
end
|
||||
|
||||
context '(auth not configured)' do
|
||||
it 'does not extend VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: false
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1", '', {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
vm = fetch_vm('abcdefghijklmnop')
|
||||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
it 'extends VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: true
|
||||
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1", '', {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
vm = fetch_vm('abcdefghijklmnop')
|
||||
expect(vm['lifetime'].to_i).to eq(2)
|
||||
end
|
||||
|
||||
it 'does not extend VM lifetime if auth token is not provided' do
|
||||
app.settings.set :config, auth: true
|
||||
create_ready_vm 'pool1', 'abcdefghijklmnop', redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm/pool1", ''
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
vm = fetch_vm('abcdefghijklmnop')
|
||||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
402
spec/integration/api/v2/config_spec.rb
Normal file
402
spec/integration/api/v2/config_spec.rb
Normal file
|
|
@ -0,0 +1,402 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
# Added to ensure no leakage in rack state from previous tests.
|
||||
# Removes all routes, filters, middleware and extension hooks from the current class
|
||||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
end
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
'experimental_features' => true
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1', 'clone_target' => 'default_cluster'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
pools_at_startup: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1', 'clone_target' => 'default_cluster'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
pool_names: [ 'pool1', 'pool2', 'poolone' ]
|
||||
}
|
||||
}
|
||||
|
||||
describe '/config/pooltemplate' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, metrics, nil)
|
||||
app.settings.set :config, auth: false
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'DELETE /config/pooltemplate/:pool' do
|
||||
it 'resets a pool template' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"templates/new_template"}'
|
||||
delete "#{prefix}/config/pooltemplate/pool1"
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
template_before_reset: 'templates/new_template',
|
||||
template_before_overrides: 'templates/pool1'
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds when the pool has not been overridden' do
|
||||
delete "#{prefix}/config/pooltemplate/pool1"
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'fails on nonexistent pools' do
|
||||
delete "#{prefix}/config/pooltemplate/poolpoolpool"
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
delete "#{prefix}/config/pooltemplate/pool1"
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'POST /config/pooltemplate' do
|
||||
it 'updates a pool template' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"templates/new_template"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails on nonexistent pools' do
|
||||
post "#{prefix}/config/pooltemplate", '{"poolpoolpool":"templates/newtemplate"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
end
|
||||
|
||||
it 'updates multiple pools' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"templates/new_template","pool2":"templates/new_template2"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when not all pools exist' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"templates/new_template","pool3":"templates/new_template2"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_templates: ['pool3']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'returns no changes when the template does not change' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"templates/pool1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a invalid template parameter is provided' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"template1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_templates: ['pool1']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a template starts with /' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"/template1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_templates: ['pool1']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a template ends with /' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"template1/"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_templates: ['pool1']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
post "#{prefix}/config/pooltemplate", '{"pool1":"template/template1"}'
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'DELETE /config/poolsize' do
|
||||
it 'resets a pool size' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"2"}'
|
||||
delete "#{prefix}/config/poolsize/pool1"
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool_size_before_reset: 2,
|
||||
pool_size_before_overrides: 5
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a specified pool does not exist' do
|
||||
delete "#{prefix}/config/poolsize/pool10"
|
||||
expect_json(ok = false, http = 404)
|
||||
expected = { ok: false }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds when a pool has not been overridden' do
|
||||
delete "#{prefix}/config/poolsize/pool1"
|
||||
expect_json(ok = true, http = 200)
|
||||
expected = {
|
||||
ok: true,
|
||||
pool_size_before_reset: 5,
|
||||
pool_size_before_overrides: 5
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
delete "#{prefix}/config/poolsize/pool1"
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /config/poolsize' do
|
||||
it 'changes a pool size' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"2"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'changes a pool size for multiple pools' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"2","pool2":"2"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a specified pool does not exist' do
|
||||
post "#{prefix}/config/poolsize", '{"pool10":"2"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
expected = {
|
||||
ok: false,
|
||||
not_configured: ['pool10']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds with 200 when no change is required' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"5"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds with 201 when at least one pool changes' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"5","pool2":"5"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a non-integer value is provided for size' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"four"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
not_configured: ['pool1']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a negative value is provided for size' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"-1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
not_configured: ['pool1']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
post "#{prefix}/config/poolsize", '{"pool1":"1"}'
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /config/clonetarget' do
|
||||
it 'changes the clone target' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"cluster1"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'changes a pool size for multiple pools' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"cluster1","pool2":"cluster2"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when a specified pool does not exist' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool10":"cluster1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_templates: ['pool10']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds with 200 when no change is required' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"default_cluster"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'succeeds with 201 when at least one pool changes' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"default_cluster","pool2":"cluster2"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
post "#{prefix}/config/clonetarget", '{"pool1":"cluster1"}'
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /config' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
|
||||
it 'returns pool configuration when set' do
|
||||
get "#{prefix}/config"
|
||||
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result['pool_configuration']).to eq(config[:pools])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
412
spec/integration/api/v2/ondemandvm_spec.rb
Normal file
412
spec/integration/api/v2/ondemandvm_spec.rb
Normal file
|
|
@ -0,0 +1,412 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
# Added to ensure no leakage in rack state from previous tests.
|
||||
# Removes all routes, filters, middleware and extension hooks from the current class
|
||||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
end
|
||||
|
||||
describe '/ondemandvm' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
'max_ondemand_instances_per_request' => 50,
|
||||
'backend_weight' => {
|
||||
'compute1' => 5,
|
||||
'compute2' => 0
|
||||
}
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 0, 'clone_target' => 'compute1'},
|
||||
{'name' => 'pool2', 'size' => 0, 'clone_target' => 'compute2'},
|
||||
{'name' => 'pool3', 'size' => 0, 'clone_target' => 'compute1'}
|
||||
],
|
||||
alias: {
|
||||
'poolone' => ['pool1'],
|
||||
'pool2' => ['pool1']
|
||||
},
|
||||
pool_names: [ 'pool1', 'pool2', 'pool3', 'poolone' ],
|
||||
providers: {
|
||||
:dummy => {
|
||||
'domain' => 'dummy.com'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:current_time) { Time.now }
|
||||
let(:vmname) { 'abcdefghijkl' }
|
||||
let(:checkoutlock) { Mutex.new }
|
||||
let(:uuid) { SecureRandom.uuid }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, metrics, nil)
|
||||
app.settings.set :config, auth: false
|
||||
app.settings.set :checkoutlock, checkoutlock
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
config[:pools].each do |pool|
|
||||
redis.sadd('vmpooler__pools', pool['name'])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /ondemandvm' do
|
||||
|
||||
context 'with a configured pool' do
|
||||
|
||||
context 'with no request_id provided in payload' do
|
||||
before(:each) do
|
||||
expect(SecureRandom).to receive(:uuid).and_return(uuid)
|
||||
end
|
||||
|
||||
it 'generates a request_id when none is provided' do
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"1"}'
|
||||
expect_json(true, 201)
|
||||
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'uses a configured platform to fulfill a ondemand request' do
|
||||
post "#{prefix}/ondemandvm", '{"poolone":"1"}'
|
||||
expect_json(true, 201)
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'creates a provisioning request in redis' do
|
||||
expect(redis).to receive(:zadd).with('vmpooler__provisioning__request', Integer, uuid).and_return(1)
|
||||
post "#{prefix}/ondemandvm", '{"poolone":"1"}'
|
||||
end
|
||||
|
||||
it 'sets a platform string in redis for the request to indicate selected platforms' do
|
||||
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'poolone:pool1:1')
|
||||
post "#{prefix}/ondemandvm", '{"poolone":"1"}'
|
||||
end
|
||||
|
||||
context 'with a backend of 0 weight' do
|
||||
before(:each) do
|
||||
config[:config]['backend_weight']['compute1'] = 0
|
||||
end
|
||||
|
||||
it 'sets the platform string in redis for the request to indicate the selected platforms' do
|
||||
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'pool1:pool1:1')
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"1"}'
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets the platform string in redis for the request to indicate the selected platforms using weight' do
|
||||
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'requested', 'pool2:pool1:1')
|
||||
post "#{prefix}/ondemandvm", '{"pool2":"1"}'
|
||||
end
|
||||
|
||||
context 'with domain set in the config' do
|
||||
let(:domain) { 'example.com' }
|
||||
before(:each) do
|
||||
config[:config]['domain'] = domain
|
||||
end
|
||||
|
||||
it 'should include domain in the return reply' do
|
||||
post "#{prefix}/ondemandvm", '{"poolone":"1"}'
|
||||
expect_json(true, 201)
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a resource request that exceeds the specified limit' do
|
||||
let(:max_instances) { 50 }
|
||||
before(:each) do
|
||||
config[:config]['max_ondemand_instances_per_request'] = max_instances
|
||||
end
|
||||
|
||||
it 'should reject the request with a message' do
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"51"}'
|
||||
expect_json(false, 403)
|
||||
expected = {
|
||||
"ok": false,
|
||||
"message": "requested amount of instances exceeds the maximum #{max_instances}"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with request_id provided in the payload' do
|
||||
it 'uses the given request_id when provided' do
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"1","request_id":"1234"}'
|
||||
expect_json(true, 201)
|
||||
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": "1234"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'returns 409 conflict error when the request_id has been used' do
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"1","request_id":"1234"}'
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"1","request_id":"1234"}'
|
||||
expect_json(false, 409)
|
||||
|
||||
expected = {
|
||||
"ok": false,
|
||||
"request_id": "1234",
|
||||
"message": "request_id '1234' has already been created"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with auth configured' do
|
||||
|
||||
it 'sets the token and user' do
|
||||
app.settings.set :config, auth: true
|
||||
expect(SecureRandom).to receive(:uuid).and_return(uuid)
|
||||
allow(redis).to receive(:hset)
|
||||
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'token:token', 'abcdefghijklmnopqrstuvwxyz012345')
|
||||
expect(redis).to receive(:hset).with("vmpooler__odrequest__#{uuid}", 'token:user', 'jdoe')
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"1"}', {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a pool that is not configured' do
|
||||
let(:badpool) { 'pool4' }
|
||||
it 'returns the bad template' do
|
||||
post "#{prefix}/ondemandvm", '{"pool4":"1"}'
|
||||
expect_json(false, 404)
|
||||
|
||||
expected = {
|
||||
"ok": false,
|
||||
"bad_templates": [ badpool ]
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns 400 and a message when JSON is invalid' do
|
||||
post "#{prefix}/ondemandvm", '{"pool1":"1}'
|
||||
expect_json(false, 400)
|
||||
expected = {
|
||||
"ok": false,
|
||||
"message": "JSON payload could not be parsed"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /ondemandvm' do
|
||||
it 'returns 404 with message when request is not found' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expect_json(false, 404)
|
||||
expected = {
|
||||
"ok": false,
|
||||
"message": "no request found for request_id '#{uuid}'"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'when the request is found' do
|
||||
let(:score) { current_time }
|
||||
let(:platforms_string) { 'pool1:pool1:1' }
|
||||
before(:each) do
|
||||
create_ondemand_request_for_test(uuid, score, platforms_string, redis)
|
||||
end
|
||||
|
||||
it 'returns 202 while the request is waiting' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expect_json(true, 202)
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": false,
|
||||
"pool1": {
|
||||
"ready": "0",
|
||||
"pending": "1"
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with ready instances' do
|
||||
before(:each) do
|
||||
create_ondemand_vm(vmname, uuid, 'pool1', 'pool1', redis)
|
||||
set_ondemand_request_status(uuid, 'ready', redis)
|
||||
end
|
||||
|
||||
it 'returns 200 with hostnames when the request is ready' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expect_json(true, 200)
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
vmname
|
||||
]
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with domain set' do
|
||||
let(:domain) { 'example.com' }
|
||||
before(:each) do
|
||||
config[:config]['domain'] = domain
|
||||
end
|
||||
|
||||
it 'should include the domain in the hostname as fqdn, not a separate key unlike in v1' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
"#{vmname}.#{domain}"
|
||||
]
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with domain set in the provider' do
|
||||
let(:domain) { 'dummy.com' }
|
||||
before(:each) do
|
||||
config[:pools][0]['provider'] = 'dummy'
|
||||
end
|
||||
|
||||
it 'should include the domain in the hostname as fqdn, not a separate key unlike in v1' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": true,
|
||||
"pool1": {
|
||||
"hostname": [
|
||||
"#{vmname}.#{domain}"
|
||||
]
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a deleted request' do
|
||||
before(:each) do
|
||||
set_ondemand_request_status(uuid, 'deleted', redis)
|
||||
end
|
||||
|
||||
it 'returns a message that the request has been deleted' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expect_json(true, 200)
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": false,
|
||||
"message": "The request has been deleted"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a failed request' do
|
||||
let(:ondemand_request_ttl) { 5 }
|
||||
before(:each) do
|
||||
config[:config]['ondemand_request_ttl'] = ondemand_request_ttl
|
||||
set_ondemand_request_status(uuid, 'failed', redis)
|
||||
end
|
||||
|
||||
it 'returns a message that the request has failed' do
|
||||
get "#{prefix}/ondemandvm/#{uuid}"
|
||||
expect_json(true, 200)
|
||||
expected = {
|
||||
"ok": true,
|
||||
"request_id": uuid,
|
||||
"ready": false,
|
||||
"message": "The request failed to provision instances within the configured ondemand_request_ttl '#{ondemand_request_ttl}'"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /ondemandvm' do
|
||||
let(:expiration) { 129_600_0 }
|
||||
it 'returns 404 with message when request is not found' do
|
||||
delete "#{prefix}/ondemandvm/#{uuid}"
|
||||
expect_json(false, 404)
|
||||
expected = {
|
||||
"ok": false,
|
||||
"message": "no request found for request_id '#{uuid}'"
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'when the request is found' do
|
||||
let(:platforms_string) { 'pool1:pool1:1' }
|
||||
let(:score) { current_time.to_i }
|
||||
before(:each) do
|
||||
create_ondemand_request_for_test(uuid, score, platforms_string, redis)
|
||||
end
|
||||
|
||||
it 'returns 200 for a deleted request' do
|
||||
delete "#{prefix}/ondemandvm/#{uuid}"
|
||||
expect_json(true, 200)
|
||||
expected = { 'ok': true }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'marks the request hash for expiration in two weeks' do
|
||||
expect(redis).to receive(:expire).with("vmpooler__odrequest__#{uuid}", expiration)
|
||||
delete "#{prefix}/ondemandvm/#{uuid}"
|
||||
end
|
||||
|
||||
context 'with running instances' do
|
||||
let(:pool) { 'pool1' }
|
||||
let(:pool_alias) { pool }
|
||||
before(:each) do
|
||||
create_ondemand_vm(vmname, uuid, pool, pool_alias, redis)
|
||||
end
|
||||
|
||||
it 'moves allocated instances to the completed queue' do
|
||||
expect(redis).to receive(:smove).with("vmpooler__running__#{pool}", "vmpooler__completed__#{pool}", vmname)
|
||||
delete "#{prefix}/ondemandvm/#{uuid}"
|
||||
end
|
||||
|
||||
it 'deletes the set tracking instances allocated for the request' do
|
||||
expect(redis).to receive(:del).with("vmpooler__#{uuid}__#{pool_alias}__#{pool}")
|
||||
delete "#{prefix}/ondemandvm/#{uuid}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
120
spec/integration/api/v2/poolreset.rb
Normal file
120
spec/integration/api/v2/poolreset.rb
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
Vmpooler::API.reset!
|
||||
end
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
'experimental_features' => true
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'template' => 'templates/pool1', 'clone_target' => 'default_cluster'},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
pool_names: [ 'pool1', 'pool2', 'poolone' ]
|
||||
}
|
||||
}
|
||||
|
||||
describe '/poolreset' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, metrics, nil)
|
||||
app.settings.set :config, auth: false
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'POST /poolreset' do
|
||||
it 'refreshes ready and pending instances from a pool' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails on nonexistent pools' do
|
||||
post "#{prefix}/poolreset", '{"poolpoolpool":"1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
end
|
||||
|
||||
it 'resets multiple pools' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1","pool2":"1"}'
|
||||
expect_json(ok = true, http = 201)
|
||||
|
||||
expected = { ok: true }
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'fails when not all pools exist' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1","pool3":"1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = {
|
||||
ok: false,
|
||||
bad_pools: ['pool3']
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
context 'with experimental features disabled' do
|
||||
before(:each) do
|
||||
config[:config]['experimental_features'] = false
|
||||
end
|
||||
|
||||
it 'should return 405' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1"}'
|
||||
expect_json(ok = false, http = 405)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
|
||||
it 'should return 400 for invalid json' do
|
||||
post "#{prefix}/poolreset", '{"pool1":"1}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'should return 400 with a bad pool name' do
|
||||
post "#{prefix}/poolreset", '{"pool11":"1"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
|
||||
it 'should return 404 when there is no payload' do
|
||||
post "#{prefix}/poolreset"
|
||||
expect_json(ok = false, http = 404)
|
||||
|
||||
expected = { ok: false }
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
247
spec/integration/api/v2/status_spec.rb
Normal file
247
spec/integration/api/v2/status_spec.rb
Normal file
|
|
@ -0,0 +1,247 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
def has_set_tag?(vm, tag, value)
|
||||
value == redis.hget("vmpooler__vm__#{vm}", "tag:#{tag}")
|
||||
end
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
# Added to ensure no leakage in rack state from previous tests.
|
||||
# Removes all routes, filters, middleware and extension hooks from the current class
|
||||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
end
|
||||
|
||||
describe 'status and metrics endpoints' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'alias' => ['poolone', 'poolun']},
|
||||
{'name' => 'pool2', 'size' => 10},
|
||||
{'name' => 'pool3', 'size' => 10, 'alias' => 'NotArray'}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, nil, nil)
|
||||
app.settings.set :config, auth: false
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'GET /status' do
|
||||
it 'returns the configured maximum size for each pool' do
|
||||
get "#{prefix}/status/"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"]["pool1"]["max"]).to be(5)
|
||||
expect(result["pools"]["pool2"]["max"]).to be(10)
|
||||
end
|
||||
|
||||
it 'returns the number of ready vms for each pool' do
|
||||
3.times {|i| create_ready_vm("pool1", "vm-#{i}", redis) }
|
||||
get "#{prefix}/status/"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"]["pool1"]["ready"]).to be(3)
|
||||
expect(result["pools"]["pool2"]["ready"]).to be(0)
|
||||
end
|
||||
|
||||
it 'returns the number of running vms for each pool' do
|
||||
3.times {|i| create_running_vm("pool1", "vm-#{i}", redis) }
|
||||
4.times {|i| create_running_vm("pool2", "vm-#{i}", redis) }
|
||||
|
||||
get "#{prefix}/status/"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"]["pool1"]["running"]).to be(3)
|
||||
expect(result["pools"]["pool2"]["running"]).to be(4)
|
||||
end
|
||||
|
||||
it 'returns the number of pending vms for each pool' do
|
||||
3.times {|i| create_pending_vm("pool1", "vm-#{i}", redis) }
|
||||
4.times {|i| create_pending_vm("pool2", "vm-#{i}", redis) }
|
||||
|
||||
get "#{prefix}/status/"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"]["pool1"]["pending"]).to be(3)
|
||||
expect(result["pools"]["pool2"]["pending"]).to be(4)
|
||||
end
|
||||
|
||||
it 'returns aliases if configured in the pool' do
|
||||
get "#{prefix}/status/"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"]["pool1"]["alias"]).to eq(['poolone', 'poolun'])
|
||||
expect(result["pools"]["pool2"]["alias"]).to be(nil)
|
||||
expect(result["pools"]["pool3"]["alias"]).to eq('NotArray')
|
||||
end
|
||||
|
||||
it '(for v1 backwards compatibility) lists any empty pools in the status section' do
|
||||
get "#{prefix}/status/"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["status"]["empty"].sort).to eq(["pool1", "pool2", "pool3"])
|
||||
end
|
||||
end
|
||||
describe 'GET /status with view query parameter' do
|
||||
it 'returns capacity when specified' do
|
||||
get "#{prefix}/status?view=capacity"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["capacity"]).to_not be(nil)
|
||||
expect(result["queue"]).to be(nil)
|
||||
expect(result["clone"]).to be(nil)
|
||||
expect(result["boot"]).to be(nil)
|
||||
expect(result["pools"]).to be(nil)
|
||||
expect(result["status"]).to_not be(nil)
|
||||
end
|
||||
it 'returns pools and queue when specified' do
|
||||
get "#{prefix}/status?view=pools,queue"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["capacity"]).to be(nil)
|
||||
expect(result["queue"]).to_not be(nil)
|
||||
expect(result["clone"]).to be(nil)
|
||||
expect(result["boot"]).to be(nil)
|
||||
expect(result["pools"]).to_not be(nil)
|
||||
expect(result["status"]).to_not be(nil)
|
||||
end
|
||||
it 'does nothing with invalid view names' do
|
||||
get "#{prefix}/status?view=clone,boot,invalidThingToView"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["capacity"]).to be(nil)
|
||||
expect(result["queue"]).to be(nil)
|
||||
expect(result["clone"]).to_not be(nil)
|
||||
expect(result["boot"]).to_not be(nil)
|
||||
expect(result["pools"]).to be(nil)
|
||||
expect(result["status"]).to_not be(nil)
|
||||
end
|
||||
it 'returns everything when view is not specified' do
|
||||
get "#{prefix}/status"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["capacity"]).to_not be(nil)
|
||||
expect(result["queue"]).to_not be(nil)
|
||||
expect(result["clone"]).to_not be(nil)
|
||||
expect(result["boot"]).to_not be(nil)
|
||||
expect(result["pools"]).to_not be(nil)
|
||||
expect(result["status"]).to_not be(nil)
|
||||
end
|
||||
it 'returns everything when view is alone' do
|
||||
get "#{prefix}/status?view"
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["capacity"]).to_not be(nil)
|
||||
expect(result["queue"]).to_not be(nil)
|
||||
expect(result["clone"]).to_not be(nil)
|
||||
expect(result["boot"]).to_not be(nil)
|
||||
expect(result["pools"]).to_not be(nil)
|
||||
expect(result["status"]).to_not be(nil)
|
||||
end
|
||||
it 'returns status only when view is empty' do
|
||||
get "#{prefix}/status?view="
|
||||
|
||||
# of course /status doesn't conform to the weird standard everything else uses...
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["capacity"]).to be(nil)
|
||||
expect(result["queue"]).to be(nil)
|
||||
expect(result["clone"]).to be(nil)
|
||||
expect(result["boot"]).to be(nil)
|
||||
expect(result["pools"]).to be(nil)
|
||||
expect(result["status"]).to_not be(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /poolstat' do
|
||||
it 'returns empty list when pool is not set' do
|
||||
get "#{prefix}/poolstat"
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result == {})
|
||||
end
|
||||
it 'returns empty list when pool is not found' do
|
||||
get "#{prefix}/poolstat?pool=unknownpool"
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result == {})
|
||||
end
|
||||
it 'returns one pool when requesting one with alias' do
|
||||
get "#{prefix}/poolstat?pool=pool1"
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"].size == 1)
|
||||
expect(result["pools"]["pool1"]["ready"]).to eq(0)
|
||||
expect(result["pools"]["pool1"]["max"]).to eq(5)
|
||||
expect(result["pools"]["pool1"]["alias"]).to eq(['poolone', 'poolun'])
|
||||
end
|
||||
it 'returns one pool when requesting one without alias' do
|
||||
get "#{prefix}/poolstat?pool=pool2"
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"].size == 1)
|
||||
expect(result["pools"]["pool2"]["ready"]).to eq(0)
|
||||
expect(result["pools"]["pool2"]["max"]).to eq(10)
|
||||
expect(result["pools"]["pool2"]["alias"]).to be(nil)
|
||||
end
|
||||
it 'returns multiple pools when requesting csv' do
|
||||
get "#{prefix}/poolstat?pool=pool1,pool2"
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["pools"].size == 2)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /totalrunning' do
|
||||
it 'returns the number of running VMs' do
|
||||
get "#{prefix}/totalrunning"
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
5.times {|i| create_running_vm("pool1", "vm-#{i}", redis, redis) }
|
||||
5.times {|i| create_running_vm("pool3", "vm-#{i}", redis, redis) }
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result["running"] == 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
210
spec/integration/api/v2/token_spec.rb
Normal file
210
spec/integration/api/v2/token_spec.rb
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
# Added to ensure no leakage in rack state from previous tests.
|
||||
# Removes all routes, filters, middleware and extension hooks from the current class
|
||||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
end
|
||||
|
||||
describe '/token' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:current_time) { Time.now }
|
||||
let(:config) { {
|
||||
config: {}
|
||||
} }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, nil, nil)
|
||||
end
|
||||
|
||||
describe 'GET /token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { {
|
||||
config: {},
|
||||
auth: false
|
||||
} }
|
||||
|
||||
it 'returns a 404' do
|
||||
get "#{prefix}/token"
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
let(:config) {
|
||||
{
|
||||
config: {},
|
||||
auth: {
|
||||
'provider' => 'dummy'
|
||||
}
|
||||
}
|
||||
}
|
||||
let(:username_str) { 'admin' }
|
||||
let(:password_str) { 's3cr3t' }
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
get "#{prefix}/token"
|
||||
expect_json(ok = false, http = 401)
|
||||
end
|
||||
|
||||
it 'returns a list of tokens if authed' do
|
||||
create_token "abc", "admin", current_time
|
||||
|
||||
authorize 'admin', 's3cr3t'
|
||||
get "#{prefix}/token"
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect(JSON.parse(last_response.body)['abc']['created']).to eq(current_time.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { {
|
||||
config: {},
|
||||
auth: false
|
||||
} }
|
||||
|
||||
it 'returns a 404' do
|
||||
post "#{prefix}/token"
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
let(:config) {
|
||||
{
|
||||
config: {},
|
||||
auth: {
|
||||
'provider' => 'dummy'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
post "#{prefix}/token"
|
||||
expect_json(ok = false, http = 401)
|
||||
end
|
||||
|
||||
it 'returns a newly created token if authed' do
|
||||
authorize 'admin', 's3cr3t'
|
||||
post "#{prefix}/token"
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
returned_token = JSON.parse(last_response.body)['token']
|
||||
expect(returned_token.length).to be(32)
|
||||
expect(get_token_data(returned_token)['user']).to eq("admin")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '/token/:token' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, nil, nil)
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
end
|
||||
|
||||
def create_vm_for_token(token, pool, vm)
|
||||
redis.sadd("vmpooler__running__#{pool}", vm)
|
||||
redis.hset("vmpooler__vm__#{vm}", "token:token", token)
|
||||
end
|
||||
|
||||
describe 'GET /token/:token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { {
|
||||
config: {},
|
||||
auth: false
|
||||
} }
|
||||
|
||||
it 'returns a 404' do
|
||||
get "#{prefix}/token/this"
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
let(:config) { {
|
||||
config: {},
|
||||
auth: true,
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5}
|
||||
]
|
||||
} }
|
||||
|
||||
it 'returns a token' do
|
||||
create_token "mytoken", "admin", current_time
|
||||
create_vm_for_token "mytoken", "pool1", "vmhostname"
|
||||
|
||||
get "#{prefix}/token/mytoken"
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect(JSON.parse(last_response.body)['ok']).to eq(true)
|
||||
expect(JSON.parse(last_response.body)['mytoken']['user']).to eq('admin')
|
||||
expect(JSON.parse(last_response.body)['mytoken']['vms']['running']).to include('vmhostname')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /token/:token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { {
|
||||
config: {},
|
||||
auth: false
|
||||
} }
|
||||
|
||||
it 'returns a 404' do
|
||||
delete "#{prefix}/token/this"
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
let(:config) {
|
||||
{
|
||||
config: {},
|
||||
auth: {
|
||||
'provider' => 'dummy'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
delete "#{prefix}/token/this"
|
||||
expect_json(ok = false, http = 401)
|
||||
end
|
||||
|
||||
it 'deletes a token if authed' do
|
||||
create_token("mytoken", "admin", current_time)
|
||||
authorize 'admin', 's3cr3t'
|
||||
|
||||
delete "#{prefix}/token/mytoken"
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
it 'fails if token does not exist' do
|
||||
authorize 'admin', 's3cr3t'
|
||||
|
||||
delete "#{prefix}/token/missingtoken"
|
||||
expect_json(ok = false, http = 401) # TODO: should this be 404?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
352
spec/integration/api/v2/vm_hostname_spec.rb
Normal file
352
spec/integration/api/v2/vm_hostname_spec.rb
Normal file
|
|
@ -0,0 +1,352 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
def has_set_tag?(vm, tag, value)
|
||||
value == redis.hget("vmpooler__vm__#{vm}", "tag:#{tag}")
|
||||
end
|
||||
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
Vmpooler::API
|
||||
end
|
||||
|
||||
# Added to ensure no leakage in rack state from previous tests.
|
||||
# Removes all routes, filters, middleware and extension hooks from the current class
|
||||
# https://rubydoc.info/gems/sinatra/Sinatra/Base#reset!-class_method
|
||||
before(:each) do
|
||||
app.reset!
|
||||
end
|
||||
|
||||
describe '/vm/:hostname' do
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
|
||||
let(:config) {
|
||||
{
|
||||
config: {
|
||||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
auth: false
|
||||
}
|
||||
}
|
||||
|
||||
let(:current_time) { Time.now }
|
||||
|
||||
before(:each) do
|
||||
expect(app).to receive(:run!).once
|
||||
app.execute([:api], config, redis, metrics, nil)
|
||||
create_token('abcdefghijklmnopqrstuvwxyz012345', 'jdoe', current_time)
|
||||
end
|
||||
|
||||
describe 'PUT /vm/:hostname' do
|
||||
it 'allows tags to be set' do
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"tested_by":"rspec"}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect has_set_tag?('testhost', 'tested_by', 'rspec')
|
||||
end
|
||||
|
||||
it 'skips empty tags' do
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"tested_by":""}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect !has_set_tag?('testhost', 'tested_by', '')
|
||||
end
|
||||
|
||||
it 'does not set tags if request body format is invalid' do
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"tested"}}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expect !has_set_tag?('testhost', 'tested', '')
|
||||
end
|
||||
|
||||
context '(allowed_tags configured)' do
|
||||
it 'fails if specified tag is not in allowed_tags array' do
|
||||
app.settings.set :config,
|
||||
{ :config => { 'allowed_tags' => ['created_by', 'project', 'url'] } }
|
||||
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"created_by":"rspec","tested_by":"rspec"}}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
expect !has_set_tag?('testhost', 'tested_by', 'rspec')
|
||||
end
|
||||
end
|
||||
|
||||
context '(tagfilter configured)' do
|
||||
before(:each) do
|
||||
app.settings.set :config, tagfilter: { 'url' => '(.*)\/' }
|
||||
end
|
||||
|
||||
it 'correctly filters tags' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"url":"foo.com/something.html"}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect has_set_tag?('testhost', 'url', 'foo.com')
|
||||
end
|
||||
|
||||
it "doesn't eat tags not matching filter" do
|
||||
create_vm('testhost', redis)
|
||||
put "#{prefix}/vm/testhost", '{"tags":{"url":"foo.com"}}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect has_set_tag?('testhost', 'url', 'foo.com')
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth not configured)' do
|
||||
before(:each) do
|
||||
app.settings.set :config, auth: false
|
||||
end
|
||||
|
||||
it 'allows VM lifetime to be modified without a token' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
vm = fetch_vm('testhost')
|
||||
expect(vm['lifetime'].to_i).to eq(1)
|
||||
end
|
||||
|
||||
it 'does not allow a lifetime to be 0' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"0"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
vm = fetch_vm('testhost')
|
||||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
|
||||
it 'does not enforce a lifetime' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"20000"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
vm = fetch_vm('testhost')
|
||||
expect(vm['lifetime']).to eq("20000")
|
||||
end
|
||||
|
||||
it 'does not allow a lifetime to be initially past config max_lifetime_upper_limit' do
|
||||
app.settings.set :config,
|
||||
{ :config => { 'max_lifetime_upper_limit' => 168 } }
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"200"}'
|
||||
expect_json(ok = false, http = 400)
|
||||
|
||||
vm = fetch_vm('testhost')
|
||||
expect(vm['lifetime']).to be_nil
|
||||
end
|
||||
|
||||
# it 'does not allow a lifetime to be extended past config 168' do
|
||||
# app.settings.set :config,
|
||||
# { :config => { 'max_lifetime_upper_limit' => 168 } }
|
||||
# create_vm('testhost', redis)
|
||||
#
|
||||
# set_vm_data('testhost', "checkout", (Time.now - (69*60*60)), redis)
|
||||
# puts redis.hget("vmpooler__vm__testhost", 'checkout')
|
||||
# put "#{prefix}/vm/testhost", '{"lifetime":"100"}'
|
||||
# expect_json(ok = false, http = 400)
|
||||
#
|
||||
# vm = fetch_vm('testhost')
|
||||
# expect(vm['lifetime']).to be_nil
|
||||
# end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
before(:each) do
|
||||
app.settings.set :config, auth: true
|
||||
end
|
||||
|
||||
it 'allows VM lifetime to be modified with a token' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"1"}', {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
vm = fetch_vm('testhost')
|
||||
expect(vm['lifetime'].to_i).to eq(1)
|
||||
end
|
||||
|
||||
it 'does not allows VM lifetime to be modified without a token' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
put "#{prefix}/vm/testhost", '{"lifetime":"1"}'
|
||||
expect_json(ok = false, http = 401)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /vm/:hostname' do
|
||||
context '(auth not configured)' do
|
||||
it 'does not delete a non-existant VM' do
|
||||
delete "#{prefix}/vm/testhost"
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'deletes an existing VM' do
|
||||
create_running_vm('pool1', 'testhost', redis)
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost"
|
||||
expect_json(ok = true, http = 200)
|
||||
expect !fetch_vm('testhost')
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
before(:each) do
|
||||
app.settings.set :config, auth: true
|
||||
end
|
||||
|
||||
context '(checked-out without token)' do
|
||||
it 'deletes a VM without supplying a token' do
|
||||
create_running_vm('pool1', 'testhost', redis)
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost"
|
||||
expect_json(ok = true, http = 200)
|
||||
expect !fetch_vm('testhost')
|
||||
end
|
||||
end
|
||||
|
||||
context '(checked-out with token)' do
|
||||
it 'fails to delete a VM without supplying a token' do
|
||||
create_running_vm('pool1', 'testhost', redis, 'abcdefghijklmnopqrstuvwxyz012345')
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost"
|
||||
expect_json(ok = false, http = 401)
|
||||
expect fetch_vm('testhost')
|
||||
end
|
||||
|
||||
it 'deletes a VM when token is supplied' do
|
||||
create_running_vm('pool1', 'testhost', redis, 'abcdefghijklmnopqrstuvwxyz012345')
|
||||
expect fetch_vm('testhost')
|
||||
|
||||
delete "#{prefix}/vm/testhost", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expect !fetch_vm('testhost')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /vm/:hostname/snapshot' do
|
||||
context '(auth not configured)' do
|
||||
it 'creates a snapshot' do
|
||||
create_vm('testhost', redis)
|
||||
post "#{prefix}/vm/testhost/snapshot"
|
||||
expect_json(ok = true, http = 202)
|
||||
expect(JSON.parse(last_response.body)['testhost']['snapshot'].length).to be(32)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
before(:each) do
|
||||
app.settings.set :config, auth: true
|
||||
end
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
post "#{prefix}/vm/testhost/snapshot"
|
||||
expect_json(ok = false, http = 401)
|
||||
expect !has_vm_snapshot?('testhost', redis)
|
||||
end
|
||||
|
||||
it 'creates a snapshot if authed' do
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 202)
|
||||
expect(JSON.parse(last_response.body)['testhost']['snapshot'].length).to be(32)
|
||||
expect has_vm_snapshot?('testhost', redis)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /vm/:hostname/snapshot/:snapshot' do
|
||||
context '(auth not configured)' do
|
||||
it 'reverts to a snapshot' do
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot"
|
||||
expect_json(ok = true, http = 202)
|
||||
expect vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
|
||||
it 'fails if the specified snapshot does not exist' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = false, http = 404)
|
||||
expect !vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
before(:each) do
|
||||
app.settings.set :config, auth: true
|
||||
end
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot"
|
||||
expect_json(ok = false, http = 401)
|
||||
expect !vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
|
||||
it 'fails if authed and the specified snapshot does not exist' do
|
||||
create_vm('testhost', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = false, http = 404)
|
||||
expect !vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
|
||||
it 'reverts to a snapshot if authed' do
|
||||
create_vm('testhost', redis)
|
||||
snapshot_vm('testhost', 'testsnapshot', redis)
|
||||
|
||||
post "#{prefix}/vm/testhost/snapshot/testsnapshot", "", {
|
||||
'HTTP_X_AUTH_TOKEN' => 'abcdefghijklmnopqrstuvwxyz012345'
|
||||
}
|
||||
expect_json(ok = true, http = 202)
|
||||
expect vm_reverted_to_snapshot?('testhost', redis, 'testsnapshot')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -16,7 +16,7 @@ describe Vmpooler::API::V3 do
|
|||
end
|
||||
|
||||
describe '/vm' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
|
|
@ -25,28 +25,14 @@ describe Vmpooler::API::V3 do
|
|||
'vm_lifetime_auth' => 2
|
||||
},
|
||||
providers: {
|
||||
vsphere: {},
|
||||
gce: {},
|
||||
foo: {}
|
||||
},
|
||||
dns_configs: {
|
||||
:one => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'one.example.com'
|
||||
},
|
||||
:two => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'two.example.com'
|
||||
},
|
||||
:three => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'three.example.com'
|
||||
}
|
||||
vsphere: {'domain' => 'one.example.com'},
|
||||
gce: {'domain' => 'two.example.com'},
|
||||
foo: {'domain' => 'three.example.com'}
|
||||
},
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'provider' => 'vsphere', 'dns_plugin' => 'one'},
|
||||
{'name' => 'pool2', 'size' => 10, 'provider' => 'gce', 'dns_plugin' => 'two'},
|
||||
{'name' => 'pool3', 'size' => 10, 'provider' => 'foo', 'dns_plugin' => 'three'}
|
||||
{'name' => 'pool1', 'size' => 5, 'provider' => 'vsphere'},
|
||||
{'name' => 'pool2', 'size' => 10, 'provider' => 'gce'},
|
||||
{'name' => 'pool3', 'size' => 10, 'provider' => 'foo'}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => ['pool1'] },
|
||||
|
|
@ -355,28 +341,6 @@ describe Vmpooler::API::V3 do
|
|||
expect(pool_has_ready_vm?('pool1', '2abcdefghijklmnop', redis)).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns the second VM when the first fails to respond' do
|
||||
create_running_vm 'pool1', vmname, redis
|
||||
create_ready_vm 'pool1', "2#{vmname}", redis
|
||||
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).with(vmname, nil).and_raise('mockerror')
|
||||
allow_any_instance_of(Vmpooler::API::Helpers).to receive(:open_socket).with("2#{vmname}", nil).and_return(socket)
|
||||
|
||||
post "#{prefix}/vm", '{"pool1":"1"}'
|
||||
expect_json(ok = true, http = 200)
|
||||
|
||||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: "2#{vmname}.one.example.com"
|
||||
}
|
||||
}
|
||||
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
||||
expect(pool_has_ready_vm?('pool1', vmname, redis)).to be false
|
||||
end
|
||||
|
||||
context '(auth not configured)' do
|
||||
it 'does not extend VM lifetime if auth token is provided' do
|
||||
app.settings.set :config, auth: false
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
describe Vmpooler::API::V3 do
|
||||
describe Vmpooler::API::V2 do
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app()
|
||||
|
|
@ -16,7 +16,7 @@ describe Vmpooler::API::V3 do
|
|||
end
|
||||
|
||||
describe '/vm/:template' do
|
||||
let(:prefix) { '/api/v3' }
|
||||
let(:prefix) { '/api/v2' }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) {
|
||||
{
|
||||
|
|
@ -24,17 +24,11 @@ describe Vmpooler::API::V3 do
|
|||
'site_name' => 'test pooler',
|
||||
'vm_lifetime_auth' => 2,
|
||||
},
|
||||
dns_configs: {
|
||||
:example => {
|
||||
'dns_class' => 'mock',
|
||||
'domain' => 'example.com'
|
||||
}
|
||||
},
|
||||
providers: { vsphere: {} },
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5, 'provider' => 'vsphere', 'dns_plugin' => 'example'},
|
||||
{'name' => 'pool2', 'size' => 10, 'provider' => 'vsphere', 'dns_plugin' => 'example'},
|
||||
{'name' => 'poolone', 'size' => 1, 'provider' => 'vsphere', 'dns_plugin' => 'example'}
|
||||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10},
|
||||
{'name' => 'poolone', 'size' => 1}
|
||||
],
|
||||
statsd: { 'prefix' => 'stats_prefix'},
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
|
|
@ -66,7 +60,7 @@ describe Vmpooler::API::V3 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +77,7 @@ describe Vmpooler::API::V3 do
|
|||
expected = {
|
||||
ok: true,
|
||||
poolone: {
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
|
@ -132,10 +126,10 @@ describe Vmpooler::API::V3 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
hostname: 'abcdefghijklmnop'
|
||||
},
|
||||
pool2: {
|
||||
hostname: 'qrstuvwxyz012345.example.com'
|
||||
hostname: 'qrstuvwxyz012345'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,17 +151,17 @@ describe Vmpooler::API::V3 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: [ '1abcdefghijklmnop.example.com', '2abcdefghijklmnop.example.com' ]
|
||||
hostname: [ '1abcdefghijklmnop', '2abcdefghijklmnop' ]
|
||||
},
|
||||
pool2: {
|
||||
hostname: [ '1qrstuvwxyz012345.example.com', '2qrstuvwxyz012345.example.com', '3qrstuvwxyz012345.example.com' ]
|
||||
hostname: [ '1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345' ]
|
||||
}
|
||||
}
|
||||
|
||||
result = JSON.parse(last_response.body)
|
||||
expect(result['ok']).to eq(true)
|
||||
expect(result['pool1']['hostname']).to include('1abcdefghijklmnop.example.com', '2abcdefghijklmnop.example.com')
|
||||
expect(result['pool2']['hostname']).to include('1qrstuvwxyz012345.example.com', '2qrstuvwxyz012345.example.com', '3qrstuvwxyz012345.example.com')
|
||||
expect(result['pool1']['hostname']).to include('1abcdefghijklmnop', '2abcdefghijklmnop')
|
||||
expect(result['pool2']['hostname']).to include('1qrstuvwxyz012345', '2qrstuvwxyz012345', '3qrstuvwxyz012345')
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
|
||||
|
|
@ -271,7 +265,7 @@ describe Vmpooler::API::V3 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -297,7 +291,7 @@ describe Vmpooler::API::V3 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect(last_response.body).to eq(JSON.pretty_generate(expected))
|
||||
|
|
@ -317,7 +311,7 @@ describe Vmpooler::API::V3 do
|
|||
expected = {
|
||||
ok: true,
|
||||
pool1: {
|
||||
hostname: 'abcdefghijklmnop.example.com'
|
||||
hostname: 'abcdefghijklmnop'
|
||||
}
|
||||
}
|
||||
expect_json(ok = true, http = 200)
|
||||
|
|
@ -16,12 +16,14 @@ describe Vmpooler::API::Helpers do
|
|||
|
||||
describe '#hostname_shorten' do
|
||||
[
|
||||
['example.com', 'example'],
|
||||
['sub.example.com', 'sub'],
|
||||
['adjective-noun.example.com', 'adjective-noun'],
|
||||
['abc123.example.com', 'abc123']
|
||||
].each do |hostname, expected|
|
||||
it { expect(subject.hostname_shorten(hostname)).to eq expected }
|
||||
['example.com', 'not-example.com', 'example'],
|
||||
['example.com', 'example.com', 'example'],
|
||||
['sub.example.com', 'example.com', 'sub'],
|
||||
['adjective-noun.example.com', 'example.com', 'adjective-noun'],
|
||||
['abc123.example.com', 'example.com', 'abc123'],
|
||||
['example.com', nil, 'example']
|
||||
].each do |hostname, domain, expected|
|
||||
it { expect(subject.hostname_shorten(hostname, domain)).to eq expected }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -116,7 +118,7 @@ describe Vmpooler::API::Helpers do
|
|||
allow(redis).to receive(:pipelined).with(no_args).and_return [0]
|
||||
allow(redis).to receive(:get).and_return 0
|
||||
|
||||
expect(subject.get_queue_metrics([], redis)).to eq({requested: 0, pending: 0, cloning: 0, booting: 0, ready: 0, running: 0, completed: 0, total: 0})
|
||||
expect(subject.get_queue_metrics([], redis)).to eq({pending: 0, cloning: 0, booting: 0, ready: 0, running: 0, completed: 0, total: 0})
|
||||
end
|
||||
|
||||
it 'adds pool queues correctly' do
|
||||
|
|
@ -125,14 +127,10 @@ describe Vmpooler::API::Helpers do
|
|||
{'name' => 'p2'}
|
||||
]
|
||||
|
||||
# Mock returns 7*2 + 2 = 16 results (7 queue types for 2 pools + 2 global counters)
|
||||
# For each pool: [request, processing, odcreate, pending, ready, running, completed]
|
||||
# Plus 2 global counters: clone (1), ondemandclone (0)
|
||||
# Results array: [1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1, 0]
|
||||
# [req, proc, odc, pend, rdy, run, comp, clone, odc]
|
||||
allow(redis).to receive(:pipelined).with(no_args).and_return [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0]
|
||||
allow(redis).to receive(:pipelined).with(no_args).and_return [1,1]
|
||||
allow(redis).to receive(:get).and_return(1,0)
|
||||
|
||||
expect(subject.get_queue_metrics(pools, redis)).to eq({requested: 6, pending: 2, cloning: 1, booting: 1, ready: 2, running: 2, completed: 2, total: 14})
|
||||
expect(subject.get_queue_metrics(pools, redis)).to eq({pending: 2, cloning: 1, booting: 1, ready: 2, running: 2, completed: 2, total: 8})
|
||||
end
|
||||
|
||||
it 'sets booting to 0 when negative calculation' do
|
||||
|
|
@ -141,10 +139,10 @@ describe Vmpooler::API::Helpers do
|
|||
{'name' => 'p2'}
|
||||
]
|
||||
|
||||
# Mock returns 7*2 + 2 = 16 results with clone=5 to cause negative booting
|
||||
allow(redis).to receive(:pipelined).with(no_args).and_return [1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,0]
|
||||
allow(redis).to receive(:pipelined).with(no_args).and_return [1,1]
|
||||
allow(redis).to receive(:get).and_return(5,0)
|
||||
|
||||
expect(subject.get_queue_metrics(pools, redis)).to eq({requested: 6, pending: 2, cloning: 5, booting: 0, ready: 2, running: 2, completed: 2, total: 14})
|
||||
expect(subject.get_queue_metrics(pools, redis)).to eq({pending: 2, cloning: 5, booting: 0, ready: 2, running: 2, completed: 2, total: 8})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -272,62 +270,22 @@ describe Vmpooler::API::Helpers do
|
|||
:tls_options => { :ssl_version => 'TLSv1' }
|
||||
}
|
||||
end
|
||||
it 'should attempt ldap authentication' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str)
|
||||
|
||||
context 'without a service account' do
|
||||
it 'should attempt ldap authentication' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str, nil)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should return true when authentication is successful' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str, nil).and_return(true)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be true
|
||||
end
|
||||
|
||||
it 'should return false when authentication fails' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str, nil).and_return(false)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be false
|
||||
end
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
context 'with a service account' do
|
||||
let(:service_account_hash) do
|
||||
{
|
||||
:user_dn => 'cn=Service Account,ou=users,dc=example,dc=com',
|
||||
:password => 's3cr3t'
|
||||
}
|
||||
end
|
||||
let(:auth) {
|
||||
{
|
||||
'provider' => 'ldap',
|
||||
ldap: {
|
||||
'host' => host,
|
||||
'base' => base,
|
||||
'user_object' => user_object,
|
||||
'service_account_hash' => service_account_hash
|
||||
}
|
||||
}
|
||||
}
|
||||
it 'should attempt ldap authentication' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str, service_account_hash)
|
||||
it 'should return true when authentication is successful' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str).and_return(true)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be true
|
||||
end
|
||||
|
||||
it 'should return true when authentication is successful' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str, service_account_hash).and_return(true)
|
||||
it 'should return false when authentication fails' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str).and_return(false)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be true
|
||||
end
|
||||
|
||||
it 'should return false when authentication fails' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base, username_str, password_str, service_account_hash).and_return(false)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be false
|
||||
end
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be false
|
||||
end
|
||||
|
||||
context 'with an alternate ssl_version' do
|
||||
|
|
@ -342,7 +300,7 @@ describe Vmpooler::API::Helpers do
|
|||
end
|
||||
|
||||
it 'should specify the alternate ssl_version when authenticating' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, secure_encryption, user_object, base, username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, secure_encryption, user_object, base, username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
|
@ -355,7 +313,7 @@ describe Vmpooler::API::Helpers do
|
|||
end
|
||||
|
||||
it 'should specify the alternate port when authenticating' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(alternate_port, host, default_encryption, user_object, base, username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(alternate_port, host, default_encryption, user_object, base, username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
|
@ -375,7 +333,7 @@ describe Vmpooler::API::Helpers do
|
|||
end
|
||||
|
||||
it 'should specify the secure port and encryption options when authenticating' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(secure_port, host, secure_encryption, user_object, base, username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(secure_port, host, secure_encryption, user_object, base, username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
|
@ -393,36 +351,36 @@ describe Vmpooler::API::Helpers do
|
|||
end
|
||||
|
||||
it 'should attempt to bind with each base' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should not search the second base when the first binds' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str, nil).and_return(true)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str).and_return(true)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should search the second base when the first bind fails' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should return true when any bind succeeds' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str, nil).and_return(true)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str).and_return(true)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be true
|
||||
end
|
||||
|
||||
it 'should return false when all bind attempts fail' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object, base[1], username_str, password_str).and_return(false)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be false
|
||||
end
|
||||
|
|
@ -440,36 +398,36 @@ describe Vmpooler::API::Helpers do
|
|||
end
|
||||
|
||||
it 'should attempt to bind with each user object' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should not search the second user object when the first binds' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str, nil).and_return(true)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str).and_return(true)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should search the second user object when the first bind fails' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should return true when any bind succeeds' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str, nil).and_return(true)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str).and_return(true)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be true
|
||||
end
|
||||
|
||||
it 'should return false when all bind attempts fail' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base, username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base, username_str, password_str).and_return(false)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be false
|
||||
end
|
||||
|
|
@ -494,64 +452,64 @@ describe Vmpooler::API::Helpers do
|
|||
end
|
||||
|
||||
it 'should attempt to bind with each user object and base' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should not continue searching when the first combination binds' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str, nil).and_return(true)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str, nil)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str, nil)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str).and_return(true)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str)
|
||||
expect(subject).to_not receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should search the remaining combinations when the first bind fails' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should search the remaining combinations when the first two binds fail' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should search the remaining combination when the first three binds fail' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str, nil)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str)
|
||||
|
||||
subject.authenticate(auth, username_str, password_str)
|
||||
end
|
||||
|
||||
it 'should return true when any bind succeeds' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str, nil).and_return(true)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str).and_return(true)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be true
|
||||
end
|
||||
|
||||
it 'should return false when all bind attempts fail' do
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str, nil).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[0], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[0], base[1], username_str, password_str).and_return(false)
|
||||
expect(subject).to receive(:authenticate_ldap).with(default_port, host, default_encryption, user_object[1], base[1], username_str, password_str).and_return(false)
|
||||
|
||||
expect(subject.authenticate(auth, username_str, password_str)).to be false
|
||||
end
|
||||
|
|
@ -585,12 +543,6 @@ describe Vmpooler::API::Helpers do
|
|||
:tls_options => { :ssl_version => 'TLSv1' }
|
||||
}
|
||||
end
|
||||
let(:service_account_hash) do
|
||||
{
|
||||
:user_dn => 'cn=Service Account,ou=users,dc=example,dc=com',
|
||||
:password => 's3cr3t'
|
||||
}
|
||||
end
|
||||
let(:ldap) { double('ldap') }
|
||||
it 'should create a new ldap connection' do
|
||||
allow(ldap).to receive(:bind)
|
||||
|
|
@ -622,20 +574,6 @@ describe Vmpooler::API::Helpers do
|
|||
|
||||
expect(subject.authenticate_ldap(port, host, encryption, user_object, base, username_str, password_str)).to be false
|
||||
end
|
||||
|
||||
it 'should return true when a bind_as is successful' do
|
||||
expect(Net::LDAP).to receive(:new).and_return(ldap)
|
||||
expect(ldap).to receive(:bind_as).and_return(true)
|
||||
|
||||
expect(subject.authenticate_ldap(port, host, encryption, user_object, base, username_str, password_str, service_account_hash)).to be true
|
||||
end
|
||||
|
||||
it 'should return false when a bind_as fails' do
|
||||
expect(Net::LDAP).to receive(:new).and_return(ldap)
|
||||
expect(ldap).to receive(:bind_as).and_return(false)
|
||||
|
||||
expect(subject.authenticate_ldap(port, host, encryption, user_object, base, username_str, password_str, service_account_hash)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,184 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
require 'vmpooler/api/input_validator'
|
||||
|
||||
describe Vmpooler::API::InputValidator do
|
||||
let(:test_class) do
|
||||
Class.new do
|
||||
include Vmpooler::API::InputValidator
|
||||
end
|
||||
end
|
||||
let(:validator) { test_class.new }
|
||||
|
||||
describe '#validate_hostname' do
|
||||
it 'accepts valid hostnames' do
|
||||
expect(validator.validate_hostname('test-host.example.com')).to be true
|
||||
expect(validator.validate_hostname('host123')).to be true
|
||||
end
|
||||
|
||||
it 'rejects invalid hostnames' do
|
||||
result = validator.validate_hostname('invalid_host!')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('Invalid hostname format')
|
||||
end
|
||||
|
||||
it 'rejects hostnames that are too long' do
|
||||
long_hostname = 'a' * 300
|
||||
result = validator.validate_hostname(long_hostname)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('too long')
|
||||
end
|
||||
|
||||
it 'rejects empty hostnames' do
|
||||
result = validator.validate_hostname('')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('required')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validate_pool_name' do
|
||||
it 'accepts valid pool names' do
|
||||
expect(validator.validate_pool_name('centos-7-x86_64')).to be true
|
||||
expect(validator.validate_pool_name('ubuntu-2204')).to be true
|
||||
end
|
||||
|
||||
it 'rejects invalid pool names' do
|
||||
result = validator.validate_pool_name('invalid pool!')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('Invalid pool name format')
|
||||
end
|
||||
|
||||
it 'rejects pool names that are too long' do
|
||||
result = validator.validate_pool_name('a' * 150)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('too long')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validate_tag' do
|
||||
it 'accepts valid tags' do
|
||||
expect(validator.validate_tag('project', 'test-123')).to be true
|
||||
expect(validator.validate_tag('owner', 'user@example.com')).to be true
|
||||
end
|
||||
|
||||
it 'rejects tags with invalid keys' do
|
||||
result = validator.validate_tag('invalid key!', 'value')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('Invalid tag key format')
|
||||
end
|
||||
|
||||
it 'rejects tags with invalid characters in value' do
|
||||
result = validator.validate_tag('key', 'value<script>')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('invalid characters')
|
||||
end
|
||||
|
||||
it 'rejects tags that are too long' do
|
||||
result = validator.validate_tag('key', 'a' * 300)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('too long')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validate_vm_count' do
|
||||
it 'accepts valid VM counts' do
|
||||
expect(validator.validate_vm_count(5)).to eq(5)
|
||||
expect(validator.validate_vm_count('10')).to eq(10)
|
||||
end
|
||||
|
||||
it 'rejects counts less than 1' do
|
||||
result = validator.validate_vm_count(0)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('at least 1')
|
||||
end
|
||||
|
||||
it 'rejects counts greater than 100' do
|
||||
result = validator.validate_vm_count(150)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('at most 100')
|
||||
end
|
||||
|
||||
it 'rejects non-integer values' do
|
||||
result = validator.validate_vm_count('abc')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('valid integer')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validate_disk_size' do
|
||||
it 'accepts valid disk sizes' do
|
||||
expect(validator.validate_disk_size(50)).to eq(50)
|
||||
expect(validator.validate_disk_size('100')).to eq(100)
|
||||
end
|
||||
|
||||
it 'rejects sizes less than 1' do
|
||||
result = validator.validate_disk_size(0)
|
||||
expect(result['ok']).to be false
|
||||
end
|
||||
|
||||
it 'rejects sizes greater than 2048' do
|
||||
result = validator.validate_disk_size(3000)
|
||||
expect(result['ok']).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validate_lifetime' do
|
||||
it 'accepts valid lifetimes' do
|
||||
expect(validator.validate_lifetime(24)).to eq(24)
|
||||
expect(validator.validate_lifetime('48')).to eq(48)
|
||||
end
|
||||
|
||||
it 'rejects lifetimes greater than 168 hours (1 week)' do
|
||||
result = validator.validate_lifetime(200)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('at most 168')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sanitize_json_body' do
|
||||
it 'parses valid JSON' do
|
||||
result = validator.sanitize_json_body('{"key": "value"}')
|
||||
expect(result).to eq('key' => 'value')
|
||||
end
|
||||
|
||||
it 'rejects invalid JSON' do
|
||||
result = validator.sanitize_json_body('{invalid}')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('Invalid JSON')
|
||||
end
|
||||
|
||||
it 'rejects non-object JSON' do
|
||||
result = validator.sanitize_json_body('["array"]')
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('must be a JSON object')
|
||||
end
|
||||
|
||||
it 'rejects deeply nested JSON' do
|
||||
deep_json = '{"a":{"b":{"c":{"d":{"e":{"f":"too deep"}}}}}}'
|
||||
result = validator.sanitize_json_body(deep_json)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('too complex')
|
||||
end
|
||||
|
||||
it 'rejects bodies that are too large' do
|
||||
large_json = '{"data":"' + ('a' * 20000) + '"}'
|
||||
result = validator.sanitize_json_body(large_json)
|
||||
expect(result['ok']).to be false
|
||||
expect(result['error']).to include('too large')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#validation_error?' do
|
||||
it 'returns true for error responses' do
|
||||
error = { 'ok' => false, 'error' => 'test error' }
|
||||
expect(validator.validation_error?(error)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for successful responses' do
|
||||
expect(validator.validation_error?(true)).to be false
|
||||
expect(validator.validation_error?(5)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'vmpooler/dns/base'
|
||||
|
||||
# This spec does not really exercise code paths but is merely used
|
||||
# to enforce that certain methods are defined in the base classes
|
||||
|
||||
describe 'Vmpooler::PoolManager::Dns::Base' do
|
||||
let(:logger) { MockLogger.new }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) { {} }
|
||||
let(:dns_plugin_name) { 'base' }
|
||||
let(:dns_options) { { 'param' => 'value' } }
|
||||
|
||||
let(:fake_vm) {
|
||||
fake_vm = {}
|
||||
fake_vm['name'] = 'vm1'
|
||||
fake_vm['hostname'] = 'vm1'
|
||||
fake_vm['template'] = 'pool1'
|
||||
fake_vm['boottime'] = Time.now
|
||||
fake_vm['powerstate'] = 'PoweredOn'
|
||||
|
||||
fake_vm
|
||||
}
|
||||
|
||||
let(:redis_connection_pool) { Vmpooler::PoolManager::GenericConnectionPool.new(
|
||||
metrics: metrics,
|
||||
connpool_type: 'redis_connection_pool',
|
||||
connpool_provider: 'testprovider',
|
||||
size: 1,
|
||||
timeout: 5
|
||||
) { MockRedis.new }
|
||||
}
|
||||
|
||||
subject { Vmpooler::PoolManager::Dns::Base.new(config, logger, metrics, redis_connection_pool, dns_plugin_name, dns_options) }
|
||||
|
||||
# Helper attr_reader methods
|
||||
describe '#logger' do
|
||||
it 'should come from the provider initialization' do
|
||||
expect(subject.logger).to be(logger)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#metrics' do
|
||||
it 'should come from the provider initialization' do
|
||||
expect(subject.metrics).to be(metrics)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dns_options' do
|
||||
it 'should come from the provider initialization' do
|
||||
expect(subject.dns_options).to be(dns_options)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#pool_config' do
|
||||
let(:poolname) { 'pool1' }
|
||||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
:pools:
|
||||
- name: '#{poolname}'
|
||||
alias: [ 'mockpool' ]
|
||||
template: 'Templates/pool1'
|
||||
folder: 'Pooler/pool1'
|
||||
datastore: 'datastore0'
|
||||
size: 5
|
||||
timeout: 10
|
||||
ready_ttl: 1440
|
||||
clone_target: 'cluster1'
|
||||
EOT
|
||||
)
|
||||
}
|
||||
context 'Given a pool that does not exist' do
|
||||
it 'should return nil' do
|
||||
expect(subject.pool_config('missing_pool')).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'Given a pool that does exist' do
|
||||
it 'should return the pool\'s configuration' do
|
||||
result = subject.pool_config(poolname)
|
||||
expect(result['name']).to eq(poolname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dns_config' do
|
||||
let(:poolname) { 'pool1' }
|
||||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
:dns_configs:
|
||||
:#{dns_plugin_name}:
|
||||
option1: 'value1'
|
||||
EOT
|
||||
)
|
||||
}
|
||||
|
||||
context 'Given a dns plugin with no configuration' do
|
||||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
:dns_configs:
|
||||
:bad_dns:
|
||||
option1: 'value1'
|
||||
option2: 'value1'
|
||||
EOT
|
||||
)
|
||||
}
|
||||
it 'should return nil' do
|
||||
expect(subject.dns_config).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'Given a correct dns config name' do
|
||||
it 'should return the dns\'s configuration' do
|
||||
result = subject.dns_config
|
||||
expect(result['option1']).to eq('value1')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#global_config' do
|
||||
it 'should come from the dns initialization' do
|
||||
expect(subject.global_config).to be(config)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#name' do
|
||||
it "should come from the dns initialization" do
|
||||
expect(subject.name).to eq(dns_plugin_name)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get_ip' do
|
||||
it 'calls redis hget with vm name and ip' do
|
||||
redis_connection_pool.with do |redis|
|
||||
expect(redis).to receive(:hget).with("vmpooler__vm__vm1", 'ip')
|
||||
end
|
||||
subject.get_ip(fake_vm['name'])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#provided_pools' do
|
||||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
:pools:
|
||||
- name: 'pool1'
|
||||
dns_config: 'base'
|
||||
- name: 'pool2'
|
||||
dns_config: 'base'
|
||||
- name: 'otherpool'
|
||||
dns_config: 'other provider'
|
||||
- name: 'no name'
|
||||
EOT
|
||||
)
|
||||
}
|
||||
|
||||
it "should return pools serviced by this provider" do
|
||||
expect(subject.provided_pools).to eq(['pool1','pool2'])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create_or_replace_record' do
|
||||
it 'should raise error' do
|
||||
expect{subject.create_or_replace_record('pool')}.to raise_error(/does not implement create_or_replace_record/)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete_record' do
|
||||
it 'should raise error' do
|
||||
expect{subject.delete_record('pool')}.to raise_error(/does not implement delete_record/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Vmpooler::Dns' do
|
||||
let(:dns_class) { 'mock-dnsservice' }
|
||||
let(:dns_config_name) { 'mock' }
|
||||
let(:pool) { 'pool1' }
|
||||
let(:config) { YAML.load(<<~EOT
|
||||
---
|
||||
:dns_configs:
|
||||
:mock:
|
||||
dns_class: 'mock'
|
||||
domain: 'example.com'
|
||||
:pools:
|
||||
- name: 'pool1'
|
||||
dns_plugin: 'mock'
|
||||
EOT
|
||||
)}
|
||||
subject { Vmpooler::Dns.new }
|
||||
|
||||
describe '.get_dns_plugin_class_by_name' do
|
||||
it 'returns the plugin class for the specified config' do
|
||||
result = Vmpooler::Dns.get_dns_plugin_class_by_name(config, dns_config_name)
|
||||
expect(result).to eq('mock')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.get_domain_for_pool' do
|
||||
it 'returns the domain for the specified pool' do
|
||||
result = Vmpooler::Dns.get_domain_for_pool(config, pool)
|
||||
expect(result).to eq('example.com')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.get_dns_plugin_domain_by_name' do
|
||||
it 'returns the domain for the specified config' do
|
||||
result = Vmpooler::Dns.get_dns_plugin_domain_by_name(config, dns_config_name)
|
||||
expect(result).to eq('example.com')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.get_dns_plugin_config_classes' do
|
||||
it 'returns the list of dns plugin classes' do
|
||||
result = Vmpooler::Dns.get_dns_plugin_config_classes(config)
|
||||
expect(result).to eq(['mock'])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#load_from_gems' do
|
||||
let(:gem_name) { 'mock-dnsservice' }
|
||||
let(:translated_gem_name) { 'mock/dnsservice' }
|
||||
|
||||
before(:each) do
|
||||
allow(subject).to receive(:require).with(gem_name).and_return(true)
|
||||
end
|
||||
|
||||
it 'loads the specified gem' do
|
||||
expect(subject).to receive(:require).with("vmpooler/dns/#{translated_gem_name}")
|
||||
result = subject.load_from_gems(gem_name)
|
||||
expect(result).to eq("vmpooler/dns/#{translated_gem_name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -22,6 +22,7 @@ describe 'Vmpooler' do
|
|||
['prefix', test_string, ""],
|
||||
['logfile', test_string, nil],
|
||||
['site_name', test_string, nil],
|
||||
['domain', test_string, nil],
|
||||
['clone_target', test_string, nil],
|
||||
['create_folders', test_bool, nil],
|
||||
['create_template_delta_disks', test_bool, nil],
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,497 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require 'vmpooler/pool_manager'
|
||||
|
||||
describe 'Vmpooler::PoolManager - Queue Reliability Features' do
|
||||
let(:logger) { MockLogger.new }
|
||||
let(:redis_connection_pool) { ConnectionPool.new(size: 1) { redis } }
|
||||
let(:metrics) { Vmpooler::Metrics::DummyStatsd.new }
|
||||
let(:config) { YAML.load(<<~EOT
|
||||
---
|
||||
:config:
|
||||
task_limit: 10
|
||||
vm_checktime: 1
|
||||
vm_lifetime: 12
|
||||
prefix: 'pooler-'
|
||||
dlq_enabled: true
|
||||
dlq_ttl: 168
|
||||
dlq_max_entries: 100
|
||||
purge_enabled: true
|
||||
purge_dry_run: false
|
||||
max_pending_age: 7200
|
||||
max_ready_age: 86400
|
||||
max_completed_age: 3600
|
||||
health_check_enabled: true
|
||||
health_check_interval: 300
|
||||
health_thresholds:
|
||||
pending_queue_max: 100
|
||||
ready_queue_max: 500
|
||||
dlq_max_warning: 100
|
||||
dlq_max_critical: 1000
|
||||
stuck_vm_age_threshold: 7200
|
||||
:providers:
|
||||
:dummy: {}
|
||||
:pools:
|
||||
- name: 'test-pool'
|
||||
size: 5
|
||||
provider: 'dummy'
|
||||
EOT
|
||||
)
|
||||
}
|
||||
|
||||
subject { Vmpooler::PoolManager.new(config, logger, redis_connection_pool, metrics) }
|
||||
|
||||
describe 'Dead-Letter Queue (DLQ)' do
|
||||
let(:vm) { 'vm-abc123' }
|
||||
let(:pool) { 'test-pool' }
|
||||
let(:error_class) { 'StandardError' }
|
||||
let(:error_message) { 'template does not exist' }
|
||||
let(:request_id) { 'req-123' }
|
||||
let(:pool_alias) { 'test-alias' }
|
||||
|
||||
before(:each) do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
allow(redis_connection).to receive(:zadd)
|
||||
allow(redis_connection).to receive(:zcard).and_return(0)
|
||||
allow(redis_connection).to receive(:expire)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dlq_enabled?' do
|
||||
it 'returns true when dlq_enabled is true in config' do
|
||||
expect(subject.dlq_enabled?).to be true
|
||||
end
|
||||
|
||||
it 'returns false when dlq_enabled is false in config' do
|
||||
config[:config]['dlq_enabled'] = false
|
||||
expect(subject.dlq_enabled?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dlq_ttl' do
|
||||
it 'returns configured TTL' do
|
||||
expect(subject.dlq_ttl).to eq(168)
|
||||
end
|
||||
|
||||
it 'returns default TTL when not configured' do
|
||||
config[:config].delete('dlq_ttl')
|
||||
expect(subject.dlq_ttl).to eq(168)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#dlq_max_entries' do
|
||||
it 'returns configured max entries' do
|
||||
expect(subject.dlq_max_entries).to eq(100)
|
||||
end
|
||||
|
||||
it 'returns default max entries when not configured' do
|
||||
config[:config].delete('dlq_max_entries')
|
||||
expect(subject.dlq_max_entries).to eq(10000)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#move_to_dlq' do
|
||||
context 'when DLQ is enabled' do
|
||||
it 'adds entry to DLQ sorted set' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
dlq_key = 'vmpooler__dlq__pending'
|
||||
|
||||
expect(redis_connection).to receive(:zadd).with(dlq_key, anything, anything)
|
||||
expect(redis_connection).to receive(:expire).with(dlq_key, anything)
|
||||
|
||||
subject.move_to_dlq(vm, pool, 'pending', error_class, error_message,
|
||||
redis_connection, request_id: request_id, pool_alias: pool_alias)
|
||||
end
|
||||
end
|
||||
|
||||
it 'includes error details in DLQ entry' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
expect(redis_connection).to receive(:zadd) do |_key, _score, entry|
|
||||
expect(entry).to include(vm)
|
||||
expect(entry).to include(error_message)
|
||||
expect(entry).to include(error_class)
|
||||
end
|
||||
|
||||
subject.move_to_dlq(vm, pool, 'pending', error_class, error_message, redis_connection)
|
||||
end
|
||||
end
|
||||
|
||||
it 'increments DLQ metrics' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
expect(metrics).to receive(:increment).with('vmpooler_dlq.pending.count')
|
||||
|
||||
subject.move_to_dlq(vm, pool, 'pending', error_class, error_message, redis_connection)
|
||||
end
|
||||
end
|
||||
|
||||
it 'enforces max entries limit' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
allow(redis_connection).to receive(:zcard).and_return(150)
|
||||
expect(redis_connection).to receive(:zremrangebyrank).with(anything, 0, 49)
|
||||
|
||||
subject.move_to_dlq(vm, pool, 'pending', error_class, error_message, redis_connection)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when DLQ is disabled' do
|
||||
before { config[:config]['dlq_enabled'] = false }
|
||||
|
||||
it 'does not add entry to DLQ' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
expect(redis_connection).not_to receive(:zadd)
|
||||
|
||||
subject.move_to_dlq(vm, pool, 'pending', error_class, error_message, redis_connection)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Auto-Purge' do
|
||||
describe '#purge_enabled?' do
|
||||
it 'returns true when purge_enabled is true in config' do
|
||||
expect(subject.purge_enabled?).to be true
|
||||
end
|
||||
|
||||
it 'returns false when purge_enabled is false in config' do
|
||||
config[:config]['purge_enabled'] = false
|
||||
expect(subject.purge_enabled?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#purge_dry_run?' do
|
||||
it 'returns false when purge_dry_run is false in config' do
|
||||
expect(subject.purge_dry_run?).to be false
|
||||
end
|
||||
|
||||
it 'returns true when purge_dry_run is true in config' do
|
||||
config[:config]['purge_dry_run'] = true
|
||||
expect(subject.purge_dry_run?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#max_pending_age' do
|
||||
it 'returns configured max age' do
|
||||
expect(subject.max_pending_age).to eq(7200)
|
||||
end
|
||||
|
||||
it 'returns default max age when not configured' do
|
||||
config[:config].delete('max_pending_age')
|
||||
expect(subject.max_pending_age).to eq(7200)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#purge_pending_queue' do
|
||||
let(:pool) { 'test-pool' }
|
||||
let(:old_vm) { 'vm-old' }
|
||||
let(:new_vm) { 'vm-new' }
|
||||
|
||||
before(:each) do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
# Old VM (3 hours old, exceeds 2 hour threshold)
|
||||
redis_connection.sadd("vmpooler__pending__#{pool}", old_vm)
|
||||
redis_connection.hset("vmpooler__vm__#{old_vm}", 'clone', (Time.now - 10800).to_s)
|
||||
|
||||
# New VM (30 minutes old, within threshold)
|
||||
redis_connection.sadd("vmpooler__pending__#{pool}", new_vm)
|
||||
redis_connection.hset("vmpooler__vm__#{new_vm}", 'clone', (Time.now - 1800).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not in dry-run mode' do
|
||||
it 'purges stale pending VMs' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
purged_count = subject.purge_pending_queue(pool, redis_connection)
|
||||
|
||||
expect(purged_count).to eq(1)
|
||||
expect(redis_connection.sismember("vmpooler__pending__#{pool}", old_vm)).to be false
|
||||
expect(redis_connection.sismember("vmpooler__pending__#{pool}", new_vm)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it 'moves purged VMs to DLQ' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
expect(subject).to receive(:move_to_dlq).with(
|
||||
old_vm, pool, 'pending', 'Purge', anything, redis_connection, anything
|
||||
)
|
||||
|
||||
subject.purge_pending_queue(pool, redis_connection)
|
||||
end
|
||||
end
|
||||
|
||||
it 'increments purge metrics' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
expect(metrics).to receive(:increment).with("vmpooler_purge.pending.#{pool}.count")
|
||||
|
||||
subject.purge_pending_queue(pool, redis_connection)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when in dry-run mode' do
|
||||
before { config[:config]['purge_dry_run'] = true }
|
||||
|
||||
it 'detects but does not purge stale VMs' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
purged_count = subject.purge_pending_queue(pool, redis_connection)
|
||||
|
||||
expect(purged_count).to eq(1)
|
||||
expect(redis_connection.sismember("vmpooler__pending__#{pool}", old_vm)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not move to DLQ' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
expect(subject).not_to receive(:move_to_dlq)
|
||||
|
||||
subject.purge_pending_queue(pool, redis_connection)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#purge_ready_queue' do
|
||||
let(:pool) { 'test-pool' }
|
||||
let(:old_vm) { 'vm-old-ready' }
|
||||
let(:new_vm) { 'vm-new-ready' }
|
||||
|
||||
before(:each) do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
# Old VM (25 hours old, exceeds 24 hour threshold)
|
||||
redis_connection.sadd("vmpooler__ready__#{pool}", old_vm)
|
||||
redis_connection.hset("vmpooler__vm__#{old_vm}", 'ready', (Time.now - 90000).to_s)
|
||||
|
||||
# New VM (2 hours old, within threshold)
|
||||
redis_connection.sadd("vmpooler__ready__#{pool}", new_vm)
|
||||
redis_connection.hset("vmpooler__vm__#{new_vm}", 'ready', (Time.now - 7200).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
it 'moves stale ready VMs to completed queue' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
purged_count = subject.purge_ready_queue(pool, redis_connection)
|
||||
|
||||
expect(purged_count).to eq(1)
|
||||
expect(redis_connection.sismember("vmpooler__ready__#{pool}", old_vm)).to be false
|
||||
expect(redis_connection.sismember("vmpooler__completed__#{pool}", old_vm)).to be true
|
||||
expect(redis_connection.sismember("vmpooler__ready__#{pool}", new_vm)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#purge_completed_queue' do
|
||||
let(:pool) { 'test-pool' }
|
||||
let(:old_vm) { 'vm-old-completed' }
|
||||
let(:new_vm) { 'vm-new-completed' }
|
||||
|
||||
before(:each) do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
# Old VM (2 hours old, exceeds 1 hour threshold)
|
||||
redis_connection.sadd("vmpooler__completed__#{pool}", old_vm)
|
||||
redis_connection.hset("vmpooler__vm__#{old_vm}", 'destroy', (Time.now - 7200).to_s)
|
||||
|
||||
# New VM (30 minutes old, within threshold)
|
||||
redis_connection.sadd("vmpooler__completed__#{pool}", new_vm)
|
||||
redis_connection.hset("vmpooler__vm__#{new_vm}", 'destroy', (Time.now - 1800).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
it 'removes stale completed VMs' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
purged_count = subject.purge_completed_queue(pool, redis_connection)
|
||||
|
||||
expect(purged_count).to eq(1)
|
||||
expect(redis_connection.sismember("vmpooler__completed__#{pool}", old_vm)).to be false
|
||||
expect(redis_connection.sismember("vmpooler__completed__#{pool}", new_vm)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Health Checks' do
|
||||
describe '#health_check_enabled?' do
|
||||
it 'returns true when health_check_enabled is true in config' do
|
||||
expect(subject.health_check_enabled?).to be true
|
||||
end
|
||||
|
||||
it 'returns false when health_check_enabled is false in config' do
|
||||
config[:config]['health_check_enabled'] = false
|
||||
expect(subject.health_check_enabled?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#health_thresholds' do
|
||||
it 'returns configured thresholds' do
|
||||
thresholds = subject.health_thresholds
|
||||
expect(thresholds['pending_queue_max']).to eq(100)
|
||||
expect(thresholds['stuck_vm_age_threshold']).to eq(7200)
|
||||
end
|
||||
|
||||
it 'merges with defaults when partially configured' do
|
||||
config[:config]['health_thresholds'] = { 'pending_queue_max' => 200 }
|
||||
thresholds = subject.health_thresholds
|
||||
|
||||
expect(thresholds['pending_queue_max']).to eq(200)
|
||||
expect(thresholds['ready_queue_max']).to eq(500) # default
|
||||
end
|
||||
end
|
||||
|
||||
describe '#calculate_queue_ages' do
|
||||
let(:pool) { 'test-pool' }
|
||||
let(:vm1) { 'vm-1' }
|
||||
let(:vm2) { 'vm-2' }
|
||||
let(:vm3) { 'vm-3' }
|
||||
|
||||
before(:each) do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
redis_connection.hset("vmpooler__vm__#{vm1}", 'clone', (Time.now - 3600).to_s)
|
||||
redis_connection.hset("vmpooler__vm__#{vm2}", 'clone', (Time.now - 7200).to_s)
|
||||
redis_connection.hset("vmpooler__vm__#{vm3}", 'clone', (Time.now - 1800).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
it 'calculates ages for all VMs' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
vms = [vm1, vm2, vm3]
|
||||
ages = subject.calculate_queue_ages(vms, 'clone', redis_connection)
|
||||
|
||||
expect(ages.length).to eq(3)
|
||||
expect(ages[0]).to be_within(5).of(3600)
|
||||
expect(ages[1]).to be_within(5).of(7200)
|
||||
expect(ages[2]).to be_within(5).of(1800)
|
||||
end
|
||||
end
|
||||
|
||||
it 'skips VMs with missing timestamps' do
|
||||
redis_connection_pool.with do |redis_connection|
|
||||
vms = [vm1, 'vm-nonexistent', vm3]
|
||||
ages = subject.calculate_queue_ages(vms, 'clone', redis_connection)
|
||||
|
||||
expect(ages.length).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#determine_health_status' do
|
||||
let(:base_metrics) do
|
||||
{
|
||||
'queues' => {
|
||||
'test-pool' => {
|
||||
'pending' => { 'size' => 10, 'stuck_count' => 2 },
|
||||
'ready' => { 'size' => 50 }
|
||||
}
|
||||
},
|
||||
'errors' => {
|
||||
'dlq_total_size' => 50,
|
||||
'stuck_vm_count' => 2
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns healthy when all metrics are within thresholds' do
|
||||
status = subject.determine_health_status(base_metrics)
|
||||
expect(status).to eq('healthy')
|
||||
end
|
||||
|
||||
it 'returns degraded when DLQ size exceeds warning threshold' do
|
||||
metrics = base_metrics.dup
|
||||
metrics['errors']['dlq_total_size'] = 150
|
||||
|
||||
status = subject.determine_health_status(metrics)
|
||||
expect(status).to eq('degraded')
|
||||
end
|
||||
|
||||
it 'returns unhealthy when DLQ size exceeds critical threshold' do
|
||||
metrics = base_metrics.dup
|
||||
metrics['errors']['dlq_total_size'] = 1500
|
||||
|
||||
status = subject.determine_health_status(metrics)
|
||||
expect(status).to eq('unhealthy')
|
||||
end
|
||||
|
||||
it 'returns degraded when pending queue exceeds warning threshold' do
|
||||
metrics = base_metrics.dup
|
||||
metrics['queues']['test-pool']['pending']['size'] = 120
|
||||
|
||||
status = subject.determine_health_status(metrics)
|
||||
expect(status).to eq('degraded')
|
||||
end
|
||||
|
||||
it 'returns unhealthy when pending queue exceeds critical threshold' do
|
||||
metrics = base_metrics.dup
|
||||
metrics['queues']['test-pool']['pending']['size'] = 250
|
||||
|
||||
status = subject.determine_health_status(metrics)
|
||||
expect(status).to eq('unhealthy')
|
||||
end
|
||||
|
||||
it 'returns unhealthy when stuck VM count exceeds critical threshold' do
|
||||
metrics = base_metrics.dup
|
||||
metrics['errors']['stuck_vm_count'] = 60
|
||||
|
||||
status = subject.determine_health_status(metrics)
|
||||
expect(status).to eq('unhealthy')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#push_health_metrics' do
|
||||
let(:metrics_data) do
|
||||
{
|
||||
'queues' => {
|
||||
'test-pool' => {
|
||||
'pending' => { 'size' => 10, 'oldest_age' => 3600, 'stuck_count' => 2 },
|
||||
'ready' => { 'size' => 50, 'oldest_age' => 7200 },
|
||||
'completed' => { 'size' => 5 }
|
||||
}
|
||||
},
|
||||
'tasks' => {
|
||||
'clone' => { 'active' => 3 },
|
||||
'ondemand' => { 'active' => 2, 'pending' => 5 }
|
||||
},
|
||||
'errors' => {
|
||||
'dlq_total_size' => 25,
|
||||
'stuck_vm_count' => 2,
|
||||
'orphaned_metadata_count' => 3
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
it 'pushes status metric' do
|
||||
allow(metrics).to receive(:gauge)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.status', 0)
|
||||
|
||||
subject.push_health_metrics(metrics_data, 'healthy')
|
||||
end
|
||||
|
||||
it 'pushes error metrics' do
|
||||
allow(metrics).to receive(:gauge)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.dlq.total_size', 25)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.stuck_vms.count', 2)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.orphaned_metadata.count', 3)
|
||||
|
||||
subject.push_health_metrics(metrics_data, 'healthy')
|
||||
end
|
||||
|
||||
it 'pushes per-pool queue metrics' do
|
||||
allow(metrics).to receive(:gauge)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.queue.test-pool.pending.size', 10)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.queue.test-pool.pending.oldest_age', 3600)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.queue.test-pool.pending.stuck_count', 2)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.queue.test-pool.ready.size', 50)
|
||||
|
||||
subject.push_health_metrics(metrics_data, 'healthy')
|
||||
end
|
||||
|
||||
it 'pushes task metrics' do
|
||||
allow(metrics).to receive(:gauge)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.tasks.clone.active', 3)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.tasks.ondemand.active', 2)
|
||||
expect(metrics).to receive(:gauge).with('vmpooler_health.tasks.ondemand.pending', 5)
|
||||
|
||||
subject.push_health_metrics(metrics_data, 'healthy')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,11 +1,104 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# The only method previously tested here was '#get_domain_for_pool'
|
||||
# which was moved to Vmpooler::Dns as the more appropriate class
|
||||
#
|
||||
# TODO: Add tests for last remaining method, or move to more appropriate class
|
||||
describe 'Vmpooler::Parsing' do
|
||||
describe 'Parser' do
|
||||
let(:pool) { 'pool1' }
|
||||
subject { Vmpooler::Parsing }
|
||||
describe '.get_domain_for_pool' do
|
||||
let(:provider_name) { 'mock_provider' }
|
||||
context 'No provider is set' do
|
||||
let(:config) { YAML.load(<<~EOT
|
||||
---
|
||||
:config:
|
||||
:providers:
|
||||
:mock_provider:
|
||||
:pools:
|
||||
- name: '#{pool}'
|
||||
size: 1
|
||||
EOT
|
||||
)}
|
||||
|
||||
it 'should return nil' do
|
||||
result = subject.get_domain_for_pool(config, pool)
|
||||
expect(result).to be_nil
|
||||
end
|
||||
end
|
||||
context 'Provider is vsphere by default' do
|
||||
let(:config) { YAML.load(<<~EOT
|
||||
---
|
||||
:config:
|
||||
:providers:
|
||||
:vsphere:
|
||||
domain: myown.com
|
||||
:pools:
|
||||
- name: '#{pool}'
|
||||
size: 1
|
||||
EOT
|
||||
)}
|
||||
|
||||
it 'should return the domain set for vsphere' do
|
||||
result = subject.get_domain_for_pool(config, pool)
|
||||
expect(result).to eq('myown.com')
|
||||
end
|
||||
end
|
||||
context 'No domain is set' do
|
||||
let(:config) { YAML.load(<<~EOT
|
||||
---
|
||||
:config:
|
||||
:providers:
|
||||
:mock_provider:
|
||||
:pools:
|
||||
- name: '#{pool}'
|
||||
size: 1
|
||||
provider: #{provider_name}
|
||||
EOT
|
||||
)}
|
||||
|
||||
it 'should return nil' do
|
||||
result = subject.get_domain_for_pool(config, pool)
|
||||
expect(result).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'Only a global domain is set' do
|
||||
let(:config) { YAML.load(<<~EOT
|
||||
---
|
||||
:config:
|
||||
domain: example.com
|
||||
:providers:
|
||||
:mock_provider:
|
||||
:pools:
|
||||
- name: '#{pool}'
|
||||
size: 1
|
||||
provider: #{provider_name}
|
||||
EOT
|
||||
)}
|
||||
|
||||
it 'should return the domain set in the config section' do
|
||||
result = subject.get_domain_for_pool(config, pool)
|
||||
expect(result).to_not be_nil
|
||||
expect(result).to eq('example.com')
|
||||
end
|
||||
end
|
||||
|
||||
context 'A provider specified a domain to use' do
|
||||
let(:config) { YAML.load(<<~EOT
|
||||
---
|
||||
:config:
|
||||
:providers:
|
||||
:mock_provider:
|
||||
domain: m.example.com
|
||||
:pools:
|
||||
- name: '#{pool}'
|
||||
size: 1
|
||||
provider: #{provider_name}
|
||||
EOT
|
||||
)}
|
||||
|
||||
it 'should return the domain set in the config section' do
|
||||
result = subject.get_domain_for_pool(config, pool)
|
||||
expect(result).to_not be_nil
|
||||
expect(result).to eq('m.example.com')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -63,37 +63,12 @@ describe 'Vmpooler' do
|
|||
expect(Vmpooler.config[:providers].keys).to include(:dummy)
|
||||
expect(Vmpooler.config[:providers].keys).to include(:alice)
|
||||
expect(Vmpooler.config[:providers].keys).to include(:bob)
|
||||
merged_pools = [{"name"=>"pool03", "provider"=>"dummy", "dns_plugin"=>"example", "ready_ttl"=>5, "size"=>5},
|
||||
{"name"=>"pool04", "provider"=>"dummy", "dns_plugin"=>"example", "ready_ttl"=>5, "size"=>5},
|
||||
{"name"=>"pool05", "provider"=>"dummy", "dns_plugin"=>"example", "ready_ttl"=>5, "size"=>5}]
|
||||
merged_pools = [{"name"=>"pool03", "provider"=>"dummy", "ready_ttl"=>5, "size"=>5},
|
||||
{"name"=>"pool04", "provider"=>"dummy", "ready_ttl"=>5, "size"=>5},
|
||||
{"name"=>"pool05", "provider"=>"dummy", "ready_ttl"=>5, "size"=>5}]
|
||||
expect(Vmpooler.config[:pools]).to eq(merged_pools)
|
||||
expect(Vmpooler.config[:config]).not_to be_nil #merge does not deleted existing keys
|
||||
end
|
||||
end
|
||||
|
||||
context 'when domain' do
|
||||
context 'is set as a variable' do
|
||||
before(:each) do
|
||||
ENV['VMPOOLER_CONFIG_FILE'] = config_file
|
||||
ENV['DOMAIN'] = 'example.com'
|
||||
end
|
||||
|
||||
it 'should exit' do
|
||||
expect { Vmpooler.config }.to raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'is set in a config file' do
|
||||
let(:config_file) { File.join(fixtures_dir, 'vmpooler_domain.yaml') }
|
||||
|
||||
before(:each) do
|
||||
ENV['VMPOOLER_CONFIG_FILE'] = config_file
|
||||
end
|
||||
|
||||
it 'should exit' do
|
||||
expect { Vmpooler.config }.to raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
# The container tag should closely match what is used in `docker/Dockerfile` in vmpooler-deployment
|
||||
docker run -it --rm \
|
||||
-v $(pwd):/app \
|
||||
jruby:9.4.12.1-jdk11 \
|
||||
/bin/bash -c 'apt-get update -qq && apt-get install -y --no-install-recommends git make netbase build-essential && cd /app && gem install bundler && bundle install --jobs 3 && bundle update; echo "LOCK_FILE_UPDATE_EXIT_CODE=$?"'
|
||||
jruby:9.4.1.0-jdk11 \
|
||||
/bin/bash -c 'apt-get update -qq && apt-get install -y --no-install-recommends git make netbase && cd /app && gem install bundler && bundle install --jobs 3 && bundle update; echo "LOCK_FILE_UPDATE_EXIT_CODE=$?"'
|
||||
|
|
|
|||
|
|
@ -17,34 +17,33 @@ Gem::Specification.new do |s|
|
|||
s.executables = 'vmpooler'
|
||||
s.require_paths = ["lib"]
|
||||
s.add_dependency 'concurrent-ruby', '~> 1.1'
|
||||
s.add_dependency 'connection_pool', '~> 2.4'
|
||||
s.add_dependency 'connection_pool', '~> 2.2'
|
||||
s.add_dependency 'deep_merge', '~> 1.2'
|
||||
s.add_dependency 'net-ldap', '~> 0.16'
|
||||
s.add_dependency 'opentelemetry-exporter-jaeger', '= 0.23.0'
|
||||
s.add_dependency 'opentelemetry-instrumentation-concurrent_ruby', '= 0.21.1'
|
||||
s.add_dependency 'opentelemetry-instrumentation-http_client', '= 0.22.2'
|
||||
s.add_dependency 'opentelemetry-instrumentation-rack', '= 0.23.4'
|
||||
s.add_dependency 'opentelemetry-instrumentation-redis', '= 0.25.3'
|
||||
s.add_dependency 'opentelemetry-instrumentation-sinatra', '= 0.23.2'
|
||||
s.add_dependency 'opentelemetry-resource_detectors', '= 0.24.2'
|
||||
s.add_dependency 'opentelemetry-sdk', '~> 1.8'
|
||||
s.add_dependency 'opentelemetry-exporter-jaeger', '= 0.20.1'
|
||||
s.add_dependency 'opentelemetry-instrumentation-concurrent_ruby', '= 0.19.2'
|
||||
s.add_dependency 'opentelemetry-instrumentation-http_client', '= 0.19.4'
|
||||
s.add_dependency 'opentelemetry-instrumentation-redis', '= 0.21.3'
|
||||
s.add_dependency 'opentelemetry-instrumentation-sinatra', '= 0.19.3'
|
||||
s.add_dependency 'opentelemetry-resource_detectors', '= 0.19.1'
|
||||
s.add_dependency 'opentelemetry-sdk', '~> 1.0', '>= 1.0.2'
|
||||
s.add_dependency 'pickup', '~> 0.0.11'
|
||||
s.add_dependency 'prometheus-client', '>= 2', '< 5'
|
||||
s.add_dependency 'puma', '>= 5.0.4', '< 7'
|
||||
s.add_dependency 'rack', '>= 2.2', '< 4.0'
|
||||
s.add_dependency 'prometheus-client', '~> 2.0'
|
||||
s.add_dependency 'puma', '~> 5.0', '>= 5.0.4'
|
||||
s.add_dependency 'rack', '~> 2.2'
|
||||
s.add_dependency 'rake', '~> 13.0'
|
||||
s.add_dependency 'redis', '~> 5.0'
|
||||
s.add_dependency 'sinatra', '>= 2', '< 4'
|
||||
s.add_dependency 'redis', '~> 4.1'
|
||||
s.add_dependency 'sinatra', '~> 2.0'
|
||||
s.add_dependency 'spicy-proton', '~> 2.1'
|
||||
s.add_dependency 'statsd-ruby', '~> 1.4'
|
||||
|
||||
# Testing dependencies
|
||||
s.add_development_dependency 'climate_control', '>= 0.2.0'
|
||||
s.add_development_dependency 'mock_redis', '= 0.37.0'
|
||||
s.add_development_dependency 'mock_redis', '>= 0.17.0'
|
||||
s.add_development_dependency 'pry'
|
||||
s.add_development_dependency 'rack-test', '>= 0.6'
|
||||
s.add_development_dependency 'rspec', '>= 3.2'
|
||||
s.add_development_dependency 'rubocop', '~> 1.56.0'
|
||||
s.add_development_dependency 'rubocop', '~> 1.28.2'
|
||||
s.add_development_dependency 'simplecov', '>= 0.11.2'
|
||||
s.add_development_dependency 'thor', '~> 1.0', '>= 1.0.1'
|
||||
s.add_development_dependency 'yarjuf', '>= 2.0'
|
||||
|
|
|
|||
|
|
@ -3,12 +3,6 @@
|
|||
:dummy:
|
||||
filename: '/tmp/dummy-backing.yaml'
|
||||
|
||||
:dns_configs:
|
||||
:example:
|
||||
dns_class: dynamic-dns
|
||||
#domain: 'localhost' # Flip these out for local requests
|
||||
domain: 'example.com'
|
||||
|
||||
:redis:
|
||||
server: 'localhost'
|
||||
|
||||
|
|
@ -23,13 +17,14 @@
|
|||
logfile: '/var/log/vmpooler.log'
|
||||
task_limit: 10
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
vm_checktime: 1
|
||||
vm_lifetime: 12
|
||||
vm_lifetime_auth: 24
|
||||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
#domain: 'localhost' # Flip these out for local requests
|
||||
prefix: 'poolvm-'
|
||||
|
||||
:pools:
|
||||
|
|
@ -40,10 +35,8 @@
|
|||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
- name: 'debian-7-x86_64'
|
||||
alias: [ 'debian-7-64', 'debian-7-amd64' ]
|
||||
template: 'Templates/debian-7-x86_64'
|
||||
|
|
@ -51,7 +44,6 @@
|
|||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: dummy
|
||||
dns_plugin: 'example'
|
||||
|
||||
|
|
|
|||
|
|
@ -367,15 +367,6 @@
|
|||
# - user_object
|
||||
# The LDAP object-type used to designate a user object.
|
||||
#
|
||||
# - service_account_hash
|
||||
# A hash containing the following parameters for a service account to perform the
|
||||
# initial bind. After the initial bind, then a search query is performed using the
|
||||
# 'base' and 'user_object', then re-binds as the returned user.
|
||||
# - :user_dn
|
||||
# The full distinguished name (DN) of the service account used to bind.
|
||||
# - :password
|
||||
# The password for the service account used to bind.
|
||||
#
|
||||
# Example:
|
||||
# :auth:
|
||||
# provider: 'ldap'
|
||||
|
|
@ -384,23 +375,6 @@
|
|||
# port: 389
|
||||
# base: 'ou=users,dc=company,dc=com'
|
||||
# user_object: 'uid'
|
||||
#
|
||||
# :auth:
|
||||
# provider: 'ldap'
|
||||
# :ldap:
|
||||
# host: 'ldap.example.com'
|
||||
# port: 636
|
||||
# service_account_hash:
|
||||
# :user_dn: 'cn=Service Account,ou=Accounts,dc=ldap,dc=example,dc=com'
|
||||
# :password: 'service-account-password'
|
||||
# encryption:
|
||||
# :method: :simple_tls
|
||||
# :tls_options:
|
||||
# :ssl_version: 'TLSv1_2'
|
||||
# base:
|
||||
# - 'ou=Accounts,dc=company,dc=com'
|
||||
# user_object:
|
||||
# - 'samAccountName'
|
||||
|
||||
:auth:
|
||||
provider: 'ldap'
|
||||
|
|
@ -456,12 +430,6 @@
|
|||
# How long (in minutes) before marking a clone in 'pending' queues as 'failed' and retrying.
|
||||
# (default: 15)
|
||||
#
|
||||
# - max_vm_retries
|
||||
# Maximum number of times to retry VM creation for a failed request before marking it as permanently failed.
|
||||
# This helps prevent infinite retry loops when there are configuration issues like invalid template paths.
|
||||
# Permanent errors (like invalid template paths) are detected and will not be retried.
|
||||
# (default: 3)
|
||||
#
|
||||
# - vm_checktime
|
||||
# How often (in minutes) to check the sanity of VMs in 'ready' queues.
|
||||
# (default: 1)
|
||||
|
|
@ -477,6 +445,12 @@
|
|||
# - allowed_tags
|
||||
# If set, restricts tags to those specified in this array.
|
||||
#
|
||||
# - domain
|
||||
# If set, returns a top-level 'domain' JSON key in POST requests (v1).
|
||||
# in the v2 API, it concatenates the hostname to include the domain, either set here or at the provider level
|
||||
# With the introduction of vmpooler-provider-gce, domains can now be set at the provider level. The
|
||||
# domain key is only retained in v1 for backwards compatibility and will be removed in the future.
|
||||
#
|
||||
# - prefix
|
||||
# If set, prefixes all created VMs with this string. This should include
|
||||
# a separator.
|
||||
|
|
@ -621,43 +595,19 @@
|
|||
logfile: '/var/log/vmpooler.log'
|
||||
task_limit: 10
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
vm_checktime: 1
|
||||
vm_lifetime: 12
|
||||
vm_lifetime_auth: 24
|
||||
max_vm_retries: 3
|
||||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
prefix: 'poolvm-'
|
||||
experimental_features: true
|
||||
backend_weight:
|
||||
'backend1': 60
|
||||
'backend2': 40
|
||||
|
||||
# :dns_configs:
|
||||
#
|
||||
# This section a list of dns configurations to be referenced by one or more pools.
|
||||
#
|
||||
# The currently supported backing services are:
|
||||
# - dynamic-dns (This assumes that dynamic dns is handling record management and VMPooler does not require interaction)
|
||||
# - gcp (Google Cloud DNS https://github.com/puppetlabs/vmpooler-dns-gcp)
|
||||
#
|
||||
# - dns_class
|
||||
# Specify one of the supported backing services.
|
||||
#
|
||||
# - domain
|
||||
# The domain expected to make up the FQDN when attempting to resolve VM instances.
|
||||
#
|
||||
# See DNS plugin docs for additional options specific to that class.
|
||||
#
|
||||
# Example
|
||||
|
||||
:dns_configs:
|
||||
:example:
|
||||
dns_class: dynamic-dns
|
||||
domain: 'example.com'
|
||||
|
||||
# :pools:
|
||||
#
|
||||
# This section contains a list of virtual machine 'pools' for vmpooler to
|
||||
|
|
@ -688,12 +638,6 @@
|
|||
# If you have more than one provider, this is where you would choose which
|
||||
# one to use for this pool
|
||||
#
|
||||
# - dns_plugin
|
||||
# The name of the DNS plugin to use with this pool in order to determine the
|
||||
# domain and settings specific to a DNS service. This should match
|
||||
# a name in the :dns_configs: section above. e.g. example
|
||||
# (required)
|
||||
#
|
||||
# - clone_target
|
||||
# Per-pool option to override the global 'clone_target' cluster.
|
||||
# (optional)
|
||||
|
|
@ -745,7 +689,6 @@
|
|||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: vsphere
|
||||
create_linked_clone: true
|
||||
|
|
@ -756,7 +699,6 @@
|
|||
datastore: 'vmstorage'
|
||||
size: 5
|
||||
timeout: 15
|
||||
timeout_notification: 5
|
||||
ready_ttl: 1440
|
||||
provider: vsphere
|
||||
create_linked_clone: false
|
||||
|
|
|
|||
|
|
@ -1,92 +0,0 @@
|
|||
---
|
||||
# VMPooler Configuration Example with Dead-Letter Queue, Auto-Purge, and Health Checks
|
||||
|
||||
# Redis Configuration
|
||||
:redis:
|
||||
server: 'localhost'
|
||||
port: 6379
|
||||
data_ttl: 168 # hours - how long to keep VM metadata in Redis
|
||||
|
||||
# Dead-Letter Queue (DLQ) Configuration
|
||||
dlq_enabled: true
|
||||
dlq_ttl: 168 # hours (7 days) - how long to keep DLQ entries
|
||||
dlq_max_entries: 10000 # maximum entries per DLQ queue before trimming
|
||||
|
||||
# Application Configuration
|
||||
:config:
|
||||
# ... other existing config ...
|
||||
|
||||
# Dead-Letter Queue (DLQ) - Optional, defaults shown
|
||||
dlq_enabled: false # Set to true to enable DLQ
|
||||
dlq_ttl: 168 # hours (7 days)
|
||||
dlq_max_entries: 10000 # per DLQ queue
|
||||
|
||||
# Auto-Purge Stale Queue Entries
|
||||
purge_enabled: false # Set to true to enable auto-purge
|
||||
purge_interval: 3600 # seconds (1 hour) - how often to run purge cycle
|
||||
purge_dry_run: false # Set to true to log what would be purged without actually purging
|
||||
|
||||
# Auto-Purge Age Thresholds (in seconds)
|
||||
max_pending_age: 7200 # 2 hours - VMs stuck in pending
|
||||
max_ready_age: 86400 # 24 hours - VMs idle in ready queue
|
||||
max_completed_age: 3600 # 1 hour - VMs in completed queue
|
||||
max_orphaned_age: 86400 # 24 hours - orphaned VM metadata
|
||||
max_request_age: 86400 # 24 hours - stale on-demand requests
|
||||
|
||||
# Health Checks
|
||||
health_check_enabled: false # Set to true to enable health checks
|
||||
health_check_interval: 300 # seconds (5 minutes) - how often to run health checks
|
||||
|
||||
# Health Check Thresholds
|
||||
health_thresholds:
|
||||
pending_queue_max: 100 # Warning threshold for pending queue size
|
||||
ready_queue_max: 500 # Warning threshold for ready queue size
|
||||
dlq_max_warning: 100 # Warning threshold for DLQ size
|
||||
dlq_max_critical: 1000 # Critical threshold for DLQ size
|
||||
stuck_vm_age_threshold: 7200 # 2 hours - age at which VM is considered "stuck"
|
||||
stuck_vm_max_warning: 10 # Warning threshold for stuck VM count
|
||||
stuck_vm_max_critical: 50 # Critical threshold for stuck VM count
|
||||
|
||||
# Pool Configuration
|
||||
:pools:
|
||||
- name: 'centos-7-x86_64'
|
||||
size: 5
|
||||
provider: 'vsphere'
|
||||
# ... other pool settings ...
|
||||
|
||||
# Provider Configuration
|
||||
:providers:
|
||||
:vsphere:
|
||||
server: 'vcenter.example.com'
|
||||
username: 'vmpooler'
|
||||
password: 'secret'
|
||||
# ... other provider settings ...
|
||||
|
||||
# Example: Production Configuration
|
||||
# For production use, you might want:
|
||||
# :config:
|
||||
# dlq_enabled: true
|
||||
# dlq_ttl: 168 # Keep failed VMs for a week
|
||||
#
|
||||
# purge_enabled: true
|
||||
# purge_interval: 1800 # Run every 30 minutes
|
||||
# purge_dry_run: false
|
||||
# max_pending_age: 3600 # Purge pending VMs after 1 hour
|
||||
# max_ready_age: 172800 # Purge ready VMs after 2 days
|
||||
#
|
||||
# health_check_enabled: true
|
||||
# health_check_interval: 300 # Check every 5 minutes
|
||||
|
||||
# Example: Development Configuration
|
||||
# For development/testing, you might want:
|
||||
# :config:
|
||||
# dlq_enabled: true
|
||||
# dlq_ttl: 24 # Keep failed VMs for a day
|
||||
#
|
||||
# purge_enabled: true
|
||||
# purge_interval: 600 # Run every 10 minutes
|
||||
# purge_dry_run: true # Test mode - log but don't actually purge
|
||||
# max_pending_age: 1800 # More aggressive - 30 minutes
|
||||
#
|
||||
# health_check_enabled: true
|
||||
# health_check_interval: 60 # Check every minute
|
||||
Loading…
Add table
Add a link
Reference in a new issue