Guest User

Untitled

a guest
Oct 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. def createContext = {
  2. ContextBuilder.newBuilder(new AWSEC2ProviderMetadata)
  3. .credentials("<>", "<>")
  4. .buildView(classOf[AWSEC2ComputeServiceContext])
  5. .unwrap(classOf[RestContext[AWSEC2Client, AWSEC2AsyncClient]])
  6. }
  7.  
  8. implicit def syncApi = createContext.getApi
  9.  
  10. def createInstance(imageId: String, hwType: String, group: String, key: String)(implicit c: AWSEC2Client, region: String = null) = {
  11. val opts = AWSRunInstancesOptions.Builder.asType(hwType).withSecurityGroup(group).withKeyName(key)
  12. val instances = c.getInstanceServices.runInstancesInRegion(region,null,imageId,1,1,opts)
  13. instances.headOption
  14. }
  15.  
  16. def destroyInstance(id: String)(implicit c: AWSEC2Client, region: String = null) = {
  17. val instances = c.getInstanceServices.terminateInstancesInRegion(region, id)
  18. instances.headOption
  19. }
  20.  
  21. def runningInstance(id: String)(implicit c: AWSEC2Client, region: String = null): Option[RunningInstance] = {
  22. val instance = c.getInstanceServices.describeInstancesInRegion(region, id).headOption
  23. for {
  24. i <- instance
  25. runningInstance <- i.headOption
  26. } yield runningInstance
  27. }
Add Comment
Please, Sign In to add comment