It’s been a few clicks since my last blog post. Honestly, it continues to be a drag everytime I have to state that, but that’s a topic for yet another blog post. That’s not to say that I haven’t been busy. Lately, within the OpenStack community, I’ve managed to begin my work to interface with the OpenStack API using the primary programming language that Apple developer use to create iOS apps, Swift. The purpose is to show how easy (or difficult) it is to create apps that interface with OpenStack, in an effort to illustrate the idea of developing mobile solutions for OpenStack operators and end-users. I’ll start this series of blog posts with a quick how-to on using Swift combined with a popular HTTP networking library, Alamofire. I figured that it could be beneficial to others to see how this works, so if you’re at all interested, read on.
Let’s start by getting your iOS development environment ready to interface with the OpenStack REST API. The steps below will illustrate how to prepare a local development environment, which will leverage Apple Xcode, Swift Playgrounds, the AlamoFire HTTP networking library, and API-level access to an OpenStack deployment.
iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
API-level access to an OpenStack deployment
Create a new Xcode project by opening Xcode, and selecting New -> Project… from the File menu.
In the left pane of the ‘Choose a template for your new project’ window, ensure that Application is selected underneath the iOS category.
The right pane of this window will offer your several application options. For now, select the Single View Application template, and press the Next button.
Next you will configure additional options for the new project. Since we will use a Swift playground for most of our initial vahana development, fill in the options as follows:
Product Name: myVahanaProject Organization Name: OpenStack Organization Identifier: org.openstack Language: Swift Devices: Universal
Choose where you want to store your Xcode project.
Alamofire is a Swift-based HTTP networking library for iOS and Mac OS X.
CocoaPods makes installing Xcode project dependencies much easier. To install CocoaPods:
gem install cocoapods
In the left-pane of the ‘Choose a template for your new project’ popup window, select iOS->Application, then choose Single View Application.
Enter in the project credentials:
Project Name: myVahanaTestProj Organization Name: Openstack Organization Identifier: org.openstack.myvahanatestproj Language: Swift Devices: Universal
After the project is created, locate the project directory, and create a file named ‘Podfile’ with the following contents:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! pod 'Alamofire', '~> 3.0'
Save this file, then run ‘pod install’ to install the Alamofire cocoapod.
After the Alamofire cocopod is installed, re-open the test-project .xcworkspace instead of the test-project .xcodeproj file.
In the Project Navigator, you should now see two projects as part of the Xcode workspace. Your test project, and the Pods project, which contains the AlamoFire library.
To test that Alamofire is working within your new Xcode project, create an Xcode playground:
In the ‘Choose options for your new playground’ window type the name of your Playground, and ensure that iOS is selected for the platform.
IMPORTANT: Ensure that your new Xcode playground has been added to the Xcode WORKSPACE, not the Xcode PROJECT. If you make the mistake of adding your new Playground directly to the project, the Alamofire Module will not be imported.
Test that AlamoFire is working by entering the following code into your new Xcode playground:
This will issue a short HTTP GET request to https://httpbin.org/get, and if it is successful, it will return a chunk of JSON data. At this point, you have confirmed the ability to make HTTP requests using Alamofire as the primary networking resource. OpenStack-Vahana currently uses Alamofire for each of the REST API requests
There are many ways to access an OpenStack deployment using the OpenStack REST API:
Deploying an instance of OpenStack locally, using tools like devstack and/or RDO. Use this option for a completely controlled environment
trystack.org, the free OpenStack sandbox used for testing. Note, this option only allows users to run test code for a brief period of time.
Vendor-specific OpenStack offerings. Whether a free tier or as a paid service, several vendors offer OpenStack deployments with API access for the end user(s).
In order to utilize openstack-vahana in conjunction with the OpenStack deployment you’ve selected, you will need the following information:
auth_url username password project_id
With this information in hand, you’re ready to test out openstack-vahana, the project I’ve been working on to revive the iOS client for OpenStack. The next blog post in the series will talk about how to do just that.