OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 /** | 3 /** |
4 Sandbox APIs mimicking communications with the Go and Juju backends. | 4 Sandbox APIs mimicking communications with the Go and Juju backends. |
5 | 5 |
6 @module env | 6 @module env |
7 @submodule env.sandbox | 7 @submodule env.sandbox |
8 */ | 8 */ |
9 | 9 |
10 YUI.add('juju-env-sandbox', function(Y) { | 10 YUI.add('juju-env-sandbox', function(Y) { |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 data.err = res.error; | 552 data.err = res.error; |
553 data.result = (res.error === undefined); | 553 data.result = (res.error === undefined); |
554 | 554 |
555 this.get('client').receiveNow(data); | 555 this.get('client').receiveNow(data); |
556 }, | 556 }, |
557 | 557 |
558 /** | 558 /** |
559 Handles adding a relation between two supplied services from the client | 559 Handles adding a relation between two supplied services from the client |
560 | 560 |
561 @method performOp_add_relation | 561 @method performOp_add_relation |
562 @param {Array | String} data containing either a string in the format | 562 @param {Object} data Object contains the operation, two endpoint strings |
563 wordpress:db or an array in the format | 563 and request id. |
564 ['wordpress', { name: 'db', role: 'client'}]. | |
565 */ | 564 */ |
566 performOp_add_relation: function(data) { | 565 performOp_add_relation: function(data) { |
567 var relation = this.get('state').addRelation( | 566 var relation = this.get('state').addRelation( |
568 data.endpoint_a, data.endpoint_b); | 567 data.endpoint_a, data.endpoint_b); |
569 | 568 |
570 if (relation === false) { | 569 if (relation === false) { |
571 // If everything checks out but could not create a new relation model | 570 // If everything checks out but could not create a new relation model |
572 data.err = 'Unable to create relation'; | 571 data.err = 'Unable to create relation'; |
573 this.get('client').receiveNow(data); | 572 this.get('client').receiveNow(data); |
574 return; | 573 return; |
(...skipping 13 matching lines...) Expand all Loading... |
588 data.result = { | 587 data.result = { |
589 endpoints: [epA, epB], | 588 endpoints: [epA, epB], |
590 id: relation.relationId, | 589 id: relation.relationId, |
591 // interface is a reserved word | 590 // interface is a reserved word |
592 'interface': relation.type, | 591 'interface': relation.type, |
593 scope: relation.scope, | 592 scope: relation.scope, |
594 request_id: data.request_id | 593 request_id: data.request_id |
595 }; | 594 }; |
596 | 595 |
597 this.get('client').receive(data); | 596 this.get('client').receive(data); |
| 597 }, |
| 598 |
| 599 /** |
| 600 Handles removing a relation between two supplied services from the client |
| 601 |
| 602 @method performOp_remove_relation |
| 603 @param {Object} data Object contains the operation, two endpoint strings |
| 604 and request id. |
| 605 */ |
| 606 performOp_remove_relation: function(data) { |
| 607 var relation = this.get('state').removeRelation( |
| 608 data.endpoint_a, data.endpoint_b); |
| 609 |
| 610 if (relation.error) { |
| 611 data.err = relation.error; |
| 612 } else { |
| 613 data.result = true; |
| 614 } |
| 615 |
| 616 this.get('client').receive(data); |
598 } | 617 } |
| 618 |
599 }); | 619 }); |
600 | 620 |
601 sandboxModule.PyJujuAPI = PyJujuAPI; | 621 sandboxModule.PyJujuAPI = PyJujuAPI; |
602 }, '0.1.0', { | 622 }, '0.1.0', { |
603 requires: [ | 623 requires: [ |
604 'base', | 624 'base', |
605 'timers', | 625 'timers', |
606 'json-parse' | 626 'json-parse' |
607 ] | 627 ] |
608 }); | 628 }); |
OLD | NEW |