Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        public VcapClientResult DeleteUser(string email)
        {
            var appsHelper = new AppsHelper(credMgr);
            foreach (Application a in appsHelper.GetApplications(email))
            {
                appsHelper.Delete(a.Name);
            }

            var servicesHelper = new ServicesHelper(credMgr);
            foreach (ProvisionedService ps in servicesHelper.GetProvisionedServices(email))
            {
                servicesHelper.DeleteService(ps.Name);
            }

            var r = new VcapJsonRequest(credMgr, Method.DELETE, Constants.USERS_PATH, email);
            RestResponse response = r.Execute();
            return new VcapClientResult();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
 public void Delete(string name)
 {
     var r = new VcapJsonRequest(credMgr, Method.DELETE, Constants.APPS_PATH, name);
     r.Execute();
 }
Ejemplo n.º 9
0
        private void uploadAppBits(string name, DirectoryInfo path)
        {
            /*
             * Before creating the app, ensure we can build resource list
             */
            string uploadFile = Path.GetTempFileName();
            DirectoryInfo explodeDir = Utility.GetTempDirectory();
            Utility.CopyDirectory(path, explodeDir);
            try
            {
                var resources = new List<Resource>();
                ulong totalSize = addDirectoryToResources(resources, explodeDir, explodeDir.FullName);

                if (false == resources.IsNullOrEmpty())
                {
                    Resource[] appcloudResources = null;
                    if (totalSize > (64 * 1024))
                    {
                        appcloudResources = checkResources(resources.ToArray());
                    }
                    if (appcloudResources.IsNullOrEmpty())
                    {
                        appcloudResources = resources.ToArrayOrNull();
                    }
                    else
                    {
                        foreach (Resource r in appcloudResources)
                        {
                            string localPath = Path.Combine(explodeDir.FullName, r.FN);
                            var localFileInfo = new FileInfo(localPath);
                            localFileInfo.Delete();
                            resources.Remove(r);
                        }
                    }
                    if (resources.IsNullOrEmpty())
                    {
                        /*
                            If no resource needs to be sent, add an empty file to ensure we have
                            a multi-part request that is expected by nginx fronting the CC.
                         */
                        File.WriteAllText(Path.Combine(explodeDir.FullName, ".__empty__"), String.Empty);
                    }

                    var zipper = new FastZip();
                    zipper.CreateZip(uploadFile, explodeDir.FullName, true, String.Empty);
                    var request = new VcapJsonRequest(credMgr, Method.PUT, Constants.APPS_PATH, name, "application");
                    request.AddFile("application", uploadFile);
                    request.AddParameter("resources", JsonConvert.SerializeObject(appcloudResources.ToArrayOrNull()));
                    RestResponse response = request.Execute();
                }
            }
            finally
            {
                Directory.Delete(explodeDir.FullName, true);
                File.Delete(uploadFile);
            }
        }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
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>();
 }
Ejemplo n.º 12
0
 public VcapClientResult DeleteService(string argProvisionedServiceName)
 {
     var request = new VcapJsonRequest(credMgr, Method.DELETE, Constants.SERVICES_PATH, argProvisionedServiceName);
     request.Execute();
     return new VcapClientResult();
 }
Ejemplo n.º 13
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();
        }