예제 #1
0
        public VcapResponse UpdateApplication(Application app)
        {
            var r = new VcapJsonRequest(credMgr, Method.PUT, Constants.APPS_PATH, app.Name);

            r.AddBody(app);
            return(r.Execute <VcapResponse>());
        }
예제 #2
0
        public VcapClientResult AddUser(string email, string password)
        {
            var r = new VcapJsonRequest(credMgr, Method.POST, Constants.USERS_PATH);

            r.AddBody(new { email = email, password = password });
            RestResponse response = r.Execute();

            return(new VcapClientResult());
        }
예제 #3
0
        public VcapClientResult ChangePassword(string user, string newpassword)
        {
            var          r        = new VcapRequest(credMgr, Constants.USERS_PATH, user);
            RestResponse response = r.Execute();

            JObject parsed = JObject.Parse(response.Content);

            parsed["password"] = newpassword;

            var put = new VcapJsonRequest(credMgr, Method.PUT, Constants.USERS_PATH, user);

            put.AddBody(parsed);
            response = put.Execute();

            return(new VcapClientResult());
        }
예제 #4
0
        private Resource[] checkResources(Resource[] resourceAry)
        {
            /*
             *  Send in a resources manifest array to the system to have
             *  it check what is needed to actually send. Returns array
             *  indicating what is needed. This returned manifest should be
             *  sent in with the upload if resources were removed.
             *  E.g. [{:sha1 => xxx, :size => xxx, :fn => filename}]
             */
            var r = new VcapJsonRequest(credMgr, Method.POST, Constants.RESOURCES_PATH);

            r.AddBody(resourceAry);
            RestResponse response = r.Execute();

            return(JsonConvert.DeserializeObject <Resource[]>(response.Content));
        }
예제 #5
0
        public VcapClientResult UnbindService(string argProvisionedServiceName, string argAppName)
        {
            var    apps      = new AppsHelper(credMgr);
            string appJson   = apps.GetApplicationJson(argAppName);
            var    appParsed = JObject.Parse(appJson);
            var    services  = (JArray)appParsed["services"];

            appParsed["services"] = new JArray(services.Where(s => ((string)s) != argProvisionedServiceName));

            var r = new VcapJsonRequest(credMgr, Method.PUT, Constants.APPS_PATH, argAppName);

            r.AddBody(appParsed);
            RestResponse response = r.Execute();

            apps = new AppsHelper(credMgr);
            apps.Restart(argAppName);

            return(new VcapClientResult());
        }
예제 #6
0
        public VcapClientResult BindService(string argProvisionedServiceName, string argAppName)
        {
            var apps = new AppsHelper(credMgr);

            Application app = apps.GetApplication(argAppName);

            app.Services.Add(argProvisionedServiceName);

            var request = new VcapJsonRequest(credMgr, Method.PUT, Constants.APPS_PATH, app.Name);

            request.AddBody(app);
            RestResponse response = request.Execute();

            // Ruby code re-gets info
            app = apps.GetApplication(argAppName);
            if (app.IsStarted)
            {
                apps.Restart(app);
            }
            return(new VcapClientResult());
        }
예제 #7
0
        public VcapClientResult Login(string argEmail, string argPassword)
        {
            VcapClientResult rv;

            var r = new VcapJsonRequest(credMgr, Method.POST, Constants.USERS_PATH, argEmail, "tokens");

            r.AddBody(new { password = argPassword });
            RestResponse response = r.Execute();

            if (response.Content.IsNullOrEmpty())
            {
                rv = new VcapClientResult(false, Resources.Vmc_NoContentReturned_Text);
            }
            else
            {
                var    parsed = JObject.Parse(response.Content);
                string token  = parsed.Value <string>("token");
                credMgr.RegisterToken(token);
                rv = new VcapClientResult();
            }

            return(rv);
        }
예제 #8
0
        public VcapClientResult CreateService(string argServiceName, string argProvisionedServiceName)
        {
            VcapClientResult rv;

            IEnumerable <SystemService> services = GetSystemServices();

            if (services.IsNullOrEmpty())
            {
                rv = new VcapClientResult(false);
            }
            else
            {
                SystemService svc = services.FirstOrDefault(s => s.Vendor == argServiceName);
                if (null == svc)
                {
                    rv = new VcapClientResult(false);
                }
                else
                {
                    // from vmc client.rb
                    var data = new
                    {
                        name    = argProvisionedServiceName,
                        type    = svc.Type,
                        tier    = "free",
                        vendor  = svc.Vendor,
                        version = svc.Version,
                    };
                    var r = new VcapJsonRequest(credMgr, Method.POST, Constants.SERVICES_PATH);
                    r.AddBody(data);
                    RestResponse response = r.Execute();
                    rv = new VcapClientResult();
                }
            }

            return(rv);
        }
예제 #9
0
        public VcapClientResult Push(string name, string deployFQDN, ushort instances,
                                     DirectoryInfo path, uint memoryMB, string[] provisionedServiceNames, string framework, string runtime)
        {
            VcapClientResult rv;

            if (path == null)
            {
                rv = new VcapClientResult(false, "Application local location is needed");
            }
            else if (deployFQDN == null)
            {
                rv = new VcapClientResult(false, "Please specify the url to deploy as.");
            }
            else if (framework == null)
            {
                rv = new VcapClientResult(false, "Please specify application framework");
            }
            else
            {
                if (AppExists(name))
                {
                    rv = new VcapClientResult(false, String.Format(Resources.AppsHelper_PushApplicationExists_Fmt, name));
                }
                else
                {
                    /*
                     * Before creating the app, ensure we can build resource list
                     */
                    var   resources = new List <Resource>();
                    ulong totalSize = addDirectoryToResources(resources, path, path.FullName);

                    var manifest = new AppManifest
                    {
                        Name    = name,
                        Staging = new Staging {
                            Framework = framework, Runtime = runtime
                        },
                        Uris      = new string[] { deployFQDN },
                        Instances = instances,
                        Resources = new AppResources {
                            Memory = memoryMB
                        },
                    };

                    var r = new VcapJsonRequest(credMgr, Method.POST, Constants.APPS_PATH);
                    r.AddBody(manifest);
                    RestResponse response = r.Execute();

                    uploadAppBits(name, path);

                    Application app = GetApplication(name);
                    app.Start();
                    r = new VcapJsonRequest(credMgr, Method.PUT, Constants.APPS_PATH, name);
                    r.AddBody(app);
                    response = r.Execute();

                    bool started = isStarted(app.Name);

                    if (started && false == provisionedServiceNames.IsNullOrEmpty())
                    {
                        foreach (string svcName in provisionedServiceNames)
                        {
                            var servicesHelper = new ServicesHelper(credMgr);
                            servicesHelper.BindService(svcName, app.Name);
                        }
                    }

                    rv = new VcapClientResult(started);
                }
            }

            return(rv);
        }