Пример #1
0
    def test_template_builders(self):
        expected_json = """
        {
          "builders": [
            {
              "source": "/source/path",
              "target": "/target/path",
              "type": "file"
            },
            {
              "source": "/source/path",
              "target": "/target/path",
              "type": "file"
            }
          ]
        }
        """

        t = Template()
        t.add_builder([
            builder.File(
                target="/target/path",
                source="/source/path",
            ),
            builder.File(
                target="/target/path",
                source="/source/path",
            )
        ])

        to_json = t.to_json()
        assert to_json == json.dumps(json.loads(expected_json),
                                     sort_keys=True,
                                     indent=2,
                                     separators=(',', ': '))
Пример #2
0
def main():
	"""
	main method.
	"""

	args = get_args()
	
	ami_config_file = args.var_file

	ami_config = get_config(ami_config_file)

	target_ami_name = generate_ami_name(ami_config['ami_name_prefix'])

	print(target_ami_name)

	template = Template()

	template.add_builder(
		builder.AmazonEbs(
			region=ami_config['region'],
			ami_name=target_ami_name,
			instance_type=ami_config['instance_type'],
			source_ami=ami_config['source_ami'],
			ssh_username=ami_config['ssh_username'],
			ami_description=ami_config['ami_description'],
			ami_virtualization_type=ami_config['ami_virtualization_type'],
			force_deregister=ami_config['force_deregister'],
			shutdown_behavior=ami_config['shutdown_behavior'],
			vpc_id=ami_config['vpc_id'],
			subnet_id=ami_config['subnet_id'],
			ssh_private_key_file=ami_config['ssh_private_key_file'],
			ssh_keypair_name=ami_config['ssh_keypair_name'],
			security_group_id=ami_config['security_group_id'],
		)
	)

	template.add_provisioner(
		provisioner.Ansible(
			playbook_file=ami_config['playbook_name'],
			command=ami_config['cmd_ansible'],
			user=ami_config['ssh_username'],
		)
	)

	PackerExecutable(machine_readable=False)

	p = PackerExecutable(executable_path=ami_config['cmd_packer'])

	(ret, out, err) = p.build(
		template.to_json(),
	)

	print(out)
	print(err)
Пример #3
0
 def create_template_from_config(self, tag_configs):
     """
     Generate a packer template using configurations.
     :param tag_configs: dict containing the tag details
     :return: template of type packerlicious.Template
     """
     template = Template()
     template.add_builder(
         builder.AmazonEbs(
             access_key="{{user `aws_access_key`}}",
             secret_key="{{user `aws_secret_key`}}",
             region=builder_config.get("region", "ap-southeast-2"),
             instance_type=builder_config.get("type", "t2.micro"),
             ssh_username="******",
             ami_name=self.ami_name,
             source_ami="ami-02769748522663066",
             tags=tag_configs))
     template.add_provisioner(provisioner.Shell(script=script_path))
     return template
Пример #4
0
    def test_support_named_builds(self):
        expected_json = """
                {
                  "builders": [
                    {
                      "type": "file",
                      "name": "linuxFileBuilder",
                      "source": "/tmp/source/path",
                      "target": "/tmp/target/path"
                    },
                    {
                      "type": "file",
                      "name": "windowsFileBuilder",
                      "source": "C:/Source/Path",
                      "target": "C:/Target/Path"
                    }
                  ]
                }
                """

        b = [
            builder.File(
                name="linuxFileBuilder",
                source="/tmp/source/path",
                target="/tmp/target/path",
            ),
            builder.File(
                name="windowsFileBuilder",
                source='C:/Source/Path',
                target='C:/Target/Path',
            )
        ]

        t = Template()
        t.add_builder(b)

        to_json = t.to_json()
        assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2,
                                     separators=(',', ': '))
Пример #5
0
    def test_jagged_array_render(self):
        expected_json = """
        {
          "builders": [
            {
              "boot_wait": "10s",
              "floppy_files": [
                ""
              ],
              "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
              "guest_os_type": "Ubuntu_64",
              "http_directory": "",
              "iso_checksum": "sha512",
              "iso_checksum_type": "sha512",
              "iso_url": "",
              "ssh_port": 22,
              "type": "virtualbox-iso",
              "vboxmanage": [
                [
                  "modifyvm", "{{.Name}}", "--memory", "1024"
                ],
                [ 
                  "modifyvm", "{{.Name}}", "--vram", "36"
                ],
                [
                  "modifyvm", "{{.Name}}", "--cpus", "1"
                ]
              ],
              "virtualbox_version_file": ".vbox_version",
              "vm_name": "my_name"
            }
          ]
        }
        """

        t = Template()
        t.add_builder(
            builder.VirtualboxIso(
                boot_wait="10s",
                guest_os_type="Ubuntu_64",
                http_directory="",
                iso_url="",
                iso_checksum_type="sha512",
                iso_checksum="sha512",
                ssh_port=22,
                guest_additions_path="VBoxGuestAdditions_{{.Version}}.iso",
                virtualbox_version_file=".vbox_version",
                vm_name="my_name",
                floppy_files=[""],
                vboxmanage=[
                    "modifyvm {{.Name}} --memory 1024".split(),
                    "modifyvm {{.Name}} --vram 36".split(),
                    "modifyvm {{.Name}} --cpus 1".split()
                ]
                # vboxmanage=[['modifyvm {{.Name}} --memory 1024', "modifyvm {{.Name}} --cpus 1"]]
            ))

        to_json = t.to_json()
        assert to_json == json.dumps(json.loads(expected_json),
                                     sort_keys=True,
                                     indent=2,
                                     separators=(',', ': '))
Пример #6
0
            str(int(current_box_version["version"].split('.')[2]) + 1)

print("Building new catosplace/ubuntu1804-desktop-base box version " + next_box_version)
version = UserVar("version", next_box_version)

post_processors = [
    post_processor.Vagrant(
        output = "builds/ubuntu1804-desktop-base.box",
        include = [
            "info.json"
        ]
    )
]

t = Template()
t.add_variable(desktop_user_variables)
t.add_variable(version)
t.add_builder(builders)
t.add_provisioner(provisioners)
# Move to new script user artifice
#t.add_post_processor(post_processors)

# View Packer Template
print(t.to_json())

(ret, out, err) = PackerExecutable(machine_readable=False).validate(t.to_json())
print(out.decode('unicode_escape'))

(ret, out, err) = PackerExecutable(machine_readable=False).build(t.to_json())
print(out.decode('unicode_escape'))