libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/5] libcloud git commit: Move provider-specific examples to demos/ directory.
Date Sat, 25 Jun 2016 10:17:29 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 2ffa00053 -> afa09ef99


Move provider-specific examples to demos/ directory.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/555fdf23
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/555fdf23
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/555fdf23

Branch: refs/heads/trunk
Commit: 555fdf23a66eebb0e335ca28e9fb6e73d9033e4a
Parents: 2ffa000
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Sat Jun 25 11:43:39 2016 +0200
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Sat Jun 25 11:43:39 2016 +0200

----------------------------------------------------------------------
 demos/example_aliyun_ecs.py | 85 ++++++++++++++++++++++++++++++++++++++++
 demos/example_aliyun_oss.py | 82 ++++++++++++++++++++++++++++++++++++++
 demos/example_aliyun_slb.py | 55 ++++++++++++++++++++++++++
 example_aliyun_ecs.py       | 85 ----------------------------------------
 example_aliyun_oss.py       | 82 --------------------------------------
 example_aliyun_slb.py       | 55 --------------------------
 6 files changed, 222 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/555fdf23/demos/example_aliyun_ecs.py
----------------------------------------------------------------------
diff --git a/demos/example_aliyun_ecs.py b/demos/example_aliyun_ecs.py
new file mode 100644
index 0000000..c7de072
--- /dev/null
+++ b/demos/example_aliyun_ecs.py
@@ -0,0 +1,85 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import sys
+
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
+from libcloud.compute.base import NodeAuthPassword
+
+ECSDriver = get_driver(Provider.ALIYUN_ECS)
+
+region = 'cn-hangzhou'
+
+your_access_key_id = ''
+your_access_key_secret = ''
+ecs = ECSDriver(your_access_key_id, your_access_key_secret, region=region)
+
+sizes = ecs.list_sizes()
+small = sizes[1]
+
+locations = ecs.list_locations()
+location = None
+for each in locations:
+    if each.id == region:
+        location = each
+        break
+if location is None:
+    print('could not find cn-qingdao location')
+    sys.exit(-1)
+print(location.name)
+
+images = ecs.list_images()
+print('Found %d images' % len(images))
+for each in images:
+    if 'ubuntu' in each.id.lower():
+        image = each
+        break
+else:
+    image = images[0]
+print('Use image %s' % image)
+
+sgs = ecs.ex_list_security_groups()
+print('Found %d security groups' % len(sgs))
+if len(sgs) == 0:
+    sg = ecs.ex_create_security_group(description='test')
+    print('Create security group %s' % sg)
+else:
+    sg = sgs[0].id
+    print('Use security group %s' % sg)
+
+nodes = ecs.list_nodes()
+print('Found %d nodes' % len(nodes))
+if len(nodes) == 0:
+    print('Starting create a new node')
+    data_disk = {
+        'size': 5,
+        'category': ecs.disk_categories.CLOUD,
+        'disk_name': 'data_disk1',
+        'delete_with_instance': True}
+
+    auth = NodeAuthPassword('P@$$w0rd')
+
+    node = ecs.create_node(image=image, size=small, name='test',
+                           ex_security_group_id=sg,
+                           ex_internet_charge_type=ecs.internet_charge_types.BY_TRAFFIC,
+                           ex_internet_max_bandwidth_out=1,
+                           ex_data_disk=data_disk,
+                           auth=auth)
+    print('Created node %s' % node)
+    nodes = ecs.list_nodes()
+
+for each in nodes:
+    print('Found node %s' % each)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/555fdf23/demos/example_aliyun_oss.py
----------------------------------------------------------------------
diff --git a/demos/example_aliyun_oss.py b/demos/example_aliyun_oss.py
new file mode 100644
index 0000000..6bda227
--- /dev/null
+++ b/demos/example_aliyun_oss.py
@@ -0,0 +1,82 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from libcloud.storage.types import Provider
+from libcloud.storage.providers import get_driver
+
+OSSDriver = get_driver(Provider.ALIYUN_OSS)
+
+your_access_key_id = ''
+your_access_key_secret = ''
+oss = OSSDriver(your_access_key_id, your_access_key_secret)
+
+container_name = 'CONTAINER_NAME_FOR_TEST'
+object_name = 'OBJECT_NAME_FOR_TEST'
+local_file_path = 'LOCAL_FILE_FULL_PATH_TO_UPLOAD'
+upload_object_name = 'OBJECT_NAME_FOR_UPLOAD_FILE'
+for container in oss.iterate_containers():
+    print('container: %s' % container)
+
+c1 = oss.get_container(container_name)
+print('Got container %s:' % c1)
+
+objects = c1.list_objects()
+count = len(objects)
+print('Has %d objects' % count)
+
+objects = oss.list_container_objects(c1, ex_prefix='en')
+print('Has %d objects with prefix "en"' % len(objects))
+for each in objects:
+    print(each)
+
+obj = oss.get_object(container_name, object_name)
+print('Got object %s:' % obj)
+
+# Download object
+oss.download_object(obj, object_name, overwrite_existing=True)
+for trunk in oss.download_object_as_stream(obj):
+    print(trunk)
+
+# Upload object
+obj = oss.upload_object(local_file_path, c1, upload_object_name)
+
+# Upload multipart
+uploads = list(oss.ex_iterate_multipart_uploads(c1))
+print('Found %d incompleted uploads' % len(uploads))
+if len(uploads) > 0:
+    oss.ex_abort_all_multipart_uploads(c1)
+    print('Abort them all')
+
+def data_iter(limit):
+    i = 0
+    while True:
+        yield i
+        i += 1
+        if i >= limit:
+            break
+
+print('Starting to upload 1MB using multipart api')
+one_mb = 1024*1024
+obj = oss.upload_object_via_stream(data_iter(one_mb), c1, upload_object_name)
+print('Finish uploading')
+
+# Delete objects
+print('Delete object %s' % obj)
+oss.delete_object(obj)
+
+# Create container
+#c2 = oss.create_container(container_name='20160117')
+#c2 = oss.create_container(container_name='20160117', ex_location='oss-cn-beijing')
+#c2_got = oss.get_container('20160117')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/555fdf23/demos/example_aliyun_slb.py
----------------------------------------------------------------------
diff --git a/demos/example_aliyun_slb.py b/demos/example_aliyun_slb.py
new file mode 100644
index 0000000..0b41839
--- /dev/null
+++ b/demos/example_aliyun_slb.py
@@ -0,0 +1,55 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from libcloud.compute.types import Provider as NodeProvider
+from libcloud.compute.providers import get_driver as get_node_driver
+from libcloud.loadbalancer.providers import get_driver
+from libcloud.loadbalancer.base import Algorithm, Member
+from libcloud.loadbalancer.types import Provider
+
+SLBDriver = get_driver(Provider.ALIYUN_SLB)
+ECSDriver = get_node_driver(NodeProvider.ALIYUN_ECS)
+
+region = 'cn-hangzhou'
+
+your_access_key_id = ''
+your_access_key_secret = ''
+slb = SLBDriver(your_access_key_id, your_access_key_secret, region=region)
+ecs = ECSDriver(your_access_key_id, your_access_key_secret, region=region)
+
+protos = slb.list_protocols()
+print('Found %d protocols: %s' % (len(protos), protos))
+
+balancers = slb.list_balancers()
+print('Found %d load balancers' % len(balancers))
+print(balancers)
+
+if len(balancers) > 0:
+    b1 = balancers[0]
+    print('Delete %s' % b1)
+    slb.destroy_balancer(b1)
+else:
+    extra = {'AddressType': 'internet',
+             'Bandwidth': 1,
+             'StickySession': 'off',
+             'HealthCheck': 'off'}
+    nodes = ecs.list_nodes()
+    print('Found %d nodes' % len(nodes))
+    members = [Member(node.id, node.public_ips[0], 80, extra={'Weight': 50*(i+1)})
+               for i, node in enumerate(nodes)]
+    new_b = slb.create_balancer('test-balancer', 80, 'http',
+                                Algorithm.WEIGHTED_ROUND_ROBIN, members,
+                                **extra)
+    print('Created balancer %s' % new_b)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/555fdf23/example_aliyun_ecs.py
----------------------------------------------------------------------
diff --git a/example_aliyun_ecs.py b/example_aliyun_ecs.py
deleted file mode 100644
index c7de072..0000000
--- a/example_aliyun_ecs.py
+++ /dev/null
@@ -1,85 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import sys
-
-from libcloud.compute.types import Provider
-from libcloud.compute.providers import get_driver
-from libcloud.compute.base import NodeAuthPassword
-
-ECSDriver = get_driver(Provider.ALIYUN_ECS)
-
-region = 'cn-hangzhou'
-
-your_access_key_id = ''
-your_access_key_secret = ''
-ecs = ECSDriver(your_access_key_id, your_access_key_secret, region=region)
-
-sizes = ecs.list_sizes()
-small = sizes[1]
-
-locations = ecs.list_locations()
-location = None
-for each in locations:
-    if each.id == region:
-        location = each
-        break
-if location is None:
-    print('could not find cn-qingdao location')
-    sys.exit(-1)
-print(location.name)
-
-images = ecs.list_images()
-print('Found %d images' % len(images))
-for each in images:
-    if 'ubuntu' in each.id.lower():
-        image = each
-        break
-else:
-    image = images[0]
-print('Use image %s' % image)
-
-sgs = ecs.ex_list_security_groups()
-print('Found %d security groups' % len(sgs))
-if len(sgs) == 0:
-    sg = ecs.ex_create_security_group(description='test')
-    print('Create security group %s' % sg)
-else:
-    sg = sgs[0].id
-    print('Use security group %s' % sg)
-
-nodes = ecs.list_nodes()
-print('Found %d nodes' % len(nodes))
-if len(nodes) == 0:
-    print('Starting create a new node')
-    data_disk = {
-        'size': 5,
-        'category': ecs.disk_categories.CLOUD,
-        'disk_name': 'data_disk1',
-        'delete_with_instance': True}
-
-    auth = NodeAuthPassword('P@$$w0rd')
-
-    node = ecs.create_node(image=image, size=small, name='test',
-                           ex_security_group_id=sg,
-                           ex_internet_charge_type=ecs.internet_charge_types.BY_TRAFFIC,
-                           ex_internet_max_bandwidth_out=1,
-                           ex_data_disk=data_disk,
-                           auth=auth)
-    print('Created node %s' % node)
-    nodes = ecs.list_nodes()
-
-for each in nodes:
-    print('Found node %s' % each)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/555fdf23/example_aliyun_oss.py
----------------------------------------------------------------------
diff --git a/example_aliyun_oss.py b/example_aliyun_oss.py
deleted file mode 100644
index 6bda227..0000000
--- a/example_aliyun_oss.py
+++ /dev/null
@@ -1,82 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-from libcloud.storage.types import Provider
-from libcloud.storage.providers import get_driver
-
-OSSDriver = get_driver(Provider.ALIYUN_OSS)
-
-your_access_key_id = ''
-your_access_key_secret = ''
-oss = OSSDriver(your_access_key_id, your_access_key_secret)
-
-container_name = 'CONTAINER_NAME_FOR_TEST'
-object_name = 'OBJECT_NAME_FOR_TEST'
-local_file_path = 'LOCAL_FILE_FULL_PATH_TO_UPLOAD'
-upload_object_name = 'OBJECT_NAME_FOR_UPLOAD_FILE'
-for container in oss.iterate_containers():
-    print('container: %s' % container)
-
-c1 = oss.get_container(container_name)
-print('Got container %s:' % c1)
-
-objects = c1.list_objects()
-count = len(objects)
-print('Has %d objects' % count)
-
-objects = oss.list_container_objects(c1, ex_prefix='en')
-print('Has %d objects with prefix "en"' % len(objects))
-for each in objects:
-    print(each)
-
-obj = oss.get_object(container_name, object_name)
-print('Got object %s:' % obj)
-
-# Download object
-oss.download_object(obj, object_name, overwrite_existing=True)
-for trunk in oss.download_object_as_stream(obj):
-    print(trunk)
-
-# Upload object
-obj = oss.upload_object(local_file_path, c1, upload_object_name)
-
-# Upload multipart
-uploads = list(oss.ex_iterate_multipart_uploads(c1))
-print('Found %d incompleted uploads' % len(uploads))
-if len(uploads) > 0:
-    oss.ex_abort_all_multipart_uploads(c1)
-    print('Abort them all')
-
-def data_iter(limit):
-    i = 0
-    while True:
-        yield i
-        i += 1
-        if i >= limit:
-            break
-
-print('Starting to upload 1MB using multipart api')
-one_mb = 1024*1024
-obj = oss.upload_object_via_stream(data_iter(one_mb), c1, upload_object_name)
-print('Finish uploading')
-
-# Delete objects
-print('Delete object %s' % obj)
-oss.delete_object(obj)
-
-# Create container
-#c2 = oss.create_container(container_name='20160117')
-#c2 = oss.create_container(container_name='20160117', ex_location='oss-cn-beijing')
-#c2_got = oss.get_container('20160117')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/555fdf23/example_aliyun_slb.py
----------------------------------------------------------------------
diff --git a/example_aliyun_slb.py b/example_aliyun_slb.py
deleted file mode 100644
index 0b41839..0000000
--- a/example_aliyun_slb.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-from libcloud.compute.types import Provider as NodeProvider
-from libcloud.compute.providers import get_driver as get_node_driver
-from libcloud.loadbalancer.providers import get_driver
-from libcloud.loadbalancer.base import Algorithm, Member
-from libcloud.loadbalancer.types import Provider
-
-SLBDriver = get_driver(Provider.ALIYUN_SLB)
-ECSDriver = get_node_driver(NodeProvider.ALIYUN_ECS)
-
-region = 'cn-hangzhou'
-
-your_access_key_id = ''
-your_access_key_secret = ''
-slb = SLBDriver(your_access_key_id, your_access_key_secret, region=region)
-ecs = ECSDriver(your_access_key_id, your_access_key_secret, region=region)
-
-protos = slb.list_protocols()
-print('Found %d protocols: %s' % (len(protos), protos))
-
-balancers = slb.list_balancers()
-print('Found %d load balancers' % len(balancers))
-print(balancers)
-
-if len(balancers) > 0:
-    b1 = balancers[0]
-    print('Delete %s' % b1)
-    slb.destroy_balancer(b1)
-else:
-    extra = {'AddressType': 'internet',
-             'Bandwidth': 1,
-             'StickySession': 'off',
-             'HealthCheck': 'off'}
-    nodes = ecs.list_nodes()
-    print('Found %d nodes' % len(nodes))
-    members = [Member(node.id, node.public_ips[0], 80, extra={'Weight': 50*(i+1)})
-               for i, node in enumerate(nodes)]
-    new_b = slb.create_balancer('test-balancer', 80, 'http',
-                                Algorithm.WEIGHTED_ROUND_ROBIN, members,
-                                **extra)
-    print('Created balancer %s' % new_b)


Mime
View raw message