private void bttDeploy_Click(object sender, EventArgs e) { string poaHostname = ((DataRowView)cbOSAServers.SelectedValue)["poa_hostname"].ToString(); string poaPassword = ((DataRowView)cbOSAServers.SelectedValue)["poa_password"].ToString(); string endpointHostname = ((DataRowView)cbOSAServers.SelectedValue)["endpoint_hostname"].ToString(); string endpointPassword = ((DataRowView)cbOSAServers.SelectedValue)["endpoint_password"].ToString(); string APSUrl = ""; string EndpointUrl = ""; int application_id = 0; XmlRPC xml = new XmlRPC("http://" + poaHostname + ":8440/RPC2"); SSHCommunication ssh; OpenAPI.pem.getAccountTokenResponse accountTokenResponse = xml.getAccountToken(1, 1); lsbStatus.Items.Insert(0, "account Token: " + accountTokenResponse.aps_token); lsbStatus.Items.Insert(0, "controller Uri: " + accountTokenResponse.controller_uri); string accountToken = accountTokenResponse.aps_token; string controllerUri = accountTokenResponse.controller_uri; APSController.Controller c = new APSController.Controller(controllerUri, accountToken); foreach (DataRowView drvResource in lsbResources.Items) { var newResource = new ExpandoObject() as IDictionary <string, Object>; newResource.Add("aps", new aps() { type = drvResource["type"].ToString() }); foreach (DataRow dr in db.APSResourceProperties_Get(drvResource["id"].ToString()).Rows) { newResource.Add(dr["name"].ToString(), dr["value"].ToString()); } c.Resources.CreateResource(newResource); } //return; pbDeployment.Step = 10; lsbStatus.Items.Insert(0, "Checking APS Package..."); if (!File.Exists(txtAPSPackage.Text)) { pbDeployment.Value = 0; lsbStatus.Items.Insert(0, "ERROR: APS file does not exist"); return; } lsbStatus.Items.Insert(0, "File exists... progressing..."); pbDeployment.PerformStep(); pbDeployment.Value = 10; lsbStatus.Items.Insert(0, "Checking endpoint server connectivity"); try { ssh = new SSHCommunication(endpointHostname, "root", endpointPassword); } catch (Exception err) { pbDeployment.Value = 0; lsbStatus.Items.Insert(0, err.Message); lsbStatus.Items.Insert(0, "ERROR: Connection to endpoint server was not success..."); return; } lsbStatus.Items.Insert(0, "Connection success."); try { ssh.CopyFile(txtAPSPackage.Text, "/var/www/html/"); lsbStatus.Items.Insert(0, "File uploaded(" + Path.GetFileName(txtAPSPackage.Text) + ")..."); APSUrl = "http://" + endpointHostname + "/" + Path.GetFileName(txtAPSPackage.Text); lsbStatus.Items.Insert(0, APSUrl); } catch (Exception ex) { lsbStatus.Items.Insert(0, "ERROR: " + ex.Message + ex.StackTrace); pbDeployment.Value = 0; return; } if (ckbDeployEndpoint.Checked) { if (!File.Exists(SSHCommunication.EndpointSH)) { lsbStatus.Items.Insert(0, "Downloading endpoint.sh from apsstandard.org..."); SSHCommunication.DownloadEndpoint(); lsbStatus.Items.Insert(0, "Downloaded."); } lsbStatus.Items.Insert(0, "Uploading file to server..."); try { ssh.CopyFile(SSHCommunication.EndpointSH); lsbStatus.Items.Insert(0, "File uploaded(" + Path.GetFileName(SSHCommunication.EndpointSH) + ")..."); } catch (Exception err) { lsbStatus.Items.Insert(0, "ERROR: " + err.Message + err.StackTrace); pbDeployment.Value = 0; return; } lsbStatus.Items.Insert(0, "Creating endpoint for " + Path.GetFileName(SSHCommunication.EndpointSH)); Renci.SshNet.SshCommand commandResult = ssh.RunCommand("sh endpoint.sh " + txtEndpointName.Text + " " + Path.GetFileName(txtAPSPackage.Text)); if (commandResult.Result.Contains("already exists")) { commandResult = ssh.RunCommand("sh endpoint.sh --upgrade " + txtEndpointName.Text + " /var/www/html/" + Path.GetFileName(txtAPSPackage.Text)); } if (commandResult.Result.Contains("CONGRATULATIONS")) { lsbStatus.Items.Insert(0, "Endpoint created"); } else { lsbStatus.Items.Insert(0, "ERROR: Endpoint failed to create: " + commandResult.Result); return; } EndpointUrl = "https://" + endpointHostname + "/" + txtEndpointName.Text; } try { lsbStatus.Items.Insert(0, "Importing APS Package"); var importPackage = xml.importPackage(APSUrl); lsbStatus.Items.Insert(0, "APS Package Imported"); application_id = importPackage.application_id; } catch (Exception ex) { lsbStatus.Items.Insert(0, "ERROR: " + ex.Message); return; } List <OpenAPI.pem.settings> settings = new List <OpenAPI.pem.settings>(); foreach (DataRowView drv in this.lsbParameters.Items) { settings.Add(new OpenAPI.pem.settings() { name = drv["name"].ToString(), value = drv["value"].ToString() }); } var provideApplication = xml.provideApplicationInstance(0, 0, application_id, EndpointUrl, settings.ToArray(), new string[] { }); lsbStatus.Items.Insert(0, "Finish!"); }
private void bttDeploy_Click(object sender, EventArgs e) { string poaHostname = ((DataRowView)cbOSAServers.SelectedValue)["poa_hostname"].ToString(); string poaPassword = ((DataRowView)cbOSAServers.SelectedValue)["poa_password"].ToString(); string endpointHostname = ((DataRowView)cbOSAServers.SelectedValue)["endpoint_hostname"].ToString(); string endpointPassword = ((DataRowView)cbOSAServers.SelectedValue)["endpoint_password"].ToString(); string APSUrl = ""; string EndpointUrl = ""; int application_id = 0; XmlRPC xml = new XmlRPC("http://" + poaHostname + ":8440/RPC2"); SSHCommunication ssh; OpenAPI.pem.getAccountTokenResponse accountTokenResponse = xml.getAccountToken(1, 1); lsbStatus.Items.Insert(0, "account Token: " + accountTokenResponse.aps_token); lsbStatus.Items.Insert(0, "controller Uri: " + accountTokenResponse.controller_uri); string accountToken = accountTokenResponse.aps_token; string controllerUri = accountTokenResponse.controller_uri; APSController.Controller c = new APSController.Controller(controllerUri, accountToken); foreach(DataRowView drvResource in lsbResources.Items) { var newResource = new ExpandoObject() as IDictionary<string, Object>; newResource.Add("aps", new aps() { type = drvResource["type"].ToString() }); foreach(DataRow dr in db.APSResourceProperties_Get(drvResource["id"].ToString()).Rows) { newResource.Add(dr["name"].ToString(), dr["value"].ToString()); } c.Resources.CreateResource(newResource); } //return; pbDeployment.Step = 10; lsbStatus.Items.Insert(0, "Checking APS Package..."); if (!File.Exists(txtAPSPackage.Text)) { pbDeployment.Value = 0; lsbStatus.Items.Insert(0, "ERROR: APS file does not exist"); return; } lsbStatus.Items.Insert(0, "File exists... progressing..."); pbDeployment.PerformStep(); pbDeployment.Value = 10; lsbStatus.Items.Insert(0, "Checking endpoint server connectivity"); try { ssh = new SSHCommunication(endpointHostname, "root", endpointPassword); } catch (Exception err) { pbDeployment.Value = 0; lsbStatus.Items.Insert(0, err.Message); lsbStatus.Items.Insert(0, "ERROR: Connection to endpoint server was not success..."); return; } lsbStatus.Items.Insert(0, "Connection success."); try { ssh.CopyFile(txtAPSPackage.Text, "/var/www/html/"); lsbStatus.Items.Insert(0, "File uploaded(" + Path.GetFileName(txtAPSPackage.Text) + ")..."); APSUrl = "http://" + endpointHostname + "/" + Path.GetFileName(txtAPSPackage.Text); lsbStatus.Items.Insert(0, APSUrl); } catch (Exception ex) { lsbStatus.Items.Insert(0, "ERROR: " + ex.Message + ex.StackTrace); pbDeployment.Value = 0; return; } if (ckbDeployEndpoint.Checked) { if (!File.Exists(SSHCommunication.EndpointSH)) { lsbStatus.Items.Insert(0, "Downloading endpoint.sh from apsstandard.org..."); SSHCommunication.DownloadEndpoint(); lsbStatus.Items.Insert(0, "Downloaded."); } lsbStatus.Items.Insert(0, "Uploading file to server..."); try { ssh.CopyFile(SSHCommunication.EndpointSH); lsbStatus.Items.Insert(0, "File uploaded(" + Path.GetFileName(SSHCommunication.EndpointSH) + ")..."); } catch (Exception err) { lsbStatus.Items.Insert(0, "ERROR: " + err.Message + err.StackTrace); pbDeployment.Value = 0; return; } lsbStatus.Items.Insert(0, "Creating endpoint for " + Path.GetFileName(SSHCommunication.EndpointSH)); Renci.SshNet.SshCommand commandResult = ssh.RunCommand("sh endpoint.sh " + txtEndpointName.Text + " " + Path.GetFileName(txtAPSPackage.Text)); if (commandResult.Result.Contains("already exists")) commandResult = ssh.RunCommand("sh endpoint.sh --upgrade " + txtEndpointName.Text + " /var/www/html/" + Path.GetFileName(txtAPSPackage.Text)); if (commandResult.Result.Contains("CONGRATULATIONS")) lsbStatus.Items.Insert(0, "Endpoint created"); else { lsbStatus.Items.Insert(0, "ERROR: Endpoint failed to create: " + commandResult.Result); return; } EndpointUrl = "https://" + endpointHostname + "/" + txtEndpointName.Text; } try { lsbStatus.Items.Insert(0, "Importing APS Package"); var importPackage = xml.importPackage(APSUrl); lsbStatus.Items.Insert(0, "APS Package Imported"); application_id = importPackage.application_id; } catch (Exception ex) { lsbStatus.Items.Insert(0, "ERROR: " + ex.Message); return; } List<OpenAPI.pem.settings> settings = new List<OpenAPI.pem.settings>(); foreach (DataRowView drv in this.lsbParameters.Items) { settings.Add(new OpenAPI.pem.settings() { name = drv["name"].ToString(), value = drv["value"].ToString() }); } var provideApplication = xml.provideApplicationInstance(0, 0, application_id, EndpointUrl, settings.ToArray(), new string[] { }); lsbStatus.Items.Insert(0, "Finish!"); }