Skip to content
Permalink
Browse files
Add Vagrant provider
  • Loading branch information
neykov authored and nacx committed Jan 25, 2017
1 parent b083f4c commit 3caff210f7d739860dd2bc10d36800403b80f5f8
Show file tree
Hide file tree
Showing 39 changed files with 3,711 additions and 0 deletions.
@@ -83,6 +83,7 @@
<module>profitbricks-rest</module>
<module>oneandone</module>
<module>packet</module>
<module>vagrant</module>
</modules>

<build>
@@ -0,0 +1,122 @@
Vagrant provider for jclouds
============================

Building
--------

* `git clone https://github.com/jclouds/jclouds-labs`
* `cd jclouds-labs/vagrant`
* `mvn clean install`
* Copy `target/vagrant-2.0.0-SNAPSHOT.jar` to your classpath

Local caching proxy
-------------------

### Polipo

Use `polipo` for caching proxy. On OS X install with

```
brew install polipo
```

From [SO](http://superuser.com/questions/192696/how-can-i-make-tor-and-polipo-run-and-automatically-restart-using-launchd-on-m):

* Create a config file at ~/.polipo/config

```
# logLevel = 0xFF
dnsNameServer=8.8.8.8
diskCacheRoot = "~/.polipo/cache/"
```

* As root create the file `/Library/LaunchDaemons/fr.jussieu.pps.polipo.plist`, replace $USER with your username:
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>fr.jussieu.pps.polipo</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/polipo</string>
<string>-c</string>
<string>/Users/$USER/.polipo/config</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>OnDemand</key>
<false/>
<key>UserName</key>
<string>$USER</string>
<key>GroupName</key>
<string>daemon</string>
<key>StandardOutPath</key>
<string>/Users/$USER/.polipo/polipo.log</string>
<key>StandardErrorPath</key>
<string>/Users/$USER/.polipo/polipo.log</string>
</dict>
</plist>
```

* `sudo chown root:wheel /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist`
* `sudo chmod 755 /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist`
* `sudo launchctl load -w /Library/LaunchDaemons/fr.jussieu.pps.polipo.plist`

### Vagrant

* `vagrant plugin install vagrant-proxyconf`
* add to `~/.vagrant.d/Vagrantfile`:

```
Vagrant.configure("2") do |config|
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://10.0.2.2:8123/"
config.proxy.https = "http://10.0.2.2:8123/"
config.proxy.no_proxy = "localhost,127.0.0.1"
end
end
```

Where `10.0.2.2` is the IP of your host as seen from the vagrant machines (in this case the NAT interface).
Optionally could add all your private network IPs from your Vagrant subnet to `no_proxy` to skip the proxy for inter-VM communications.

Testing
-----------

```
mvn clean install -Plive
```

Cleaning up
-----------

Sometimes users (or tests) do not stop correctly the machines so they need to be destroyed manually periodically.
All machines live in `~/.jclouds/vagrant`. Create `cleanup.sh` in the folder and execute it to destroy machines created by the provider:

```
for node in `find ~/.jclouds/vagrant -name Vagrantfile | xargs -n1 dirname`; do
pushd $node > /dev/null
echo Destroying $node
vagrant destroy --force
popd> /dev/null
rm -rf $machine
done
```

Same as a one-liner

```
for f in `find ~/.jclouds/vagrant/tests -name Vagrantfile | xargs -n1 dirname`; do pushd $f; vagrant destroy --force; popd; rm -rf $f; done
```


Limitations
-----------

* Machines are created sequentially, no support for parallel execution from virtualbox provider
* Something prevents using vagrant at the same time with other jclouds providers - they try to login with vagrant user.
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.jclouds.labs</groupId>
<artifactId>jclouds-labs</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>

<artifactId>vagrant</artifactId>
<name>Vagrant provider</name>
<packaging>bundle</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<test.vagrant.template>imageId=ubuntu/xenial64</test.vagrant.template>
<jclouds.osgi.export>org.jclouds.vagrant*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
</properties>

<dependencies>
<dependency>
<groupId>name.neykov</groupId>
<artifactId>vagrant-java-bindings</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test.vagrant.template>${test.vagrant.template}</test.vagrant.template>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
@@ -0,0 +1,81 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.vagrant;

import java.net.URI;
import java.util.Properties;

import org.jclouds.apis.ApiMetadata;
import org.jclouds.apis.internal.BaseApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.config.ComputeServiceProperties;
import org.jclouds.vagrant.config.VagrantComputeServiceContextModule;
import org.jclouds.vagrant.reference.VagrantConstants;

import com.google.auto.service.AutoService;

@AutoService(ApiMetadata.class)
public class VagrantApiMetadata extends BaseApiMetadata {

public VagrantApiMetadata() {
this(new Builder());
}

protected VagrantApiMetadata(Builder builder) {
super(builder);
}

@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}

public static class Builder extends BaseApiMetadata.Builder<Builder> {

protected Builder() {
id("vagrant")
.name("Vagrant API")
.identityName("User")
.credentialName("Password")
.defaultEndpoint("https://atlas.hashicorp.com/")
.documentation(URI.create("https://www.vagrantup.com/docs"))
.view(ComputeServiceContext.class)
.defaultIdentity("guest")
.defaultCredential("guest")
.defaultProperties(defaultProperties())
.defaultModule(VagrantComputeServiceContextModule.class);
}

private Properties defaultProperties() {
Properties defaultProperties = BaseApiMetadata.defaultProperties();
defaultProperties.setProperty(VagrantConstants.JCLOUDS_VAGRANT_HOME, VagrantConstants.JCLOUDS_VAGRANT_HOME_DEFAULT);
defaultProperties.put(ComputeServiceProperties.TEMPLATE, "osFamily=UBUNTU");
return defaultProperties;
}

@Override
public ApiMetadata build() {
return new VagrantApiMetadata(this);
}

@Override
protected Builder self() {
return this;
}

}
}
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.vagrant.api;

import java.io.File;
import java.util.Collection;

import org.jclouds.domain.LoginCredentials;

public interface VagrantApiFacade<B> {
interface Factory<B> {
VagrantApiFacade<B> create(File path);
}

/**
* Start the named machine
*
* @return the raw output of the configured provisioners
*/
String up(String machineName);
void halt(String machineName);
void destroy(String machineName);
LoginCredentials sshConfig(String machineName);
Collection<B> listBoxes();
B getBox(String boxName);
void haltForced(String name);
boolean exists();
}

0 comments on commit 3caff21

Please sign in to comment.