57 | | === Chef configuration === |
58 | | The {{{chef_instancedata_file}}} option is the absolute path to the ec2 instance/user data generated by chef's knife command: |
59 | | {{{ |
60 | | % knife ec2 instance data role[<desired-role>] > /path/to/instance-data.json |
61 | | }}} |
62 | | |
63 | | The plugin will use this file for the instance data replacing the role information as needed. As the file contains the {{{validation.pem}}} data, be sure to secure it accordingly. In cases where you need different credentials and/or chefserver url, you can use the following option to specify a base directory which must contain the typical {{{.chef}}} directory and its contents plus (optionally) a {{{validation.pem}}} file within the {{{.chef}}} directory: |
64 | | {{{ |
65 | | [cloud] |
66 | | .. |
67 | | chef_base_path = /path/to/dir/that/contains/.chef |
68 | | }}} |
69 | | |
70 | | It's currently assumed that you're using one of Opscode's AMIs or a homegrown AMI derived from it. These AMIs use the instance's id as the node name. However, you may have recipes which for one reason or another change the node's name after the first chef-client run. If so, you need to specify the boto field that maps to the final node name using this config option: |
71 | | {{{ |
72 | | [cloud] |
73 | | .. |
74 | | boto_field_node_name = private_dns_name |
75 | | }}} |
76 | | |
77 | | Adding this option will cause the plugin to create a new node of that name upon launching a new ec2 instance and once it checks in will remove the original node. Otherwise you'll have two chef nodes for the same ec2 instance - something you likely don't want. Yeah, this is a bit complicated - an area ripe for improvement. |
78 | | |
79 | | The plugin is intended to support multiple AWS resource types in addition to instances as needed for orchestration with chef. You specify the default resource to view using this config option: |
80 | | {{{ |
81 | | [cloud] |
82 | | .. |
83 | | default_resource = instance |
84 | | }}} |
85 | | |
86 | | Each AWS resource type such as {{{instance}}} above is configured independently. See the examples section [wiki:CloudPlugin#Examples below] for how to specify these resources. |
87 | | |
131 | | * {{{class}}} - must map to the exact python class name for that instance. For ec2 instances, it's {{{Ec2Instance}}}. |
132 | | * {{{title}}} - used in the sub-navigation (aka contextual) menu - see screenshot above. |
133 | | * {{{order}}} - defines the order in the contextual menu (much like custom field ordering). |
134 | | * {{{label}}} - used in several views to describe a single one of these resources. |
135 | | * {{{description}}} - used in the grid view - see screenshot above. |
| 104 | The {{{title}}} and {{{order}}} options are used for contextual navigation - see screenshot above. The {{{order}}} should start with {{{1}}}. If {{{order}}} is set to an empty string then the resource will not be shown in the contextual menu (but is still accessible by its url). The {{{label}}} value is displayed in various buttons and forms for the name of a single resource item. The {{{description}}} option is displayed in the grid view - see screenshot above - much like a Trac report description. |
141 | | .. |
142 | | fields = name < NameHandler, ec2.instance_id as Instance ID, run_list_ as Roles < RunListHandler, created_by as Created By < AuthorHandler, |
143 | | created_at_ as Created At < EpochHandler, ohai_time_ as Last Check-in < AgoEpochHandler, ec2.instance_type as Instance Type, |
144 | | ec2.hostname as Private Hostname, ec2.public_hostname_ as Public Hostname < SshHandler, ec2.placement_availability_zone as Availability Zone, |
145 | | ec2.ami_id as Image ID, supervisord.ssl_port_ as supervisord < HttpsHandler |
| 110 | .. |
| 111 | field.name = text |
| 112 | field.name.label = Name |
| 113 | field.name.handler = NameHandler |
| 114 | field.run_list = multiselect |
| 115 | field.run_list.label = Roles |
| 116 | field.run_list.databag = roles # special token |
| 117 | field.run_list.handler = RunListHandler |
| 118 | field.ec2.placement_availability_zone = select |
| 119 | field.ec2.placement_availability_zone.label = Availability Zone |
| 120 | field.ec2.placement_availability_zone.options = No preference|us-east-1a|us-east-1b|us-east-1c|us-east-1d |
| 121 | .. many more fields .. |
153 | | grid_index = node |
154 | | grid_columns = name, run_list_, created_by, ohai_time_, ec2.instance_type, ec2.placement_availability_zone |
155 | | grid_sort = created_at_ |
| 132 | [cloud.instance] |
| 133 | .. |
| 134 | field.ec2.ami_id = select |
| 135 | field.ec2.ami_id.label = Image ID |
| 136 | field.ec2.ami_id.databag = ec2_ami_id |
| 137 | }}} |
| 138 | |
| 139 | will query chef for and use the {{{ec2_ami_id}}} data bag items. The individual data bag items should be formatted like this: |
| 140 | {{{ |
| 141 | { |
| 142 | "id": "ami-xxxxxxxx", |
| 143 | "value": "ami-xxxxxxxx", |
| 144 | "name": "ami-xxxxxxxx (64-bit)", |
| 145 | "order": 1 |
| 146 | } |
| 147 | }}} |
| 148 | |
| 149 | The {{{name}}} will be used as the option's displayed name and the {{{value}}} will be used as the option's value. If an {{{order}}} field is provided, it will be used to order the options accordingly (much like custom field ordering). |
| 150 | |
| 151 | Specifying {{{roles}}} as a data bag has a special meaning (see the {{{run_list}}} field example above) - chef will be queried for the list of [http://wiki.opscode.com/display/chef/Roles roles] instead of a data bag. |
| 152 | |
| 153 | ===== Field handlers ===== |
| 154 | A field handler converts a raw chef attribute value into something more human-readable and vice-versa. For example, the {{{RunListHandler}}} defined above for the {{{run_list}}} field extracts roles from a chef node's run_list and displays them in an easy-to-read way. It also converts data the other direction - i.e., it converts the list of roles from a web form into the correct format to set the node's {{{run_list}}}. |
| 155 | |
| 156 | Other field handler examples include displaying a url to a web site at a specific port, converting epoch's to dates and times, etc. See [browser:cloudplugin/0.12/cloud/handlers.py handlers.py] for the full list of provided field handlers and [browser:cloudplugin/0.12/cloud/defaults.py defaults.py] for examples of which fields they're used for by default |
| 157 | |
| 158 | ==== Views ==== |
| 159 | In addition to field definitions, you can define which fields should be viewed in which views, their order, and whether or not a field should be read-only in that view. Example: |
| 160 | {{{ |
| 161 | [cloud.instance] |
| 162 | .. |
| 163 | crud_view = name, ec2.instance_type, ohai_time, .. |
| 164 | crud_new = roles, created_by, created_at, .. |
| 165 | crud_edit = roles, created_by, created_at*, .. |
| 166 | |
| 167 | grid_columns = name, ec2.instance_type, ohai_time, .. |
| 168 | grid_sort = ohai_time |
159 | | The {{{grid_*}}} options configure the grid view of the resource - i.e., the view shown in the screenshot above: |
160 | | * {{{grid_index}}} - must map to the chef search index name. For ec2 instances, this is {{{node}}}. |
161 | | * {{{grid_columns}}} - the list of chef attributes to display in order. The column names will use any display names from {{{fields}}} and its cell values will be formatted using any handlers from {{{fields}}}. |
162 | | * {{{grid_sort}}} - the default sort attribute/field. You can resort the grid by clicking on the column name. |
163 | | * {{{grid_asc}}} - the default sort direction. You can change the sort direction by clicking on the same column name. |
| 172 | The {{{crud_view}}}, {{{crud_new}}}, {{{crud_edit}}}, and {{{grid_columns}}} options are lists of field names in the order to be displayed in their respective views. ("crud" stands for "create, read, update, delete".) An asterisk ({{{*}}}) appended to a field name (only applicable for {{{crud_new}}} and {{{crud_edit}}}) indicates that the field should be read-only in that view. All fields in the {{{crud_new}}} and {{{crud_edit}}} views will be used to set or update the chef resource item. |
165 | | {{{ |
166 | | crud_resource = nodes |
167 | | crud_view = name, ec2.instance_id, run_list_, created_by, created_at_, ohai_time_, ec2.instance_type, ec2.hostname, ec2.public_hostname_, ec2.placement_availability_zone, ec2.ami_id, supervisord.ssl_port_ |
168 | | crud_new = run_list_||, created_by, ec2.instance_type|, ec2.ami_id|, ec2.placement_availability_zone|us-east-1a|us-east-1b|us-east-1c|us-east-1d |
169 | | crud_edit = run_list_||, created_by, ec2.instance_type*, ec2.ami_id*, ec2.placement_availability_zone* |
170 | | }}} |
171 | | |
172 | | The {{{crud_*}}} options configure aspects for creating, reading updating, and deleting (i.e., CRUD) the resource: |
173 | | * {{{crud_resource}}} - must map to the chef resource name. For ec2 instances, this is {{{nodes}}}. |
174 | | * {{{crud_view}}} - the list of chef attributes to display in order. The field names will use any display names from {{{fields}}} and its cell values will be formatted using any handlers from {{{fields}}}. |
175 | | * {{{crud_new}}} and {{{crud_edit}}} - the list of augmented chef attributes to display for editing in order. The field names will use any display names from {{{fields}}} and its cell values will be formatted using any handlers from {{{fields}}}. |
176 | | |
177 | | The field names in {{{crud_new}}} and {{{crud_edit}}} are augmented to provide additional metadata so the plugin knows how to properly configure the form. So for example: |
178 | | {{{ |
179 | | ec2.placement_availability_zone|us-east-1a|us-east-1b|us-east-1c|us-east-1d |
180 | | }}} |
181 | | |
182 | | The pipe ({{{|}}}) after the field name indicates that the form should use a select/dropdown menu for this field. If the select/dropdown should support multiple selections, then use two pipes instead of one as in {{{run_list_||}}}. The remainder of the definition is a pipe-delimited list of options for this field (much like how custom field options are defined). If there's no list of options, then the plugin will search a chefserver data bag of the same name as the field for the list of options. So for example, {{{ec2.instance_type|}}} will direct the plugin to search for a data bag on the chefserver named {{{ec2_instance_type}}} (periods are invalid and so are replaced with underscores). The individual data bag items should be formatted like this: |
183 | | {{{ |
184 | | { |
185 | | "id": "m1_large", |
186 | | "value": "m1.large", |
187 | | "name": "m1.large - Large (64-bit)", |
188 | | "order": 3 |
189 | | } |
190 | | }}} |
191 | | |
192 | | The {{{name}}} will be used as the option's displayed name and the {{{value}}} will be used as the option's value. If {{{order}}} fields are provided, then they'll be used to order the options accordingly (much like custom field ordering). |
193 | | |
194 | | Lastly, if you want to have a field displayed but as read-only, then the field name should be immediately postfixed with an asterisk as in {{{ec2.ami_id*}}} above. The {{{crud_new}}} config example above results in the following screenshot: |
195 | | [[Image(instance-new.png)]] |
196 | | |
197 | | Any regular (i.e., non-handled) fields in the {{{crud_new}}} and {{{crud_edit}}} lists will get added as attributes to the chef node such as {{{created_by}}} above. |
| 174 | The {{{grid_sort}}} and {{{grid_asc}}} are for default sorting in the grid view. |