public void CreateKeypair(string name, Identity identity, FileInfo output) { Keypair keypair = new Keypair(); RequestManager requestManager = new RequestManager(identity); Keypair bodyObject = new Keypair() { name = name }; System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string body = oSerializer.Serialize(bodyObject); var uri = String.Format("/os-keypairs"); JObject response = requestManager.Post(uri, "{\"keypair\":" + body + "}", "nova"); keypair.publicKey = response["keypair"]["public_key"].ToString(); keypair.privateKey = response["keypair"]["private_key"].ToString(); keypair.userId = response["keypair"]["user_id"].ToString(); keypair.name = response["keypair"]["name"].ToString(); keypair.fingerprint = response["keypair"]["fingerprint"].ToString(); StreamWriter stream = new StreamWriter(output.FullName + name + ".pem"); stream.Write(keypair.privateKey); stream.Close(); }
public Instance CreateInstance(string instanceName, string imageId, string keypairName, string flavorId, Identity identity) { RequestManager requestManager = new RequestManager(identity); var uri = string.Format("/servers"); var bodyObject = new InstanceRequestBodyWrapper() { server = new InstanceRequestBody() { name = instanceName, imageRef = imageId, key_name = keypairName, flavorRef = flavorId, } }; System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string body = oSerializer.Serialize(bodyObject); JObject response = requestManager.Post(uri, body, "nova"); if (response != null) { var tempinstance = response["server"]; var instance = new Instance() { Id = tempinstance["id"].ToString(), }; return instance; } return null; }