Skip to content

Commit

Permalink
Merge pull request #245 from IBM/jiangnan
Browse files Browse the repository at this point in the history
add registry management page
  • Loading branch information
Catherine2019 authored Jan 18, 2021
2 parents 5b4b60c + ed6bda9 commit 4c0a957
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 10 deletions.
10 changes: 9 additions & 1 deletion web/clui/conf/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Compute_Storage = Compute & Storage
Instances = Instances
Flavors = Flavors
Images = Images
Registry = Registry
Volumes = Volumes
Platform_Service = Platform Service
Openshift = Openshift
Expand Down Expand Up @@ -77,12 +78,16 @@ HyperID = HyperID
ParentID = ParentID
Children = Children
Console = Console
Label = Label
OcpVersion = Ocp Version
RegistryContent = Registry Content

User_Manage_Panel = User Manage Panel
Organization_Manage_Panel = Organization Manage Panel
Key_Manage_Panel = Key Manage Panel
Instance_Manage_Panel = Instance Manage Panel
Flavor_Manage_Panel = Flavor Manage Panel
Registry_Manage_Panel = Registry Manage Panel
Image_Manage_Panel = Image Manage Panel
Volume_Manage_Panel = Volume Manage Panel
Openshift_Cluster_Manage_Panel = Openshift Cluster Manage Panel
Expand Down Expand Up @@ -110,6 +115,7 @@ Create_an_OpenShift_cluster = Create an OpenShift cluster
Advanced = Advanced
Create New Flavor = Create New Flavor
Create New Registry = Create New Registry
Create New Floating Ip = Create New Floating Ip
Address = Address
Type = Type
Expand Down Expand Up @@ -213,6 +219,8 @@ Instance Deletion = Instance Deletion
Instance_Deletion_Confirm = This instance is going to be deleted permanently, do you want to continue?
Flavor Deletion = Flavor Deletion
Flavor_Deletion_Confirm = This flavor is going to be deleted permanently, do you want to continue?
Registry Deletion = Registry Deletion
Registry_Deletion_Confirm = This registry is going to be deleted permanently, do you want to continue?
FloatingIP Deletion = FloatingIP Deletion
FloatingIP_Deletion_Confirm = This floating ip is going to be deleted permanently, do you want to continue?
Gateway Deletion = Gateway Deletion
Expand Down Expand Up @@ -270,4 +278,4 @@ additionalTrustBundle = additionalTrustBundle
imageContentSources = imageContentSources
Default Username = Default Username
Default Username = Default Username
14 changes: 11 additions & 3 deletions web/clui/conf/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Worker_Flavor = Worker配置
Worker Flavor = Worker�蔭
Console = �批��
Images = ��
Registry = 隞�
Volumes = ��
Platform_Service = 撟喳 = �
Openshift = Openshift
Expand Down Expand Up @@ -77,12 +78,16 @@ HyperID = 标识
ParentID = �嗆�霂�
Children = 銝漣��
Console = �批��
Label = �妍
OcpVersion = Ocp�
RegistryContent = �蔭�捆

User_Manage_Panel = �冽蝞∠��X
Organization_Manage_Panel = 蝏�蝞∠��X
Key_Manage_Panel = 撖蝞∠��X
Instance_Manage_Panel = 摰�蝞∠��X
Flavor_Manage_Panel = 配置管理面板
Flavor_Manage_Panel = �蔭蝞∠��X�
Registry_Manage_Panel = Registry Manage Panel
Image_Manage_Panel = ��蝞∠��X
Volume_Manage_Panel = �瑞恣���
Openshift_Cluster_Manage_Panel = Openshift�黎蝞∠��X
Expand All @@ -109,7 +114,8 @@ Use_your_instance_content = 其中用户名对应于CentOS, CoreOS, 和Ubuntu镜
Create_an_OpenShift_cluster = �遣OpenShift�黎
Advanced = 擃漣

Create New Flavor = 创建新的配置
Create New Flavor = �遣�啁���
Create New Registry = �遣�啁�隞�
Create New Floating Ip = �遣�啁�瘚桀IP
Address = �啣�
Type = 蝐餃�
Expand Down Expand Up @@ -212,7 +218,9 @@ No = 否
Instance Deletion = 摰��
Instance_Deletion_Confirm = 甇文�靘�鋡急偶銋��歹�蝖桀�蝏抒賒嚗�
Flavor Deletion = �蔭�
Flavor_Deletion_Confirm = 此配置将被永久删除,确定继续?
Flavor_Deletion_Confirm = 甇日�蝵桀�鋡急偶銋��歹�蝖桀�蝏抒賒�
Registry Deletion = Registry Deletion
Registry_Deletion_Confirm = This registry is going to be deleted permanently, do you want to continue?�
FloatingIP Deletion = 瘚桀IP�
FloatingIP_Deletion_Confirm = 甇斗筑�沉P撠◤瘞訾��嚗&摰誧蝏哨�
Gateway Deletion = 蝵�
Expand Down
22 changes: 22 additions & 0 deletions web/clui/model/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright <holder> All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package model

import (
"github.com/IBM/cloudland/web/sca/dbs"
)

type Registry struct {
Model
Label string `gorm:"type:varchar(128)"`
OcpVersion string `gorm:"type:varchar(128)"`
RegistryContent string `gorm:"type:varchar(128)"`
}

func init() {
dbs.AutoMigrate(&Registry{})
}
2 changes: 1 addition & 1 deletion web/clui/routes/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (a *InstanceAdmin) Create(ctx context.Context, count int, prefix, userdata
}
}
}
hyperGroup, err := instanceAdmin.getHyperGroup(image.HypervisorType, zoneID)
hyperGroup, err := instanceAdmin.getHyperGroup(image.VirtType, zoneID)
if err != nil {
log.Println("No valid hypervisor", err)
return
Expand Down
190 changes: 190 additions & 0 deletions web/clui/routes/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*
Copyright <holder> All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package routes

import (
"fmt"
"log"
"net/http"

"github.com/IBM/cloudland/web/clui/model"
"github.com/IBM/cloudland/web/sca/dbs"
"github.com/go-macaron/session"
macaron "gopkg.in/macaron.v1"
)

var (
registryAdmin = &RegistryAdmin{}
registryView = &RegistryView{}
)

type RegistryAdmin struct{}
type RegistryView struct{}

func (a *RegistryAdmin) Create(label, ocpVersion, registryContent string) (registry *model.Registry, err error) {
db := DB()
registry = &model.Registry{
Label: label,
OcpVersion: ocpVersion,
RegistryContent: registryContent,
}
err = db.Create(registry).Error
return
}

func (a *RegistryAdmin) Delete(id int64) (err error) {
db := DB()
db = db.Begin()
defer func() {
if err == nil {
db.Commit()
} else {
db.Rollback()
}
}()
if err = db.Delete(&model.Registry{Model: model.Model{ID: id}}).Error; err != nil {
log.Println("Failed to delete registry", err)
return
}
return
}

func (a *RegistryAdmin) List(offset, limit int64, order, query string) (total int64, registrys []*model.Registry, err error) {
db := DB()
if limit == 0 {
limit = 16
}

if order == "" {
order = "created_at"
}
if query != "" {
query = fmt.Sprintf("label like '%%%s%%'", query)
}

registrys = []*model.Registry{}
if err = db.Model(&model.Registry{}).Where(query).Count(&total).Error; err != nil {
return
}
db = dbs.Sortby(db.Offset(offset).Limit(limit), order)
if err = db.Where(query).Find(&registrys).Error; err != nil {
return
}

return
}

func (v *RegistryView) List(c *macaron.Context, store session.Store) {
offset := c.QueryInt64("offset")
limit := c.QueryInt64("limit")
if limit == 0 {
limit = 16
}
order := c.Query("order")
if order == "" {
order = "-created_at"
}
query := c.QueryTrim("q")
total, registrys, err := registryAdmin.List(offset, limit, order, query)
if err != nil {
if c.Req.Header.Get("X-Json-Format") == "yes" {
c.JSON(500, map[string]interface{}{
"error": err.Error(),
})
return
}
c.Data["ErrorMsg"] = err.Error()
c.HTML(500, "500")
return
}
pages := GetPages(total, limit)
c.Data["Registrys"] = registrys
c.Data["Total"] = total
c.Data["Pages"] = pages
c.Data["Query"] = query
if c.Req.Header.Get("X-Json-Format") == "yes" {
c.JSON(200, map[string]interface{}{
"registrys": registrys,
"total": total,
"pages": pages,
"query": query,
})
return
}
c.HTML(200, "registrys")
}

func (v *RegistryView) Delete(c *macaron.Context, store session.Store) (err error) {
memberShip := GetMemberShip(c.Req.Context())
permit := memberShip.CheckPermission(model.Admin)
if !permit {
log.Println("Not authorized for this operation")
c.Data["ErrorMsg"] = "Not authorized for this operation"
c.HTML(http.StatusBadRequest, "error")
return
}
id := c.ParamsInt64("id")
if id <= 0 {
c.Data["ErrorMsg"] = "id <= 0"
c.HTML(http.StatusBadRequest, "error")
return
}
err = registryAdmin.Delete(id)
if err != nil {
c.Data["ErrorMsg"] = err.Error()
c.HTML(http.StatusBadRequest, "error")
return
}
c.JSON(200, map[string]interface{}{
"redirect": "registrys",
})
return
}

func (v *RegistryView) New(c *macaron.Context, store session.Store) {
memberShip := GetMemberShip(c.Req.Context())
permit := memberShip.CheckPermission(model.Admin)
if !permit {
log.Println("Not authorized for this operation")
c.Data["ErrorMsg"] = "Not authorized for this operation"
c.HTML(http.StatusBadRequest, "error")
return
}
c.HTML(200, "registrys_new")
}

func (v *RegistryView) Create(c *macaron.Context, store session.Store) {
memberShip := GetMemberShip(c.Req.Context())
permit := memberShip.CheckPermission(model.Admin)
if !permit {
log.Println("Not authorized for this operation")
c.Data["ErrorMsg"] = "Not authorized for this operation"
c.HTML(http.StatusBadRequest, "error")
return
}
redirectTo := "../registrys"
label := c.Query("label")
ocpVersion := c.Query("ocpversion")
registryContent := c.Query("registrycontent")
registry, err := registryAdmin.Create(label, ocpVersion, registryContent)
if err != nil {
log.Println("Create registry failed", err)
if c.Req.Header.Get("X-Json-Format") == "yes" {
c.JSON(500, map[string]interface{}{
"error": err.Error(),
})
return
}
c.HTML(500, "500")
return
} else if c.Req.Header.Get("X-Json-Format") == "yes" {
c.JSON(200, registry)
return
}
c.Redirect(redirectTo)
}
4 changes: 4 additions & 0 deletions web/clui/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func New() (m *macaron.Macaron) {
m.Get("/flavors/new", flavorView.New)
m.Post("/flavors/new", flavorView.Create)
m.Delete("/flavors/:id", flavorView.Delete)
m.Get("/registrys", registryView.List)
m.Get("/registrys/new", registryView.New)
m.Post("/registrys/new", registryView.Create)
m.Delete("/registrys/:id", registryView.Delete)
m.Get("/images", imageView.List)
m.Get("/images/new", imageView.New)
m.Post("/images/new", imageView.Create)
Expand Down
5 changes: 5 additions & 0 deletions web/clui/templates/_left.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<a {{ if eq .Link "/images" }} class="active item" {{ else }} class="item" {{ end }} href="/images">
{{.i18n.Tr "Images"}}
</a>
{{ if $.IsAdmin }}
<a {{ if eq .Link "/registrys" }} class="active item" {{ else }} class="item" {{ end }} href="/registrys">
{{.i18n.Tr "Registry"}}
</a>
{{ end }}
<div class="header item">{{.i18n.Tr "Platform_Service"}}</div>
<a {{ if eq .Link "/openshifts" }} class="active item" {{ else }} class="item" {{ end }} href="/openshifts">
{{.i18n.Tr "Openshift"}}
Expand Down
4 changes: 2 additions & 2 deletions web/clui/templates/images.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
<td><span title="Tue, 18 Dec 2018 14:24:59 &#43;0800">{{.CreatedAt}}</span></td>
<td>{{.OsVersion}}</td>
<td>
{{ if eq .HypervisorType "zkvm" }}
{{ if eq .VirtType "zkvm" }}
KVM on Z
{{ else }}
{{ if eq .HypervisorType "zvm" }}
{{ if eq .VirtType "zvm" }}
z/VM
{{ else }}
KVM on x86-64
Expand Down
6 changes: 3 additions & 3 deletions web/clui/templates/instances_new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@
{{ if eq .Status "available" }}

<div class="item" data-value={{.ID}} data-text={{.Name}}>
{{ if eq .HypervisorType "zvm" }}
{{ if eq .VirtType "zvm" }}

{{.Name}} for z/VM

{{ else if eq .HypervisorType "zkvm" }}
{{ else if eq .VirtType "zkvm" }}

{{.Name}} for KVM on Z

{{ else if eq .HypervisorType "xkvm" }}
{{ else if eq .VirtType "xkvm" }}

{{.Name}} for KVM on x86-64

Expand Down
Loading

0 comments on commit 4c0a957

Please sign in to comment.