예제 #1
0
    def pre_check(self):
        """
        Check that security config exists and that lD library is importable
        """
        import kavedeploy as lD
        import kaveaws as lA

        lD.debug = self.debug
        lD.strict_host_key_checking = False
        import os

        if "AWSSECCONF" not in os.environ:
            raise SystemError(
                "You need to set the environment variable AWSSECCONF to point to your security config file before "
                "running this test")
        self.assertTrue(lA.testaws(),
                        "Local aws installation incomplete, try again")
        self.assertTrue(
            len(lA.detect_region()) > 0,
            "Failed to detect aws region, have you run aws configure?")
        import json

        jsondat = open(os.path.expanduser(os.environ["AWSSECCONF"]))
        l = jsondat.read()
        jsondat.close()
        # print l
        security_config = json.loads(l)
        # print lD.checksecjson(security_config)
        self.assertTrue(
            lA.checksecjson(security_config),
            "Security config not readable correctly or does not contain enough keys!"
        )
        if self.branch == "__local__":
            self.branch = lD.run_quiet("bash -c \"cd " +
                                       os.path.dirname(__file__) +
                                       "; git branch | sed -n '/\* /s///p'\"")
        if self.branch == "__service__":
            self.branch = self.service
        if self.branch is not None:
            stdout = lD.run_quiet("bash -c 'cd " + os.path.dirname(__file__) +
                                  "; git branch -r;'")
            self.assertTrue(
                "origin/" + self.branch
                in [s.strip() for s in stdout.split()
                    if len(s.strip())], "There is no remote branch called " +
                self.branch + " push your branch back to the origin "
                "to run this automated test")
        return lD
예제 #2
0
    def pre_check(self):
        """
        Check that security config exists and that lD library is importable
        """
        import kavedeploy as lD
        import kaveaws as lA

        lD.debug = self.debug
        lD.strict_host_key_checking = False
        import os

        if "AWSSECCONF" not in os.environ:
            raise SystemError(
                "You need to set the environment variable AWSSECCONF to point to your security config file before "
                "running this test")
        self.assertTrue(lA.testaws(), "Local aws installation incomplete, try again")
        self.assertTrue(len(lA.detect_region()) > 0, "Failed to detect aws region, have you run aws configure?")
        import json

        jsondat = open(os.path.expanduser(os.environ["AWSSECCONF"]))
        l = jsondat.read()
        jsondat.close()
        # print l
        security_config = json.loads(l)
        # print lD.checksecjson(security_config)
        self.assertTrue(lA.checksecjson(security_config),
                        "Security config not readable correctly or does not contain enough keys!")
        if self.branch == "__local__":
            self.branch = lD.run_quiet(
                "bash -c \"cd " + os.path.dirname(__file__) + "; git branch | sed -n '/\* /s///p'\"")
        if self.branch == "__service__":
            self.branch = self.service
        if self.branch is not None:
            stdout = lD.run_quiet("bash -c 'cd " + os.path.dirname(__file__) + "; git branch -r;'")
            self.assertTrue("origin/" + self.branch in [s.strip() for s in stdout.split() if len(s.strip())],
                            "There is no remote branch called " + self.branch + " push your branch back to the origin "
                                                                                "to run this automated test")
        return lD
            insttype = sys.argv[4]
    else:
        if "AWSSECCONF" not in os.environ:
            help()
            raise IOError("please specify security config file or set AWSSECCONF environment variable!")
        secf = os.path.expanduser(os.environ["AWSSECCONF"])
        if len(sys.argv) > 3:
            insttype = sys.argv[3]
    return osval, macname, secf, insttype


osval, machinename, secf, instancetype = parse_opts()
jsondat = open(secf)
security_config = json.loads(jsondat.read())
jsondat.close()
lA.checksecjson(security_config, requirekeys=["AWS"])

security_group = security_config["SecurityGroup"]
keypair = security_config["AccessKeys"]["AWS"]["KeyName"]
keyloc = security_config["AccessKeys"]["AWS"]["KeyFile"]
subnet = None

if "Subnet" in security_config:
    subnet = security_config["Subnet"]

lA.testaws()

if lD.detect_proxy() and lD.proxy_blocks_22:
    raise SystemError(
        "This proxy blocks port 22, that means you can't ssh to your machines to do the initial configuration. To "
        "skip this check set kavedeploy.proxy_blocks_22 to false and kavedeploy.proxy_port=22")
예제 #4
0
    return (ip, iid, otherargs[2], dest_type)


if __name__ == "__main__":
    ip, iid, security_conf, dest_type = parse_opts()
    # only needed in main function
    installfrom = os.path.realpath(os.sep.join(__file__.split(os.sep)[:-1]))
    liblocation = os.path.realpath(installfrom)
    jsondat = open(os.path.expanduser(security_conf))
    security_config = json.loads(jsondat.read())
    jsondat.close()
    sys.path.append(liblocation)
    import kavedeploy as lD
    import kaveaws as lA

    lA.checksecjson(security_config, requirefield=[], requirekeys=["SSH"])
    if ip is None:
        lA.testaws()
        ip = lA.pub_ip(iid)
    git = False
    gitenv = None
    if lD.detect_proxy():
        print "Did you already configure this machine to access port " + str(
            lD.proxy_port) + "? If not you'll need to turn your proxy off."
    lD.testproxy()
    remote = lD.remoteHost('root', ip, security_config["AccessKeys"]["SSH"]["KeyFile"])
    if "GIT" in security_config["AccessKeys"]:
        git = True
        gitenv = security_config["AccessKeys"]["GIT"]
    lD.deploy_our_soft(remote, pack="kavetoolbox", git=git,
                       gitenv=gitenv, options='--' + dest_type)
예제 #5
0
            "please specify keyfile or set AWSSECCONF environment variable!")
    keyfile = os.path.expanduser(os.environ["AWSSECCONF"])

import kavedeploy as lD

lD.debug = verbose
lD.testproxy()
import kaveaws as lA

import json

try:
    jsondat = open(keyfile)
    security_config = json.loads(jsondat.read())
    jsondat.close()
    lA.checksecjson(security_config, requirekeys=["AWS"])
    keyfile = security_config["AccessKeys"]["AWS"]["KeyFile"]
except:
    pass

if not os.path.exists(os.path.expanduser(keyfile)):
    raise IOError("That is not a valid keyfile!", keyfile)
if "------" not in lD.run_quiet("ls -l " + keyfile):
    raise IOError("Your private keyfile " + keyfile +
                  " needs to have X00 permissions (400 or 600).")

print "Choose instance ID from:"
iidtoip = {}
nametoip = {}
ips = []
예제 #6
0
if len(sys.argv) == 2:
    keyfile = sys.argv[1]
else:
    if "AWSSECCONF" not in os.environ:
        print __doc__
        raise IOError(
            "please specify keyfile or set AWSSECCONF environment variable!")
    keyfile = os.path.expanduser(os.environ["AWSSECCONF"])

import json

jsondat = open(keyfile)
security_config = json.loads(jsondat.read())
jsondat.close()
lA.checksecjson(security_config)
amazon_keypair_name = security_config["AccessKeys"]["AWS"]["KeyName"]
subnet = security_config["Subnet"]

existing_sn = lA.runawstojson(
    "ec2 describe-subnets")  # "GroupId": "sg-c7c322b1"

found = False
for existing in existing_sn["Subnets"]:
    if existing["SubnetId"] == subnet:
        found = True
        break
if not found:
    raise ValueError("no such subnet " + sn)

# find all instances in the subgroup/subnet
예제 #7
0
if len(sys.argv) > 3:
    print __doc__
    raise ValueError("Only two arguements allowed! The keyfile/security config and the hours")

if not len(keyfile):
    if "AWSSECCONF" not in os.environ:
        print __doc__
        raise IOError("please specify keyfile or set AWSSECCONF environment variable!")
    keyfile = os.path.expanduser(os.environ["AWSSECCONF"])


jsondat = open(keyfile)
security_config = json.loads(jsondat.read())
jsondat.close()
lA.checksecjson(security_config)
amazon_keypair_name = security_config["AccessKeys"]["AWS"]["KeyName"]
subnet = security_config["Subnet"]

existing_sn = lA.runawstojson("ec2 describe-subnets")  # "GroupId": "sg-c7c322b1"

found = False
for existing in existing_sn["Subnets"]:
    if existing["SubnetId"] == subnet:
        found = True
        break
if not found:
    raise ValueError("no such subnet " + subnet)

#
# Find and kill all instances
예제 #8
0
    return (ip, iid, otherargs[2], dest_type)


if __name__ == "__main__":
    ip, iid, security_conf, dest_type = parse_opts()
    # only needed in main function
    installfrom = os.path.realpath(os.sep.join(__file__.split(os.sep)[:-1]))
    liblocation = os.path.realpath(installfrom)
    jsondat = open(os.path.expanduser(security_conf))
    security_config = json.loads(jsondat.read())
    jsondat.close()
    sys.path.append(liblocation)
    import kavedeploy as lD
    import kaveaws as lA

    lA.checksecjson(security_config, requirefield=[], requirekeys=["SSH"])
    if ip is None:
        lA.testaws()
        ip = lA.pub_ip(iid)
    git = False
    gitenv = None
    if lD.detect_proxy():
        print "Did you already configure this machine to access port " + str(
            lD.proxy_port) + "? If not you'll need to turn your proxy off."
    lD.testproxy()
    remote = lD.remoteHost('root', ip,
                           security_config["AccessKeys"]["SSH"]["KeyFile"])
    if "GIT" in security_config["AccessKeys"]:
        git = True
        gitenv = security_config["AccessKeys"]["GIT"]
    lD.deploy_our_soft(remote,