4 # Copyright 2016 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
25 from rift
.tasklets
.rwimagemgr
import tasklet
, glance_client
26 from rift
.mano
.cloud
import accounts
29 gi
.require_version('RwCloudYang', '1.0')
30 gi
.require_version('RwLog', '1.0')
31 from gi
.repository
import (
38 'password': 'mypasswd',
39 'project_name': 'demo',
40 'auth_url': 'http://10.66.4.18:5000/v3',
41 'mgmt_network': 'private'
45 def create_account(log
):
46 account_msg
= RwCloudYang
.CloudAccount
.from_dict(dict(
48 account_type
="openstack",
50 key
=openstack_info
["username"],
51 secret
=openstack_info
["password"],
52 tenant
=openstack_info
["project_name"],
53 auth_url
=openstack_info
["auth_url"]
58 account
= accounts
.CloudAccount(
60 RwLog
.Ctx
.new(__file__
),
67 def parse_args(argv
=sys
.argv
[1:]):
68 parser
= argparse
.ArgumentParser()
69 parser
.add_argument("--image-name", required
=True)
70 parser
.add_argument("--image-checksum", required
=True)
72 return parser
.parse_args()
77 logging
.basicConfig(level
=logging
.DEBUG
)
78 log
= logging
.getLogger("upload_image.py")
79 loop
= asyncio
.get_event_loop()
80 cloud_account
= create_account(log
)
81 client
= glance_client
.OpenstackGlanceClient
.from_token(
82 log
, "127.0.0.1", 9292, "test"
84 task_creator
= tasklet
.GlanceClientUploadTaskCreator(
85 log
, loop
, {"openstack": cloud_account
}, client
,
88 tasks
= loop
.run_until_complete(
89 task_creator
.create_tasks(
96 log
.debug("Created tasks: %s", tasks
)
98 log
.debug("uploading images")
99 loop
.run_until_complete(asyncio
.wait([t
.start() for t
in tasks
], loop
=loop
))
102 if __name__
== "__main__":