Revision ade6513a src/market_mad/one_market.rb

View differences:

src/market_mad/one_market.rb
93 93
    end
94 94

  
95 95
    ############################################################################
96
    # Image Manager Protocol Actions (generic implementation)
96
    # Import a marketplace app into the marketplace. This is a two step process:
97
    #   1- The associated datastore_mad/export script is invoked to generate
98
    #      a file representation of the app.
99
    #   2- The resulting file path is used to import it into the marketplace
100
    #      invoking marketplace_mad/import.
97 101
    ############################################################################
98

  
99 102
    def import(id, drv_message)
100 103
        xml = decode(drv_message)
101 104

  
......
105 108
        end
106 109

  
107 110
        type   = xml['MARKETPLACEAPP/TYPE']
108
        origin = xml['MARKETPLACEAPP/ORIGIN']
111
        origin = xml['MARKETPLACEAPP/ORIGIN_ID']
109 112
        mp_mad = xml['MARKETPLACE/MARKET_MAD']
110 113

  
111 114
        if type.nil? || origin.nil? || mp_mad.nil?
112
            failure(:import, id,"Wrong driver message format")
115
            failure(:import, id, "Wrong driver message format")
113 116
            return
114 117
        end
115 118

  
119
        case OpenNebula::MarketPlaceApp::MARKETPLACEAPP_TYPES[type.to_i]
116 120
        #-----------------------------------------------------------------------
117
        #  Export origin to a path
121
        # Export marketplace origin to a file path, IMAGE
118 122
        #-----------------------------------------------------------------------
119
        case OpenNebula::MarketPlaceApp::MARKETPLACEAPP_TYPES[type.to_i]
120
          when "IMAGE" then
121
            if ( origin =~ /\d+$/ )
122
                # Get the associated datastore ID
123
                image = OpenNebula::Image.new_with_id(origin, @one)
124
                rc    = image.info
125

  
126
                if OpenNebula.is_error?(rc)
127
                    failure(:import, id, "Cannot find information for image "\
128
                            "#{origin}: #{rc.to_str()}")
129
                    return
130
                end
131

  
132
                ds_id = image['DATASTORE_ID']
133

  
134
                if ds_id.nil?
135
                    failure(:import, id, "Cannot find datastore for image #{origin}")
136
                    return
137
                end
138

  
139
                ds = OpenNebula::Datastore.new_with_id(ds_id, @one)
140
                rc = ds.info
141

  
142
                if OpenNebula.is_error?(rc)
143
                    failure(:import, id, "Datastore #{ds_id} not found: #{rc}")
144
                    return
145
                end
146

  
147
                ds_mad = ds['DS_MAD']
148

  
149
                if ds_mad.nil?
150
                    failure(:import, id, "Cannot find datastore driver")
151
                    return
152
                end
153

  
154
                #Execute export action from Datastore
155
                ds_msg   = "<DS_DRIVER_ACTION_DATA>"\
156
                           "#{image.to_xml}"\
157
                           "#{ds.to_xml}"\
158
                           "</DS_DRIVER_ACTION_DATA>"
159
                ds_msg64 = Base64::strict_encode64(ds_msg)
160

  
161
                result, info = do_action(id, nil, ds_mad, :export,
162
                    "#{ds_msg64} #{id}", false)
163

  
164
                if ( result == RESULT[:failure] )
165
                    failure(:import, id, "Error exporting image to file: #{info}")
166
                    return
167
                end
168

  
169
                source = info
170
            elsif ( source =~ /\/.+|https?:\/\// )
171
                source = origin
172
            else
173
                failure(:import, id, "Origin is not a valid ID, path or URL")
123
        when "IMAGE" then
124
            # ------------ Execute export action from Datastore ----------------
125
            ds_mad = xml['DATASTORE/DS_MAD']
126

  
127
            if ds_mad.nil?
128
                failure(:import, id, "Wrong driver message format")
174 129
                return
175 130
            end
176
          else # Only IMAGE type is supported
177
                failure(:import, id, "Type #{apptype} not supported")
131

  
132
            ds_msg = "<DS_DRIVER_ACTION_DATA>"\
133
                     "#{xml.element_xml('IMAGE')}"\
134
                     "#{xml.element_xml('DATASTORE')}"\
135
                     "</DS_DRIVER_ACTION_DATA>"
136

  
137
            ds_msg64 = Base64::strict_encode64(ds_msg)
138

  
139
            result, info = do_action(id, nil, ds_mad, :export,
140
                "#{ds_msg64} #{id}", false)
141

  
142
            if ( result == RESULT[:failure] )
143
                failure(:import, id, "Error exporting image to file: #{info}")
178 144
                return
145
            end
146

  
147
            info_doc = OpenNebula::XMLElement.new
148
            info_doc.initialize_xml(info, 'IMPORT_INFO')
149
        #-----------------------------------------------------------------------
150
        # Only IMAGE type is supported
151
        #-----------------------------------------------------------------------
152
        else
153
            failure(:import, id, "Type #{apptype} not supported")
154
            return
179 155
        end
180 156

  
157
        # --------------- Import image app into the marketplace ----------------
181 158
        xml.add_element('/MARKET_DRIVER_ACTION_DATA',
182
            'IMPORT_SOURCE' => "#{source}")
159
                        'IMPORT_SOURCE' => "#{info_doc['IMPORT_SOURCE']}",
160
                        'CHECKSUM'      => "#{info_doc['CHECKSUM']}",
161
                        'SIZE'          => "#{info_doc['SIZE']}",
162
                        'FORMAT'        => "#{info_doc['FORMAT']}",
163
                        'DISPOSE'       => "#{info_doc['DISPOSE']}")
164

  
183 165
        mp_msg64 = Base64::strict_encode64(xml.to_xml)
184 166

  
185 167
        result, info = do_action(id, mp_mad, nil, :import, "#{mp_msg64} #{id}",
......
236 218

  
237 219
        result, info = get_info_from_execution(rc)
238 220

  
239
        info = Base64::strict_encode64(info) if encode
221
        info = Base64::strict_encode64(info) if encode && result != RESULT[:failure]
240 222

  
241 223
        return result, info
242 224
    end

Also available in: Unified diff