Skip to content

Commit

Permalink
Merge pull request #130 from kthcloud/dev
Browse files Browse the repository at this point in the history
fix new template after old one mysteriously stopped working
  • Loading branch information
saffronjam authored Aug 3, 2023
2 parents ea90734 + 728ed51 commit 0674c79
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 34 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
repairer := isFlagPassed("repairer")

var options *app.StartOptions
if confirmer || statusUpdater || jobExecutor || repairer {
if confirmer || statusUpdater || jobExecutor || repairer || api {
options = &app.StartOptions{
API: api,
Confirmer: confirmer,
Expand Down
37 changes: 6 additions & 31 deletions pkg/subsystems/cs/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,10 @@ func (client *Client) HasCapacity(vmID, hostName string) (bool, error) {
}

type cloudInit struct {
FQDN string `yaml:"fqdn"`
Users []cloudInitUser `yaml:"users"`
SshPasswordAuth bool `yaml:"ssh_pwauth"`
RunCMD []string `yaml:"runcmd"`
GrowPart cloudInitGrowPart `yaml:"growpart"`
FQDN string `yaml:"fqdn"`
Users []cloudInitUser `yaml:"users"`
SshPasswordAuth bool `yaml:"ssh_pwauth"`
RunCMD []string `yaml:"runcmd"`
}

type cloudInitUser struct {
Expand All @@ -294,47 +293,23 @@ type cloudInitUser struct {
SshAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
}

type cloudInitGrowPart struct {
Mode string `yaml:"mode"`
Devices []string `yaml:"devices"`
IgnoreGrowRootPassword bool `yaml:"ignore_growroot_password"`
}

func createUserData(vmName, userSshPublicKey, adminSshPublicKey string) string {
init := cloudInit{}
init.FQDN = vmName
init.SshPasswordAuth = false
init.RunCMD = []string{
"sudo mkdir /home/deploy",
"sudo /usr/sbin/deploy-init.sh | /home/deploy/deploy-init-result",
}

// imitate mkpasswd --method=SHA-512 --rounds=4096
passwd := hashPassword("root", generateSalt())

init.Users = append(init.Users, cloudInitUser{
Name: "cloud",
Sudo: []string{"ALL=(ALL) NOPASSWD:ALL"},
Passwd: passwd,
LockPasswd: true,
Shell: "/bin/bash",
SshAuthorizedKeys: []string{userSshPublicKey},
})

init.Users = append(init.Users, cloudInitUser{
Name: "deploy",
Name: "root",
Sudo: []string{"ALL=(ALL) NOPASSWD:ALL"},
Passwd: passwd,
LockPasswd: true,
Shell: "/bin/bash",
SshAuthorizedKeys: []string{adminSshPublicKey},
SshAuthorizedKeys: []string{userSshPublicKey, adminSshPublicKey},
})

init.GrowPart = cloudInitGrowPart{
Mode: "auto",
Devices: []string{"/dev/vda3"},
}

// marshal the struct to yaml
data, err := yaml.Marshal(init)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion service/vm_service/internal_service/cs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func CreateCS(params *vmModel.CreateParams) (*CsCreated, error) {
// vm
csVM := &vm.Subsystems.CS.VM
if !csVM.Created() {
public := createCsVmPublic(params.Name, serviceOffering.ID, "2b17786b-0a4c-4c51-8a59-39c9042b6155", createDeployTags(params.Name, params.Name))
temporaryTemplateID := "cbac58b6-336b-49ab-b4d7-341586dfefcc"
public := createCsVmPublic(params.Name, serviceOffering.ID, temporaryTemplateID, createDeployTags(params.Name, params.Name))

csVM, err = createCsVM(client, vm, public, userSshPublicKey, adminSshPublicKey)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion service/vm_service/vm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func GetConnectionString(vm *vmModel.VM) (*string, error) {
return nil, nil
}

connectionString := fmt.Sprintf("ssh cloud@%s -p %d", domainName, port)
connectionString := fmt.Sprintf("ssh root@%s -p %d", domainName, port)

return &connectionString, nil
}
Expand Down

0 comments on commit 0674c79

Please sign in to comment.