Esempio n. 1
0
    def test_user_variable(self):
        var = UserVar("MY_TEST_USER", "testValue")

        assert var.title == "MY_TEST_USER"
        assert var.data == "testValue"
        assert var.ref().data == "{{user `MY_TEST_USER`}}"
        assert Ref(var).data == "{{user `MY_TEST_USER`}}"
Esempio n. 2
0
    def test_environment_variable(self):
        var = EnvVar("MY_TEST_ENV")

        assert var.title == "my_test_env"
        assert var.data == "{{env `MY_TEST_ENV`}}"
        assert var.ref().data == "{{user `my_test_env`}}"
        assert Ref(var).data == "{{user `my_test_env`}}"
Esempio n. 3
0
    def test_environment_variable_name_specified(self):
        var = EnvVar("my_other_name", "MY_TEST_ENV")

        assert var.title == "my_other_name"
        assert var.data == "{{env `MY_TEST_ENV`}}"
        assert var.ref().data == "{{user `my_other_name`}}"
        assert Ref(var).data == "{{user `my_other_name`}}"
Esempio n. 4
0
class TestPacker(unittest.TestCase):

    aws_access_key = UserVar("aws_access_key", "")
    aws_secret_key = UserVar("aws_secret_key", "")
    user_variables = [aws_access_key, aws_secret_key]
    builders = [
        builder.AmazonEbs(access_key=Ref(aws_access_key),
                          secret_key=Ref(aws_secret_key),
                          region="us-east-1",
                          source_ami_filter=builder.AmazonSourceAmiFilter(
                              filters={
                                  "virtualization-type": "hvm",
                                  "name":
                                  "*ubuntu-xenial-16.04-amd64-server-*",
                                  "root-device-type": "ebs"
                              },
                              owners=["099720109477"],
                              most_recent=True),
                          instance_type="t2.micro",
                          ami_name="packer-example {{timestamp}}",
                          ssh_username="******")
    ]
    template = Template()
    template.add_variable(user_variables)
    template.add_builder(builders)

    def test_validate(self):
        output = packer.validate(TestPacker.template)
        assert output.return_code == 0
        assert "successfully" in output.output

    def test_build(self):
        output = packer.build(TestPacker.template)
        assert output.return_code == 0
        assert "successful" in output.output

    def test_inspect(self):
        output = packer.inspect(TestPacker.template)
        assert output.return_code == 0
Esempio n. 5
0
	iso_url,
	locale,
	memory,
	UserVar("preseed","desktop.cfg"),
	ssh_password,
	ssh_username,
	time_zone,
	user_uid,
        UserVar("vm_name","ubuntu1804-desktop-base")
        ]

builders = [
	builder.VirtualboxIso(
                
		boot_command = [
			Ref(boot_command_prefix),
			"/install/vmlinuz",
                        " noapic",
                        " initrd=/install/initrd.gz",
			" debian-installer/locale=" + Ref(locale).data,
                        " debian-installer/language=en",
                        " debian-installer/country=NZ",
                        " auto",
                        " kbd-chooser/method=us",
                        " hostname=" + Ref(hostname).data,
			" grub-installer/bootdev=/dev/sda<wait>",
                        " fb=false",
                        " debconf/frontend=noninteractive",
			" keyboard-configuration/modelcode=SKIP",
                        " keyboard-configuration/layout=USA",
                        " keyboard-configuration/variant=USA",
# https://www.packer.io/intro/getting-started/build-image.html#the-template
from packerlicious import builder, Ref, Template, UserVar

aws_access_key = UserVar("aws_access_key", "")
aws_secret_key = UserVar("aws_secret_key", "")
user_variables = [aws_access_key, aws_secret_key]

builders = [
    builder.AmazonEbs(access_key=Ref(aws_access_key),
                      secret_key=Ref(aws_secret_key),
                      region="us-east-1",
                      source_ami_filter=builder.AmazonSourceAmiFilter(
                          filters={
                              "virtualization-type": "hvm",
                              "name": "*ubuntu-xenial-16.04-amd64-server-*",
                              "root-device-type": "ebs"
                          },
                          owners=["099720109477"],
                          most_recent=True),
                      instance_type="t2.micro",
                      ami_name="packer-example {{timestamp}}",
                      ssh_username="******")
]

t = Template()
t.add_variable(user_variables)
t.add_builder(builders)

t.to_json()
Esempio n. 7
0
    def test_packer_variable(self):
        var = PackerVariable("{{timestamp}}")

        assert var.data == "{{timestamp}}"
        assert var.ref().data.data == "{{timestamp}}"
        assert Ref(var).data.data == "{{timestamp}}"
Esempio n. 8
0
    def test_template_variable(self):
        var = TemplateVar("MY_TEST_TEMPLATE")

        assert var.data == "MY_TEST_TEMPLATE"
        assert var.ref().data == "{{.MY_TEST_TEMPLATE}}"
        assert Ref(var).data == "{{.MY_TEST_TEMPLATE}}"
Esempio n. 9
0
from dotenv import load_dotenv
load_dotenv()

import os
token = os.environ.get("cloud_token")

cloud_token = UserVar("cloud_token", token)

user_variables = [cloud_token]

builders = [builder.Null(communicator="none")]

post_processors = [[
    post_processor.Artifice(files=["builds/ubuntu1804-desktop-base.box"]),
    post_processor.VagrantCloud(box_tag="catosplace/ubuntu1804-desktop-base",
                                access_token=Ref(cloud_token),
                                version="1.0.2"),
    #post_processor.Checksum(
    #    checksum_types = [ "md5", "sha1", "sha256" ]
    #),
]]

t = Template()
t.add_variable(user_variables)
t.add_builder(builders)
t.add_post_processor(post_processors)

print(t.to_json())

(ret, out,
 err) = PackerExecutable(machine_readable=False).validate(t.to_json())