def _upload_resources(manager_node, fabric_env, management_ip, rest_port, protocol): """ Uploads resources supplied in the manager blueprint. uses both fabric for the dsl_resources, and the upload plugins mechanism for plugin_resources. :param manager_node: The manager node from which to retrieve the properties from. :param fabric_env: fabric env in order to upload the dsl_resources. :param management_ip: used to retrieve rest client for the the manager. :param rest_port: used to retrieve rest client for the the manager. :param protocol: used to retrieve rest client for the the manager. """ upload_resources = \ manager_node.properties['cloudify'].get('upload_resources', {}) # upload the plugin using CLI upload command rest_client = utils.get_rest_client(management_ip, rest_port, protocol) # This import is necessary to prevent from utils importing plugins, which # will cause a cyclic import. Another way is to forgo the validate part from cloudify_cli.commands import plugins temp_dir = tempfile.mkdtemp() try: for plugin_archive_source in \ upload_resources.get('plugin_resources', ()): plugin_archive_path = \ _get_resource_into_dir(temp_dir, plugin_archive_source) utils.upload_plugin(file(plugin_archive_path), management_ip, rest_client, plugins.validate) # uploading dsl resources remote_plugins_folder = '/opt/manager/resources/' for dsl_resource in upload_resources.get('dsl_resources', ()): plugin_local_yaml_path = dsl_resource.get('source_path') plugin_remote_yaml_path = dsl_resource.get('destination_path') if not plugin_local_yaml_path or not plugin_remote_yaml_path: missing_fields = [] if plugin_local_yaml_path is None: missing_fields.append('source_path') if plugin_remote_yaml_path is None: missing_fields.append('destination_path') raise \ CloudifyBootstrapError('The following fields are missing: ' '{0}.' .format(','.join(missing_fields))) if plugin_remote_yaml_path.startswith('/'): plugin_remote_yaml_path = plugin_remote_yaml_path[1:] plugin_local_yaml_path = \ _get_resource_into_dir(temp_dir, plugin_local_yaml_path) # copy plugin's yaml file to the manager's fileserver remote_paths = plugin_remote_yaml_path.split('/') with fabric.settings(**fabric_env): # Creating a remote folder if len(remote_paths) > 1: remote_plugin_folder_path = \ os.path.join(remote_plugins_folder, *remote_paths[:-1]) fabric.run('sudo mkdir -p {0}'.format( remote_plugin_folder_path)) # Uploading the plugin file remote_plugin_path = os.path.join(remote_plugins_folder, *remote_paths) fabric.put(plugin_local_yaml_path, remote_plugin_path, use_sudo=True) finally: shutil.rmtree(temp_dir, ignore_errors=True)
def upload(plugin_path): rest_host = utils.get_rest_host() utils.upload_plugin(plugin_path, utils.get_rest_client(rest_host), validate)
def upload(plugin_path): server_ip = utils.get_management_server_ip() utils.upload_plugin(plugin_path, server_ip, utils.get_rest_client(server_ip), validate)
def upload_plugin(plugin_path): utils.upload_plugin(file(plugin_path), management_ip, rest_client, plugins.validate)