Skip to content

[WIP]: Rewritting to use boto3 #1186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
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: 5 additions & 0 deletions nix/ec2-keypair.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ with lib;
description = "AWS region.";
};

profile = mkOption {
type = types.str;
description = "Name of the profile.";
};

accessKeyId = mkOption {
default = "";
type = types.str;
Expand Down
11 changes: 11 additions & 0 deletions nix/ec2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ in

options = {

deployment.ec2.profile = mkOption {
default = null;
example = "dev-Administrator";
type = types.str;
description = ''
The profile name as defined in <filename>~/.aws/config</filename>
If left empty it will be left to boto to decide, which means it will
check <envvar>AWS_PROFILE</envvar> and use "default".
'';
};

deployment.ec2.accessKeyId = mkOption {
default = "";
example = "AKIABOGUSACCESSKEY";
Expand Down
28 changes: 19 additions & 9 deletions nixops/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import os
import re
import subprocess

import nixops.util
from typing import List

import nixops.resources
import nixops.ssh_util
import nixops.util


class MachineDefinition(nixops.resources.ResourceDefinition):
"""Base class for NixOps machine definitions."""
Expand Down Expand Up @@ -114,13 +118,16 @@ def get_load_avg(self):
def check(self):
"""Check machine state."""
res = CheckResult()
self._check(res)
self._machine_check(res)
return res

def _check(self, res):
def _machine_check(self, res):
# type: (CheckResult) -> None

avg = self.get_load_avg()
if avg == None:
if self.state == self.UP: self.state = self.UNREACHABLE
if avg is None:
if self.state == self.UP:
self.state = self.UNREACHABLE
res.is_reachable = False
else:
self.state = self.UP
Expand All @@ -136,11 +143,13 @@ def _check(self, res):
res.in_progress_units = []
for l in out:
match = re.match("^([^ ]+) .* failed .*$", l)
if match: res.failed_units.append(match.group(1))
if match:
res.failed_units.append(match.group(1))

# services that are in progress
match = re.match("^([^ ]+) .* activating .*$", l)
if match: res.in_progress_units.append(match.group(1))
if match:
res.in_progress_units.append(match.group(1))

# Currently in systemd, failed mounts enter the
# "inactive" rather than "failed" state. So check for
Expand Down Expand Up @@ -275,6 +284,7 @@ def get_ssh_name(self):
assert False

def get_ssh_flags(self, scp=False):
# type: (bool) -> List[str]
if scp:
return ["-P", str(self.ssh_port)]
else:
Expand Down Expand Up @@ -312,7 +322,7 @@ def wait_for_ssh(self, check=False):

def write_ssh_private_key(self, private_key):
key_file = "{0}/id_nixops-{1}".format(self.depl.tempdir, self.name)
with os.fdopen(os.open(key_file, os.O_CREAT | os.O_WRONLY, 0600), "w") as f:
with os.fdopen(os.open(key_file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as f:
f.write(private_key)
self._ssh_private_key_file = key_file
return key_file
Expand Down
Loading