forked from compozed/ops_manager_cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,198 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2.3 | ||
2.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
FROM ruby:2.3.0 | ||
FROM ruby:2.4.1 | ||
|
||
ENV GEM_NAME ops_manager_cli | ||
ENV GEM_VERSION 0.5.2 | ||
ENV GEM_VERSION 0.7.5 | ||
ENV OVFTOOL_VERSION 4.1.0-2459827 | ||
ENV OVFTOOL_INSTALLER VMware-ovftool-${OVFTOOL_VERSION}-lin.x86_64.bundle | ||
ARG DOWNLOAD_URL | ||
|
||
# ================== Installs sshpass =============== | ||
RUN echo "deb http://httpredir.debian.org/debian jessie utils" >> sources.list | ||
RUN apt-get update | ||
RUN apt-get install -y sshpass unzip | ||
|
||
# ================== Installs OVF tools ============== | ||
RUN echo $DOWNLOAD_URL | ||
RUN wget -v ${DOWNLOAD_URL} \ | ||
&& sh ${OVFTOOL_INSTALLER} -p /usr/local --eulas-agreed --required \ | ||
&& rm -f ${OVFTOOL_INSTALLER}* | ||
|
||
# ================== Installs Spruce ============== | ||
RUN wget -v --no-check-certificate https://github.com/geofffranks/spruce/releases/download/v1.0.1/spruce_1.0.1_linux_amd64.tar.gz \ | ||
&& tar -xvf spruce_1.0.1_linux_amd64.tar.gz \ | ||
&& chmod +x /spruce_1.0.1_linux_amd64/spruce \ | ||
&& ln -s /spruce_1.0.1_linux_amd64/spruce /usr/bin/. | ||
RUN wget -v --no-check-certificate https://github.com/geofffranks/spruce/releases/download/v1.13.1/spruce-linux-amd64 \ | ||
&& chmod +x spruce-linux-amd64 \ | ||
&& ln -s /spruce-linux-amd64 /usr/bin/spruce | ||
|
||
# ================== Installs JQ ============== | ||
RUN wget -v -O /usr/local/bin/jq --no-check-certificate https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 | ||
RUN chmod +x /usr/local/bin/jq | ||
|
||
# ================== Installs ops_manager_cli gem ============== | ||
COPY pkg/${GEM_NAME}-${GEM_VERSION}.gem /tmp/ | ||
|
||
RUN gem install /tmp/${GEM_NAME}-${GEM_VERSION}.gem | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
require 'fog/aws' | ||
require 'ops_manager/appliance/base' | ||
|
||
class OpsManager | ||
module Appliance | ||
class AWS < Base | ||
|
||
def deploy_vm | ||
image_id = ::YAML.load_file(ami_mapping_file)[config[:opts][:region]] | ||
|
||
server = connection.servers.create( | ||
block_device_mapping: [{ | ||
'DeviceName' => '/dev/xvda', | ||
'Ebs.VolumeSize' => config[:opts][:disk_size_in_gb], | ||
}], | ||
key_name: config[:opts][:ssh_keypair_name], | ||
flavor_id: config[:opts][:instance_type], | ||
subnet_id: config[:opts][:subnet_id], | ||
image_id: image_id, | ||
private_ip_address: config[:ip], | ||
security_group_ids: security_group_ids, | ||
availability_zone: config[:opts][:availability_zone], | ||
iam_instance_profile_name: config[:opts][:instance_profile_name], | ||
tags: { | ||
'Name' => vm_name, | ||
} | ||
) | ||
server.wait_for { ready? } | ||
return server | ||
end | ||
|
||
def stop_current_vm(name) | ||
server = connection.servers.all("private-ip-address" => config[:ip], "tag:Name" => name).first | ||
if ! server | ||
fail "VM not found matching IP '#{config[:ip]}', named '#{name}'" | ||
end | ||
server.stop | ||
server.wait_for { server.state == "stopped" } | ||
|
||
# Create ami of stopped server | ||
response = connection.create_image(server.id, "#{name}-backup", "Backup of #{name}") | ||
image = connection.images.get( response.data[:body]['imageId']) | ||
image.wait_for 36000 { image.state == "available" } | ||
if image.state != "available" | ||
fail "Error creating backup AMI, bailing out before destroying the VM" | ||
end | ||
|
||
puts "Saved #{name} to AMI #{image.id} (#{name}-backup) for safe-keeping" | ||
|
||
server.destroy | ||
if !Fog.mocking? | ||
server.wait_for { server.state == 'terminated' } | ||
else | ||
# Fog's mock doesn't support transitioning state from terminating -> terminated | ||
# so we have to hack this here | ||
server.wait_for { server.state == 'terminating' } | ||
end | ||
end | ||
|
||
private | ||
def ami_mapping_file | ||
Dir.glob(config[:opts][:ami_mapping_file]).first | ||
end | ||
|
||
def security_group_ids | ||
config[:opts][:security_groups].collect do |sg| | ||
connection.security_groups.get(sg).group_id | ||
end | ||
end | ||
|
||
def connection | ||
if config[:opts][:use_iam_profile] | ||
@connection ||= Fog::Compute.new({ | ||
provider: config[:provider], | ||
use_iam_profile: config[:opts][:use_iam_profile], | ||
aws_access_key_id: "", | ||
aws_secret_access_key: "", | ||
}) | ||
else | ||
@connection ||= Fog::Compute.new({ | ||
provider: config[:provider], | ||
aws_access_key_id: config[:opts][:access_key], | ||
aws_secret_access_key: config[:opts][:secret_key], | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
class OpsManager | ||
module Appliance | ||
class Base | ||
attr_reader :config | ||
|
||
def initialize(config) | ||
@config = config | ||
end | ||
def deploy_vm | ||
raise NotImplementedError.new("You must implement deploy_vm.") | ||
end | ||
def stop_current_vm(name) | ||
raise NotImplementedError.new("You must implement stop_current_vm.") | ||
end | ||
|
||
private | ||
def vm_name | ||
@vm_name ||= "#{config[:name]}-#{config[:desired_version]}" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.