def _get_private_key(private_key_path): pk_node_by_rel = \ get_single_connected_node_by_openstack_type( ctx, KEYPAIR_OPENSTACK_TYPE, True) if private_key_path: if pk_node_by_rel: raise NonRecoverableError("server can't both have a " '"private_key_path" input and be ' 'connected to a keypair via a ' 'relationship at the same time') key_path = private_key_path else: if pk_node_by_rel and pk_node_by_rel.properties['private_key_path']: key_path = pk_node_by_rel.properties['private_key_path'] else: key_path = ctx.bootstrap_context.cloudify_agent.agent_key_path if key_path: key_path = os.path.expanduser(key_path) if os.path.isfile(key_path): return key_path err_message = 'Cannot find private key file' if key_path: err_message += '; expected file path was {0}'.format(key_path) raise NonRecoverableError(err_message)
def _get_private_key(private_key_path): pk_node_by_rel = \ get_single_connected_node_by_openstack_type( ctx, KEYPAIR_OPENSTACK_TYPE, True) if private_key_path: if pk_node_by_rel: raise NonRecoverableError("server can't both have a " '"private_key_path" input and be ' 'connected to a keypair via a ' 'relationship at the same time') key_path = private_key_path else: key_path = \ pk_node_by_rel.properties['private_key_path'] or \ ctx.bootstrap_context.cloudify_agent.agent_key_path if key_path: key_path = os.path.expanduser(key_path) if os.path.isfile(key_path): return key_path err_message = 'Cannot find private key file' if key_path: err_message += '; expected file path was {0}'.format(key_path) raise NonRecoverableError(err_message)
def create(neutron_client, args, **kwargs): if use_external_floatingip(neutron_client, 'floating_ip_address', lambda ext_fip: ext_fip['floating_ip_address']): return floatingip = { # No defaults } floatingip.update(ctx.node.properties[FLOATINGIP_OPENSTACK_TYPE], **args) # Do we have a relationship with a network? connected_network = \ get_single_connected_node_by_openstack_type( ctx, NETWORK_OPENSTACK_TYPE, True) if connected_network: network_from_rel = connected_network.runtime_properties[ OPENSTACK_ID_PROPERTY] else: network_from_rel = None # TODO: Should we check whether this is really an "external" network? network_name_provided = 'floating_network_name' in floatingip network_id_provided = 'floating_network_id' in floatingip provided = [ network_name_provided, network_id_provided, network_from_rel is not None ].count(True) # At most one is expected. if provided > 1: raise NonRecoverableError( FLOATING_NETWORK_ERROR_MSG.format(network_from_rel, floatingip)) if network_from_rel: floatingip['floating_network_id'] = network_from_rel elif network_name_provided: floatingip['floating_network_id'] = neutron_client.cosmo_get_named( 'network', floatingip['floating_network_name'])['id'] del floatingip['floating_network_name'] elif not network_id_provided: provider_context = provider(ctx) ext_network = provider_context.ext_network if ext_network: floatingip['floating_network_id'] = ext_network['id'] else: raise NonRecoverableError( FLOATING_NETWORK_ERROR_MSG.format(None, None)) fip = neutron_client.create_floatingip( {FLOATINGIP_OPENSTACK_TYPE: floatingip})[FLOATINGIP_OPENSTACK_TYPE] set_floatingip_runtime_properties(fip['id'], fip['floating_ip_address']) ctx.logger.info('Floating IP creation response: {0}'.format(fip))
def test_get_single_node_if_exists_none_found(self): ctx = self._make_instances([]) found = get_single_connected_node_by_openstack_type( ctx, NETWORK_OPENSTACK_TYPE, if_exists=True) self.assertIsNone(found)
def test_get_single_node(self): ctx = self._make_instances(['the node id']) found_node = get_single_connected_node_by_openstack_type( ctx, NETWORK_OPENSTACK_TYPE) self.assertEqual('the node id', found_node.id)
def test_get_single_node_if_exists_none_found(self): ctx = self._make_instances([]) found = get_single_connected_node_by_openstack_type(ctx, NETWORK_OPENSTACK_TYPE, if_exists=True) self.assertIsNone(found)
def test_get_single_node(self): ctx = self._make_instances(["the node id"]) found_node = get_single_connected_node_by_openstack_type(ctx, NETWORK_OPENSTACK_TYPE) self.assertEqual("the node id", found_node.id)