~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/volume/drivers/zadara.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
               default=None,
45
45
               help='Zadara VPSA port number'),
46
46
    cfg.BoolOpt('zadara_vpsa_use_ssl',
47
 
               default=False,
48
 
               help='Use SSL connection'),
 
47
                default=False,
 
48
                help='Use SSL connection'),
49
49
    cfg.StrOpt('zadara_user',
50
50
               default=None,
51
51
               help='User name for the VPSA'),
73
73
               default='OS_%s',
74
74
               help='Default template for VPSA volume names'),
75
75
    cfg.BoolOpt('zadara_vpsa_auto_detach_on_delete',
76
 
               default=True,
77
 
               help="Automatically detach from servers on volume delete"),
 
76
                default=True,
 
77
                help="Automatically detach from servers on volume delete"),
78
78
    cfg.BoolOpt('zadara_vpsa_allow_nonexistent_delete',
79
 
               default=True,
80
 
               help="Don't halt on deletion of non-existing volumes"),
81
 
    ]
 
79
                default=True,
 
80
                help="Don't halt on deletion of non-existing volumes"), ]
82
81
 
83
82
FLAGS = flags.FLAGS
84
83
FLAGS.register_opts(zadara_opts)
139
138
            # Attach/Detach operations
140
139
            'attach_volume': ('POST',
141
140
                              '/api/servers/%s/volumes.xml'
142
 
                                    % kwargs.get('vpsa_srv'),
 
141
                              % kwargs.get('vpsa_srv'),
143
142
                              {'volume_name[]': kwargs.get('vpsa_vol'),
144
143
                               'force': 'NO'}),
145
144
            'detach_volume': ('POST',
146
145
                              '/api/volumes/%s/detach.xml'
147
 
                                    % kwargs.get('vpsa_vol'),
 
146
                              % kwargs.get('vpsa_vol'),
148
147
                              {'server_name[]': kwargs.get('vpsa_srv'),
149
148
                               'force': 'NO'}),
150
149
 
160
159
                             {}),
161
160
            'list_vol_attachments': ('GET',
162
161
                                     '/api/volumes/%s/servers.xml'
163
 
                                            % kwargs.get('vpsa_vol'),
164
 
                                     {}),
165
 
            }
 
162
                                     % kwargs.get('vpsa_vol'),
 
163
                                     {}), }
166
164
 
167
165
        if cmd not in vpsa_commands.keys():
168
166
            raise exception.UnknownCmd(cmd=cmd)
203
201
        user = xml_tree.find('user')
204
202
        if user is None:
205
203
            raise exception.MalformedResponse(cmd=cmd,
206
 
                                        reason='no "user" field')
 
204
                                              reason='no "user" field')
207
205
 
208
206
        access_key = user.findtext('access-key')
209
207
        if access_key is None:
210
208
            raise exception.MalformedResponse(cmd=cmd,
211
 
                                        reason='no "access-key" field')
 
209
                                              reason='no "access-key" field')
212
210
 
213
211
        self.access_key = access_key
214
212
 
219
217
 
220
218
        (method, url, body) = self._generate_vpsa_cmd(cmd, **kwargs)
221
219
        LOG.debug(_('Sending %(method)s to %(url)s. Body "%(body)s"')
222
 
                        % locals())
 
220
                  % locals())
223
221
 
224
222
        if self.use_ssl:
225
223
            connection = httplib.HTTPSConnection(self.host, self.port)
308
306
        """Return details of VPSA's active controller."""
309
307
        xml_tree = self.vpsa.send_cmd('list_controllers')
310
308
        ctrl = self._xml_parse_helper(xml_tree, 'vcontrollers',
311
 
                                        ('state', 'active'))
 
309
                                      ('state', 'active'))
312
310
        if ctrl is not None:
313
311
            return dict(target=ctrl.findtext('target'),
314
312
                        ip=ctrl.findtext('iscsi-ip'),
335
333
 
336
334
    def create_volume(self, volume):
337
335
        """Create volume."""
338
 
        self.vpsa.send_cmd('create_volume',
339
 
                    name=FLAGS.zadara_vol_name_template % volume['name'],
340
 
                    size=volume['size'])
 
336
        self.vpsa.send_cmd(
 
337
            'create_volume',
 
338
            name=FLAGS.zadara_vol_name_template % volume['name'],
 
339
            size=volume['size'])
341
340
 
342
341
    def delete_volume(self, volume):
343
342
        """
350
349
        vpsa_vol = self._get_vpsa_volume_name(name)
351
350
        if not vpsa_vol:
352
351
            msg = _('Volume %(name)s could not be found. '
353
 
                'It might be already deleted') % locals()
 
352
                    'It might be already deleted') % locals()
354
353
            LOG.warning(msg)
355
354
            if FLAGS.zadara_vpsa_allow_nonexistent_delete:
356
355
                return
361
360
        xml_tree = self.vpsa.send_cmd('list_vol_attachments',
362
361
                                      vpsa_vol=vpsa_vol)
363
362
        servers = self._xml_parse_helper(xml_tree, 'servers',
364
 
                                ('iqn', None), first=False)
 
363
                                         ('iqn', None), first=False)
365
364
        if servers:
366
365
            if not FLAGS.zadara_vpsa_auto_detach_on_delete:
367
366
                raise exception.VolumeAttached(volume_id=name)
370
369
                vpsa_srv = server.findtext('name')
371
370
                if vpsa_srv:
372
371
                    self.vpsa.send_cmd('detach_volume',
373
 
                                vpsa_srv=vpsa_srv, vpsa_vol=vpsa_vol)
 
372
                                       vpsa_srv=vpsa_srv,
 
373
                                       vpsa_vol=vpsa_vol)
374
374
 
375
375
        # Delete volume
376
376
        self.vpsa.send_cmd('delete_volume', vpsa_vol=vpsa_vol)
417
417
 
418
418
        # Attach volume to server
419
419
        self.vpsa.send_cmd('attach_volume',
420
 
                            vpsa_srv=vpsa_srv, vpsa_vol=vpsa_vol)
 
420
                           vpsa_srv=vpsa_srv,
 
421
                           vpsa_vol=vpsa_vol)
421
422
 
422
423
        # Get connection info
423
424
        xml_tree = self.vpsa.send_cmd('list_vol_attachments',
429
430
        target = server.findtext('target')
430
431
        lun = server.findtext('lun')
431
432
        if target is None or lun is None:
432
 
            raise exception.ZadaraInvalidAttachmentInfo(name=name,
433
 
                            reason='target=%s, lun=%s' % (target, lun))
 
433
            raise exception.ZadaraInvalidAttachmentInfo(
 
434
                name=name,
 
435
                reason='target=%s, lun=%s' % (target, lun))
434
436
 
435
437
        properties = {}
436
438
        properties['target_discovered'] = False
465
467
 
466
468
        # Detach volume from server
467
469
        self.vpsa.send_cmd('detach_volume',
468
 
                            vpsa_srv=vpsa_srv, vpsa_vol=vpsa_vol)
 
470
                           vpsa_srv=vpsa_srv,
 
471
                           vpsa_vol=vpsa_vol)
469
472
 
470
473
    def create_volume_from_snapshot(self, volume, snapshot):
471
474
        raise NotImplementedError()
475
478
 
476
479
    def delete_snapshot(self, snapshot):
477
480
        raise NotImplementedError()
 
481
 
 
482
    def copy_image_to_volume(self, context, volume, image_service, image_id):
 
483
        """Fetch the image from image_service and write it to the volume."""
 
484
        raise NotImplementedError()
 
485
 
 
486
    def copy_volume_to_image(self, context, volume, image_service, image_id):
 
487
        """Copy the volume to the specified image."""
 
488
        raise NotImplementedError()
 
489
 
 
490
    def create_cloned_volume(self, volume, src_vref):
 
491
        """Creates a clone of the specified volume."""
 
492
        raise NotImplementedError()