40
41
# NOTE(justinsb): The OpenStack API can't upload an image?
41
42
# So, make sure we've got one..
42
43
timestamp = datetime.datetime(2011, 01, 01, 01, 02, 03)
43
image = {'id': '123456',
44
'name': 'fakeimage123456',
45
'created_at': timestamp,
46
'updated_at': timestamp,
48
'container_format': 'ami',
50
'properties': {'kernel_id': FLAGS.null_kernel,
51
'ramdisk_id': FLAGS.null_kernel}}
52
self.create(None, image)
53
super(FakeImageService, self).__init__()
55
def index(self, context, filters=None):
44
image1 = {'id': '123456',
45
'name': 'fakeimage123456',
46
'created_at': timestamp,
47
'updated_at': timestamp,
49
'container_format': 'ami',
51
'properties': {'kernel_id': FLAGS.null_kernel,
52
'ramdisk_id': FLAGS.null_kernel,
53
'architecture': 'x86_64'}}
55
image2 = {'id': 'fake',
56
'name': 'fakeimage123456',
57
'created_at': timestamp,
58
'updated_at': timestamp,
60
'container_format': 'ami',
62
'properties': {'kernel_id': FLAGS.null_kernel,
63
'ramdisk_id': FLAGS.null_kernel}}
66
'name': 'fakeimage123456',
67
'created_at': timestamp,
68
'updated_at': timestamp,
70
'container_format': 'ami',
72
'properties': {'kernel_id': FLAGS.null_kernel,
73
'ramdisk_id': FLAGS.null_kernel}}
76
'name': 'fakeimage123456',
77
'created_at': timestamp,
78
'updated_at': timestamp,
80
'container_format': 'ami',
82
'properties': {'kernel_id': FLAGS.null_kernel,
83
'ramdisk_id': FLAGS.null_kernel}}
86
'name': 'fakeimage123456',
87
'created_at': timestamp,
88
'updated_at': timestamp,
90
'container_format': 'ami',
92
'properties': {'kernel_id': FLAGS.null_kernel,
93
'ramdisk_id': FLAGS.null_kernel}}
95
self.create(None, image1)
96
self.create(None, image2)
97
self.create(None, image3)
98
self.create(None, image4)
99
self.create(None, image5)
100
super(_FakeImageService, self).__init__()
102
def index(self, context, filters=None, marker=None, limit=None):
56
103
"""Returns list of images."""
57
104
return copy.deepcopy(self.images.values())
59
def detail(self, context, filters=None):
106
def detail(self, context, filters=None, marker=None, limit=None):
60
107
"""Return list of detailed image information."""
61
108
return copy.deepcopy(self.images.values())
66
113
Returns a dict containing image data for the given opaque image id.
69
image_id = int(image_id)
70
image = self.images.get(image_id)
116
image = self.images.get(str(image_id))
72
118
return copy.deepcopy(image)
73
119
LOG.warn('Unable to find image id %s. Have images: %s',
74
120
image_id, self.images)
75
121
raise exception.ImageNotFound(image_id=image_id)
77
def create(self, context, data):
123
def create(self, context, metadata, data=None):
78
124
"""Store the image data and return the new image id.
80
126
:raises: Duplicate if the image already exist.
83
image_id = int(data['id'])
130
image_id = metadata['id']
132
image_id = random.randint(0, 2 ** 31 - 1)
133
image_id = str(image_id)
84
135
if self.images.get(image_id):
85
136
raise exception.Duplicate()
87
self.images[image_id] = copy.deepcopy(data)
138
metadata['id'] = image_id
139
self.images[image_id] = copy.deepcopy(metadata)
140
return self.images[image_id]
89
def update(self, context, image_id, data):
142
def update(self, context, image_id, metadata, data=None):
90
143
"""Replace the contents of the given image with the new data.
92
145
:raises: ImageNotFound if the image does not exist.
95
image_id = int(image_id)
96
148
if not self.images.get(image_id):
97
149
raise exception.ImageNotFound(image_id=image_id)
98
self.images[image_id] = copy.deepcopy(data)
150
self.images[image_id] = copy.deepcopy(metadata)
100
152
def delete(self, context, image_id):
101
153
"""Delete the given image.