summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/vm/DockerMetaDataDummy.java
blob: 73cd92e0b4e878b2ffe853245dde17a72a7cb78a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package org.openslx.vm;

import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.thrifthelper.TConst;
import org.openslx.vm.disk.DiskImage;
import org.openslx.vm.disk.DiskImage.ImageFormat;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

class DockerSoundCardMeta
{
}

class DockerDDAccelMeta
{
}

class DockerHWVersionMeta
{
}

class DockerEthernetDevTypeMeta
{
}

class DockerUsbSpeedMeta
{
}

public class DockerMetaDataDummy extends VmMetaData<DockerSoundCardMeta, DockerDDAccelMeta, DockerHWVersionMeta, DockerEthernetDevTypeMeta, DockerUsbSpeedMeta> {

	/**
	 * List of supported image formats by the Docker hypervisor.
	 */
	private static final List<DiskImage.ImageFormat> SUPPORTED_IMAGE_FORMATS = Collections.unmodifiableList(
			Arrays.asList( ImageFormat.NONE ) );
	
	private static final Logger LOGGER = Logger.getLogger( DockerMetaDataDummy.class);

	private final Virtualizer virtualizer = new Virtualizer(TConst.VIRT_DOCKER, "Docker");

	/**
	 * containerDefinition is a serialized tar.gz archive and represents a
	 * ContainerDefinition. This archive contains a serialized Container Recipe (e.g. Dockerfile)
	 * and a ContainerMeta witch is serialized as a json file.
	 * <p>
	 * See ContainerDefintion in tutor-module (bwsuite).
	 * <p>
	 * This field is in vm context the machine description e.g. vmware = vmx.
	 * This field will be stored in table  imageversion.virtualizerconfig
	 */
	private byte[] containerDefinition;

	@SuppressWarnings( "deprecation" )
	public DockerMetaDataDummy(List<OperatingSystem> osList, File file) throws UnsupportedVirtualizerFormatException {
		super(osList);

		BufferedInputStream bis = null;
		
		try {
			bis = new BufferedInputStream(new FileInputStream(file));
			containerDefinition = new byte[(int) file.length()];
			bis.read(containerDefinition);

			checkIsTarGz();
		} catch (IOException | UnsupportedVirtualizerFormatException e) {
			LOGGER.error("Couldn't read dockerfile", e);
		} finally {
			IOUtils.closeQuietly( bis );
		}
	}

	public DockerMetaDataDummy(List<OperatingSystem> osList, byte[] vmContent, int length)
			throws UnsupportedVirtualizerFormatException {
		super(osList);

		containerDefinition = vmContent;

		checkIsTarGz();
	}

	/*
	TODO This is just a simple check to prevent the workflow from considering any content as acceptable.
	 */
	/**
	 * Checks if the first two bytes of the content identifies a tar.gz archive.
	 * The first byte is 31 == 0x1f, the second byte has to be -117 == 0x8b.
	 *
	 * @throws UnsupportedVirtualizerFormatException
	 */
	private void checkIsTarGz() throws UnsupportedVirtualizerFormatException {
		if (!((31 == containerDefinition[0]) && (-117 == containerDefinition[1]))) {
			LOGGER.warn("Not Supported Content.");
			throw new UnsupportedVirtualizerFormatException(
					"DockerMetaDataDummy: Not tar.gz encoded content!");
		}
	}

	@Override public byte[] getFilteredDefinitionArray() {
		return containerDefinition;
	}
	
	@Override
	public List<DiskImage.ImageFormat> getSupportedImageFormats()
	{
		return DockerMetaDataDummy.SUPPORTED_IMAGE_FORMATS;
	}

	@Override public void applySettingsForLocalEdit() {

	}

	@Override public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) {
		return false;
	}

	@Override public boolean addHddTemplate(String diskImagePath, String hddMode, String redoDir) {
		return false;
	}

	@Override public boolean addDefaultNat() {
		return false;
	}

	@Override public void setOs(String vendorOsId) {

	}

	@Override public boolean addDisplayName(String name) {
		return false;
	}

	@Override public boolean addRam(int mem) {
		return false;
	}

	@Override public void addFloppy(int index, String image, boolean readOnly) {

	}

	@Override public boolean addCdrom(String image) {
		return false;
	}

	@Override public boolean addCpuCoreCount(int nrOfCores) {
		return false;
	}

	@Override public void setSoundCard(SoundCardType type) {

	}

	@Override public SoundCardType getSoundCard() {
		return SoundCardType.NONE;
	}

	@Override public void setDDAcceleration(DDAcceleration type) {

	}

	@Override public DDAcceleration getDDAcceleration() {
		return DDAcceleration.OFF;
	}

	@Override public void setHWVersion(HWVersion type) {

	}

	@Override public HWVersion getHWVersion() {
		return HWVersion.DEFAULT;
	}

	@Override public void setEthernetDevType(int cardIndex, EthernetDevType type) {

	}

	@Override public EthernetDevType getEthernetDevType(int cardIndex) {
		return EthernetDevType.NONE;
	}

	@Override public void setMaxUsbSpeed(UsbSpeed speed) {

	}

	@Override public UsbSpeed getMaxUsbSpeed() {
		return UsbSpeed.NONE;
	}

	@Override public byte[] getDefinitionArray() {
		return new byte[0];
	}

	@Override public boolean addEthernet(EtherType type) {
		return false;
	}

	@Override public Virtualizer getVirtualizer() {
		return virtualizer;
	}

	@Override public boolean tweakForNonPersistent() {
		return false;
	}

	@Override public void registerVirtualHW() {

	}
}