Skip to content

Commit 0e9c6c2

Browse files
committed
Initial commit.
0 parents  commit 0e9c6c2

File tree

64 files changed

+1583
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1583
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*~
2+
3+
artefacts/
4+
machines/
5+
roles/thydel.patch/
6+
roles/yaegashi.blockinfile/

LICENSE.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Virtualmicromagnetics source code, documentation, and build artefacts are
2+
licensed by the 3-Clause BSD License as follows:
3+
4+
Copyright (c) 2015, Mark Vousden, University of Southampton
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the University of Southampton nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYWRITE OWNERS OR SOFTWARE CONTRIBUTORS BE
22+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27+
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This makefile is the user interface to jobs that the user may wish to carry
2+
# out using virtual machines.
3+
4+
# This target builds a virtual hard disk file containing various open
5+
# micromagnetics simulation technologies and other convenient packages.
6+
full:
7+
ansible-playbook master.yml -c local -i localhost, -v -k --extra-vars="vm_name=virtualmicromagnetics-full playbook=provision_virtualmicromagnetics_full.yml hookbook=hook_virtualmicromagnetics_full.yml extra_resources_dir=guest_resources/"
8+
9+
# This target builds a virtual hard disk file containing various open
10+
# micromagnetics simulation technologies.
11+
lite:
12+
ansible-playbook master.yml -c local -i localhost, -v -k --extra-vars="vm_name=virtualmicromagnetics-lite playbook=provision_virtualmicromagnetics_lite.yml hookbook=hook_virtualmicromagnetics_lite.yml extra_resources_dir=guest_resources/"

README.md

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
Objective
2+
=========
3+
4+
To use virtual machine software VirtualBox and vagrant, and provisioning
5+
software Ansible, to produce an environment suitable for micromagnetic
6+
simulation.
7+
8+
Quick Start
9+
===========
10+
11+
To get started with this repository and creating virtual machines without
12+
understanding the underlying concepts, simply adhere to the "Requirements"
13+
section below and use the Makefile as described in the "How to Use" section
14+
following it.
15+
16+
Just remember that there is no shortcut to work done true and well.
17+
18+
Introduction to Concepts
19+
========================
20+
21+
A number of different concepts interplay in this repository, so a brief
22+
introduction to them is provided here.
23+
24+
Virtual Machines
25+
----------------
26+
27+
A virtual machine is a software that imitates a certain other software (usually
28+
an operating system or environment) on a certain hardware. For our purposes
29+
however, it can be thought of as an operating system running in an operating
30+
system. Virtual machines are useful because they allow software tasks to be
31+
undertaken in precisely defined environments with little repercussion on the
32+
host system they run on. These machines themselves can be described by single
33+
files representing the equivalent of a hard disk of the machine, as well as a
34+
description of the hardware that the virtual machine emulates.
35+
36+
VirtualBox (www.virtualbox.org) is a virtualizer software that can create and
37+
manage virtual machines, and is open source and freely available under the GNU
38+
GPL (https://www.gnu.org/copyleft/gpl.html) at time of writing. It is a
39+
"provider" of virtual machines. Other popular provider software includes VMWare
40+
and KVM.
41+
42+
Vagrant (www.vagrantup.com) is a wrapper around multiple pieces of software. It
43+
provides a command-line interface to the creation and provision of virtual
44+
machines, and provides a framework in which virtual machines can be easily
45+
shared. Most importantly for our purpose, this interfacing can be automated to
46+
generate virtual machines containing an environment without user
47+
intervention. This environment can then be used to complete our objectives. To
48+
specify this environment however, provisioning software is required.
49+
50+
Provisioning
51+
------------
52+
53+
In the context of virtual machines, provisioning is the action of taking an
54+
existing virtual machine, and running select commands on it to result in a
55+
desired end-state. By "state", here we mean how storage is populated with
56+
packages, environment definitions, and more. The user of a provisioner
57+
describes the desired state of the system, and the provisioner makes it so. In
58+
the absence of a provisioner, shell commands can be executed by Vagrant to
59+
specify the state of the system, but for large projects this becomes unwieldy
60+
because focus is placed on the instructions needed to obtain the desired state,
61+
as opposed to the state itself. Since nobody really likes to write large
62+
projects in shell, a provisioner is recommended.
63+
64+
Ansible (www.ansible.com) is a provisioner supported by Vagrant. It uses YAML
65+
syntax to describe plays to run on a remote system to define the
66+
environment. Since the focus is on the end-state of the system, idempotency a
67+
strong design concern, meaning that tasks only need to be run to achieve a
68+
change in the state, and are not run if they do not change the state or obtain
69+
information about it. Plays are described by playbook files, and may contain
70+
many roles; hence the existence of a "roles" directory in this
71+
repository. Roles are a way of breaking down a play into sensible sentence-like
72+
instructions, which in turn contain a number of tasks. Examples of role
73+
descriptions include "Install magpar." and "Configure passwordless SSH for
74+
BitBucket access."
75+
76+
In addition to provisioning virtual machines, Ansible is a general framework
77+
for running instructions to define a state on any machine. This means that
78+
Ansible can be (and is) used by a host to create virtual machines using
79+
vagrant. This is convenient due to its inherent idempotency; a virtual machine
80+
need not be created and defined again from scratch if it already exists.
81+
82+
Tying it together
83+
-----------------
84+
85+
To conclude, virtual machines are created in this repository to produce build
86+
artefacts. Ansible is used to define the state of virtual machines, which are
87+
managed by Vagrant. Vagrant commands VirtualBox to create and internally manage
88+
virtual machines in an automated way. These virtual machines are in turn
89+
provisioned by Ansible to define their internal state. Once this provisioning
90+
has happened, a build artefact is produced according to the desired objective.
91+
92+
Requirements
93+
============
94+
95+
This repository was developed on and designed for use by Ubuntu GNU/Linux, but
96+
should be usable by anyone using GNU/Linux and enough modification and
97+
persistence. The following software are required to use this repository for its
98+
intended purpose:
99+
100+
- 2.6 <= Python < 3.0
101+
> A note for bleeding-edge distribution users like ArchLinux; Ansible
102+
doesn't like Python 3.0. You may need to create a virtualenv
103+
(https://pypi.python.org/pypi/virtualenv) to ensure you are working with
104+
an older python version.
105+
- VirtualBox >= 4.3.28
106+
- Vagrant >= 1.7.2
107+
- Ansible >= 1.9
108+
> available from the python package index (https://pypi.python.org/pypi).
109+
- thydel.patch Ansible role
110+
> command "ansible-galaxy install thydel.patch" with privileges.
111+
- yaegashi.blockinfile Ansible role
112+
> command "ansible-galaxy install yaegashi.blockinfile" with privileges.
113+
- Vagrant-vbguest plugin >= 0.10.0
114+
> command "vagrant plugin install vagrant-vbguest"
115+
116+
The following software is recommended:
117+
118+
- Cowsay
119+
120+
How to Use
121+
==========
122+
123+
Now that you have prepared your host machine by following the "Requirements"
124+
section, you will probably want to build a virtual machine. By way of example,
125+
if you want the full virtualmicromagnetics experience, command:
126+
127+
make full
128+
129+
This Makefile uses the master.yml playbook, which runs the "create_vm"
130+
role. This will create a virtual machine and provision it with the playbook
131+
passed as a command-line argument in the makefile, which should live in the
132+
jobs directory (see "Where things are" below). It will also do some
133+
post-provisioning tasks using the hookbook, again passed as a command-line
134+
argument. The fundamental difference between the playbook and the hookbook is
135+
that the playbook is run on the guest virtual machine by vagrant, and the
136+
hookbook is run on the host machine. Different Makefile targets may place
137+
different build artefacts in the artefacts directory (see 'Where Things Are'
138+
and 'Artefacts').
139+
140+
Artefacts
141+
=========
142+
143+
After running a job from the Makefile, certain build artefacts may be
144+
created. At present only *.vhd (virtual hard disk) files are created, but other
145+
file types could be produced by future jobs. These files are to be used with
146+
virtual machine providers, such as VirtualBox. To use these files with the
147+
VirtualBox GUI, build a "New" machine with an 64 bit Ubuntu OS, and supply as
148+
much RAM as you are able. All virtual machines in this repository are built off
149+
such an operating system.
150+
151+
Where Things Are
152+
================
153+
154+
In order to add jobs, one should edit the Makefile. In order to do that, one
155+
would need to know where things are, hence the purpose of this section. This
156+
repository is structured as follows:
157+
158+
- Makefile: This is the makefile through which all jobs are conducted.
159+
160+
- ansible.cfg and inventory.txt: These files are used by Ansible when the
161+
master.yml playbook is run. They contain configuration information.
162+
163+
- roles/: This directory contains roles (obviously). Each role is given a
164+
subdirectory, and should not overlap. Each role directory contains
165+
tasks, and may also contain the subdirectories:
166+
167+
- vars/ (variable definitions),
168+
- templates/ (files to duplicate to the guest virtual machine),
169+
- meta/ (metadata, such as role dependencies),
170+
- files/ (files used by tasks that aren't covered by the usecases of
171+
templates)
172+
173+
as well as others we haven't thought of yet.
174+
175+
- jobs/: This directory contains playbooks and directories that can be
176+
thought of as jobs in the Makefile. They are either provisioning playbooks,
177+
or post-provisioning hookbooks.
178+
179+
- machines/: This directory is created by the Makefile, and houses the
180+
vagrant environment for each individual virtual machine. The provision
181+
process is recorded to a log file in the machine's directory (for example,
182+
the provision log for the lite build job exists in
183+
machines/virtualmicromagnetics-lite/virtualmicromagnetics-lite.log)
184+
185+
- artefacts/: This directory is created by the Makefile, and houses build
186+
artefacts.
187+
188+
Postamble
189+
=========
190+
191+
See LICENSE.md for licensing details regarding distribution and
192+
liability. These tools are provided by the University of Southampton (Mark
193+
Vousden, Max Albert, Hans Fangohr and others). Neither the University of
194+
Southampton nor the authors assume any responsibility whatsoever for its use by
195+
other parties, and makes no guarantees, expressed or implied, about its
196+
quality, reliability, or any other characteristic.
197+
198+
List of Things to do
199+
====================
200+
201+
- Learn how YAML linebreaks work, and reduce the lengths of lines to <80
202+
characters.
203+
- Make syntax more consistent.

ansible.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[ssh_connection]
2+
ssh_args = -o IdentityFile=~/.vagrant.d/insecure_private_key
3+

guest_resources/welcome.rst

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Welcome to the Virtual Micromagnetics Simulation Environment!
2+
-------------------------------------------------------------
3+
4+
This virtual machine contains a number of distributable software packages that
5+
are often used by the micromagnetic community to simulate relevant
6+
problems. These software can be downloaded from this machine; tarballs are
7+
available in the home directory. Micromagnetic software includes (in no
8+
particular order):
9+
10+
| OOMMF 1.2a5 (The Object Oriented MicroMagnetic Framework): http://math.nist.gov/oommf/
11+
| Documentation: http://math.nist.gov/oommf/doc/
12+
13+
| Nmag 0.2: http://nmag.soton.ac.uk/nmag/
14+
| Documentation: http://nmag.soton.ac.uk/nmag/current/manual/singlehtml/manual.html
15+
16+
| magpar 0.9 (Parallel Finite Element Micromagnetics Package): http://www.magpar.net/
17+
| Documentation: http://www.magpar.net/static/magpar-0.9/doc/html/
18+
19+
For more information about these packages, see their respective websites and
20+
`Examples.html <Examples.html>`_, which walks the prospective user through some
21+
examples and tests where applicable. Users are also encouraged to install their
22+
own simulation packages for use on this machine. To that end, a number of other
23+
software packages have been provided:
24+
25+
| FEniCS 1.5.0: http://fenicsproject.org/
26+
| The FEniCS project is a collection of free software tools with many features for solving differential equations in an automated and efficient manner.
27+
28+
| gmsh 2.8.5: http://geuz.org/gmsh/
29+
| Netgen: http://sourceforge.net/projects/netgen-mesher/files/
30+
| gmsh and Netgen are 3D mesh generators often used for the finite element method in micromagnetic modelling.
31+
32+
Other lower-level tools are installed for convenience, such as paraview, grace,
33+
gnuplot, the IPython (Jupyter) Notebook and more. This machine runs on 64-bit
34+
Ubuntu with Xfce as a desktop environment.
35+
36+
These tools are provided by the University of Southampton (Mark Vousden, Max
37+
Albert, Hans Fangohr and others). Neither the University of Southampton nor the
38+
authors assume any responsibility whatsoever for its use by other parties, and
39+
makes no guarantees, expressed or implied, about its quality, reliability, or
40+
any other characteristic. Please provide feedback about this machine to Mark
41+

inventory.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[local]
2+
127.0.0.1
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
# This Ansible playbook outlines actions taken on the host machine on the
3+
# virtual machine after the virtual machine is provisioned. It is included in
4+
# the create_VM playbook.
5+
6+
- name: Set the location to look for and place build artefacts, and whether or not to clobber the output virtual hard disk file.
7+
set_fact:
8+
artefact_dir: "{{ vm_dir }}/../../artefacts/"
9+
clobber_vhd: false
10+
11+
- name: Ensure that a directory is created for build artefacts.
12+
file:
13+
name={{ artefact_dir }}
14+
state=directory
15+
16+
- name: Get current repository version.
17+
command: git rev-parse HEAD
18+
register: current_revision
19+
20+
- name: Define the name used for output files, sans extension.
21+
set_fact:
22+
output_name: virtualmicromagnetics_full_{{ current_revision.stdout }}
23+
24+
# We can skip the creation of the VHD if it already exists (for
25+
# idempotency). Hence we check for the VHD here and, if it is found, other
26+
# creation tasks are not run. User can override this setting by setting
27+
# clobber_vhd to true.
28+
- name: Determine whether or not the VHD is already built.
29+
stat:
30+
path={{ artefact_dir }}/{{ output_name }}.vhd
31+
register: vhd_status
32+
33+
- name: Create box file using vagrant.
34+
command: vagrant package --output {{ artefact_dir }}/{{ output_name }}.box
35+
chdir={{ vm_dir }}
36+
creates={{ artefact_dir }}/{{ output_name }}.box
37+
when: not vhd_status.stat.exists or (vhd_status.stat.isreg and clobber_vhd)
38+
39+
- name: Extract the virtual machine disk (VMDK) file from the box.
40+
command: tar -xvf {{ output_name }}.box -C {{ artefact_dir }} ./box-disk1.vmdk
41+
chdir={{ artefact_dir }}
42+
creates={{ artefact_dir }}/box-disk1.vmdk
43+
when: not vhd_status.stat.exists or (vhd_status.stat.isreg and clobber_vhd)
44+
45+
- name: Convert the virtual machine disk (VMDK) to a virtual hard disk (VHD).
46+
command: VBoxManage clonehd --format VHD box-disk1.vmdk {{ output_name }}.vhd
47+
chdir={{ artefact_dir }}
48+
creates={{ artefact_dir }}/{{ output_name }}.vhd
49+
when: not vhd_status.stat.exists or (vhd_status.stat.isreg and clobber_vhd)
50+
51+
- name: Remove the box.
52+
file:
53+
path={{ artefact_dir }}/{{ output_name }}.box
54+
state=absent
55+
56+
- name: Remove the virtual machine disk (VMDK).
57+
file:
58+
path={{ artefact_dir }}/box-disk1.vmdk
59+
state=absent
60+
61+
- name: Destroy the virtual machine.
62+
command: vagrant destroy --force
63+
chdir={{ vm_dir }}
64+
65+
- name: Inform the user that the virtual hard disk has been created.
66+
debug:
67+
msg="Virtual machine '{{ vm_name }}' has been successfully created, and a build artefact is in {{ artefact_dir }}."

0 commit comments

Comments
 (0)