Search in sources :

Example 1 with Keypair

use of org.openstack4j.model.compute.Keypair in project camel by apache.

the class KeypairProducer method doCreate.

private void doCreate(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String name = msg.getHeader(OpenstackConstants.NAME, String.class);
    ObjectHelper.notEmpty(name, "Keypair name");
    final String body = msg.getBody(String.class);
    final Keypair kp = os.compute().keypairs().create(name, body);
    msg.setBody(kp);
}
Also used : Keypair(org.openstack4j.model.compute.Keypair) Message(org.apache.camel.Message)

Example 2 with Keypair

use of org.openstack4j.model.compute.Keypair in project camel by apache.

the class KeypairProducer method doGet.

private void doGet(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String keypairName = msg.getHeader(OpenstackConstants.NAME, String.class);
    ObjectHelper.notEmpty(keypairName, "Keypair name");
    final Keypair kp = os.compute().keypairs().get(keypairName);
    msg.setBody(kp);
}
Also used : Keypair(org.openstack4j.model.compute.Keypair) Message(org.apache.camel.Message)

Example 3 with Keypair

use of org.openstack4j.model.compute.Keypair in project camel by apache.

the class KeypairProducerTest method createKeypair.

@Test
public void createKeypair() throws Exception {
    final String fingerPrint = "fp";
    final String privatecKey = "prk";
    when(osTestKeypair.getName()).thenReturn(KEYPAIR_NAME);
    when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey());
    when(osTestKeypair.getFingerprint()).thenReturn(fingerPrint);
    when(osTestKeypair.getPrivateKey()).thenReturn(privatecKey);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME);
    producer.process(exchange);
    ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class);
    verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture());
    assertEquals(KEYPAIR_NAME, nameCaptor.getValue());
    assertNull(keypairCaptor.getValue());
    Keypair result = msg.getBody(Keypair.class);
    assertEquals(fingerPrint, result.getFingerprint());
    assertEquals(privatecKey, result.getPrivateKey());
    assertEquals(dummyKeypair.getName(), result.getName());
    assertEquals(dummyKeypair.getPublicKey(), result.getPublicKey());
}
Also used : Keypair(org.openstack4j.model.compute.Keypair) NovaKeypair(org.openstack4j.openstack.compute.domain.NovaKeypair) Test(org.junit.Test)

Example 4 with Keypair

use of org.openstack4j.model.compute.Keypair in project camel by apache.

the class KeypairProducerTest method createKeypairFromExisting.

@Test
public void createKeypairFromExisting() throws Exception {
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME);
    String key = "existing public key string";
    when(osTestKeypair.getPublicKey()).thenReturn(key);
    msg.setBody(key);
    producer.process(exchange);
    ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class);
    verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture());
    assertEquals(KEYPAIR_NAME, nameCaptor.getValue());
    assertEquals(key, keypairCaptor.getValue());
    Keypair result = msg.getBody(Keypair.class);
    assertEquals(dummyKeypair.getName(), result.getName());
    assertEquals(dummyKeypair.getFingerprint(), result.getFingerprint());
    assertEquals(dummyKeypair.getPrivateKey(), result.getPrivateKey());
    assertEquals(key, result.getPublicKey());
}
Also used : Keypair(org.openstack4j.model.compute.Keypair) NovaKeypair(org.openstack4j.openstack.compute.domain.NovaKeypair) Test(org.junit.Test)

Example 5 with Keypair

use of org.openstack4j.model.compute.Keypair in project wildfly-camel by wildfly-extras.

the class OpenstackIntegrationTest method testNovaKeypair.

@Test
public void testNovaKeypair() throws Exception {
    when(osTestKeypair.getName()).thenReturn(KEYPAIR_NAME);
    when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey());
    when(osTestKeypair.getFingerprint()).thenReturn("fp");
    when(osTestKeypair.getPrivateKey()).thenReturn("prk");
    CamelContext camelContext = Mockito.mock(CamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());
    Message msg = new DefaultMessage(camelContext);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);
    NovaEndpoint endpoint = Mockito.mock(NovaEndpoint.class);
    Producer producer = new KeypairProducer(endpoint, client);
    producer.process(exchange);
    ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class);
    verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture());
    assertEquals(KEYPAIR_NAME, nameCaptor.getValue());
    assertNull(keypairCaptor.getValue());
    Keypair result = msg.getBody(Keypair.class);
    assertEquals("fp", result.getFingerprint());
    assertEquals("prk", result.getPrivateKey());
    assertEquals(dummyKeypair.getName(), result.getName());
    assertEquals(dummyKeypair.getPublicKey(), result.getPublicKey());
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultMessage(org.apache.camel.impl.DefaultMessage) Exchange(org.apache.camel.Exchange) NovaEndpoint(org.apache.camel.component.openstack.nova.NovaEndpoint) NovaKeypair(org.openstack4j.openstack.compute.domain.NovaKeypair) Keypair(org.openstack4j.model.compute.Keypair) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) VolumeProducer(org.apache.camel.component.openstack.cinder.producer.VolumeProducer) ProjectProducer(org.apache.camel.component.openstack.keystone.producer.ProjectProducer) ContainerProducer(org.apache.camel.component.openstack.swift.producer.ContainerProducer) GlanceProducer(org.apache.camel.component.openstack.glance.GlanceProducer) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Producer(org.apache.camel.Producer) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) DefaultHeadersMapFactory(org.apache.camel.impl.DefaultHeadersMapFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Test(org.junit.Test)

Aggregations

Keypair (org.openstack4j.model.compute.Keypair)9 Test (org.junit.Test)4 Message (org.apache.camel.Message)3 NovaKeypair (org.openstack4j.openstack.compute.domain.NovaKeypair)3 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)2 FileNotFoundException (java.io.FileNotFoundException)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudSshKey (com.sequenceiq.cloudbreak.cloud.model.CloudSshKey)1 CloudSshKeys (com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)1 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)1 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Scanner (java.util.Scanner)1 Set (java.util.Set)1 CloudInterface (org.apache.airavata.cloud.intf.CloudInterface)1 OpenstackIntfImpl (org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 Producer (org.apache.camel.Producer)1