Skip to content

Commit 74a5a52

Browse files
committed
Merge branch 'main' of https://github.com/apache/cloudstack-go into fix-vm-usage-history
2 parents 818910e + cff4f1b commit 74a5a52

File tree

135 files changed

+110497
-73063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+110497
-73063
lines changed

.asf.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
118
github:
219
description: "CloudStack Go SDK"
320
homepage: https://cloudstack.apache.org
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: 'Setup Go Environment'
19+
description: 'Set up Go with caching and install required tools'
20+
21+
inputs:
22+
go-version:
23+
description: 'Go version to use'
24+
required: false
25+
default: '1.23'
26+
27+
runs:
28+
using: 'composite'
29+
steps:
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: ${{ inputs.go-version }}
34+
check-latest: true
35+
36+
- name: Cache Go modules
37+
uses: actions/cache@v4
38+
with:
39+
path: |
40+
~/.cache/go-build
41+
~/go/pkg/mod
42+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
43+
restore-keys: |
44+
${{ runner.os }}-go-
45+
46+
- name: Set up tools
47+
shell: bash
48+
run: |
49+
go install golang.org/x/tools/cmd/goimports@latest
50+
go install go.uber.org/mock/mockgen@latest
51+
52+
53+
- name: Build
54+
shell: bash
55+
run: |
56+
export PATH=$PATH:$(go env GOPATH)/bin
57+
make code
58+
make mocks

.github/workflows/build.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,8 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v4
3535

36-
- name: Set up Go
37-
uses: actions/setup-go@v4
38-
with:
39-
go-version: 1.23
40-
41-
- name: Set up tools
42-
run: |
43-
go install golang.org/x/tools/cmd/goimports@latest
44-
go install go.uber.org/mock/mockgen@latest
36+
- name: Setup Go Environment
37+
uses: ./.github/actions/setup-go-and-build
4538

4639
- name: Build
4740
run: |
@@ -50,4 +43,4 @@ jobs:
5043
make mocks
5144
5245
- name: Test
53-
run: go test -v ./...
46+
run: go test -v ./test/... ./examples/...

.github/workflows/ci.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: CI
19+
20+
on:
21+
push:
22+
branches: ["main"]
23+
pull_request:
24+
branches: ["main"]
25+
26+
permissions:
27+
contents: read
28+
29+
env:
30+
CLOUDSTACK_API_URL: http://localhost:8080/client/api
31+
32+
jobs:
33+
build:
34+
runs-on: ubuntu-latest
35+
services:
36+
cloudstack-simulator:
37+
image: apache/cloudstack-simulator:4.20.0.0
38+
ports:
39+
- 8080:5050
40+
options: >-
41+
--health-cmd "curl -f http://localhost:5050 || exit 1"
42+
--health-interval 30s
43+
--health-timeout 10s
44+
--health-retries 5
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Setup Go Environment & build code & mocks
49+
uses: ./.github/actions/setup-go-and-build
50+
51+
- name: Set up CloudStack
52+
id: setup-cloudstack
53+
shell: bash
54+
run: |
55+
set -e
56+
57+
# Deploy datacenter configuration
58+
container_id=$(docker container ls --format=json -l | jq -r .ID)
59+
if [ -z "$container_id" ] || [ "$container_id" = "null" ]; then
60+
echo "Failed to get CloudStack container ID"
61+
exit 1
62+
fi
63+
64+
echo "Deploying CloudStack datacenter configuration..."
65+
docker exec "$container_id" python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg
66+
67+
# Login and get API credentials
68+
echo "Logging into CloudStack..."
69+
session_key=$(curl -sf --location "${CLOUDSTACK_API_URL}" \
70+
--header 'Content-Type: application/x-www-form-urlencoded' \
71+
--data-urlencode 'command=login' \
72+
--data-urlencode 'username=admin' \
73+
--data-urlencode 'password=password' \
74+
--data-urlencode 'response=json' \
75+
--data-urlencode 'domain=/' -j -c cookies.txt | jq -r ".loginresponse.sessionkey")
76+
77+
78+
echo "::add-mask::$session_key" # Mask the session key
79+
80+
echo "Retrieving API keys..."
81+
CLOUDSTACK_USER_ID=$(curl -fs "${CLOUDSTACK_API_URL}?command=listUsers&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.listusersresponse.user[0].id')
82+
api_key=$(curl -s "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.apikey')
83+
secret_key=$(curl -fs "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.secretkey')
84+
85+
86+
echo "::add-mask::$api_key" # Mask the API key
87+
echo "::add-mask::$secret_key" # Mask the secret key
88+
89+
echo "CLOUDSTACK_API_KEY=$api_key" >> $GITHUB_OUTPUT
90+
echo "CLOUDSTACK_SECRET_KEY=$secret_key" >> $GITHUB_OUTPUT
91+
92+
- name: Run tests
93+
run: |
94+
go test -v -timeout=30m ./ci/...
95+
env:
96+
CLOUDSTACK_API_URL: ${{ env.CLOUDSTACK_API_URL }}
97+
CLOUDSTACK_API_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_API_KEY }}
98+
CLOUDSTACK_SECRET_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_SECRET_KEY }}

.github/workflows/rat.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: RAT Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
rat:
13+
name: Apache RAT Check
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Java
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: temurin
24+
java-version: 17
25+
26+
- name: Download Apache RAT
27+
run: |
28+
curl -L -O https://downloads.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz
29+
tar -xzf apache-rat-0.16.1-bin.tar.gz
30+
31+
- name: Run RAT
32+
run: |
33+
java -jar apache-rat-0.16.1/apache-rat-0.16.1.jar -d . -E .rat-excludes > rat-report.txt
34+
cat rat-report.txt
35+
# Fail if unapproved licenses are found
36+
grep -qe '^0 Unknown Licenses' rat-report.txt && exit 0 || exit 1

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
118
# Compiled Object files, Static and Dynamic libs (Shared Objects)
219
*.o
320
*.a

.rat-excludes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.rat-excludes
2+
go.mod
3+
go.sum
4+
rat-report.txt
5+
apache-rat-0.16.1

Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
118
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
219
ifeq (,$(shell go env GOBIN))
320
GOBIN=$(shell go env GOPATH)/bin
@@ -11,6 +28,8 @@ endif
1128
SHELL = /usr/bin/env bash -o pipefail
1229
.SHELLFLAGS = -ec
1330

31+
.PHONY: all code mocks test mockgen
32+
1433
all: code mocks test
1534

1635
code:
@@ -26,6 +45,6 @@ test:
2645
go test -v github.com/apache/cloudstack-go/v2/test
2746

2847
MOCKGEN := mockgen
29-
mockgen: ## Download conversion-gen locally if necessary.
48+
mockgen: ## Install mockgen locally via go install.
3049
go install go.uber.org/mock/mockgen@latest
3150

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ The `listAPIs.json` file holds the output of `listApis` command for a specific r
6464
```
6565
# Run it via the Makefile
6666
make all
67-
6867
```
6968

69+
### Prerequisites
70+
71+
* `goimports`: Install by running `go install golang.org/x/tools/cmd/goimports@latest`
72+
73+
* `mockgen`: Install by running `go install go.uber.org/mock/mockgen@latest`
74+
7075
## Getting Help
7176

7277
_Please try to see if the [module documentation](https://pkg.go.dev/github.com/apache/cloudstack-go/v2/cloudstack) can provide some answers first!_

0 commit comments

Comments
 (0)