-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from cneira/v1.2
V1.2
- Loading branch information
Showing
43 changed files
with
308 additions
and
7,174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
/* Firecracker-task-driver is a task driver for Hashicorp's nomad that allows | ||
* to create microvms using AWS Firecracker vmm | ||
* Copyright (C) 2019 Carlos Neira [email protected] | ||
* | ||
* | ||
* This file is part of Firecracker-task-driver. | ||
* | ||
* | ||
* Foobar is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* | ||
* Firecracker-task-driver is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Firecracker-task-driver. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
@@ -84,18 +84,19 @@ func taskConfig2FirecrackerOpts(taskConfig TaskConfig, cfg *drivers.TaskConfig) | |
opts.Debug = true | ||
opts.FcLogLevel = "Debug" | ||
} | ||
if taskConfig.Vcpus > 0 { | ||
opts.FcCPUCount = int64(taskConfig.Vcpus) | ||
|
||
if cfg.Resources.NomadResources.Cpu.CpuShares > 100 { | ||
opts.FcCPUCount = cfg.Resources.NomadResources.Cpu.CpuShares / 100 | ||
} else { | ||
opts.FcCPUCount = int64(1) | ||
opts.FcCPUCount = 1 | ||
} | ||
opts.FcCPUTemplate = taskConfig.Cputype | ||
opts.FcDisableHt = taskConfig.DisableHt | ||
|
||
if taskConfig.Mem > 0 { | ||
opts.FcMemSz = int64(taskConfig.Mem) | ||
if cfg.Resources.NomadResources.Memory.MemoryMB > 0 { | ||
opts.FcMemSz = cfg.Resources.NomadResources.Memory.MemoryMB | ||
} else { | ||
opts.FcMemSz = int64(512) | ||
opts.FcMemSz = 300 | ||
} | ||
opts.FcBinary = taskConfig.Firecracker | ||
|
||
|
@@ -112,11 +113,12 @@ type Instance_info struct { | |
Ip string | ||
Serial string | ||
Pid string | ||
Vnic string | ||
} | ||
|
||
func (d *Driver) initializeContainer(ctx context.Context, cfg *drivers.TaskConfig, taskConfig TaskConfig) (*vminfo, error) { | ||
opts, _ := taskConfig2FirecrackerOpts(taskConfig, cfg) | ||
fcCfg, err := opts.getFirecrackerConfig() | ||
fcCfg, err := opts.getFirecrackerConfig(cfg.AllocID) | ||
if err != nil { | ||
log.Errorf("Error: %s", err) | ||
return nil, err | ||
|
@@ -196,27 +198,30 @@ func (d *Driver) initializeContainer(ctx context.Context, cfg *drivers.TaskConfi | |
return nil, fmt.Errorf("Failed getting pid for machine: %v", errpid) | ||
} | ||
var ip string | ||
var vnic string | ||
if len(opts.FcNetworkName) > 0 { | ||
ip = fcCfg.NetworkInterfaces[0].StaticConfiguration.IPConfiguration.IPAddr.String() | ||
vnic = fcCfg.NetworkInterfaces[0].CNIConfiguration.IfName + "vm" | ||
} else { | ||
ip = "No network chosen" | ||
vnic = ip | ||
} | ||
info := Instance_info{Serial: ftty, AllocId: cfg.AllocID, | ||
Ip: ip, | ||
Pid: strconv.Itoa(pid)} | ||
Pid: strconv.Itoa(pid), Vnic: vnic} | ||
|
||
f, _ := json.MarshalIndent(info, "", " ") | ||
|
||
logfile := fmt.Sprintf("/tmp/%s-%s", cfg.Name, cfg.AllocID) | ||
|
||
d.logger.Info("Writing to", "driver_initialize_container", hclog.Fmt("%v+", logfile)) | ||
log, err := os.OpenFile(logfile,os.O_CREATE|os.O_APPEND|os.O_WRONLY,0644) | ||
log, err := os.OpenFile(logfile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Failed creating info file=%s err=%v", logfile, err) | ||
} | ||
defer log.Close() | ||
fmt.Fprintf(log,"%s",f) | ||
fmt.Fprintf(log, "%s", f) | ||
|
||
return &vminfo{Machine: m, tty: ftty, Info: info}, nil | ||
} |
Oops, something went wrong.