Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ func main() {
panic(err)
}
printCores(contextStruct.Cores)
// cmsClient := service.NewCmsClient()
// addrResp := cmsClient.NewCmsSubnet("20.20.22.")
// fmt.Printf("%s\n", addrResp.IP)
// fmt.Printf("%s\n", addrResp.MacAddr)
// fmt.Printf("%s\n", addrResp.SdnUUID)

go func() {
err := api.Server(contextStruct.Config.Port, &contextStruct, rdb)
Expand Down
54 changes: 0 additions & 54 deletions request/guacamole.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package request

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -83,56 +82,3 @@ func (c *GuacamoleClient) Authenticate(ctx context.Context, username, password s

return nil
}

func (c *GuacamoleClient) doRequest(ctx context.Context, method, path string, requestBody, responseBody interface{}) error {
log := util.GetLogger()

var reqBodyReader io.Reader
if requestBody != nil {
jsonData, err := json.Marshal(requestBody)
if err != nil {
return fmt.Errorf("failed to marshal request body: %w", err)
}

log.Println("(-> Guacamole) request body:", string(jsonData))
reqBodyReader = bytes.NewBuffer(jsonData)
}

requestURL := c.baseURL + path
if c.authToken != "" {
if strings.Contains(path, "?") {
requestURL += "&token=" + c.authToken
} else {
requestURL += "?token=" + c.authToken
}
}

req, err := http.NewRequestWithContext(ctx, method, requestURL, reqBodyReader)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}

if requestBody != nil {
req.Header.Set("Content-Type", "application/json")
}

resp, err := c.client.Do(req)
if err != nil {
return fmt.Errorf("failed to send request: %w", err)
}
//goland:noinspection GoUnhandledErrorResult
defer resp.Body.Close()

if resp.StatusCode < 200 || resp.StatusCode >= 300 {
bodyBytes, _ := io.ReadAll(resp.Body)
return fmt.Errorf("unexpected status code: %d, body: %s", resp.StatusCode, string(bodyBytes))
}

if responseBody != nil {
if err := json.NewDecoder(resp.Body).Decode(responseBody); err != nil {
return fmt.Errorf("failed to decode response body: %w", err)
}
}

return nil
}
3 changes: 3 additions & 0 deletions request/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type ErrorDescriptor struct {

type VirError string

// 현재 미사용중
// 코어랑 에러 타입 맞출려고 짯던 코드같은데
// 이것도 다시 확인 필요
const (
FaildDeEncoding VirError = "Error Not Found"
DomainSearchError VirError = "Error Searching Domain"
Expand Down
1 change: 0 additions & 1 deletion request/ssh.go

This file was deleted.

3 changes: 3 additions & 0 deletions request/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (c *CoreClient) DeleteVM(context context.Context, req model.DeleteVMRequest
return response, nil
}

// 현재 미사용 중
// 코어 vcpu 갯수 가져오는 함수
// 코어에 문의 해봐야함 옛날에 구현 안됬다고 해서 컨트롤에서 9999로 하드코딩 했던거 같음
func (c *CoreClient) GetCoreMachineCpuInfo(context context.Context) (*model.CoreMachineCpuInfoResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서비스는 구현이 되어있을텐데, 현재 개발환경이 없어서 바로 가져다 쓸 수 있을지는 검증해봐야 됩니당.
그떄 알려드릴게요

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#27 (comment)
<-- 여기 구현되어 있다고 하네요. 참고바랍니다

var response model.CoreResponse[model.CoreMachineCpuInfoResponse]
err := c.doRequest(context, http.MethodGet, "/getStatusHost", model.GetMachineStatusRequest{
Expand Down
6 changes: 5 additions & 1 deletion service/core_allocation.go
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
package service
package service

//현재 미사용중
//이거 인스턴스 생성할 때 라운드로빈으로 코어에 할당해주는애 아니었나?
//확인 필요
5 changes: 0 additions & 5 deletions service/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ func CreateVM(w http.ResponseWriter, r *http.Request, contextStruct *vms.Control
}
}

// instanceIp, err := contextStruct.AssignInternalAddress()
// if err != nil {
// log.Error("AssignInternalAddress() failed: %v", err, true)
// return err
// }
var cmsResp *CmsResponse
cmsClient := NewCmsClient()

Expand Down
53 changes: 2 additions & 51 deletions structure/control_infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package structure
import (
"context"
"database/sql"
"fmt"
"net"
"strings"
"time"

"github.com/easy-cloud-Knet/KWS_Control/util"
Expand Down Expand Up @@ -35,54 +32,6 @@ func (c *ControlContext) FindCoreByVmUUID(uuid UUID) *Core {
return &c.Cores[coreIdx]
}

func (c *ControlContext) AssignInternalAddress() (string, error) {
var usedIPs = make(map[string]bool)

// 1. 이미 사용된 IP들을 수집
for _, core := range c.Cores {
for _, vm := range core.VMInfoIdx {
usedIPs[vm.IP_VM] = true
}
}

// 2. 서브넷을 순회하며 IP를 생성
for _, cidr := range c.Config.VmInternalSubnets {
_, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
continue
}

for ip := ipnet.IP.Mask(ipnet.Mask); ipnet.Contains(ip); incrementIP(ip) {
ipStr := ip.String()

if ipStr == ipnet.IP.String() {
continue
}

if strings.HasPrefix(ipStr, "10.5.15.") {
lastOctet := ip[3]
if lastOctet <= 10 {
continue
}
}
if !usedIPs[ipStr] && ipStr != ipnet.IP.String() {
return ipStr, nil
}
}
}

return "", fmt.Errorf("no ip available for allocation")
}

func incrementIP(ip net.IP) {
for i := len(ip) - 1; i >= 0; i-- {
ip[i]++
if ip[i] != 0 {
break
}
}
}

func (contextStructure *ControlContext) AddInstance(instanceInfo *VMInfo, coreIdx int) error {
log := util.GetLogger()
tx, err := contextStructure.DB.Begin()
Expand Down Expand Up @@ -117,6 +66,8 @@ func (contextStructure *ControlContext) AddInstance(instanceInfo *VMInfo, coreId
return tx.Commit()
}

// 현재 미사용중
// 이건 미사용중이면 안되지않나? 인스턴스정보 DB에 업데이트 하는거같은데
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_, err = tx.ExecContext(ctx, "INSERT INTO inst_info (uuid, inst_ip, guac_pass, inst_mem, inst_vcpu, inst_disk) VALUES (?, ?, ?, ?, ?, ?)",

<--- 이 친구랑 로직이 어느정도 겹치는 것 같은데 업데이트 전 db 스키마에서 쓰던 것인지, 확인하면 될 것 같아요

func (contextStructure *ControlContext) UpdateInstance(instanceInfo *VMInfo) error {
log := util.GetLogger()
tx, err := contextStructure.DB.Begin()
Expand Down