Class: CloudProcess
- Defined in:
- lib/core_process/cloud/process/rules.rb,
lib/core_process/cloud/process/rules.rb,
lib/core_process/cloud/process/flavor.rb,
lib/core_process/cloud/process/images.rb,
lib/core_process/cloud/process/router.rb,
lib/core_process/cloud/process/router.rb,
lib/core_process/cloud/process/server.rb,
lib/core_process/cloud/process/server.rb,
lib/core_process/cloud/process/network.rb,
lib/core_process/cloud/process/network.rb,
lib/core_process/cloud/process/keypairs.rb,
lib/core_process/cloud/process/keypairs.rb,
lib/core_process/cloud/process/public_ip.rb,
lib/core_process/cloud/process/public_ip.rb,
lib/core_process/cloud/process/connection.rb,
lib/core_process/cloud/process/subnetwork.rb,
lib/core_process/cloud/process/subnetwork.rb,
lib/core_process/cloud/process/security_groups.rb,
lib/core_process/cloud/process/security_groups.rb,
lib/core_process/cloud/process/external_network.rb
Overview
External network process attached to a network
Instance Method Summary collapse
- #_check_key_file(key_path, key_basename, extensions) ⇒ Object
- #assign_address(sCloudObj, hParams) ⇒ Object
-
#coherent_keypair?(loc_kpair, keypair) ⇒ Boolean
Check if 2 keypair objects are coherent (Same public key) Parameters: -
loc_kpair: Keypair structure representing local files existence. - #connect(sCloudObj, hParams) ⇒ Object
- #create_keypair(sCloudObj, hParams) ⇒ Object
-
#create_network(sCloudObj, hParams) ⇒ Object
Network creation It returns: nil or Provider Object.
- #create_router(router_name, oExternalNetwork = nil) ⇒ Object
-
#create_router_interface(oSubnet, router_obj) ⇒ Object
TODO: Move router interface management to hpcloud controller.
-
#create_rule(sCloudObj, hParams) ⇒ Object
Rules internal # —————-#.
- #create_security_group(sCloudObj, hParams) ⇒ Object
- #create_server(sCloudObj, hParams) ⇒ Object
- #create_subnet(sCloudObj, hParams) ⇒ Object
- #delete_router(net_conn_obj, router_obj) ⇒ Object
- #delete_router_interface(oSubnet, router_obj) ⇒ Object
- #delete_subnet ⇒ Object
-
#find_network(sCloudObj, hParams) ⇒ Object
Search for a network from his name.
-
#forj_delete_network(sCloudObj, hParams) ⇒ Object
Process Delete handler.
-
#forj_delete_rule(sCloudObj, _hParams) ⇒ Object
Process Delete handler.
- #forj_delete_server(sCloudObj, hParams) ⇒ Object
-
#forj_delete_sg(sCloudObj, _hParams) ⇒ Object
Process Delete handler.
- #forj_get_keypair(sCloudObj, sName, _hParams) ⇒ Object
- #forj_get_network(sCloudObj, sID, hParams) ⇒ Object
-
#forj_get_or_assign_public_address(sCloudObj, hParams) ⇒ Object
Process Handler functions.
- #forj_get_or_create_ext_net(sCloudObj, hParams) ⇒ Object
-
#forj_get_or_create_flavor(sCloudObj, hParams) ⇒ Object
Depending on clouds/rights, we can create flavor or not.
- #forj_get_or_create_image(sCloudObj, hParams) ⇒ Object
-
#forj_get_or_create_keypair(sCloudObj, hParams) ⇒ Object
KeyPair Create Process Handler The process implemented is: * Check local SSH keypairs * Check remote keypair existence * Compare and warn if needed.
-
#forj_get_or_create_network(sCloudObj, hParams) ⇒ Object
Process Create handler.
-
#forj_get_or_create_router(_sCloudObj, hParams) ⇒ Object
Process Create handler.
-
#forj_get_or_create_rule(sCloudObj, hParams) ⇒ Object
Process Create handler.
-
#forj_get_or_create_server(sCloudObj, hParams) ⇒ Object
Process Handler functions.
-
#forj_get_or_create_sg(sCloudObj, hParams) ⇒ Object
Process Create handler.
- #forj_get_or_create_subnetwork(sCloudObj, hParams) ⇒ Object
- #forj_get_public_address(sCloudObj, sId, _hParams) ⇒ Object
- #forj_get_server(sCloudObj, sId, _hParams) ⇒ Object
- #forj_get_server_log(sCloudObj, sId, _hParams) ⇒ Object
- #forj_query_external_network(_sCloudObj, sQuery, _hParams) ⇒ Object
-
#forj_query_flavor(sCloudObj, sQuery, _hParams) ⇒ Object
Should return 1 or 0 flavor.
- #forj_query_image(sCloudObj, sQuery, _hParams) ⇒ Object
- #forj_query_keypair(sCloudObj, sQuery, hParams) ⇒ Object
- #forj_query_public_address(sCloudObj, sQuery, hParams) ⇒ Object
-
#forj_query_rule(sCloudObj, sQuery, hParams) ⇒ Object
Process Query handler.
- #forj_query_server(sCloudObj, sQuery, _hParams) ⇒ Object
-
#forj_query_sg(sCloudObj, sQuery, hParams) ⇒ Object
Process Query handler.
-
#get_gateway(net_conn_obj, name) ⇒ Object
Gateway management.
- #get_keypairs_path(hParams, hKeys) ⇒ Object
- #get_router(name) ⇒ Object
- #get_router_interface_attached(sCloudObj, hParams) ⇒ Object
-
#keypair_detect(keypair_name, key_fullpath) ⇒ Object
Build keypair data information structure with files found in local filesystem.
- #keypair_import(keypair_name, loc_kpair) ⇒ Object
- #query_external_network(_hParams) ⇒ Object
-
#query_flavor(sCloudObj, sQuery, hParams) ⇒ Object
Should return 1 or 0 flavor.
- #query_router_from_port(router_port, hParams) ⇒ Object
- #query_subnet_one(_sCloudObj, hParams) ⇒ Object
- #search_the_image(sCloudObj, sQuery, hParams) ⇒ Object
- #ssh_user(image_name) ⇒ Object
Instance Method Details
#_check_key_file(key_path, key_basename, extensions) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 164 def _check_key_file(key_path, key_basename, extensions) found_ext = nil files = [] extensions.each do |ext| temp_file = File.join(key_path, key_basename + ext) if File.exist?(temp_file) && !File.directory?(temp_file) found_ext = ext files << temp_file end end [found_ext, files] end |
#assign_address(sCloudObj, hParams) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/core_process/cloud/process/public_ip.rb', line 89 def assign_address(sCloudObj, hParams) name = hParams[:server, :name] begin PrcLib.state('Getting public IP for server %s', name) ip_address = controller_create(sCloudObj) PrcLib.info("Public IP '%s' for server '%s' "\ 'assigned.', ip_address[:public_ip], name) rescue => e PrcLib.fatal(1, "Unable to assign a public IP to server '%s'", name, e) end ip_address end |
#coherent_keypair?(loc_kpair, keypair) ⇒ Boolean
Check if 2 keypair objects are coherent (Same public key) Parameters:
-
loc_kpair: Keypair structure representing local files existence.see keypair_detect -
keypair: Keypair object to check.
return:
-
coherent : Boolean. True if same public key.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 216 def coherent_keypair?(loc_kpair, keypair) # send keypairs by parameter keypair_name = loc_kpair[:keypair_name] is_coherent = false pub_keypair = keypair[:public_key] # Check the public key with the one found here, locally. if !pub_keypair.nil? && pub_keypair != '' begin loc_pubkey = File.read(File.join(loc_kpair[:keypair_path], loc_kpair[:public_key_name])) rescue => e PrcLib.error("Unable to read '%s'.\n%s", loc_kpair[:public_key_file], e.) else if loc_pubkey.split(' ')[1].strip == pub_keypair.split(' ')[1].strip PrcLib.info("keypair '%s' local files are coherent with keypair in "\ 'your cloud service. You will be able to connect to '\ 'your box over SSH.', keypair_name) is_coherent = true else PrcLib.warning("Your local keypair file '%s' are incoherent with "\ "public key '%s' found in your cloud. You won't be "\ "able to access your box with this keypair.\nPublic "\ "key found in the cloud:\n%s", loc_kpair[:public_key_file], keypair_name, keypair[:public_key]) end end else PrcLib.warning('Unable to verify keypair coherence with your local '\ 'SSH keys. No public key (:public_key) provided.') end is_coherent end |
#connect(sCloudObj, hParams) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/core_process/cloud/process/connection.rb', line 22 def connect(sCloudObj, hParams) ssl_error_obj = SSLErrorMgt.new # Retry object PrcLib.debug("%s:%s Connecting to '%s' "\ "- Project '%s'", self.class, sCloudObj, config[:provider], hParams[:tenant]) begin controller_connect(sCloudObj) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) PrcLib.error('%s:%s: Unable to connect.\n%s', self.class, sCloudObj, e.) nil end end |
#create_keypair(sCloudObj, hParams) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 112 def create_keypair(sCloudObj, hParams) key_name = hParams[:keypair_name] PrcLib.state("Importing keypair '%s'", key_name) ssl_error_obj = SSLErrorMgt.new begin keypair = controller_create(sCloudObj) PrcLib.info("Keypair '%s' imported.", keypair[:name]) rescue StandardError => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) PrcLib.error "error importing keypair '%s'", key_name end keypair end |
#create_network(sCloudObj, hParams) ⇒ Object
Network creation It returns: nil or Provider Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/core_process/cloud/process/network.rb', line 85 def create_network(sCloudObj, hParams) name = hParams[:network_name] begin PrcLib.state("Creating network '%s'", name) network = controller_create(sCloudObj) PrcLib.info("Network '%s' created", network[:name]) rescue => e PrcLib.fatal(1, "Unable to create network '%s'", name, e) end network end |
#create_router(router_name, oExternalNetwork = nil) ⇒ Object
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 |
# File 'lib/core_process/cloud/process/router.rb', line 115 def create_router(router_name, oExternalNetwork = nil) begin if oExternalNetwork ext_net = get_data(oExternalNetwork, :name) PrcLib.state("Creating router '%s' attached to the external "\ "Network '%s'", router_name, ext_net) config[:external_gateway_id] = get_data(oExternalNetwork, :id) else PrcLib.state("Creating router '%s' without external Network", router_name) end router = controller_create(:router) if oExternalNetwork PrcLib.info("Router '%s' created and attached to the external "\ "Network '%s'.", router_name, ext_net) else PrcLib.info("Router '%s' created without external Network.", router_name) end rescue => e raise ForjError.new, "Unable to create '%s' router\n%s", router_name, e. end router end |
#create_router_interface(oSubnet, router_obj) ⇒ Object
TODO: Move router interface management to hpcloud controller. Router interface to connect to the network
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/core_process/cloud/process/router.rb', line 169 def create_router_interface(oSubnet, router_obj) PrcLib.state("Attaching subnet '%s' to router '%s'", oSubnet[:name], router_obj[:name]) begin controller_create(:router_interface) ################# # provider_add_interface() # router_obj.add_interface(oSubnet.id, nil) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end end |
#create_rule(sCloudObj, hParams) ⇒ Object
Rules internal # —————-#
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/core_process/cloud/process/rules.rb', line 106 def create_rule(sCloudObj, hParams) rule = '%s %s:%s - %s to %s', hParams[:dir], hParams[:rule_proto], hParams[:port_min], hParams[:port_max], hParams[:addr_map] PrcLib.state("Creating rule '%s'", rule) ssl_error_obj = SSLErrorMgt.new begin rule = controller_create(sCloudObj) PrcLib.info("Rule '%s' created.", rule) rescue StandardError => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) PrcLib.error 'error creating the rule for port %s', rule end rule end |
#create_security_group(sCloudObj, hParams) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/core_process/cloud/process/security_groups.rb', line 111 def create_security_group(sCloudObj, hParams) PrcLib.state("Creating security group '%s'", hParams[:security_group]) begin sg = controller_create(sCloudObj) PrcLib.info("Security group '%s' created.", sg[:name]) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end sg end |
#create_server(sCloudObj, hParams) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/core_process/cloud/process/server.rb', line 105 def create_server(sCloudObj, hParams) name = hParams[:server_name] begin PrcLib.info('boot: meta-data provided.') if hParams[:meta_data] PrcLib.info('boot: user-data provided.') if hParams[:user_data] PrcLib.state('creating server %s', name) server = controller_create(sCloudObj) PrcLib.info("%s '%s' created.", sCloudObj, name) rescue => e PrcLib.fatal(1, "Unable to create server '%s'", name, e) end server end |
#create_subnet(sCloudObj, hParams) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/core_process/cloud/process/subnetwork.rb', line 56 def create_subnet(sCloudObj, hParams) name = hParams[:subnetwork_name] PrcLib.state("Creating subnet '%s'", name) begin subnet = controller_create(sCloudObj) PrcLib.info("Subnet '%s' created.", subnet[:name]) rescue => e PrcLib.fatal(1, "Unable to create '%s' subnet.", name, e) end subnet end |
#delete_router(net_conn_obj, router_obj) ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/core_process/cloud/process/router.rb', line 142 def delete_router(net_conn_obj, router_obj) PrcLib.state("Deleting router '%s'", router.name) begin ################# provider_delete_router(net_conn_obj, router_obj) # net_conn_obj.routers.get(router.id).destroy rescue => e PrcLib.error("Unable to delete '%s' router ID", router_id, e) end end |
#delete_router_interface(oSubnet, router_obj) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/core_process/cloud/process/router.rb', line 183 def delete_router_interface(oSubnet, router_obj) PrcLib.state("Removing subnet '%s' from router '%s'", oSubnet.name, router_obj.name) subnet_id = oSubnet.id begin ################# router_obj.remove_interface(subnet_id) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end end |
#delete_subnet ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/core_process/cloud/process/subnetwork.rb', line 68 def delete_subnet net_conn_obj = get_cloudObj(:network_connection) sub_net_obj = get_cloudObj(:subnetwork) PrcLib.state("Deleting subnet '%s'", sub_net_obj.name) begin provider_delete_subnetwork(net_conn_obj, sub_net_obj) net_conn_obj.subnets.get(sub_net_obj.id).destroy rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end end |
#find_network(sCloudObj, hParams) ⇒ Object
Search for a network from his name. Name may be unique in project context, but not in the cloud system It returns: nil or Provider Object
101 102 103 104 105 106 107 108 |
# File 'lib/core_process/cloud/process/network.rb', line 101 def find_network(sCloudObj, hParams) query = { :name => hParams[:network_name] } # list = controller_query(sCloudObj, query) # query_single(sCloudObj, list, query, hParams[:network_name]) query_single(sCloudObj, query, hParams[:network_name]) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end |
#forj_delete_network(sCloudObj, hParams) ⇒ Object
Process Delete handler
46 47 48 49 50 |
# File 'lib/core_process/cloud/process/network.rb', line 46 def forj_delete_network(sCloudObj, hParams) oProvider.delete(sCloudObj, hParams) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end |
#forj_delete_rule(sCloudObj, _hParams) ⇒ Object
Process Delete handler
22 23 24 25 26 27 28 29 |
# File 'lib/core_process/cloud/process/rules.rb', line 22 def forj_delete_rule(sCloudObj, _hParams) ssl_error_obj = SSLErrorMgt.new begin controller_delete(sCloudObj) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_delete_server(sCloudObj, hParams) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/core_process/cloud/process/server.rb', line 36 def forj_delete_server(sCloudObj, hParams) ssl_error_obj = SSLErrorMgt.new begin controller_delete(sCloudObj) PrcLib.info('Server %s was destroyed ', hParams[:server][:name]) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_delete_sg(sCloudObj, _hParams) ⇒ Object
Process Delete handler
59 60 61 62 63 64 65 66 |
# File 'lib/core_process/cloud/process/security_groups.rb', line 59 def forj_delete_sg(sCloudObj, _hParams) ssl_error_obj = SSLErrorMgt.new begin controller_delete(sCloudObj) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_get_keypair(sCloudObj, sName, _hParams) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 177 def forj_get_keypair(sCloudObj, sName, _hParams) ssl_error_obj = SSLErrorMgt.new begin controller_get(sCloudObj, sName) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_get_network(sCloudObj, sID, hParams) ⇒ Object
52 53 54 55 56 |
# File 'lib/core_process/cloud/process/network.rb', line 52 def forj_get_network(sCloudObj, sID, hParams) oProvider.get(sCloudObj, sID, hParams) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end |
#forj_get_or_assign_public_address(sCloudObj, hParams) ⇒ Object
Process Handler functions
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/core_process/cloud/process/public_ip.rb', line 22 def forj_get_or_assign_public_address(sCloudObj, hParams) # Function which to assign a public IP address to a server. server_name = hParams[:server, :name] PrcLib.state("Searching public IP for server '%s'", server_name) addresses = controller_query(sCloudObj, :server_id => hParams[:server, :id]) if addresses.length == 0 assign_address(sCloudObj, hParams) else addresses[0] end end |
#forj_get_or_create_ext_net(sCloudObj, hParams) ⇒ Object
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 |
# File 'lib/core_process/cloud/process/external_network.rb', line 21 def forj_get_or_create_ext_net(sCloudObj, hParams) PrcLib.state("Checking router '%s' gateway", hParams[:router, :name]) router_obj = hParams[:router] router_name = hParams[:router, :name] network_id = hParams[:router, :gateway_network_id] if network_id external_network = forj_query_external_network(sCloudObj, { :id => network_id }, hParams) PrcLib.info("Router '%s' is attached to the "\ "external gateway '%s'.", router_name, external_network[:name]) else PrcLib.info("Router '%s' needs to be attached to an "\ 'external gateway.', router_name) PrcLib.state('Attaching') external_network = forj_query_external_network(:network, {}, hParams) if !external_network.empty? router_obj[:gateway_network_id] = external_network[:id] forj_update_router(:router, hParams) PrcLib.info("Router '%s' attached to the "\ "external network '%s'.", router_name, external_network[:name]) else PrcLib.fatal(1, "Unable to attach router '%s' to an external gateway. "\ 'Required for boxes to get internet access. ', get_data(:router, :name)) end end # Need to keep the :network object as :external_network object type. external_network.type = sCloudObj external_network end |
#forj_get_or_create_flavor(sCloudObj, hParams) ⇒ Object
Depending on clouds/rights, we can create flavor or not. Usually, flavor records already exists, and the controller may map them CloudProcess predefines some values. Consult CloudProcess.rb for details
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/core_process/cloud/process/flavor.rb', line 26 def forj_get_or_create_flavor(sCloudObj, hParams) flavor_name = hParams[:flavor_name] PrcLib.state("Searching for flavor '%s'", flavor_name) flavors = query_flavor(sCloudObj, { :name => flavor_name }, hParams) if flavors.length == 0 if !hParams[:create] PrcLib.error("Unable to create %s '%s'. Creation is not "\ 'supported.', sCloudObj, flavor_name) ForjLib::Data.new.set(nil, sCloudObj) else create_flavor(sCloudObj, hParams) end else flavors[0] end end |
#forj_get_or_create_image(sCloudObj, hParams) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/core_process/cloud/process/images.rb', line 23 def forj_get_or_create_image(sCloudObj, hParams) image_name = hParams[:image_name] PrcLib.state("Searching for image '%s'", image_name) search_the_image(sCloudObj, { :name => image_name }, hParams) # No creation possible. end |
#forj_get_or_create_keypair(sCloudObj, hParams) ⇒ Object
KeyPair Create Process Handler The process implemented is:
-
Check local SSH keypairs
-
Check remote keypair existence
-
Compare and warn if needed.
-
Import public key found if missing remotely and name it.
Return:
-
keypair : Lorj::Data keypair object. Following additional data should be
found in the keypair attributes-
:coherent : Boolean. True, if the local keypair (public AND
private) is coherent with remote keypair found in the cloud -
:private_key_file: String. Path to local private key file
-
:public_key_file : String. Path to local public key file
-
:public_key : String. Public key content. (config is
also set - Used to import it)
-
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 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 39 def forj_get_or_create_keypair(sCloudObj, hParams) keypair_name = hParams[:keypair_name] # setup has configured and copied the appropriate key to forj keypairs. loc_kpair = keypair_detect(keypair_name, File.(hParams[:keypair_path])) private_key_file = File.join(loc_kpair[:keypair_path], loc_kpair[:private_key_name]) public_key_file = File.join(loc_kpair[:keypair_path], loc_kpair[:public_key_name]) PrcLib.info("Found openssh private key file '%s'.", private_key_file) if loc_kpair[:private_key_exist?] PrcLib.info("Found openssh public key file '%s'.", public_key_file) if loc_kpair[:public_key_exist?] PrcLib.state("Searching for keypair '%s'", keypair_name) keypairs = forj_query_keypair(sCloudObj, { :name => keypair_name }, hParams) if keypairs.length == 0 keypair = keypair_import(keypair_name, loc_kpair) else keypair = keypairs[0] keypair[:coherent] = coherent_keypair?(loc_kpair, keypair) # Adding information about key files. end if keypair[:coherent] keypair[:private_key_file] = loc_kpair[:private_key_file] keypair[:public_key_file] = loc_kpair[:public_key_file] end keypair end |
#forj_get_or_create_network(sCloudObj, hParams) ⇒ Object
Process Create handler
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/core_process/cloud/process/network.rb', line 22 def forj_get_or_create_network(sCloudObj, hParams) PrcLib.state("Searching for network '%s'", hParams[:network_name]) networks = find_network(sCloudObj, hParams) if networks.length == 0 network = create_network(sCloudObj, hParams) else network = networks[0] end register(network) # Attaching if missing the subnet. # Creates an object subnet, attached to the network. unless hParams[:subnetwork_name] hParams[:subnetwork_name] = 'sub-' + hParams[:network_name] config[:subnetwork_name] = hParams[:subnetwork_name] end # object.Create(:subnetwork) process_create(:subnetwork) network end |
#forj_get_or_create_router(_sCloudObj, hParams) ⇒ Object
Process Create handler
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/core_process/cloud/process/router.rb', line 23 def forj_get_or_create_router(_sCloudObj, hParams) sub_net_obj = hParams[:subnetwork] unless hParams[:router_name] config[:router_name] = 'router-%s', hParams[:network, :name] hParams[:router_name] = config[:router_name] end router_name = hParams[:router_name] router_port = get_router_interface_attached(:port, hParams) if !router_port # Trying to get router router = get_router(router_name) router = create_router(router_name) unless router create_router_interface(sub_net_obj, router) if router else router = query_router_from_port(router_port, hParams) end router end |
#forj_get_or_create_rule(sCloudObj, hParams) ⇒ Object
Process Create handler
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/core_process/cloud/process/rules.rb', line 52 def forj_get_or_create_rule(sCloudObj, hParams) query = { :dir => hParams[:dir], :proto => hParams[:proto], :port_min => hParams[:port_min], :port_max => hParams[:port_max], :addr_map => hParams[:addr_map], :sg_id => hParams[:sg_id] } rules = forj_query_rule(sCloudObj, query, hParams) if rules.length == 0 create_rule(sCloudObj, hParams) else rules[0] end end |
#forj_get_or_create_server(sCloudObj, hParams) ⇒ Object
Process Handler functions
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/core_process/cloud/process/server.rb', line 24 def forj_get_or_create_server(sCloudObj, hParams) server_name = hParams[:server_name] PrcLib.state("Searching for server '%s'", server_name) servers = forj_query_server(sCloudObj, { :name => server_name }, hParams) if servers.length > 0 # Get server details forj_get_server(sCloudObj, servers[0][:attrs][:id], hParams) else create_server(sCloudObj, hParams) end end |
#forj_get_or_create_sg(sCloudObj, hParams) ⇒ Object
Process Create handler
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 |
# File 'lib/core_process/cloud/process/security_groups.rb', line 22 def forj_get_or_create_sg(sCloudObj, hParams) sg_name = hParams[:security_group] PrcLib.state("Searching for security group '%s'", sg_name) security_group = forj_query_sg(sCloudObj, { :name => sg_name }, hParams) security_group = create_security_group(sCloudObj, hParams) unless security_group register(security_group) PrcLib.info('Configuring Security Group \'%s\'', sg_name) ports = config.get(:ports) ports.each do |port| port = port.to_s if port.class != String if !(/^\d+(-\d+)?$/ =~ port) PrcLib.error("Port '%s' is not valid. Must be <Port> or "\ '<PortMin>-<PortMax>', port) else port_found_match = /^(\d+)(-(\d+))?$/.match(port) portmin = port_found_match[1] portmax = (port_found_match[3]) ? (port_found_match[3]) : (portmin) # Need to set runtime data to get or if missing # create the required rule. config[:dir] = :IN config[:proto] = 'tcp' config[:port_min] = portmin.to_i config[:port_max] = portmax.to_i config[:addr_map] = '0.0.0.0/0' # object.Create(:rule) process_create(:rule) end end security_group end |
#forj_get_or_create_subnetwork(sCloudObj, hParams) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/core_process/cloud/process/subnetwork.rb', line 21 def forj_get_or_create_subnetwork(sCloudObj, hParams) subnet = query_subnet_one(sCloudObj, hParams) unless subnet.empty? register(subnet) return subnet end # Create the subnet subnet = create_subnet(sCloudObj, hParams) return nil if subnet.nil? register(subnet) subnet end |
#forj_get_public_address(sCloudObj, sId, _hParams) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/core_process/cloud/process/public_ip.rb', line 55 def forj_get_public_address(sCloudObj, sId, _hParams) ssl_error_obj = SSLErrorMgt.new begin controller_get(sCloudObj, sId) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_get_server(sCloudObj, sId, _hParams) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/core_process/cloud/process/server.rb', line 55 def forj_get_server(sCloudObj, sId, _hParams) ssl_error_obj = SSLErrorMgt.new begin controller_get(sCloudObj, sId) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_get_server_log(sCloudObj, sId, _hParams) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/core_process/cloud/process/server.rb', line 119 def forj_get_server_log(sCloudObj, sId, _hParams) ssl_error_obj = SSLErrorMgt.new begin controller_get(sCloudObj, sId) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_query_external_network(_sCloudObj, sQuery, _hParams) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/core_process/cloud/process/external_network.rb', line 57 def forj_query_external_network(_sCloudObj, sQuery, _hParams) PrcLib.state('Identifying External gateway') begin # Searching for external network networks = controller_query(:network, sQuery.merge(:external => true)) case networks.length when 0 PrcLib.info('No external network') nil when 1 PrcLib.info("Found external network '%s'.", networks[0, :name]) networks[0] else PrcLib.warning('Found several external networks. '\ "Selecting the first one '%s'", networks[0, :name]) networks[0] end rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end end |
#forj_query_flavor(sCloudObj, sQuery, _hParams) ⇒ Object
Should return 1 or 0 flavor.
53 54 55 56 57 58 59 60 61 |
# File 'lib/core_process/cloud/process/flavor.rb', line 53 def forj_query_flavor(sCloudObj, sQuery, _hParams) ssl_error_obj = SSLErrorMgt.new begin list = controller_query(sCloudObj, sQuery) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end list end |
#forj_query_image(sCloudObj, sQuery, _hParams) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/core_process/cloud/process/images.rb', line 50 def forj_query_image(sCloudObj, sQuery, _hParams) ssl_error_obj = SSLErrorMgt.new begin images = controller_query(sCloudObj, sQuery) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end images.each do |image| image[:ssh_user] = ssh_user(image[:name]) end images end |
#forj_query_keypair(sCloudObj, sQuery, hParams) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 75 def forj_query_keypair(sCloudObj, sQuery, hParams) key_name = hParams[:keypair_name] ssl_error_obj = SSLErrorMgt.new begin # list = controller_query(sCloudObj, sQuery) # query_single(sCloudObj, list, sQuery, key_name) query_single(sCloudObj, sQuery, key_name) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_query_public_address(sCloudObj, sQuery, hParams) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/core_process/cloud/process/public_ip.rb', line 35 def forj_query_public_address(sCloudObj, sQuery, hParams) server_name = hParams[:server, :name] ssl_error_obj = SSLErrorMgt.new begin info = { :notfound => "No %s for '%s' found", :checkmatch => "Found 1 %s. checking exact match for server '%s'.", :nomatch => "No %s for '%s' match", :found => "Found %s '%s' for #{server_name}.", :more => "Found several %s. Searching for '%s'.", :items => :public_ip } # list = controller_query(sCloudObj, sQuery) # query_single(sCloudObj, list, sQuery, server_name, info) query_single(sCloudObj, sQuery, server_name, info) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_query_rule(sCloudObj, sQuery, hParams) ⇒ Object
Process Query handler
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/core_process/cloud/process/rules.rb', line 32 def forj_query_rule(sCloudObj, sQuery, hParams) rule = format('%s %s:%s - %s to %s', hParams[:dir], hParams[:rule_proto], hParams[:port_min], hParams[:port_max], hParams[:addr_map]) PrcLib.state("Searching for rule '%s'", rule) ssl_error_obj = SSLErrorMgt.new begin info = { :items => [:dir, :proto, :port_min, :port_max, :addr_map], :items_form => '%s %s:%s - %s to %s' } # list = controller_query(sCloudObj, sQuery) # query_single(sCloudObj, list, sQuery, rule, info) query_single(sCloudObj, sQuery, rule, info) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_query_server(sCloudObj, sQuery, _hParams) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/core_process/cloud/process/server.rb', line 46 def forj_query_server(sCloudObj, sQuery, _hParams) ssl_error_obj = SSLErrorMgt.new begin controller_query(sCloudObj, sQuery) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) end end |
#forj_query_sg(sCloudObj, sQuery, hParams) ⇒ Object
Process Query handler
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/core_process/cloud/process/security_groups.rb', line 69 def forj_query_sg(sCloudObj, sQuery, hParams) ssl_error_obj = SSLErrorMgt.new begin sgroups = controller_query(sCloudObj, sQuery) rescue => e retry unless ssl_error_obj.error_detected(e., e.backtrace, e) PrcLib.fatal(1, 'Unable to get list of security groups.', e) end case sgroups.length when 0 PrcLib.info("No security group '%s' found", hParams[:security_group]) nil when 1 PrcLib.info("Found security group '%s'", sgroups[0, :name]) sgroups[0] end end |
#get_gateway(net_conn_obj, name) ⇒ Object
Gateway management
222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/core_process/cloud/process/router.rb', line 222 def get_gateway(net_conn_obj, name) return nil if !name || !net_conn_obj PrcLib.state("Getting gateway '%s'", name) networks = net_conn_obj begin netty = networks.get(name) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end PrcLib.state("Found gateway '%s'", name) if netty PrcLib.state("Unable to find gateway '%s'", name) unless netty netty end |
#get_keypairs_path(hParams, hKeys) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 186 def get_keypairs_path(hParams, hKeys) keypair_name = hParams[:keypair_name] if hKeys[:private_key_exist?] hParams[:private_key_file] = File.join(hKeys[:keypair_path], hKeys[:private_key_name]) PrcLib.info("Openssh private key file '%s' exists.", hParams[:private_key_file]) end if hKeys[:public_key_exist?] hParams[:public_key_file] = File.join(hKeys[:keypair_path], hKeys[:public_key_name]) else PrcLib.fatal(1, 'Public key file is not found. Please run'\ " 'forj setup %s'", config[:account_name]) end PrcLib.state("Searching for keypair '%s'", keypair_name) hParams end |
#get_router(name) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/core_process/cloud/process/router.rb', line 99 def get_router(name) PrcLib.state("Searching for router '%s'", name) begin routers = controller_query(:router, :name => name) case routers.length when 1 routers[0] else PrcLib.info("Router '%s' not found.", name) nil end rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end end |
#get_router_interface_attached(sCloudObj, hParams) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/core_process/cloud/process/router.rb', line 195 def get_router_interface_attached(sCloudObj, hParams) PrcLib.state("Searching for router port attached to the network '%s'", hParams[:network, :name]) begin # Searching for router port attached ################# query = { :network_id => hParams[ :network, :id], :device_owner => 'network:router_interface' } ports = controller_query(sCloudObj, query) case ports.length when 0 PrcLib.info("No router port attached to the network '%s'", hParams[:network, :name]) nil else PrcLib.info("Found a router port attached to the network '%s' ", hParams[:network, :name]) ports[0] end rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end end |
#keypair_detect(keypair_name, key_fullpath) ⇒ Object
Build keypair data information structure with files found in local filesystem. Take care of priv with or without .pem and pubkey with pub.
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 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 129 def keypair_detect(keypair_name, key_fullpath) key_basename = File.basename(key_fullpath) key_path = File.(File.dirname(key_fullpath)) obj_match = key_basename.match(/^(.*?)(\.pem|\.pub)?$/) key_basename = obj_match[1] private_key_ext, files = _check_key_file(key_path, key_basename, ['', '.pem']) if private_key_ext priv_key_exist = true priv_key_name = key_basename + private_key_ext else files.each do |temp_file| PrcLib.warning('keypair_detect: Private key file name detection has '\ "detected '%s' as a directory. Usually, it should be a "\ 'private key file. Please check.', temp_file) if File.directory?(temp_file) end priv_key_exist = false priv_key_name = key_basename end pub_key_exist = File.exist?(File.join(key_path, key_basename + '.pub')) pub_key_name = key_basename + '.pub' # keypair basic structure { :keypair_name => keypair_name, :keypair_path => key_path, :key_basename => key_basename, :private_key_name => priv_key_name, :private_key_exist? => priv_key_exist, :public_key_name => pub_key_name, :public_key_exist? => pub_key_exist } end |
#keypair_import(keypair_name, loc_kpair) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/core_process/cloud/process/keypairs.rb', line 90 def keypair_import(keypair_name, loc_kpair) PrcLib.fatal(1, "Unable to import keypair '%s'. "\ 'Public key file is not found. '\ "Please run 'forj setup %s'", keypair_name, config[:account_name]) unless loc_kpair[:public_key_exist?] begin config[:public_key] = File.read(loc_kpair[:public_key_file]) rescue => e PrcLib.fatal(1, "Unable to import keypair '%s'. '%s' is "\ "unreadable.\n%s", keypair_name, loc_kpair[:public_key_file], e.) end keypair = create_keypair(sCloudObj, hParams) if !loc_kpair[:private_key_exist?] keypair[:coherent] = false else keypair[:coherent] = true end keypair end |
#query_external_network(_hParams) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/core_process/cloud/process/router.rb', line 237 def query_external_network(_hParams) PrcLib.state('Identifying External gateway') begin # Searching for router port attached ################# query = { :router_external => true } networks = controller_query(:network, query) case networks.length when 0 PrcLib.info('No external network') ForjLib::Data.new when 1 PrcLib.info("Found external network '%s'.", networks[0, :name]) networks[0] else PrcLib.warn('Found several external networks. Selecting the '\ "first one '%s'", networks[0, :name]) networks[0] end rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end end |
#query_flavor(sCloudObj, sQuery, hParams) ⇒ Object
Should return 1 or 0 flavor.
45 46 47 48 49 50 |
# File 'lib/core_process/cloud/process/flavor.rb', line 45 def query_flavor(sCloudObj, sQuery, hParams) flavor_name = hParams[:flavor_name] # list = forj_query_flavor(sCloudObj, sQuery, hParams) # query_single(sCloudObj, list, sQuery, flavor_name) query_single(sCloudObj, sQuery, flavor_name) end |
#query_router_from_port(router_port, hParams) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/core_process/cloud/process/router.rb', line 153 def query_router_from_port(router_port, hParams) query = { :id => router_port[:device_id] } routers = controller_query(:router, query) case routers.length when 1 PrcLib.info("Found router '%s' attached to the network '%s'.", routers[0, :name], hParams[:network, :name]) routers[0] else PrcLib.warning('Unable to find the router '\ "id '%s'", router_port[:device_id]) ForjLib::Data.new end end |
#query_subnet_one(_sCloudObj, hParams) ⇒ Object
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 |
# File 'lib/core_process/cloud/process/subnetwork.rb', line 81 def query_subnet_one(_sCloudObj, hParams) PrcLib.state('Searching for sub-network attached to '\ "network '%s'", hParams[:network, :name]) ####################### begin query = { :network_id => hParams[:network, :id] } subnets = controller_query(:subnetwork, query) rescue => e PrcLib.error("%s\n%s", e., e.backtrace.join("\n")) end return nil if subnets.nil? case subnets.length when 0 PrcLib.info('No subnet found from '\ "'%s' network", hParams[:network, :name]) ForjLib::Data.new when 1 PrcLib.info("Found '%s' subnet from "\ "'%s' network", subnets[0, :name], hParams[:network, :name]) subnets[0] else PrcLib.warning('Several subnet was found on '\ "'%s'. Choosing the first one "\ "= '%s'", hParams[:network, :name], subnets[0, :name]) subnets[0] end end |
#search_the_image(sCloudObj, sQuery, hParams) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/core_process/cloud/process/images.rb', line 31 def search_the_image(sCloudObj, sQuery, hParams) image_name = hParams[:image_name] images = forj_query_image(sCloudObj, sQuery, hParams) case images.length when 0 PrcLib.info("No image '%s' found", image_name) nil when 1 PrcLib.info("Found image '%s'.", image_name) images[0, :ssh_user] = ssh_user(images[0, :name]) images[0] else PrcLib.info("Found several images '%s'. Selecting the first "\ "one '%s'", image_name, images[0, :name]) images[0, :ssh_user] = ssh_user(images[0, :name]) images[0] end end |
#ssh_user(image_name) ⇒ Object
63 64 65 66 67 |
# File 'lib/core_process/cloud/process/images.rb', line 63 def ssh_user(image_name) return 'fedora' if image_name =~ /fedora/i return 'centos' if image_name =~ /centos/i 'ubuntu' end |