-
Notifications
You must be signed in to change notification settings - Fork 3
/
routes.go
105 lines (89 loc) · 3.05 KB
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* This file is part of the Dicot project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2017 Red Hat, Inc.
*
*/
package v2_1
import (
"github.com/gin-gonic/gin"
k8s "k8s.io/client-go/kubernetes"
"github.com/dicot-project/dicot-api/pkg/api"
"github.com/dicot-project/dicot-api/pkg/auth"
"github.com/dicot-project/dicot-api/pkg/rest"
"github.com/dicot-project/dicot-api/pkg/rest/middleware"
)
type service struct {
Client api.Interface
K8SClient k8s.Interface
Prefix string
ServerID string
TokenManager auth.TokenManager
}
func NewService(client api.Interface, k8sClient k8s.Interface, tm auth.TokenManager, serverID string, prefix string) rest.Service {
if prefix == "" {
prefix = "/compute/v2.1"
}
return &service{
Client: client,
K8SClient: k8sClient,
Prefix: prefix,
ServerID: serverID,
TokenManager: tm,
}
}
func (svc *service) GetPrefix() string {
return svc.Prefix
}
func (svc *service) GetName() string {
return "dicot-compute"
}
func (svc *service) GetType() string {
return "compute"
}
func (svc *service) GetUID() string {
return "f187c571-8a3d-455b-8846-1f373a2f6207"
}
func (svc *service) RegisterRoutes(router *gin.RouterGroup) {
min := &middleware.MicroVersion{
Major: 2,
Micro: 53,
}
max := &middleware.MicroVersion{
Major: 2,
Micro: 53,
}
router.Use(middleware.NewMicroVersionHandler("compute", "X-OpenStack-Nova-API-Version", min, max).Handler())
router.Use(middleware.NewTokenHandler(svc.TokenManager, svc.Client.Identity()).Handler())
//router.GET("/", svc.IndexShow)
router.GET("/", svc.VersionIndexShow)
router.GET("/flavors", svc.FlavorList)
router.POST("/flavors", svc.FlavorCreate)
router.DELETE("/flavors/:id", svc.FlavorDelete)
//router.GET("/flavors/detail", svc.FlavorListDetail)
router.GET("/flavors/:id", svc.FlavorShow)
router.GET("/flavors/:id/os-extra_specs", svc.FlavorShowExtraSpecs)
router.POST("/flavors/:id/os-extra_specs", svc.FlavorCreateExtraSpecs)
router.GET("/flavors/:id/os-extra_specs/:key", svc.FlavorShowExtraSpec)
router.POST("/flavors/:id/os-extra_specs/:key", svc.FlavorCreateExtraSpec)
router.DELETE("/flavors/:id/os-extra_specs/:key", svc.FlavorDeleteExtraSpec)
router.GET("/os-keypairs", svc.KeypairList)
router.POST("/os-keypairs", svc.KeypairCreate)
router.GET("/os-keypairs/:name", svc.KeypairShow)
router.DELETE("/os-keypairs/:name", svc.KeypairDelete)
router.GET("/os-hypervisors", svc.HypervisorList)
//router.GET("/os-hypervisors/detail", svc.HypervisorList)
router.GET("/os-hypervisors/:name", svc.HypervisorShow)
}