Skip to content
Snippets Groups Projects
Commit 2756b521 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3199213 by Xiaohua Guan, yas: Add Cloud Orchestrator cloud service provider (cloud_cluster)

parent e4f5db9c
No related branches found
No related tags found
No related merge requests found
Showing
with 1134 additions and 9 deletions
...@@ -107,6 +107,71 @@ ...@@ -107,6 +107,71 @@
.attr('d', 'M943 123 c9 -2 23 -2 30 0 6 3 -1 5 -18 5 -16 0 -22 -2 -12 -5z') .attr('d', 'M943 123 c9 -2 23 -2 30 0 6 3 -1 5 -18 5 -16 0 -22 -2 -12 -5z')
.attr('fill', '#e1a813'); .attr('fill', '#e1a813');
// SVG for Cloud Orchestrator pointer
let cloud_cluster_pointer = defs.append('g')
.attr('id', 'cloud_cluster_pointer')
.attr('transform', 'scale(0.1)');
cloud_cluster_pointer.append('path')
.attr('d', 'M42.085,118.924c-9.45,-0 -17.111,-1.384 -17.111,-3.092c0,-1.708 7.661,-3.093 17.111,-3.093c9.45,-0 17.112,1.385 17.112,3.093c0,1.708 -7.662,3.092 -17.112,3.092Z')
.attr('fill', '#dfe0e1')
.attr('fill-rule', 'nonzero');
cloud_cluster_pointer.append('path')
.attr('d', 'M99.372,14.098c0,-2.628 -2.131,-4.759 -4.759,-4.759c-0.913,0 -1.762,0.261 -2.486,0.706c-0.834,-2.659 -3.009,-4.725 -5.732,-5.405c-0.627,-0.156 -1.282,-0.239 -1.957,-0.239c-0.954,0 -1.869,0.166 -2.718,0.471l-0.014,-0.023c-1.177,0.455 -2.217,1.19 -3.006,2.146c0.561,-1.185 1.511,-2.125 2.668,-2.721c-1.63,-2.568 -4.495,-4.274 -7.762,-4.274c-5.074,0 -9.189,4.115 -9.189,9.19c0,0.185 0.007,0.369 0.018,0.551c0.959,0.266 1.824,0.741 2.536,1.371c-0.79,-0.424 -1.67,-0.715 -2.604,-0.846c-1.336,0.532 -2.426,1.537 -3.075,2.808c1.919,0.446 3.354,1.4 3.74,2.557c-0.712,-0.858 -1.991,-1.477 -3.627,-1.786c-0.12,-0.014 -0.268,-0.048 -0.39,-0.056l-0.038,0.006c-0.11,-0.006 -0.222,-0.01 -0.334,-0.01c-3.263,0 -5.908,2.645 -5.908,5.907c0,3.263 2.645,5.908 5.908,5.908c0.238,0 0.471,-0.015 0.702,-0.042c0.922,1.967 2.522,3.553 4.498,4.46c1.164,0.534 2.46,0.834 3.826,0.834c1.332,0 2.598,-0.286 3.741,-0.796c1.504,1.838 3.79,3.011 6.351,3.011c2.503,0 4.743,-1.122 6.248,-2.889c0.952,0.32 1.978,0.472 3.041,0.416c4.526,-0.236 8.003,-4.096 7.767,-8.621c-0.063,-1.191 -0.377,-2.308 -0.887,-3.305c1.987,-0.571 3.442,-2.399 3.442,-4.57Z')
.attr('fill', '#18c2e7')
.attr('fill-rule', 'nonzero');
cloud_cluster_pointer.append('path')
.attr('d', 'M49.365,28.599l0.032,0.021l-0.024,-0.027l-0.008,0.006Z')
.attr('fill', '#002742')
.attr('fill-rule', 'nonzero');
cloud_cluster_pointer.append('path')
.attr('d', 'M30.519,48.624c-10.108,-1.729 -17.819,-0.494 -19.71,3.882c-0.958,2.216 -0.302,4.968 1.639,7.945c-3.231,-3.971 -4.536,-7.69 -3.296,-10.561c2.039,-4.719 10.456,-6 21.459,-4.042l-0.016,0.295c-0.041,0.822 -0.064,1.651 -0.076,2.481Zm24.672,5.524c17.205,8.427 28.371,19.866 25.454,26.62c-1.24,2.871 -4.841,4.47 -9.948,4.841c3.498,-0.628 5.95,-2.038 6.908,-4.253c2.81,-6.508 -8.26,-17.627 -25.073,-25.553c0.917,-0.308 1.792,-0.828 2.588,-1.587l0.071,-0.068Z')
.attr('fill', '#18c2e7');
cloud_cluster_pointer.append('path')
.attr('d', 'M54.943,40.659c0.524,-0.436 1.002,-0.821 1.466,-1.222c0.452,-0.392 0.931,-0.684 1.559,-0.7c1.511,-0.039 2.696,-0.698 3.524,-1.961c0.388,-0.591 2.148,-2.313 3.16,-2.849c2.018,-1.068 4.035,-2.139 6.043,-3.227c3.82,-2.07 7.634,-4.15 11.449,-6.23c0.399,-0.218 0.82,-0.463 1.141,-0.759c0.031,-0.078 0.055,-0.094 -0.065,-0.125c-0.331,0.035 -0.713,0.129 -1.024,0.285c-1.87,0.938 -3.729,1.899 -5.586,2.861c-4.361,2.258 -8.72,4.52 -13.077,6.785c-0.234,0.122 -0.361,0.083 -0.564,-0.101c-0.198,-0.179 -0.52,-0.321 -0.781,-0.31c-0.546,0.023 -1.101,0.111 -1.629,0.256c-0.66,0.182 -1.369,0.337 -1.931,0.699c-1.72,1.11 -3.155,2.548 -4.377,4.191c-0.11,0.148 -0.201,0.417 -0.141,0.567c0.268,0.673 0.594,1.324 0.833,1.84Z')
.attr('fill', '#213468');
cloud_cluster_pointer.append('path')
.attr('d', 'M49.372,28.593l-0.012,-0.012l0.005,0.018l0.007,-0.006Z')
.attr('fill', '#061c2b');
cloud_cluster_pointer.append('path')
.attr('d', 'M26.883,25.669c-0.335,0.13 -0.658,0.288 -1.052,0.463c0.284,0.139 0.488,0.203 0.644,0.327c0.112,0.088 0.238,0.267 0.223,0.388c-0.293,2.23 -0.433,4.466 -0.354,6.714c0.036,1.001 0.208,1.964 0.732,2.853c0.582,0.988 1.119,2.004 1.647,3.022c0.403,0.778 0.979,1.377 1.795,1.662c0.888,0.31 1.809,0.53 2.723,0.759c0.488,0.122 0.772,-0.013 0.935,0.573c0.041,0.147 0.282,0.329 0.439,0.337c2.462,0.128 3.699,-0.095 6.163,0.009c0.107,0.005 2.012,0.425 2.119,0.396c1.349,-0.371 2.3,-0.659 3.657,-1.003c0.975,-0.247 1.184,-0.572 1.033,-1.587c-0.045,-0.302 0.041,-0.744 0.243,-0.942c0.748,-0.732 0.786,-0.746 0.375,-1.639c-0.475,-1.033 -0.468,-1.068 0.37,-1.854c0.402,-0.378 0.433,-0.684 0.08,-1.103c-0.356,-0.422 -0.725,-0.834 -1.1,-1.239c-0.376,-0.408 -0.578,-0.882 -0.678,-1.428c-0.224,-1.219 0.006,-2.389 0.327,-3.551c0.108,-0.391 0.289,-0.762 0.437,-1.141c0.044,0.007 0.089,0.015 0.134,0.022c0.17,0.364 0.34,0.729 0.51,1.093l0.045,-0.006c-0.053,-0.404 -0.105,-0.808 -0.175,-1.346c0.471,0.444 0.839,0.789 1.205,1.133c-0.041,-0.143 -0.058,-0.304 -0.137,-0.423c-0.609,-0.913 -1.157,-1.881 -1.868,-2.708c-1.088,-1.269 -2.416,-2.265 -4.041,-2.771c-2.799,-1.542 -7.744,-1.596 -7.744,-1.596l-0.007,0.005c-0.677,-0.012 -1.34,0.122 -1.968,0.502c-1.426,0.864 -2.806,1.801 -4.213,2.694c-0.951,0.603 -1.463,0.488 -2.094,-0.442c-0.097,-0.143 -0.175,-0.3 -0.269,-0.445c-0.084,-0.128 -0.178,-0.25 -0.267,-0.374c-0.036,0.019 -0.073,0.039 -0.11,0.059c0.02,0.098 0.032,0.198 0.06,0.294c0.162,0.576 0.318,1.154 0.497,1.725c0.102,0.322 -0.041,0.461 -0.316,0.568Z')
.attr('fill', '#213468');
cloud_cluster_pointer.append('path')
.attr('d', 'M43.328,44.292c-1.036,-0.195 -2.058,-0.587 -3.096,-0.627c-1.824,-0.07 -3.657,0.062 -5.486,0.116c-0.325,0.009 -0.49,0.179 -0.438,0.524c0.167,1.111 -0.228,2.075 -0.782,3.001c-0.828,1.386 -1.292,2.887 -1.195,4.502c0.065,1.081 0.249,2.159 0.451,3.225c0.322,1.695 0.817,3.341 1.802,4.781c0.531,0.776 0.966,1.574 1.208,2.489c0.144,0.544 0.32,1.104 0.609,1.58c0.523,0.86 0.56,1.763 0.411,2.698c-0.145,0.902 -0.296,1.807 -0.521,2.69c-0.31,1.218 -0.644,2.435 -1.061,3.62c-0.257,0.731 -0.659,1.412 -1.019,2.132c0.098,0.048 0.197,0.096 0.295,0.144c0.207,0.011 0.414,0.021 0.624,0.031c-0.029,0.078 -0.058,0.154 -0.087,0.231c1.493,0.729 3.02,1.436 4.582,2.111c4.2,1.814 8.398,3.315 12.456,4.472c0.257,-1.082 0.489,-2.173 0.651,-3.273c0.251,-1.715 0.411,-3.445 0.592,-5.17c0.028,-0.272 0.112,-0.382 0.388,-0.414c0.438,-0.051 0.869,-0.158 1.305,-0.227c0.274,-0.044 0.293,-0.161 0.248,-0.426c-0.194,-1.164 -0.429,-2.329 -0.497,-3.502c-0.084,-1.466 0.007,-2.941 -0.025,-4.411c-0.031,-1.462 -0.388,-2.842 -1.262,-4.046c-1.538,-2.117 -3.021,-4.27 -4.272,-6.575c-0.168,-0.309 -0.332,-0.62 -0.523,-0.978c0.629,-0.179 1.175,-0.321 1.711,-0.492c1.003,-0.318 1.998,-0.608 3.045,-0.146c0.138,0.06 0.364,-0.028 0.531,-0.094c0.583,-0.231 1.144,-0.531 1.74,-0.717c0.84,-0.261 1.719,-0.4 2.553,-0.674c0.893,-0.293 1.751,-0.693 2.631,-1.029c1.72,-0.656 3.446,-1.297 5.168,-1.949c0.659,-0.248 0.875,-0.542 0.759,-1.224c-0.263,-1.537 -0.88,-2.921 -1.933,-4.089c-0.383,-0.425 -0.829,-0.441 -1.374,-0.271c-1.395,0.435 -2.798,0.859 -4.222,1.187c-1.322,0.305 -2.655,0.536 -3.836,1.264c-0.264,0.164 -0.552,0.3 -0.845,0.402c-0.138,0.047 -0.314,-0.019 -0.473,-0.033c0.083,-0.134 0.134,-0.314 0.253,-0.393c0.612,-0.413 1.232,-0.818 1.87,-1.191c0.634,-0.372 0.789,-0.861 0.403,-1.495c-0.054,0.064 -0.108,0.119 -0.151,0.182c-0.384,0.557 -0.736,0.599 -1.23,0.124c-0.262,-0.25 -0.511,-0.517 -0.742,-0.796c-0.529,-0.639 -1.139,-1.232 -1.313,-2.094c-0.067,-0.328 -0.116,-0.66 -0.196,-1.122c-0.638,0.485 -1.177,0.885 -1.702,1.302c-0.074,0.058 -0.102,0.191 -0.125,0.296c-0.136,0.633 -0.379,0.814 -1.002,0.825c-0.213,0.004 -0.463,0.075 -0.631,0.203c-1.671,1.267 -3.362,2.502 -5.336,3.266c-0.273,0.105 -0.619,0.115 -0.911,0.06Z')
.attr('fill', '#213468');
cloud_cluster_pointer.append('path')
.attr('d', 'M32.525,87.933c0.008,0.89 0.04,1.778 0.125,2.66c0.125,1.309 0.481,2.601 0.797,3.885c0.33,1.344 0.773,2.395 2.528,2.455c0.49,0.017 0.894,0.478 0.894,0.934c-0.003,2.072 -0.018,4.143 -0.02,6.215c-0.002,1.527 -0.361,2.928 -1.342,4.143c-0.242,0.301 -0.455,0.661 -0.552,1.041c-0.892,3.503 2.189,3.183 3.933,5.45c0.989,0.923 3.425,2.153 4.634,2.19c0.951,0.029 1.895,0.05 2.848,0.078c0.403,0.012 0.902,0.005 1.285,-0.153c0.347,-0.142 0.65,-0.342 0.547,-0.723c-0.07,-0.259 -0.234,-0.495 -0.407,-0.719l-0.047,-0.028c-1.069,-0.751 -2.128,-1.521 -3.141,-2.345c-1.157,-0.942 -1.737,-2.189 -1.629,-3.698c0.105,-1.449 0.27,-2.893 0.374,-4.341c0.123,-1.716 0.197,-3.436 0.314,-5.153c0.068,-0.996 0.554,-1.656 1.357,-1.842c0.597,-0.138 1.205,-0.241 1.814,-0.315c0.836,-0.102 1.232,-0.424 1.458,-1.25c0.222,-0.812 0.448,-1.624 0.672,-2.436c-4.672,-1.311 -9.471,-3.011 -14.251,-5.076c-0.736,-0.317 -1.467,-0.642 -2.191,-0.972Z')
.attr('fill', '#213468');
cloud_cluster_pointer.append('path')
.attr('d', 'M81.999,74.924c1.221,2.576 1.491,4.949 0.628,6.947c-3.402,7.877 -23.091,6.949 -43.978,-2.072c-20.886,-9.021 -35.06,-22.719 -31.658,-30.596c0.863,-1.998 2.775,-3.429 5.488,-4.305c-6.003,0.679 -10.278,2.815 -11.841,6.436c-4.056,9.389 11.638,25.199 35.054,35.312c23.415,10.114 45.684,10.701 49.739,1.311c1.565,-3.621 0.188,-8.197 -3.432,-13.033Z')
.attr('fill', '#213468');
cloud_cluster_pointer.append('path')
.attr('d', 'M119.8,19.202c0.034,-0.222 0.052,-0.45 0.052,-0.681c0,-1.261 -0.526,-2.397 -1.37,-3.205c-0.796,-0.762 -1.876,-1.232 -3.066,-1.232c-1.955,-0 -3.613,1.265 -4.204,3.02l0.042,0.032c0.565,0.455 0.897,1.094 0.983,1.77c-0.197,-0.515 -0.525,-0.985 -0.982,-1.353c-0.557,-0.449 -1.219,-0.68 -1.888,-0.708c-1.862,0.029 -3.383,1.452 -3.569,3.272c0.53,0.072 1.01,0.292 1.387,0.619c-0.419,-0.219 -0.897,-0.348 -1.405,-0.362l-0.001,0.026c-0.072,-0.006 -0.144,-0.009 -0.217,-0.009c-0.246,0 -0.483,0.03 -0.711,0.088l-0.008,0.002c-0.043,0.012 -0.086,0.024 -0.128,0.037l-0.021,0.007c-1.155,0.367 -1.992,1.449 -1.992,2.725c0,1.58 1.28,2.86 2.86,2.86c0.213,0 0.421,-0.024 0.621,-0.069c0.645,0.69 1.507,1.173 2.478,1.342c0.248,0.043 0.503,0.067 0.764,0.067c0.205,-0 0.408,-0.015 0.607,-0.042c0.573,0.375 1.258,0.594 1.994,0.594c0.709,-0 1.371,-0.203 1.931,-0.553c0.626,0.399 1.37,0.632 2.168,0.632c1.576,-0 2.94,-0.902 3.606,-2.218c1.823,-0.021 3.294,-1.504 3.294,-3.331c0,-1.805 -1.435,-3.273 -3.225,-3.33Z')
.attr('fill', '#18c2e7')
.attr('fill-rule', 'nonzero');
cloud_cluster_pointer.append('path')
.attr('d', 'M110.781,41.245c-0.672,-0 -1.296,0.216 -1.822,0.584c-0.477,-1.172 -1.55,-1.991 -2.801,-1.991c-0.687,-0 -1.32,0.249 -1.831,0.666c-0.27,0.22 -0.507,0.487 -0.697,0.791c-0.703,-1.16 -1.907,-1.926 -3.277,-1.926c-0.263,0 -0.521,0.029 -0.77,0.083c-0.673,-2.031 -2.456,-3.484 -4.551,-3.484c-2.248,0 -4.136,1.674 -4.679,3.942c0.58,0.546 1.03,1.178 1.323,1.847c-0.385,-0.524 -0.856,-1.009 -1.405,-1.435c-0.072,-0.055 -0.146,-0.108 -0.221,-0.161c-0.26,-0.187 -0.535,-0.363 -0.827,-0.521c-0.112,-0.06 -0.225,-0.116 -0.339,-0.17c-0.528,-0.216 -1.1,-0.335 -1.698,-0.335c-2.672,-0 -4.837,2.362 -4.837,5.277c0,1.513 0.584,2.877 1.519,3.839c0.139,-0.846 0.446,-1.622 0.882,-2.271c-0.312,0.802 -0.484,1.696 -0.488,2.634c0,0.19 0.004,0.38 0.017,0.572l0.005,0.048c0.088,1.159 0.429,2.225 0.951,3.129c0.881,1.295 2.294,2.135 3.885,2.135c1.153,0 2.211,-0.441 3.042,-1.176c0.28,0.302 0.595,0.563 0.939,0.776c0.649,0.403 1.4,0.634 2.2,0.634c1.354,-0 2.566,-0.659 3.384,-1.697c0.559,0.334 1.201,0.524 1.883,0.524c1.693,0 3.135,-1.169 3.685,-2.808c0.761,0.656 1.721,1.049 2.765,1.049c1.927,0 3.568,-1.333 4.192,-3.199c1.667,-0.231 2.956,-1.78 2.956,-3.662c0,-2.04 -1.515,-3.694 -3.385,-3.694Z')
.attr('fill', '#18c2e7')
.attr('fill-rule', 'nonzero');
cloud_cluster_pointer.append('path')
.attr('d', 'M75.407,39.585c-1.403,-0.41 -3.13,-0.421 -3.13,-0.421c0,0 0.382,-0.329 1.074,-0.323c0.979,0.01 1.972,-0.273 1.204,-0.644c-0.768,-0.371 -2.344,-0.264 -2.678,-0.053c-0.334,0.211 -2.057,1.773 -2.838,2.265c-0.781,0.493 -2.141,1.838 -2.725,1.892c0,-0 0.598,1.019 0.731,1.427c0.129,0.397 0.318,1.791 0.318,1.791c0,-0 4.944,-2.436 5.918,-2.538c0.973,-0.102 2.073,0.06 2.327,-0.613c0.254,-0.675 -2.716,-0.555 -2.686,-0.702c0.053,-0.254 3.128,0.166 3.145,-0.444c0.017,-0.465 -2.799,-0.515 -2.773,-0.864c0.012,-0.148 1.062,0.037 1.717,0.101c1.259,0.122 1.009,-0.522 1.009,-0.522c0,-0 -0.187,-0.228 -0.613,-0.352Z')
.attr('fill', '#213468')
.attr('fill-rule', 'nonzero');
let projection = d3.geoMercator() let projection = d3.geoMercator()
.scale(width / 2 / Math.PI) .scale(width / 2 / Math.PI)
.translate([width / 2, height * 3 / 5]); .translate([width / 2, height * 3 / 5]);
...@@ -212,6 +277,9 @@ ...@@ -212,6 +277,9 @@
else if (d.Type === 'vmware') { else if (d.Type === 'vmware') {
return '#vmware_pointer'; return '#vmware_pointer';
} }
else if (d.Type === 'cloud_cluster') {
return '#cloud_cluster_pointer';
}
return '#pointer'; return '#pointer';
}) })
.attr('x', function (d) { .attr('x', function (d) {
......
(function ($, drupalSettings) { (function ($, drupalSettings) {
'use strict'; 'use strict';
let countryId = 'edit-field-location-country';
let cityId = 'edit-field-location-city-0-value';
let latitudeId = 'edit-field-location-latitude-0-value';
let longitudeId = 'edit-field-location-longitude-0-value';
if (drupalSettings.cloud.country_id) {
countryId = drupalSettings.cloud.country_id;
}
if (drupalSettings.cloud.city_id) {
cityId = drupalSettings.cloud.city_id;
}
if (drupalSettings.cloud.latitude_id) {
latitudeId = drupalSettings.cloud.latitude_id;
}
if (drupalSettings.cloud.longitude_id) {
longitudeId = drupalSettings.cloud.longitude_id;
}
let setGeolocation = function () { let setGeolocation = function () {
if (!drupalSettings.cloud || !drupalSettings.cloud.geocoder_url) { if (!drupalSettings.cloud || !drupalSettings.cloud.geocoder_url) {
return; return;
} }
let country = $('#edit-field-location-country').val();
let city = $('#edit-field-location-city-0-value').val(); let country = $('#' + countryId).val();
let city = $('#' + cityId).val();
if (country === '_none' || city.trim().length === 0) { if (country === '_none' || city.trim().length === 0) {
return; return;
} }
...@@ -22,7 +44,7 @@ ...@@ -22,7 +44,7 @@
dataType: 'json', dataType: 'json',
success: function success(data) { success: function success(data) {
if (data && data.latitude && data.longitude) { if (data && data.latitude && data.longitude) {
let step = $('#edit-field-location-latitude-0-value').attr('step'); let step = $('#' + latitudeId).attr('step');
if (step && $.isNumeric(step)) { if (step && $.isNumeric(step)) {
step = Number.parseFloat(step); step = Number.parseFloat(step);
} }
...@@ -32,26 +54,26 @@ ...@@ -32,26 +54,26 @@
step = 1 / step; step = 1 / step;
let latitude = Math.round(data.latitude * step) / step; let latitude = Math.round(data.latitude * step) / step;
let longitude = Math.round(data.longitude * step) / step; let longitude = Math.round(data.longitude * step) / step;
$('#edit-field-location-latitude-0-value').val(latitude); $('#' + latitudeId).val(latitude);
$('#edit-field-location-longitude-0-value').val(longitude); $('#' + longitudeId).val(longitude);
} }
} }
}); });
}; };
$('#edit-field-location-country').change(function () { $('#' + countryId).change(function () {
setGeolocation(); setGeolocation();
}); });
$('#edit-field-location-country').blur(function () { $('#' + countryId).blur(function () {
setGeolocation(); setGeolocation();
}); });
$('#edit-field-location-city-0-value').change(function () { $('#' + cityId).change(function () {
setGeolocation(); setGeolocation();
}); });
$('#edit-field-location-city-0-value').blur(function () { $('#' + cityId).blur(function () {
setGeolocation(); setGeolocation();
}); });
......
INTRODUCTION
============
- Cloud Cluster Worker module enables to manage multiple Cloud Orchestrator
Workers. This is a subsidiary module of Cloud module, therefore the module
does NOT work without Cloud module.
- See also [Cloud](https://drupal.org/project/cloud/) module.
REQUIREMENTS
============
- Drupal `9.1.x` or higher (The latest version of Drupal `9.x`)
- Cloud `4.x` or higher
INSTALLATION
============
- `composer require drupal/cloud`
name: 'Cloud Orchestrator Worker'
type: module
description: 'Allows users to manage Cloud Orchestrator Workers.'
package: Cloud
core_version_requirement: ^9
configure: cloud_cluster_worker.settings
dependencies:
- drupal:serialization
- cloud:cloud
# base_route: 'cloud.settings'
cloud_cluster_worker.settings.local_tasks.options:
title: 'Worker'
route_name: 'cloud_cluster_worker.settings.options'
base_route: 'cloud.settings'
description: 'Configure Cloud Orchestrator Worker.'
weight: 30
<?php
/**
* @file
* Cloud Orchestrator Worker module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function cloud_cluster_worker_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.cloud_cluster_worker':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<ul>';
$output .= '<li>' . \Drupal::service('cloud')->getVersion() . '</li>';
$output .= '<li>' . t('The cloud orchestrator worker module allows users to manage Cloud Orchestrator Worker.') . '</li>';
$output .= '</ul>';
$output .= '<p>' . t('For more information, see the <a href=":cloud_documentation">online documentation for the Cloud Orchestrator Worker module</a>.', [':cloud_documentation' => 'https://www.drupal.org/docs/8/modules/cloud']) . '</p>';
return $output;
default:
return '';
}
}
/**
* Implements hook_cron().
*/
function cloud_cluster_worker_cron() {
$entity_type_definitions = \Drupal::entityTypeManager()->getDefinitions();
$resources_queue = \Drupal::service('queue')->get('cloud_cluster_worker_sync_resources_queue');
$serializer = \Drupal::service('serializer');
$manager = \Drupal::service('plugin.manager.cloud_config_plugin');
$definitions = $manager->getDefinitions();
foreach ($definitions ?: [] as $key => $definition) {
// Ignore definitions like "aws_cloud.cloud_config:1" whose base_plugin
// is undefined. And because the value of $definition['base_plugin'] is
// empty string, the "empty" function can't be used in the condition.
if (!isset($definition['base_plugin'])) {
continue;
}
$configs = $manager->createInstance($key)->loadConfigEntities();
$cloud_name = substr($key, 0, strlen($key) - strlen('.cloud_config'));
// Skip cloud cluster.
if ($cloud_name === 'cloud_cluster') {
continue;
}
foreach ($configs ?: [] as $config) {
if (!empty($config->get('cloud_cluster_name')->value) || !empty($config->get('cloud_cluster_worker_name')->value)) {
continue;
}
$resources_queue->createItem([
'cloud_context' => $config->getCloudContext(),
'resource_jsons' => [$serializer->serialize($config, 'json')],
'entity_type' => 'cloud_config',
]);
// Loop for entity types, such as aws_cloud_instance, aws_cloud_image.
foreach ($entity_type_definitions ?: [] as $entity_type_key => $entity_type_definition) {
if (strpos($entity_type_key, $cloud_name) !== 0) {
continue;
}
$resources = \Drupal::entityTypeManager()
->getStorage($entity_type_key)
->loadByProperties([
'cloud_context' => $config->getCloudContext(),
]);
$resource_jsons = [];
foreach ($resources ?: [] as $resource) {
$resource_jsons[] = $serializer->serialize($resource, 'json');
}
$resources_queue->createItem([
'cloud_context' => $config->getCloudContext(),
'resource_jsons' => $resource_jsons,
'entity_type' => $entity_type_key,
]);
}
}
}
}
############
# Cloud Orchestrator Worker.
############
administer cloud_cluster_worker:
title: 'Administer Cloud Orchestrator Worker settings'
description: 'Perform administration tasks for Cloud Orchestrator Worker.'
# Cloud Orchestrator Worker Routing Definition.
# Cloud Orchestrator Worker Admin Settings.
cloud_cluster_worker.settings.options:
path: '/admin/config/services/cloud/cloud_cluster_worker'
defaults:
_title: Cloud Orchestrator Worker
_form: '\Drupal\cloud_cluster_worker\Form\Config\CloudClusterWorkerAdminSettings'
requirements:
_permission: 'administer cloud_cluster_worker'
cloud_cluster_worker_id: ''
cloud_cluster_worker_api_endpoint: ''
cloud_cluster_worker_token: ''
cloud_cluster_worker_tags: ''
cloud_cluster_worker_location_country: ''
cloud_cluster_worker_location_city: ''
cloud_cluster_worker_location_latitude: 0
cloud_cluster_worker_location_longitude: 0
cloud_cluster_worker.settings:
type: config_object
mapping:
cloud_cluster_worker_id:
type: string
cloud_cluster_worker_api_endpoint:
type: string
cloud_cluster_worker_token:
type: string
cloud_cluster_worker_tags:
type: string
cloud_cluster_worker_location_country:
type: string
cloud_cluster_worker_location_city:
type: string
cloud_cluster_worker_location_latitude:
type: float
cloud_cluster_worker_location_longitude:
type: float
<?php
namespace Drupal\cloud_cluster_worker\Form\Config;
use Drupal\cloud\Service\CloudServiceInterface;
use Drupal\cloud\Traits\CloudFormTrait;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Locale\CountryManager;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Routing\RouteProvider;
use Drupal\Core\Url;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class Cloud Orchestrator Worker Admin Settings.
*/
class CloudClusterWorkerAdminSettings extends ConfigFormBase {
use CloudFormTrait;
const API_PATH = '/entity/cloud_cluster_worker?_format=json';
/**
* The cloud service.
*
* @var \Drupal\cloud\Service\CloudServiceInterface
*/
protected $cloud;
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProvider
*/
protected $routeProvider;
/**
* Guzzle Http Client.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* The UUID service.
*
* @var \Drupal\Component\Uuid\UuidInterface
*/
protected $uuidService;
/**
* The Messenger Service.
*
* @var \Drupal\Core\Messenger\Messenger
*/
protected $messenger;
/**
* CloudClusterWorkerAdminSettings constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\cloud\Service\CloudServiceInterface $cloud
* The cloud service.
* @param \Drupal\Core\Routing\RouteProvider $route_provider
* The route provider.
* @param \GuzzleHttp\ClientInterface $http_client
* The http client.
* @param \Drupal\Component\Uuid\UuidInterface $uuid_service
* The uuid service.
* @param \Drupal\Core\Messenger\Messenger $messenger
* The Messenger Service.
*/
public function __construct(ConfigFactoryInterface $config_factory,
CloudServiceInterface $cloud,
RouteProvider $route_provider,
ClientInterface $http_client,
UuidInterface $uuid_service,
Messenger $messenger) {
parent::__construct($config_factory);
$this->cloud = $cloud;
$this->routeProvider = $route_provider;
$this->httpClient = $http_client;
$this->uuidService = $uuid_service;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('cloud'),
$container->get('router.route_provider'),
$container->get('http_client'),
$container->get('uuid'),
$container->get('messenger')
);
}
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'cloud_cluster_worker_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames(): array {
return ['cloud_cluster_worker.settings'];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->config('cloud_cluster_worker.settings');
$form['cloud_cluster_worker'] = [
'#type' => 'details',
'#title' => $this->t('Cloud Orchestrator'),
'#open' => TRUE,
];
$worker_id = $config->get('cloud_cluster_worker_id');
if (empty($worker_id)) {
$worker_id = $config->get('system.site')->get('uuid');
}
$form['cloud_cluster_worker']['cloud_cluster_worker_id'] = [
'#type' => 'textfield',
'#title' => $this->t('ID'),
'#description' => $this->t('The ID of worker.'),
'#disabled' => TRUE,
'#default_value' => $worker_id,
];
$form['cloud_cluster_worker']['cloud_cluster_worker_api_endpoint'] = [
'#type' => 'textfield',
'#title' => $this->t('API Endpoint'),
'#description' => $this->t('API Endpoint of Cloud Orchestrator. e.g. https://example.com/'),
'#required' => TRUE,
'#default_value' => $config->get('cloud_cluster_worker_api_endpoint'),
];
$form['cloud_cluster_worker']['cloud_cluster_worker_token'] = [
'#type' => 'textfield',
'#title' => $this->t('Token'),
'#description' => $this->t('Token of Cloud Orchestrator.'),
'#required' => TRUE,
'#default_value' => $config->get('cloud_cluster_worker_token'),
];
$form['cloud_cluster_worker']['cloud_cluster_worker_tags'] = [
'#type' => 'textfield',
'#title' => $this->t('Tags'),
'#description' => $this->t('Tags of worker separated by comma. For example, "tag1, tag2".'),
'#default_value' => $config->get('cloud_cluster_worker_tags'),
];
$form['location'] = [
'#type' => 'details',
'#title' => $this->t('Location'),
'#open' => TRUE,
];
$form['location']['cloud_cluster_worker_location_country'] = [
'#type' => 'select',
'#title' => $this->t('Country'),
'#options' => CountryManager::getStandardList(),
'#empty_value' => '',
'#default_value' => $config->get('cloud_cluster_worker_location_country'),
];
$form['location']['cloud_cluster_worker_location_city'] = [
'#type' => 'textfield',
'#title' => $this->t('City'),
'#default_value' => $config->get('cloud_cluster_worker_location_city'),
];
$form['location']['cloud_cluster_worker_location_latitude'] = [
'#type' => 'number',
'#title' => $this->t('Latitude'),
'#step' => 0.000001,
'#default_value' => $config->get('cloud_cluster_worker_location_latitude'),
];
$form['location']['cloud_cluster_worker_location_longitude'] = [
'#type' => 'number',
'#title' => $this->t('Longitude'),
'#step' => 0.000001,
'#default_value' => $config->get('cloud_cluster_worker_location_longitude'),
];
if ($this->cloud->isGeocoderAvailable()) {
$path = $this->routeProvider->getRouteByName('entity.cloud_config.geocoder')->getPath();
$path = str_replace('{country}', 'country', $path);
$path = str_replace('{city}', 'city', $path);
$url = Url::fromUri('internal:' . $path);
$form['#attached']['library'] = 'cloud/cloud_geocoder';
$form['#attached']['drupalSettings']['cloud']['geocoder_url'] = $url->toString();
$form['#attached']['drupalSettings']['cloud']['country_id'] = 'edit-cloud-cluster-worker-location-country';
$form['#attached']['drupalSettings']['cloud']['city_id'] = 'edit-cloud-cluster-worker-location-city';
$form['#attached']['drupalSettings']['cloud']['latitude_id'] = 'edit-cloud-cluster-worker-location-latitude';
$form['#attached']['drupalSettings']['cloud']['longitude_id'] = 'edit-cloud-cluster-worker-location-longitude';
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$config = $this->configFactory()->getEditable('cloud_cluster_worker.settings');
try {
$this->registerWorker($form_state);
}
catch (\Exception $e) {
$this->messenger->addError($e->getMessage());
$this->messenger->addError($this->t('Failed to register the worker.'));
return;
}
$this->messenger->addStatus('The worker is registered.');
$config->set('cloud_cluster_worker_id', $form_state->getValue('cloud_cluster_worker_id'));
$config->set('cloud_cluster_worker_api_endpoint', $form_state->getValue('cloud_cluster_worker_api_endpoint'));
$config->set('cloud_cluster_worker_token', $form_state->getValue('cloud_cluster_worker_token'));
$config->set('cloud_cluster_worker_tags', $form_state->getValue('cloud_cluster_worker_tags'));
$config->set('cloud_cluster_worker_location_country', $form_state->getValue('cloud_cluster_worker_location_country'));
$config->set('cloud_cluster_worker_location_city', $form_state->getValue('cloud_cluster_worker_location_city'));
$config->set('cloud_cluster_worker_location_latitude', $form_state->getValue('cloud_cluster_worker_location_latitude'));
$config->set('cloud_cluster_worker_location_longitude', $form_state->getValue('cloud_cluster_worker_location_longitude'));
$config->save();
parent::submitForm($form, $form_state);
}
/**
* Log errors to watchdog and throw an exception.
*
* @param string $type
* The error type.
* @param \Exception $exception
* The exception object.
* @param string $message
* The message to log.
* @param bool $throw
* TRUE to throw exception.
*
* @throws \Exception
*/
private function logError($type, \Exception $exception, $message, $throw = TRUE): void {
watchdog_exception($type, $exception, $message);
if ($throw === TRUE) {
throw new \Exception($exception->getMessage());
}
}
/**
* Register a worker.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*
* @throws \Exception
*/
private function registerWorker(FormStateInterface $form_state): void {
try {
$headers = [
'Authorization' => 'Bearer ' . base64_encode($form_state->getValue('cloud_cluster_worker_token')),
'Content-Type' => 'application/json',
];
$endpoint_url = $form_state->getValue('cloud_cluster_worker_api_endpoint');
// Remove the '/' if the endpoint url ends with '/'.
if (substr($endpoint_url, -1) === '/') {
$endpoint_url = substr($endpoint_url, 0, strlen($endpoint_url) - 1);
}
// @todo Add field tags.
$response = $this->httpClient->post(
$endpoint_url . self::API_PATH,
[
'body' => json_encode([
'name' => ['value' => $form_state->getValue('cloud_cluster_worker_id')],
'location_country' => ['value' => $form_state->getValue('cloud_cluster_worker_location_country')],
'location_city' => ['value' => $form_state->getValue('cloud_cluster_worker_location_city')],
'location_latitude' => ['value' => $form_state->getValue('cloud_cluster_worker_location_latitude')],
'location_longitude' => ['value' => $form_state->getValue('cloud_cluster_worker_location_longitude')],
]),
'headers' => $headers,
]
);
$output = json_decode($response->getBody()->getContents(), TRUE);
if ($response->getStatusCode() !== 201) {
throw new \Exception($output['error'] ?? 'Unknown error.');
}
}
catch (GuzzleException $error) {
$response = $error->getResponse();
$response_info = $response->getBody()->getContents();
$message = new FormattableMarkup(
'Cloud Orchestrator API error. Error details are as follows: <pre>@response</pre>',
[
'@response' => json_decode($response_info)->message,
]
);
$this->logError('Remote API Connection', $error, $message);
}
catch (\Exception $error) {
$this->logError('Remote API Connection', $error, $this->t('An unknown error
occurred while trying to connect to the remote API. This is not a Guzzle
error, nor an error in the remote API, rather a generic local error
occurred. The reported error was @error',
['@error' => $error->getMessage()]
));
}
}
}
<?php
namespace Drupal\cloud_cluster_worker\Plugin\QueueWorker;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use GuzzleHttp\ClientInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Processes for Cloud Cluster Worker Sync Resources Queue.
*
* @QueueWorker(
* id = "cloud_cluster_worker_sync_resources_queue",
* title = @Translation("Cloud Cluster Worker Sync Resources Queue"),
* cron = {"time" = 60}
* )
*/
class CloudClusterWorkerSyncResourcesQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
const API_PATH = '/cloud_cluster/sync';
const CLOUD_CONTEXT_UUID_LENGTH = 12;
use StringTranslationTrait;
/**
* A logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Stores the configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Guzzle Http Client.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* Constructs a new LocaleTranslation object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* A logger factory instance.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \GuzzleHttp\ClientInterface $http_client
* The http client.
*/
public function __construct(
array $configuration,
$plugin_id,
array $plugin_definition,
LoggerChannelFactoryInterface $logger_factory,
ConfigFactoryInterface $config_factory,
ClientInterface $http_client
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->logger = $logger_factory->get('cloud_cluster_worker');
$this->configFactory = $config_factory;
$this->httpClient = $http_client;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('logger.factory'),
$container->get('config.factory'),
$container->get('http_client')
);
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
$cloud_context = $data['cloud_context'];
$entity_type = $data['entity_type'];
$resource_jsons = $data['resource_jsons'];
$config = $this->configFactory
->get('cloud_cluster_worker.settings');
try {
$headers = [
'Authorization' => 'Bearer ' . base64_encode($config->get('cloud_cluster_worker_token')),
'Content-Type' => 'application/json',
];
$endpoint_url = $config->get('cloud_cluster_worker_api_endpoint');
// Remove the '/' if the endpoint url ends with '/'.
if (substr($endpoint_url, -1) === '/') {
$endpoint_url = substr($endpoint_url, 0, strlen($endpoint_url) - 1);
}
$cloud_cluster_worker_name = $config->get('cloud_cluster_worker_id');
$response = $this->httpClient->post(
$endpoint_url . self::API_PATH,
[
'body' => json_encode([
'cloud_cluster_worker_name' => $cloud_cluster_worker_name,
'cloud_context' => $cloud_context . '_' . substr($cloud_cluster_worker_name, -self::CLOUD_CONTEXT_UUID_LENGTH),
'entity_type' => $entity_type,
'resource_jsons' => $resource_jsons,
]),
'headers' => $headers,
]
);
$output = json_decode($response->getBody()->getContents(), TRUE);
if ($response->getStatusCode() !== 201) {
$this->logger->error($output['error'] ?? 'Unknown error.');
}
}
catch (\Exception $error) {
$this->logger->error($error->getMessage());
}
}
}
<?php
namespace Drupal\Tests\cloud_cluster_worker\Functional\Module;
use Drupal\Tests\cloud\Functional\Module\CloudModuleTestBase;
/**
* Tests install/uninstall module(s) and confirm table creation/deletion.
*
* @group Cloud Orchestrator
*/
class InstallUninstallTest extends CloudModuleTestBase {
/**
* Tests that a fixed set of modules can be installed and uninstalled.
*/
public function testInstallUninstall(): void {
$this->runInstallUninstall($this->getModuleName(__CLASS__));
}
}
INTRODUCTION
============
- Cloud Cluster module enables to manage multiple Cloud Orchestrators.
This is a subsidiary module of Cloud module, therefore the module does NOT
work without Cloud module.
- See also [Cloud](https://drupal.org/project/cloud/) module.
REQUIREMENTS
============
- Drupal `9.1.x` or higher (The latest version of Drupal `9.x`)
- Cloud `4.x` or higher
INSTALLATION
============
- `composer require drupal/cloud`
# Plugin property $defaults are defined in CloudConfigPluginManager.
cloud_cluster.cloud_config:
id: cloud_cluster
entity_type: cloud_config
entity_bundle: cloud_cluster
deriver: 'Drupal\cloud\Plugin\Derivative\CloudConfigCloudContextBundleDeriver'
class: '\Drupal\cloud_cluster\Plugin\cloud\config\CloudClusterCloudConfigPlugin'
name: 'Cloud Orchestrator'
type: module
description: 'Allows users to manage Cloud Orchestrators.'
package: Cloud service providers
core_version_requirement: ^9
configure: cloud_cluster.settings
dependencies:
- drupal:rest
- cloud:cloud
<?php
/**
* @file
* Install and updates for cloud cluster.
*/
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Implements hook_install().
*/
function cloud_cluster_install(): void {
// Setup default icons.
\Drupal::service('cloud')->addDefaultIcon('cloud_cluster');
}
/**
* Implements hook_uninstall().
*/
function cloud_cluster_uninstall(): void {
// Delete Cloud Orchestrator (Cloud Cluster) cloud service provider entities.
\Drupal::service('cloud')->uninstallServiceProvider('cloud_cluster');
// Delete default icon.
\Drupal::service('cloud')->deleteDefaultIcon('cloud_cluster');
// Delete cloud config fields.
// NOTE: field_location_* fields consists of two kinds of information
// such as field.field.cloud_config.aws_cloud.field_location_* and
// field.storage.cloud_config.field_location_*.
// field.field.cloud_config.*.field_location_* should be explicitly
// removed here when we uninstall this module.
// Removing field.storage.cloud_config.field_location_* are automatically
// taken care by Cloud module.
\Drupal::service('cloud')->uninstallLocationFields('cloud_cluster');
try {
$vocabulary = \Drupal::entityTypeManager()
->getStorage('taxonomy_vocabulary')
->load('cloud_cluster_tags');
if ($vocabulary) {
$vocabulary->delete();
}
}
catch (\Exception $e) {
\Drupal::service('cloud')->handleException($e);
}
drupal_flush_all_caches();
}
/**
* Add fields about location to cloud_cluster_worker.
*/
function cloud_cluster_update_9001(): void {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$fields = [];
$fields['location_country'] = BaseFieldDefinition::create('string')
->setLabel(t('Location Country'))
->setDescription(t('The country of location.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['location_city'] = BaseFieldDefinition::create('string')
->setLabel(t('Location City'))
->setDescription(t('The city of location.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['location_latitude'] = BaseFieldDefinition::create('float')
->setLabel(t('Location Latitude'))
->setDescription(t('The latitude of location.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['location_longitude'] = BaseFieldDefinition::create('float')
->setLabel(t('Location Longitude'))
->setDescription(t('The longitude of location.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
foreach ($fields ?: [] as $name => $field) {
$definition_update_manager->installFieldStorageDefinition(
$name,
'cloud_cluster_worker',
'cloud_cluster',
$field
);
}
drupal_flush_all_caches();
}
/**
* Add taxonomy vocabulary cloud_cluster_tags and tags field.
*/
function cloud_cluster_update_9002(): void {
$files = [
'taxonomy.vocabulary.cloud_cluster_tags.yml',
];
\Drupal::service('cloud')->updateYmlDefinitions($files, 'cloud_cluster');
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field = BaseFieldDefinition::create('entity_reference')
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setLabel(t('Tags'))
->setDescription(t('The tags of worker.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'taxonomy_term')
->setSetting('handler', 'default:taxonomy_term')
->setSetting('handler_settings', [
'target_bundles' => ['cloud_cluster_tags' => 'cloud_cluster_tags'],
'auto_create' => TRUE,
'auto_create_bundle' => 'cloud_cluster_tags',
])
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'entity_reference_label',
'weight' => -5,
]);
$definition_update_manager->installFieldStorageDefinition(
'tags',
'cloud_cluster_worker',
'cloud_cluster',
$field
);
drupal_flush_all_caches();
}
/**
* Add field_access_user field and cloud_cluster_worker rest setting.
*/
function cloud_cluster_update_9003(): void {
\Drupal::service('module_installer')->install(['rest']);
$files = [
'field.storage.cloud_config.field_access_user.yml',
'field.field.cloud_config.cloud_cluster.field_access_user.yml',
'core.entity_form_display.cloud_config.cloud_cluster.default.yml',
'core.entity_view_display.cloud_config.cloud_cluster.default.yml',
'rest.resource.entity.cloud_cluster_worker.yml',
];
\Drupal::service('cloud')->updateYmlDefinitions($files, 'cloud_cluster');
drupal_flush_all_caches();
}
/**
* Add operation field and cloud_cluster_worker view.
*/
function cloud_cluster_update_9004(): void {
$files = [
'views.view.cloud_cluster_worker.yml',
];
\Drupal::service('cloud')->updateYmlDefinitions($files, 'cloud_cluster');
}
/**
* Add label setting to the display of field_api_token.
*/
function cloud_cluster_update_9005(): void {
$files = [
'core.entity_view_display.cloud_config.cloud_cluster.default.yml',
];
\Drupal::service('cloud')->updateYmlDefinitions($files, 'cloud_cluster');
}
/**
* Add sync resource API rest setting.
*/
function cloud_cluster_update_9006(): void {
$files = [
'rest.resource.sync_resource.yml',
];
\Drupal::service('cloud')->updateYmlDefinitions($files, 'cloud_cluster');
drupal_flush_all_caches();
}
/**
* Add cloud_cluster_name and cloud_cluster_worker_name to aws_cloud_instance.
*/
function cloud_cluster_update_9007(): void {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$fields = [];
$fields['cloud_cluster_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Orchestrator Name'))
->setDescription(t('The name of cloud orchestrator.'));
$fields['cloud_cluster_worker_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Orchestrator Worker Name'))
->setDescription(t('The name of cloud orchestrator worker.'));
foreach ($fields as $name => $field) {
$definition_update_manager->installFieldStorageDefinition(
$name,
'aws_cloud_instance',
'aws_cloud',
$field
);
}
drupal_flush_all_caches();
}
/**
* Add cloud_cluster_name and cloud_cluster_worker_name to aws_cloud_* entities.
*/
function cloud_cluster_update_9008(): void {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$fields = [];
$fields['cloud_cluster_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Orchestrator Name'))
->setDescription(t('The name of cloud orchestrator.'));
$fields['cloud_cluster_worker_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Orchestrator Worker Name'))
->setDescription(t('The name of cloud orchestrator worker.'));
$entity_type_definitions = \Drupal::entityTypeManager()->getDefinitions();
foreach ($entity_type_definitions ?: [] as $entity_type_key => $entity_type_definition) {
if (!preg_match('/^aws_cloud_[a-z_]+$/', $entity_type_key)) {
continue;
}
foreach ($fields as $name => $field) {
$definition_update_manager->installFieldStorageDefinition(
$name,
$entity_type_key,
'aws_cloud',
$field
);
}
}
drupal_flush_all_caches();
}
/**
* Add cloud_cluster_name and cloud_cluster_worker_name to cloud_config.
*/
function cloud_cluster_update_9009(): void {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$fields = [];
$fields['cloud_cluster_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Orchestrator Name'))
->setDescription(t('The name of cloud orchestrator.'));
$fields['cloud_cluster_worker_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Orchestrator Worker Name'))
->setDescription(t('The name of cloud orchestrator worker.'));
foreach ($fields as $name => $field) {
$definition_update_manager->installFieldStorageDefinition(
$name,
'cloud_config',
'cloud',
$field
);
}
drupal_flush_all_caches();
}
####################
# Cloud Cluster Config.
####################
cloud_cluster.settings:
route_name: 'cloud_cluster.settings'
title: 'Cloud Orchestrator settings'
weight: -1
base_route: cloud.settings
cloud_cluster.settings.cloud_config.add_form:
route_name: entity.cloud_config.add_page
title: 'Add Profile'
appears_on:
- cloud_cluster.settings
entity.cloud_cluster_worker.collection:
route_name: view.cloud_cluster_worker.list
title: 'List Cloud Orchestrator Workers'
appears_on:
- entity.cloud_cluster_worker.delete_form
- entity.cloud_cluster_worker.canonical
entity.cloud_cluster_worker.delete:
route_name: entity.cloud_cluster_worker.delete_form
title: 'Delete'
appears_on:
- entity.cloud_cluster_worker.canonical
cloud_cluster.menu.cloud_context:
deriver: 'Drupal\cloud_cluster\Plugin\Derivative\CloudClusterMenuLinks'
weight: 100
# base_route: 'cloud.settings'
cloud_cluster.settings.local_tasks.profile_list:
title: 'Profiles'
route_name: 'cloud_cluster.settings'
base_route: 'cloud.settings'
description: 'Cloud Orchestrator Profile List.'
weight: 0
cloud_cluster.local_tasks.cloud_context:
deriver: 'Drupal\cloud_cluster\Plugin\Derivative\CloudClusterLocalTasks'
weight: 10
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment