Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try/catch displays error output #233

Open
sbtaylor15 opened this issue Dec 7, 2017 · 5 comments
Open

try/catch displays error output #233

sbtaylor15 opened this issue Dec 7, 2017 · 5 comments

Comments

@sbtaylor15
Copy link
Contributor

Try/Catch of invalid parse from restful_get shows output in red in log. try catch should now display output by default

@pgibbs-openmake
Copy link
Contributor

Can you paste the DMScript in here so I can see what it looks like? I presume:

try {
set res = restful_get(...);
} catch(ex) {
echo $ex;
}

Are you saying the parse error is being reported to stderr (in red) at the set res = part or the echo in the catch block (if any) is reporting to stderr?

@sbtaylor15
Copy link
Contributor Author

set servers = ${environment.servers};
set cookiejar = "";

iterate(s: $servers)
{
if (${s.name.lower().substr(0,3)} = "rs_")
{
set attrs = ${s.attributes};
set OpenStackUser = $attrs['OpenStackUser'];
set OpenStackApiKey = $attrs['OpenStackApiKey'];
set OpenStackIdentity = $attrs['OpenStackIdentity'];
set OpenStackEndPoint = $attrs['OpenStackEndPoint'];
set OpenStackTenantID = $attrs['OpenStackTenantID'];
set OpenStackImage = $attrs['OpenStackImage'];
set OpenStackFlavor = $attrs['OpenStackFlavor'];
set OpenStackKeyName = $attrs['OpenStackKeyName'];

set login = {"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"$OpenStackUser","apiKey":"$OpenStackApiKey"}}};
set res = restful_post("$OpenStackIdentity",$login);
set token = ${res.access.token.id};

set auth={"X-Auth-Token": "$token"}; // Returned token will be included in the header
set res = restful_get("https://$OpenStackEndPoint/v2/$OpenStackTenantID/servers",null,null,$auth);

set found = 0;
set instanceid = "";
set x = length(${res.servers});

for (n = 0; $n < $x; n = $n + 1)
{
set server = $res["servers"][$n];
set name = ${server.name};
set instanceid = ${server.id};

if ($name = ${s.hostname})
{
 set found = 1;
}

}

if ($found = 1)
{
echo "${s.hostname} is up and running on $instanceid";
}
else
{
set serverdef = {"server": {"name": "${s.hostname}", "imageRef": "$OpenStackImage", "flavorRef": "$OpenStackFlavor", "key_name":"$OpenStackKeyName"}};
set res = restful_post("https://$OpenStackEndPoint/v2/$OpenStackTenantID/servers",$serverdef,null,$auth);
set serverid = ${res.server.id};
echo $serverid;

set foundip=0;
set myip = "";

while ($foundip = 0)
{
 try
 {
  set res = restful_get("https://$OpenStackEndPoint/v2/$OpenStackTenantID/servers/$serverid",null,null,$auth);
  set iplist = ${res.server.addresses.public};
  set x = length($iplist);

  for (n = 0; $n < $x; n = $n + 1)
  {
   if ($iplist[$n]['version'] = 4)
   {
    set foundip = 1;
    set myip = $iplist[$n]['addr'];
   }
  }
 }
 catch (ex)
 {
				 echo "Sleeping";
  sleep(delay: 30);
 }
}

echo "Setting ${s.hostname} to $myip";
set res = restful_get("https://members.dyndns.org/v3/update?hostname=${s.hostname}&myip=$myip","","","dyndns");
echo $res;
echo "";
echo "server is ${s.name}";
echo "hostname is ${s.hostname}";
set ready = DNSReady(${s.hostname},$myip);
echo $ready;

}
}
else
{
if (${s.name.lower().substr(0,3)} != "zos")
{
set parms = ["ec2", "describe-instances", "--filters", "Name=instance-state-name,Values=running"];

set myvar = AwsEC2($parms);
set found = 0;
set instanceid = "";
set x = length(${myvar.Reservations});

for (n = 0; $n < $x; n = $n + 1)
{
set res = $myvar["Reservations"][$n];
set name = ${res.Instances[0].Tags[0].Value};
set instanceid = ${res.Instances[0].InstanceId};

 if ($name = ${s.hostname})
 {
  set found = 1;
 }

}

if ($found = 1)
{
echo "${s.hostname} is up and running on $instanceid";
}
else
{
set parms = ["ec2", "run-instances", "--image-id", $ImageId, "--count", "1", "--instance-type", $InstanceType, "--key-name", $KeyName, "--security-group-ids", $SecurityGroupIds, "--subnet-id", $SubNetId, "--associate-public-ip-address", "--tag-specifications", "ResourceType=instance,Tags=[{Key=Name,Value=${s.hostname}}]"];

set myvar = AwsEC2($parms);
set instanceid = ${myvar.Instances[0].InstanceId};
echo "INSTANCE ID=$instanceid";

set parms = ["ec2", "describe-instances", "--instance-ids", $instanceid];
set myvar = AwsEC2($parms);

set myip = ${myvar.Reservations[0].Instances[0].PublicIpAddress};
echo "Setting ${s.hostname} to $myip";
set res = restful_get("https://members.dyndns.org/v3/update?hostname=${s.hostname}&myip=$myip","","","dyndns");
echo $res;
echo "";
echo "server is ${s.name}";
echo "hostname is ${s.hostname}";
set ready = DNSReady(${s.hostname},$myip);
echo $ready;

}
}
}
}

@sbtaylor15
Copy link
Contributor Author

INFO: Starting deployment #1780

INFO: Deploying Application "IT Guys;3" into Environment "IT Guys Dev ZS"
INFO: Rolling Forward from NULL to IT Guys;3
{"server":{"imageRef":"59ab613b-8040-4a06-a5de-61a8a337b2c6","key_name":"steve","flavorRef":2,"name":"zs-itguys-dev.gotdns.com"}}
6f44aa9d-69a2-4874-b695-f088b2c3c700
Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:53Z", "hostId": "", "addresses": {>>>}<<<, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "scheduling", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {}}}syntax error, unexpected '}', expecting string literal
Sleeping
Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal
Sleeping
Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal
Sleeping
Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal
Sleeping
Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal
Sleeping
 

@pgibbs-openmake
Copy link
Contributor

Right, the error will still be thrown but it'll be caught by the catch block rather than throwing a runtime exception. I assume the "Syntax error at line 1" is what's coming out in red?

@sbtaylor15
Copy link
Contributor Author

sbtaylor15 commented Dec 7, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants