Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disk and network #3404

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Intel Inc
Massachusetts Institute of Technology (MIT)
Rackspace Inc
Alibaba Inc
Tencent LTD
3 changes: 2 additions & 1 deletion perfkitbenchmarker/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
RACKSPACE = 'Rackspace'
MESOS = 'Mesos'
PROFITBRICKS = 'ProfitBricks'
TENCENTCLOUD = 'TencentCloud'
# Though Docker is not a cloud provider, it's inclusion is useful
# for performing on premise to cloud benchmarks
DOCKER = 'Docker'

VALID_CLOUDS = (GCP, AZURE, AWS, IBMCLOUD, DIGITALOCEAN, KUBERNETES, OPENSTACK,
RACKSPACE, CLOUDSTACK, ALICLOUD, MESOS, PROFITBRICKS, DOCKER)
RACKSPACE, CLOUDSTACK, ALICLOUD, MESOS, PROFITBRICKS, DOCKER, TENCENTCLOUD)


_imported_providers = set()
Expand Down
1 change: 1 addition & 0 deletions perfkitbenchmarker/providers/alicloud/ali_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, name, region):

def _Create(self):
"""Creates the VPC."""
'aliyun ecs CreateVpc --VpcName xxx --RegionId xxx'
create_cmd = util.ALI_PREFIX + [
'ecs',
'CreateVpc',
Expand Down
1 change: 1 addition & 0 deletions perfkitbenchmarker/providers/gcp/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Sentinel value for unspecified platform.
GCP_MIN_CPU_PLATFORM_NONE = 'none'


flags.DEFINE_string('gcloud_path', 'gcloud', 'The path for the gcloud utility.')
flags.DEFINE_list('additional_gcloud_flags', [],
'Additional flags to pass to gcloud.')
Expand Down
14 changes: 14 additions & 0 deletions perfkitbenchmarker/providers/tencentcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2014 PerfKitBenchmarker Authors. All rights reserved.
#
# Licensed 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.
"""Provider for Tencent Cloud."""
31 changes: 31 additions & 0 deletions perfkitbenchmarker/providers/tencentcloud/flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2015 PerfKitBenchmarker Authors. All rights reserved.
#
# Licensed 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.
"""Module containing flags applicable across benchmark run on Tencent Cloud."""

from absl import flags

flags.DEFINE_string('tencent_path', 'tccli', 'The path for the Tencent Cloud utility.')
flags.DEFINE_string('default_region', 'ap-guangzhou-3',
'The path for the Tencent Cloud utility.')
flags.DEFINE_string('unfold', '--cli-unfold-argument',
'Unfold complicated arguments, using . to access values of '
'complicated arguments')
flags.DEFINE_integer('bandwith_out', 100,
'The maximum outbound bandwidth of the public network, in Mbps. '
'The default value is 100 Mbps. ')
flags.DEFINE_boolean('assign_public_ip', True,
'If the public network bandwidth is greater than 0 Mbps, you can '
'choose whether to assign a public IP. If the public network '
'bandwidth is 0 Mbps, you will not be able to assign a public IP.')

24 changes: 24 additions & 0 deletions perfkitbenchmarker/providers/tencentcloud/provider_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2015 PerfKitBenchmarker Authors. All rights reserved.
#
# Licensed 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.

"""Provider info for Tencent Cloud."""

from perfkitbenchmarker import provider_info
from perfkitbenchmarker import providers


class GCPProviderInfo(provider_info.BaseProviderInfo):

UNSUPPORTED_BENCHMARKS = []
CLOUD = providers.TENCENTCLOUD
113 changes: 113 additions & 0 deletions perfkitbenchmarker/providers/tencentcloud/tencentcloud_disk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright 2014 PerfKitBenchmarker Authors. All rights reserved.
#
# Licensed 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.
"""Module containing classes related to Tencent Cloud disks.

Disks can be created, deleted, attached to VMs, and detached from VMs.
Use 'DescribeDisks' to determine valid disk types.
"""

import json
import logging
import string
import threading
from absl import flags
from perfkitbenchmarker import disk
from perfkitbenchmarker import vm_util
from perfkitbenchmarker.providers.tencentcloud import tencentcloud_network
from perfkitbenchmarker.providers.tencentcloud import util

FLAGS = flags.FLAGS

DISK_TYPE = {}

class TencentDisk(disk.BaseDisk):
"""Object representing an AliCloud Disk."""

_lock = threading.Lock()
vm_devices = {}

def __init__(self, disk_spec, zone):
super(TencentDisk, self).__init__(disk_spec)
self.id = None
self.zone = zone
self.region = util.GetRegionByZone(self.zone)
self.attached_vm_id = None

def _Create(self):
"""Creates the disk."""
create_cmd = ''
create_cmd = util.GetEncodedCmd(create_cmd)
stdout, _, _ = vm_util.IssueCommand(create_cmd, raise_on_failure=False)
response = json.loads(stdout)
self.id = response['DiskId']

def _Delete(self):
"""Deletes the disk."""
delete_cmd = ''
logging.info('Deleting Tencent Cloud disk %s. This may fail if the disk is not '
'yet detached, but will be retried.', self.id)
delete_cmd = util.GetEncodedCmd(delete_cmd)
vm_util.IssueRetryableCommand(delete_cmd)

def Attach(self, vm):
"""Attaches the disk to a VM.

Args:
vm: The AliVirtualMachine instance to which the disk will be attached.
"""
with self._lock:
self.attached_vm_id = vm.id
if self.attached_vm_id not in TencentDisk.vm_devices:
TencentDisk.vm_devices[self.attached_vm_id] = set(
string.ascii_lowercase[1:])
self.device_letter = min(TencentDisk.vm_devices[self.attached_vm_id])
TencentDisk.vm_devices[self.attached_vm_id].remove(self.device_letter)

attach_cmd = ''
attach_cmd = util.GetEncodedCmd(attach_cmd)
vm_util.IssueRetryableCommand(attach_cmd)

def Detach(self):
"""Detaches the disk from a VM."""
detach_cmd = ''
detach_cmd = util.GetEncodedCmd(detach_cmd)
vm_util.IssueRetryableCommand(detach_cmd)

with self._lock:
assert self.attached_vm_id in TencentDisk.vm_devices
TencentDisk.vm_devices[self.attached_vm_id].add(self.device_letter)
self.attached_vm_id = None
self.device_letter = None

def GetDevicePath(self):
"""Returns the path to the device inside the VM."""
return '/dev/vd%s' % self.device_letter

def GetVirtualDevicePath(self):
"""Returns the path to the device visible to console users."""
return '/dev/xvd%s' % self.device_letter

@vm_util.Retry(poll_interval=5, max_retries=30, log_errors=False)
def WaitForDiskStatus(self, status_list):
"""Waits until disk is attach to the instance"""
logging.info('Waits until the disk\'s status is one of statuses: %s',
status_list)
describe_cmd = ''
attach_cmd = util.GetEncodedCmd(describe_cmd)
stdout, _ = vm_util.IssueRetryableCommand(attach_cmd)
response = json.loads(stdout)
disk = response['Disks']['Disk']
assert len(disk) == 1
status = disk[0]['Status']
assert status in status_list
167 changes: 167 additions & 0 deletions perfkitbenchmarker/providers/tencentcloud/tencentcloud_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Copyright 2014 PerfKitBenchmarker Authors. All rights reserved.
#
# Licensed 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.
"""Module containing classes related to GCE VM networking.

The Firewall class provides a way of opening VM ports. The Network class allows
VMs to communicate via internal ips and isolates PerfKitBenchmarker VMs from
others in the
same project. See https://cloud.tencent.com/document/product/213/5220 for
more information about Tencent Cloud VM networking.
"""


import json
import logging
import threading
import uuid

from absl import flags
from perfkitbenchmarker import network
from perfkitbenchmarker import providers
from perfkitbenchmarker import resource
from perfkitbenchmarker import vm_util
from perfkitbenchmarker.providers.alicloud import util
from six.moves import range

FLAGS = flags.FLAGS
MAX_NAME_LENGTH = 128


class TencentVpc(resource.BaseResource):
"""An object representing an Tencent Cloud VPC."""

def __init__(self, name, region):
pass

def _Create(self):
"""Creates the VPC."""
pass

def _Exists(self):
"""Returns true if the VPC exists."""
pass

@vm_util.Retry(poll_interval=5, max_retries=30, log_errors=False)
def _WaitForVpcStatus(self, status_list):
"""Waits until VPC's status is in status_list"""
pass

def _Delete(self):
"""Delete's the VPC."""
pass


class TencentVSwitch(resource.BaseResource):
"""An object representing an Tencent Cloud VSwitch."""

def __init__(self, name, zone, vpc_id):
pass

def _Create(self):
"""Creates the VSwitch."""
pass

def _Delete(self):
"""Deletes the VSwitch."""
pass

def _Exists(self):
"""Returns true if the VSwitch exists."""
pass


class TencentSecurityGroup(resource.BaseResource):
"""Object representing an Tencent Cloud Security Group."""

def __init__(self, name, region, use_vpc=True, vpc_id=None):
pass

def _Create(self):
"""Creates the security group."""
pass

def _Delete(self):
"""Deletes the security group."""
pass

def _Exists(self):
"""Returns true if the security group exists."""
pass


class TencentFirewall(network.BaseFirewall):
"""An object representing the Tencent Cloud Firewall."""

CLOUD = providers.TENCENTCLOUD

def __init__(self):
self.firewall_set = set()
self._lock = threading.Lock()

def AllowIcmp(self, vm):
"""Opens the ICMP protocol on the firewall.

Args:
vm: The BaseVirtualMachine object to open the ICMP protocol for.
"""
pass

def AllowPort(self, vm, start_port, end_port=None, source_range=None):
"""Opens a port on the firewall.

Args:
vm: The BaseVirtualMachine object to open the port for.
start_port: The first local port in a range of ports to open.
end_port: The last port in a range of ports to open. If None, only
start_port will be opened.
source_range: unsupported at present.
"""
pass

def _AllowPort(self, vm, port):
"""Opens a port on the firewall.

Args:
vm: The BaseVirtualMachine object to open the port for.
port: The local port to open.
"""
pass

def DisallowAllPorts(self):
"""Closes all ports on the firewall."""
pass


class TencentNetwork(network.BaseNetwork):
"""Object representing a Tencent Cloud Network."""

CLOUD = providers.TENCENTCLOUD

def __init__(self, spec):
self.name = None
self.region = util.GetRegionByZone(spec.zone)
self.use_vpc = FLAGS.ali_use_vpc
self.vpc = None
self.vswitch = None
self.security_group = None
pass

@vm_util.Retry()
def Create(self):
"""Creates the network."""
pass

def Delete(self):
"""Deletes the network."""
pass
Loading