#!/usr/bin/env ruby # (c) Copyright 2014 Hewlett-Packard Development Company, L.P. # # Licensed 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. require_relative 'compute.rb' include Compute require_relative 'network.rb' include Network require_relative 'yaml_parse.rb' include YamlParse require_relative 'security.rb' include SecurityGroup require_relative 'repositories.rb' include Repositories module Boot def boot(blueprint, cloud_provider, name, test=false) puts 'booting %s on %s' % [blueprint, cloud_provider] # boot maestro # get definitions from yaml forj_dir = File.expand_path(File.dirname(__FILE__)) Dir.chdir(forj_dir) definitions = YamlParse.get_values('../lib/catalog.yaml') # clone the maestro repo Repositories.clone_repo # upload the keypair SecurityGroup.upload_keypair(definitions[blueprint]['keypair']) # create the network where maestro will land network = Network.create_network(name) subnet = Network.create_subnet(network.id, name) router = Network.get_router(definitions[blueprint]['router']) Network.create_router_interface(subnet.id, router) # create the security groups for the blueprint security_group = SecurityGroup.create_security_group(blueprint) for port in definitions[blueprint]['ports'] do Network.create_security_group_rule(security_group.id, 'tcp', port, port) end # get image and flavor image = Compute.get_image(definitions[blueprint]['image']) flavor = Compute.get_flavor(definitions[blueprint]['flavor']) # run build.sh to boot maestro current_dir = Dir.pwd home = File.expand_path('~') build_path = home + '/.hpcloud/maestro/build' Dir.chdir(build_path) command = './bin/build.sh --box-name maestro --build-config box' Kernel.system(command) Dir.chdir(current_dir) if test puts 'test flag is on, deleting objects' Network.delete_router_interface(subnet.id, router) Network.delete_subnet(subnet.id) Network.delete_network(network.name) #Network.delete_security_group(security_group.id) end end end