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; }
public IList<Instance> ListInstances(Identity identity) { IList<Instance> list = new List<Instance>(); RequestManager requestManager = new RequestManager(identity); var uri = "/servers/detail"; JObject response = requestManager.Get(uri, "nova"); var tempinstances = response["servers"]; foreach (var tempinstance in tempinstances) { var instance = new Instance() { Id = tempinstance["id"].ToString(), Name = tempinstance["name"].ToString(), FlavorName = new FlavorManager(identity).Get(tempinstance["flavor"]["id"].ToString(), identity).Name }; list.Add(instance); } return list; }
public Instance GetInstance(Instance instance, Identity identity) { return GetInstance(instance.Id, _identity); }
public Instance GetInstance(Instance instance) { return GetInstance(instance, _identity); }
public Instance GetInstance(string instanceId, Identity identity) { Instance instance; RequestManager requestManager = new RequestManager(identity); var uri = string.Format("/servers/{0}", instanceId); JObject response = requestManager.Get(uri, "nova"); var tempinstance = response["server"]; if (response != null) { instance = new Instance() { Id = tempinstance["id"].ToString(), Name = tempinstance["name"].ToString(), status = (InstanceStatus)Enum.Parse(typeof(InstanceStatus), tempinstance["status"].ToString()), }; return instance; } return null; }
public Instance Get(string id, Identity identity) { Instance instance = null; RequestManager requestManager = new RequestManager(identity); var uri = String.Format("/servers/{0}", id); JObject response = requestManager.Get(uri, "nova"); var tempinstance = response["server"]; instance = new Instance() { Id = tempinstance["id"].ToString(), Name = tempinstance["name"].ToString() }; return instance; }