示例#1
0
        private bool loggedIn()
        {
            bool rv = false;

            VcapClientResult rslt = Info();

            if (rslt.Success)
            {
                info = rslt.GetResponseMessage <Info>();
                rv   = true;
            }

            return(rv);
        }
示例#2
0
        public VcapClientResult Update(string name, DirectoryInfo path)
        {
            VcapClientResult rv;

            if (path == null)
            {
                rv = new VcapClientResult(false, "Application local location is needed");
            }
            else
            {
                uploadAppBits(name, path);
                Application app = GetApplication(name);
                Restart(app);
                rv = new VcapClientResult();
            }

            return(rv);
        }
示例#3
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);
        }
示例#4
0
        public VcapClientResult Target(Uri argUri = null)
        {
            VcapClientResult rv;

            if (null == argUri)
            {
                // Just return current target
                rv = new VcapClientResult(false, credMgr.CurrentTarget.AbsoluteUriTrimmed());
            }
            else
            {
                // "target" does the same thing as "info", but not logged in
                // considered valid if name, build, version and support are all non-null
                // without argument, displays current target
                var  r    = new VcapRequest(credMgr, false, argUri, Constants.INFO_PATH);
                Info info = r.Execute <Info>();

                bool success = false;
                if (null != info)
                {
                    success = false == info.Name.IsNullOrWhiteSpace() &&
                              false == info.Build.IsNullOrWhiteSpace() &&
                              false == info.Version.IsNullOrWhiteSpace() &&
                              false == info.Support.IsNullOrWhiteSpace();
                }

                if (success)
                {
                    credMgr.SetTarget(argUri);
                    credMgr.StoreTarget();
                }

                rv = new VcapClientResult(success, credMgr.CurrentTarget.AbsoluteUriTrimmed());
            }

            return(rv);
        }
示例#5
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);
        }
示例#6
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);
        }